{"id":18486297,"url":"https://github.com/maxgfr/ts-essentials-functions","last_synced_at":"2026-04-12T13:57:18.952Z","repository":{"id":64206640,"uuid":"574092165","full_name":"maxgfr/ts-essentials-functions","owner":"maxgfr","description":"A set of essentials functions in typescript with zero-dependencies","archived":false,"fork":false,"pushed_at":"2025-12-04T22:15:45.000Z","size":1346,"stargazers_count":1,"open_issues_count":9,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-08T06:34:19.463Z","etag":null,"topics":["essentials-functions","functions","generic-function","typescript","zero-dependencies","zero-dependency"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ts-essentials-functions","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxgfr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-12-04T12:06:23.000Z","updated_at":"2025-12-04T22:14:09.000Z","dependencies_parsed_at":"2025-12-03T16:03:30.709Z","dependency_job_id":null,"html_url":"https://github.com/maxgfr/ts-essentials-functions","commit_stats":{"total_commits":54,"total_committers":3,"mean_commits":18.0,"dds":0.09259259259259256,"last_synced_commit":"bb98bf50b9c61eb02cdd3e398a9fe1f19e4ecc90"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/maxgfr/ts-essentials-functions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxgfr%2Fts-essentials-functions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxgfr%2Fts-essentials-functions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxgfr%2Fts-essentials-functions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxgfr%2Fts-essentials-functions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxgfr","download_url":"https://codeload.github.com/maxgfr/ts-essentials-functions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxgfr%2Fts-essentials-functions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29210230,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T21:35:21.898Z","status":"ssl_error","status_checked_at":"2026-02-07T21:35:20.106Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["essentials-functions","functions","generic-function","typescript","zero-dependencies","zero-dependency"],"created_at":"2024-11-06T12:48:55.039Z","updated_at":"2026-04-12T13:57:18.944Z","avatar_url":"https://github.com/maxgfr.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-essentials-functions\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA collection of **82 essential TypeScript utility functions** with zero dependencies. Fully typed, immutable, and tested.\n\n## Features\n\n- **Zero dependencies** - No external packages\n- **TypeScript-first** - Full generic type support, no `any` types\n- **Immutable** - All functions return new values, never mutate inputs\n- **Tested** - Test coverage with comprehensive edge case handling\n- **Tree-shakeable** - Import only what you need\n\n## Installation\n\n```bash\nnpm install ts-essentials-functions\n# or\nyarn add ts-essentials-functions\n# or\npnpm add ts-essentials-functions\n```\n\n## Quick Start\n\n```typescript\nimport {\n  chunk,\n  groupBy,\n  unique,\n  sample,\n  pick,\n  omit,\n  cloneDeep,\n  mapKeys,\n  pipe,\n  memoize,\n  once,\n  retry,\n  slugify,\n  camelCase,\n  reverse,\n  clamp,\n  sum,\n  range,\n  addDays,\n  isBefore,\n  startOfDay,\n  escapeHtml,\n  parseQueryString,\n} from 'ts-essentials-functions';\n\n// Split array into chunks\nchunk([1, 2, 3, 4, 5], 2); // [[1, 2], [3, 4], [5]]\n\n// Group items by a key\nconst users = [\n  { name: 'Alice', role: 'admin' },\n  { name: 'Bob', role: 'user' },\n];\ngroupBy(users, (u) =\u003e u.role); // Map { 'admin' =\u003e [...], 'user' =\u003e [...] }\n\n// Deduplicate an array\nunique([1, 2, 2, 3, 3]); // [1, 2, 3]\n\n// Random element from array\nsample([1, 2, 3, 4, 5]); // e.g. 3\n\n// Pick/omit object keys\npick({ id: 1, name: 'Alice', password: 'secret' }, ['id', 'name']);\nomit({ id: 1, name: 'Alice', password: 'secret' }, ['password']);\n\n// Transform object keys\nmapKeys({ name: 'Alice' }, (key) =\u003e `user_${key}`);\n// { user_name: 'Alice' }\n\n// Deep clone with circular reference support\nconst clone = cloneDeep(complexObject);\n\n// Function composition (left-to-right)\nconst transform = pipe(\n  (x: number) =\u003e x + 1,\n  (x: number) =\u003e x * 2,\n);\ntransform(5); // 12\n\n// Memoize expensive computations\nconst cachedFn = memoize(expensiveFunction);\n\n// Execute a function only once\nconst init = once(() =\u003e setupDatabase());\n\n// Retry async operations with backoff\nconst data = await retry(() =\u003e fetchData(), {\n  maxAttempts: 3,\n  delay: 1000,\n  backoff: 2,\n});\n\n// String utilities\nslugify('Crème Brûlée'); // 'creme-brulee'\ncamelCase('hello-world'); // 'helloWorld'\nreverse('hello'); // 'olleh'\n\n// Number utilities\nclamp(15, 0, 10); // 10\nsum([1, 2, 3, 4]); // 10\n\n// Generate ranges\nrange(0, 5); // [0, 1, 2, 3, 4]\n\n// Date utilities\naddDays(new Date('2025-01-15'), 3); // 2025-01-18\nisBefore(new Date('2025-01-01'), new Date('2025-12-31')); // true\nstartOfDay(new Date()); // Today at 00:00:00.000\n\n// Security\nescapeHtml('\u003cscript\u003ealert(\"xss\")\u003c/script\u003e');\n// '\u0026lt;script\u0026gt;alert(\u0026quot;xss\u0026quot;)\u0026lt;/script\u0026gt;'\n```\n\n## API Reference\n\n### Arrays (20 functions)\n\n| Function | Description |\n|----------|-------------|\n| `arrayInterpolate(a, b)` | Interleaves two equal-length arrays |\n| `chunk(array, size)` | Splits array into chunks of specified size |\n| `cleanArray(array)` | Removes all falsy values |\n| `deepMergeArray(arr1, arr2, key)` | Merges arrays of objects by matching key |\n| `detectNullOrUndefinedOrNaNInArray(array)` | Checks for null/undefined/NaN in nested structures |\n| `flatten(array, depth?)` | Flattens nested arrays to specified depth |\n| `getDifferenceArray(a1, a2)` | Symmetric difference between two arrays |\n| `getRepeatedOccurrenceArray(arr)` | Counts occurrences of each unique element |\n| `groupBy(array, keyFn)` | Groups elements by a derived key |\n| `intersection(a1, a2)` | Elements present in both arrays |\n| `nonNullable(value)` | Type guard for non-null/undefined values |\n| `orderArraySame(array, indices)` | Reorders array by index mapping |\n| `partition(array, predicate)` | Splits array into [matching, nonMatching] |\n| `range(start, end, step?)` | Generates an array of numbers |\n| `removeDuplicateObjectInArray(arr, key)` | Removes duplicates by object key |\n| `sample(array)` | Returns a random element from an array |\n| `shuffleArray(array)` | Fisher-Yates shuffle (returns new array) |\n| `unique(array)` | Removes duplicate values using Set |\n| `uniqueBy(array, keyFn)` | Removes duplicates by key function |\n| `zip(...arrays)` | Zips multiple arrays into tuples |\n\n### Objects (15 functions)\n\n| Function | Description |\n|----------|-------------|\n| `cleanObject(obj, defaults?)` | Recursively removes default values (null, undefined, NaN, '') |\n| `cloneDeep(obj)` | Deep clone with circular reference handling |\n| `deepEqualObject(a, b)` | Deep equality comparison |\n| `deepMergeObject(target, source)` | Recursively merges two objects |\n| `diffObject(obj1, obj2)` | Returns keys/values that differ between objects |\n| `hasObjectNullOrUndefined(obj)` | Recursively checks for null/undefined/NaN |\n| `invertObject(obj)` | Swaps keys and values |\n| `isObject(value)` | Type guard: checks if value is an object |\n| `mapKeys(obj, fn)` | Transforms object keys via a mapping function |\n| `mapObject(obj, fn)` | Maps over object values |\n| `objectKeyParser(key, obj, fn)` | Recursively transforms values for a specific key |\n| `omit(obj, keys)` | Creates object without specified keys |\n| `pick(obj, keys)` | Creates object with only specified keys |\n| `recursiveReplaceKey(obj, replacements, word)` | Recursively replaces string values |\n| `removeEmptyFieldObject(obj)` | Removes undefined fields recursively |\n\n### Strings (7 functions)\n\n| Function | Description |\n|----------|-------------|\n| `camelCase(str)` | Converts string to camelCase |\n| `capitalize(str)` | Capitalizes first letter, lowercases rest |\n| `kebabCase(str)` | Converts string to kebab-case |\n| `reverse(str)` | Reverses a string |\n| `slugify(str)` | Creates a URL-friendly slug |\n| `snakeCase(str)` | Converts string to snake_case |\n| `truncate(str, maxLength, suffix?)` | Truncates string with suffix (default '...') |\n\n### Numbers (5 functions)\n\n| Function | Description |\n|----------|-------------|\n| `average(numbers)` | Arithmetic average of an array of numbers |\n| `clamp(value, min, max)` | Constrains a number between bounds |\n| `randomInt(min, max)` | Random integer in inclusive range |\n| `round(value, decimals)` | Precise rounding avoiding floating point issues |\n| `sum(numbers)` | Sum of an array of numbers |\n\n### Utils (10 functions)\n\n| Function | Description |\n|----------|-------------|\n| `compose(...fns)` | Composes functions right-to-left |\n| `debounce(fn, delay?)` | Debounces function calls |\n| `memoize(fn)` | Caches function results by arguments |\n| `once(fn)` | Executes function only once, caches result |\n| `pipe(...fns)` | Pipes functions left-to-right |\n| `preventMultipleExecution(fn, interval?)` | Prevents rapid re-execution |\n| `retry(fn, options?)` | Retries async function with backoff |\n| `throttle(fn, limit)` | Throttles function calls |\n| `uuidv4()` | Generates UUID v4 string |\n| `wait(ms)` | Async delay |\n\n### Date (14 functions)\n\n| Function | Description |\n|----------|-------------|\n| `addBusinessDays(date, days)` | Adds business days (skips weekends) |\n| `addDays(date, days)` | Adds days to a date |\n| `addMonths(date, months)` | Adds months to a date |\n| `countWeekendDays(start, end)` | Counts weekend days in a date range |\n| `diffDays(date1, date2)` | Absolute number of days between dates |\n| `endOfDay(date)` | Returns date at 23:59:59.999 |\n| `formatDate(date, withHour?)` | Formats date with zero-padding (YYYY-MM-DD) |\n| `isAfter(date1, date2)` | Checks if date1 is after date2 |\n| `isBefore(date1, date2)` | Checks if date1 is before date2 |\n| `isLeapYear(year)` | Checks if a year is a leap year |\n| `isSameDay(date1, date2)` | Checks if two dates are on the same day |\n| `isWeekend(date)` | Checks if date is Saturday or Sunday |\n| `startOfDay(date)` | Returns date at 00:00:00.000 |\n| `timeZoneTransformer(dateStr, tz?)` | Transforms between UTC and timezone |\n\n### Web (9 functions)\n\n| Function | Description |\n|----------|-------------|\n| `arrayToFormData(name, arr, form)` | Appends array items to FormData |\n| `buildQueryString(params)` | Builds URL query string from object |\n| `escapeHtml(str)` | Escapes HTML special characters (XSS prevention) |\n| `isHTML(input)` | Checks if string contains HTML |\n| `isValidMail(email)` | Validates email format |\n| `isValidUrl(str)` | Validates URL format |\n| `objectToFormData(object)` | Converts object to FormData |\n| `parseQueryString(url)` | Parses URL query parameters |\n| `stripSimpleHtmlTags(text)` | Strips HTML tags from string |\n\n## License\n\n[MIT](LICENCE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxgfr%2Fts-essentials-functions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxgfr%2Fts-essentials-functions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxgfr%2Fts-essentials-functions/lists"}