Skip to content

Debguin452/utilitx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

utilitx.js

A zero-dependency JavaScript utility library. Works in the browser and Node.js. Tree-shakeable ESM + CJS + CDN script tag.

MIT License npm version

Install

npm install utilitx

Or via CDN (no install):

<script src="https://utilitx.pages.dev/utilitx.min.js"></script>

Usage

ESM (recommended)

import { slugify, chunk, timeAgo, debounce } from 'utilitx';

slugify("Hello World!");     // "hello-world"
chunk([1,2,3,4,5], 2);       // [[1,2],[3,4],[5]]
timeAgo(new Date(Date.now() - 90000)); // "1 minute ago"

CDN (browser)

<script src="https://utilitx.pages.dev/utilitx.min.js"></script>
<script>
  console.log(utilitx.slugify("Hello World")); // "hello-world"
</script>

CommonJS

const { slugify, isEmail } = require('utilitx');

Modules

String

Function Description
slugify(str) URL-safe slug from any string
truncate(str, len) Truncate with ellipsis
capitalize(str) Capitalize first letter
camelCase(str) dash-or-space to camelCase
escapeHtml(str) Escape < > & " '

Array

Function Description
chunk(arr, size) Split into equal-sized chunks
unique(arr) Remove duplicates
flatten(arr) Deep flatten nested arrays
shuffle(arr) Fisher-Yates shuffle (non-mutating)
groupBy(arr, key) Group objects by a property

Object

Function Description
deepClone(obj) Deep clone (JSON-safe)
deepMerge(a, b) Recursive object merge
pick(obj, keys) Extract keys into new object
omit(obj, keys) Remove keys from new object

Number

Function Description
clamp(n, min, max) Keep n between bounds
randomInt(min, max) Random integer, inclusive
formatBytes(bytes) 1048576"1 MB"
lerp(a, b, t) Linear interpolation

Date

Function Description
timeAgo(date) "3 hours ago"
formatDate(date, fmt) "YYYY-MM-DD" etc.
daysBetween(a, b) Integer day difference

Validate

Function Description
isEmail(str) Email format check
isURL(str) URL format check
isEmpty(val) Null / undefined / "" / [] / {}
isUUID(str) UUID v4 format check

Async

Function Description
sleep(ms) Promise delay
retry(fn, n, delay) Retry async fn on failure
debounce(fn, ms) Fire after inactivity
throttle(fn, ms) Fire at most once per ms

DOM (browser only)

Function Description
copyToClipboard(str) Copy to clipboard (Promise)
scrollTo(el) Smooth scroll to element
onClickOutside(el, fn) Click-outside listener

Deploying to Cloudflare Pages

  1. Fork this repo on GitHub
  2. Go to pages.cloudflare.com → Create a project
  3. Connect your GitHub account and select this repo
  4. Set Build command to: npm run build
  5. Set Output directory to: dist
  6. Click Save and Deploy — done!

Every git push to main auto-deploys.


Contributing

PRs welcome! Please add a test in tests/ for any new function.

npm test

License

MIT © 2026

About

Utilitx is a lightweight JavaScript utility library that provides practical helper functions for arrays, strings, numbers, objects, dates, validation, formatting, and common development tasks, helping developers write cleaner and more efficient code.

Resources

License

Stars

Watchers

Forks

Contributors