A curated library of ready-to-copy JavaScript utility functions — date formatting, array helpers, validation, async patterns, browser utilities, and more.
49 functions
formatDate(date, fmt)Formats a date using common display formats with ordinal suffixes.
getDateFromTimestamp(ts)Converts a Unix timestamp (seconds or ms) to a readable ISO date string.
getDaysBetween(d1, d2)newReturns the number of days between two dates.
isToday(date)newReturns true if the given date is today.
startOfDay(date)newReturns a new Date set to 00:00:00.000 of the given day.
addDays(date, n)newAdds N days to a date and returns the new Date.
timeAgo(date)Converts a date/timestamp into a relative human-readable string.
formatTime(date, fmt)Formats time as 12h or 24h with optional seconds.
truncate(str, len)Truncates a string to a given length and appends ellipsis.
slugify(str)Converts a string to a URL-friendly slug.
capitalize(str)Capitalizes the first letter of each word.
generateId(len)Generates a random alphanumeric ID of the given length.
formatCurrency(n, currency)Formats a number as a currency string using Intl.NumberFormat.
formatBytes(bytes)Converts raw bytes to a human-readable size string (KB, MB, GB, TB).
clamp(n, min, max)Clamps a number between min and max inclusive.
uniqueBy(arr, key)Removes duplicate objects from an array by a given key.
groupBy(arr, key)Groups an array of objects by a given key.
chunk(arr, size)newSplits an array into chunks of the given size.
flatten(arr, depth)newFlattens a nested array to the specified depth.
sortBy(arr, key, dir)newSorts an array of objects by a key, ascending or descending.
intersection(a, b)newReturns elements that exist in both arrays.
deepClone(obj)Creates a deep clone of an object (no reference sharing).
omit(obj, keys)Returns a new object with specified keys removed.
debounce(fn, ms)Delays function execution until after a wait period.
pick(obj, keys)newReturns a new object with only the specified keys.
flattenObject(obj)newFlattens a deeply nested object to dot-notation keys.
mergeDeep(target, source)newDeep-merges two objects; source values override target.
isEmail(str)Validates whether a string is a properly formed email address.
isURL(str)Validates whether a string is a valid absolute URL.
isStrongPassword(str)Checks for 8+ chars, uppercase, lowercase, number, and special character.
setStorage(key, value)newSaves any value to localStorage as JSON with an optional TTL (time-to-live).
getStorage(key)newGets a value from localStorage and auto-removes it if expired.
clearStorage(prefix)newRemoves all localStorage keys that start with the given prefix.
getURLParams(url)newParses a URL query string into a plain key-value object.
buildURL(base, params)newBuilds a URL from a base string and a params object.
setCookie(name, val, days)newSets a browser cookie with an expiry date N days from now.
getCookie(name)newReads a cookie value by name from document.cookie.
detectDevice()newDetects whether the current device is mobile, tablet, or desktop.
copyToClipboard(text)newCopies a string to the clipboard using the Clipboard API.
getScrollPercent()newReturns how far the user has scrolled down the page as a 0–100% value.
sleep(ms)Promise-based delay — use with await in async functions.
retry(fn, attempts, delay)newRetries an async function up to N times before throwing the final error.
withTimeout(promise, ms)newRejects a promise if it doesn't resolve within the specified ms.
asyncPool(limit, arr, fn)newRuns async tasks over an array with a maximum concurrency limit.
randomInt(min, max)newReturns a random integer between min and max (both inclusive).
randomPick(arr)newPicks and returns a random element from an array.
shuffle(arr)newShuffles an array in-place using the Fisher-Yates algorithm.
randomColor()newGenerates a random hex color code.
randomUUID()newGenerates a RFC 4122-compliant UUID v4.
49 functions across 11 categories · Click any card to run live · Copy the code in one click