Laravel-style helpers
for TypeScript.
js-utils is a small, typed utility collection inspired by Laravel’s helpers. Dot-path get / set, cross joins, conditional CSS classes, async sleep and until, blank / clamp / tap, and a chainable paginator — with zero runtime dependencies.
import { get, clamp, pagination } from '@0x26e/utils'
// Read deeply nested values with a dot path — and a default
const obj = { products: { desk: { price: 100 } } }
get(obj, 'products.desk.price', 0) // 100
get(obj, 'products.table.price', 0) // 0
// Keep a number inside an inclusive range
clamp(15, 1, 10) // 10
clamp(-5, 1, 10) // 1
// Paginate without the boilerplate
const page = pagination(10, 100).setPage(2)
page.getFirstItemOnPage() // 11
page.getLastItemOnPage() // 20
page.getPageCount() // 10A focused toolbox
A handful of dependable helpers that compose cleanly — each one documented with complete, copy-paste examples.
Arrays & objects
crossJoin for Cartesian products, toCssClasses for conditional class strings, and dot-path get / set for reading and writing nested data.
Async helpers
sleep (seconds) and usleep (milliseconds) for clean delays, plus until — a tiny retry loop that polls an attempt until a condition turns true.
Value helpers
blank tells you whether a value is empty across strings, objects, and arrays; clamp bounds a number to a range; tap pipes a value through an interceptor.
Chainable Paginator
A fluent Paginator class — and a one-line pagination() factory — that computes offsets, page counts, first / last items, and boundary checks.
TypeScript-first
Written in TypeScript with full type definitions built in. Generics flow through get, tap, crossJoin, and until, so return types stay precise.
ESM + CJS, zero deps
A dual package — import or require it. No runtime dependencies, fully tree-shakeable, so you only ship the helpers you actually use.
Familiar API
Helpers mirror Laravel’s names and behavior — get, blank, tap, until — so they feel instantly at home.
Tree-shakeable
Named exports only. Bundlers drop everything you don’t import from the final build.
Any runtime
Works in modern Node and any bundler — Vite, webpack, esbuild, Rollup — on the server or in the browser.
One install, every helper
Add the package, import what you need, and start writing less boilerplate. The guide documents every function with its signature, parameters, and real examples.