A comprehensive collection of JavaScript utility functions for every layer of your app — arrays, strings, objects, DOM, validation, performance, and more. One import. Zero dependencies.
CDN (jsDelivr)
<!-- Pinned version -->
<script src="https://cdn.jsdelivr.net/npm/@peterbenoit/utility-helpers@1.0.0/utilityHelpers.js"></script>
<!-- Always latest -->
<script src="https://cdn.jsdelivr.net/npm/@peterbenoit/utility-helpers/utilityHelpers.js"></script>
Also available on unpkg.
npm / Node.js
npm install @peterbenoit/utility-helpers
const UtilityHelpers = require('@peterbenoit/utility-helpers');
Usage
// After the CDN script tag, UtilityHelpers is a global class:
const uuid = UtilityHelpers.generateUUID();
const chunks = UtilityHelpers.chunk([1, 2, 3, 4], 2); // [[1,2],[3,4]]
const hex = UtilityHelpers.rgbToHex(255, 0, 0); // "#ff0000"
const slug = UtilityHelpers.kebabCase('Hello World'); // "hello-world"
80+ functions organized into nine focused categories. Every method is self-contained — import only what you need, or use the whole thing from a CDN script tag.
chunk,
shuffleArray, flattenArraygroupBy,
findDuplicates, rangegetMedian,
countOccurrences, and morecamelCase,
kebabCase, snakeCasetruncate,
pluralize, stripHtmlescapeHtml,
numberToWords, and morepick,
omit, deepMergeisEqual,
getType, isObjectEmptycopyToClipboard,
smoothScrollTolazyLoadImages,
getFormDatagetCSSVariable,
downloadFile, and moredebounce,
throttle, memoizeonce,
retry, pipe / composewait /
sleep, runInParallelisValidEmail,
isValidURLvalidateAndSanitizeInput
getImageDetails,
getAverageImageColorgetLuminance,
getContrastRatiogetImageBase64,
formatBytesgenerateUUID,
clamp, parseJSONformatNumber,
formatCurrencygetQueryParams,
levenshteinDistancerandomDateBetweenTwo
timeStampID
Debounce a search input
const search = UtilityHelpers.debounce(async (query) => {
const results = await fetchResults(query);
renderResults(results);
}, 300);
document.querySelector('#search').addEventListener('input', e => search(e.target.value));
Group an array by a key
const posts = [
{ title: 'Alpha', author: 'Alice' },
{ title: 'Beta', author: 'Bob' },
{ title: 'Gamma', author: 'Alice' },
];
const byAuthor = UtilityHelpers.groupBy(posts, 'author');
// { Alice: [{…},{…}], Bob: [{…}] }
Compose a transformation pipeline
const processName = UtilityHelpers.pipe(
str => str.trim(),
UtilityHelpers.capitalizeWords,
UtilityHelpers.kebabCase
);
processName(' hello world '); // "hello-world"
Retry a flaky API call
const data = await UtilityHelpers.retry(
() => fetch('/api/data').then(r => r.json()),
3, // max attempts
500 // base delay ms (exponential backoff)
);
No lodash, no moment, no third-party anything. Every function is pure vanilla JavaScript. Drop the CDN tag into any page and start calling methods — that's it.
escapeHtml, validateAndSanitizeInput, and parseJSON
are built with defensive patterns first — no silent failures, no XSS surprises.
Browser, Node.js, CodePen, quick prototypes — the global UtilityHelpers class
works in every environment. CommonJS require() and CDN script tag both supported.
Functions like retry, memoize, runInParallel,
and detectUserIdleTime address the patterns developers actually reach for —
not just array shuffling and string padding.
Full API reference, live examples, and release notes are on the project site. The complete source is on GitHub under the MIT license.