Introduction
js-utils — published on npm as @0x26e/utils — is a small, typed utility collection
inspired by Laravel's helpers. It gives your TypeScript and JavaScript projects a handful of
dependable functions for the everyday tasks that would otherwise be reimplemented in every codebase:
reading and writing deeply nested data, building conditional CSS class strings, pausing and polling
in async code, checking whether a value is empty, bounding a number to a range, and paginating a
list.
Every helper is a plain named export, written in TypeScript, with full type definitions built in.
There are no runtime dependencies, the package is tree-shakeable, and it ships as both ESM
and CommonJS, so it works the same whether you import it or require it.
import { get, clamp, pagination } from '@0x26e/utils'
get({ products: { desk: { price: 100 } } }, 'products.desk.price', 0) // 100
clamp(15, 1, 10) // 10
pagination(10, 100).setPage(2).getFirstItemOnPage() // 11Coming from Laravel?
Several helpers deliberately mirror Laravel's names and behavior — get, set, blank, tap,
and until will feel familiar. If you've reached for Arr::get() or blank() in PHP, the
TypeScript versions work the same way.
Highlights
- TypeScript-first — authored in TypeScript with bundled
.d.tstypes. Generics flow throughget<T>,tap<T>,crossJoin<T>, anduntil<T>so return types stay precise. - ESM + CJS dual package —
import { get } from '@0x26e/utils'in modern code, orrequire('@0x26e/utils')from CommonJS. - Tree-shakeable — named exports only, zero runtime dependencies. Bundlers drop anything you don't import.
- Runtime-agnostic — runs in modern Node and any bundler (Vite, webpack, esbuild, Rollup), on the server or in the browser.
- Tested — every helper ships with a Vitest suite covering its edge cases.
Functions at a glance
Everything the package exports, grouped by category:
Arrays & Objects
| Function | Signature | What it does |
|---|---|---|
crossJoin | crossJoin(...arrays) | Returns the Cartesian product of the given arrays. |
toCssClasses | toCssClasses(classes) | Compiles a conditional CSS class string. |
get | get(obj, path, defaultValue?) | Reads a nested value by dot path, with a fallback. |
set | set(obj, path, value) | Writes a nested value by dot path, creating objects as needed. |
Async Helpers
| Function | Signature | What it does |
|---|---|---|
sleep | sleep(seconds) | Resolves after the given number of seconds. |
usleep | usleep(ms) | Resolves after the given number of milliseconds. |
until | until(condition, attempt, pause?) | Retries attempt until condition is true. |
Value Helpers
| Function | Signature | What it does |
|---|---|---|
blank | blank(value) | True for empty strings, whitespace, null, undefined, {}, and []. |
clamp | clamp(value, min, max) | Bounds a number to an inclusive range. |
tap | tap(value, interceptor) | Passes a value to an interceptor and returns its result. |
Pagination
| Export | Signature | What it does |
|---|---|---|
pagination | pagination(perPage, itemCount) | Factory that returns a configured Paginator. |
Paginator | class Paginator | Chainable pagination calculator. |
When to reach for it
js-utils is a good fit when you want a few well-tested helpers without pulling in a large utility library. Use it to:
- Read or write config-like nested objects safely with
get/setinstead of optional-chaining ladders. - Generate combinations (sizes × colors × variants) with
crossJoin. - Build
classNamestrings conditionally without a CSS-in-JS dependency. - Add small, readable delays and polling loops in async code with
sleep,usleep, anduntil. - Compute pagination metadata (offsets, page counts, boundaries) for a list or query.
It is intentionally minimal — it does not try to replace a full toolkit like Lodash. If you only need a handful of these helpers, you only ship a handful of these helpers.
Next steps
Head to Installation to add the package to your project, then explore the API reference: