UtilityHelpers
A comprehensive collection of JavaScript utility functions covering arrays, strings, objects, DOM, validation, performance, and more. One import. Zero dependencies.
Get Started in Seconds
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"
What's Inside
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.
Arrays
- ▸
chunk,shuffleArray,flattenArray - ▸
groupBy,findDuplicates,range - ▸
getMedian,countOccurrences, and more
Strings
- ▸
camelCase,kebabCase,snakeCase - ▸
truncate,pluralize,stripHtml - ▸
escapeHtml,numberToWords, and more
Objects
- ▸
pick,omit,deepMerge - ▸
isEqual,getType,isObjectEmpty
DOM & UI
- ▸
copyToClipboard,smoothScrollTo - ▸
lazyLoadImages,getFormData - ▸
getCSSVariable,downloadFile, and more
Performance
- ▸
debounce,throttle,memoize - ▸
once,retry,pipe/compose - ▸
wait/sleep,runInParallel
Validation
- ▸
isValidEmail,isValidURL - ▸
validateAndSanitizeInput
Images
- ▸
getImageDetails,getAverageImageColor - ▸
getLuminance,getContrastRatio - ▸
getImageBase64,formatBytes
General
- ▸
generateUUID,clamp,parseJSON - ▸
formatNumber,formatCurrency - ▸
getQueryParams,levenshteinDistance
Date & Time
- ▸
randomDateBetweenTwo - ▸
timeStampID
Common Patterns
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)
);
Zero Dependencies
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.
Safe Input Handling
escapeHtml, validateAndSanitizeInput, and parseJSON
are built with defensive patterns first. No silent failures, no XSS surprises.
Works Everywhere
Browser, Node.js, CodePen, quick prototypes. The global UtilityHelpers class
works in every environment. CommonJS require() and CDN script tag both supported.
Built for the Real World
Functions like retry, memoize, runInParallel,
and detectUserIdleTime address the patterns developers actually reach for. Not just
array shuffling and string padding.
Ready to use it?
Full API reference, live examples, and release notes are on the project site. The complete source is on GitHub under the MIT license.