Skip to content

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() // 11

Coming 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.ts types. Generics flow through get<T>, tap<T>, crossJoin<T>, and until<T> so return types stay precise.
  • ESM + CJS dual packageimport { get } from '@0x26e/utils' in modern code, or require('@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

FunctionSignatureWhat it does
crossJoincrossJoin(...arrays)Returns the Cartesian product of the given arrays.
toCssClassestoCssClasses(classes)Compiles a conditional CSS class string.
getget(obj, path, defaultValue?)Reads a nested value by dot path, with a fallback.
setset(obj, path, value)Writes a nested value by dot path, creating objects as needed.

Async Helpers

FunctionSignatureWhat it does
sleepsleep(seconds)Resolves after the given number of seconds.
usleepusleep(ms)Resolves after the given number of milliseconds.
untiluntil(condition, attempt, pause?)Retries attempt until condition is true.

Value Helpers

FunctionSignatureWhat it does
blankblank(value)True for empty strings, whitespace, null, undefined, {}, and [].
clampclamp(value, min, max)Bounds a number to an inclusive range.
taptap(value, interceptor)Passes a value to an interceptor and returns its result.

Pagination

ExportSignatureWhat it does
paginationpagination(perPage, itemCount)Factory that returns a configured Paginator.
Paginatorclass PaginatorChainable 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 / set instead of optional-chaining ladders.
  • Generate combinations (sizes × colors × variants) with crossJoin.
  • Build className strings conditionally without a CSS-in-JS dependency.
  • Add small, readable delays and polling loops in async code with sleep, usleep, and until.
  • 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:

js-utils — A TypeScript utility collection similar to Laravel helpers. Released under the MIT license.