Helper functions, classes and types for various projects.
The kind of stuff that turns up in most codebases and gets copy-pasted between them: memoisation, a semaphore, debounce and retry, deep object helpers, a bit of maths, and enough type gymnastics to build small numbers out of string types.
pnpm i @inrixia/helpersRuntime helpers are exported from the package root (@inrixia/helpers). Test matchers (getExpect) live on the @inrixia/helpers/test subpath export (src/test.ts) rather than the runtime entry. Deep ./dist/* imports are also exposed via exports, and src/ is published alongside dist/ so source maps and declaration maps resolve.
| Folder / File | Contents |
|---|---|
class/ |
ArgsMap, DequalMap and StringifyMap (maps keyed by argument lists, deep equality and JSON), memoize and its variants (memoizeArgless, memoizeDequal, memoizeStringify, withCache), Promize, Semaphore (available, pending, obtainFirst, withFirst), Signal |
fn/ |
debounce (cancel, flush), asyncDebounce, retry, loopError, runFor, sleep, lazy, toRange, toBase64, fetch response helpers (statusOK, rejectNotOk, toJson, toText, toBlob, toArrayBuffer, toBytes, toFormData), registerEmitter, unloadableEmitter |
math/ |
qRnd, nPad, to360, angleDifference |
obj/ |
deepGet, deepMerge, chunkArray, setDefaults, objectify, getEnv, envOrThrow, fillTemplate, deepTypeCompare, compareTwo, rebuildTypes, recursiveUpdate |
ts/ |
typeOf, isT, isObject, isKeyOf, nullish/boolean type guards, plus the type-level number and utility helpers |
conv.ts, geo.ts |
Humidity conversions (dryBulbTemp, dewPointTemp, relativeHumidity), degrees/minutes/seconds (toDMS), radians/distance (toRad, getDistance) |
test.ts |
getExpect custom Jest/Vitest matchers (import { getExpect } from "@inrixia/helpers/test") |
typeOf separates the things typeof lumps together:
import { typeOf } from "@inrixia/helpers";
typeOf([]); // "array"
typeOf(null); // "null"
typeOf(NaN); // "NaN"memoize caches by argument:
import { memoize } from "@inrixia/helpers";
const slowSquare = memoize((n: number) => n ** 2);
slowSquare(4); // 16, computed
slowSquare(4); // 16, straight from the cacheSemaphore keeps a lid on concurrency and exposes available and pending counts:
import { Semaphore } from "@inrixia/helpers";
const sem = new Semaphore(2);
sem.available; // 2
sem.pending; // 0
await Promise.all(urls.map((url) => sem.with(() => fetch(url))));debounce supports cancel() and flush() on the returned wrapper:
import { debounce } from "@inrixia/helpers";
const save = debounce((value: string) => console.log(value), 200);
save("draft");
save.flush(); // runs immediately instead of waiting 200ms
save("discard");
save.cancel(); // drops the pending calldeepGet walks a dotted path and hands a falsy leaf back as-is:
import { deepGet } from "@inrixia/helpers";
deepGet({ a: { b: 0 } }, "a.b"); // 0
deepGet({ a: { b: { c: 5 } } }, "a.b.c"); // 5Tests run on vitest and live in test/ and beside source as src/**/*.test.ts.
pnpm test # run once
pnpm test:watch # watch mode
pnpm test:coverage # run once, plus a coverage report in coverage/
pnpm test:coverage:ci # CI mode: also writes coverage/test-results.json
pnpm lint # run ESLint
pnpm lint:fix # run ESLint with --fix
pnpm format # format with Prettier
pnpm build # clean build into dist/CI runs lint, build, and pnpm test:coverage:ci on every pull request and every push to master (.github/workflows/ci.yml), posting a sticky PR comment with coverage diffs against master via .github/workflows/coverage-comment.yml. On successful pushes to master, it regenerates the coverage and test badges in .github/badges/ and auto-raises any improved coverage floors in .github/coverage-thresholds.json.
See AGENTS.md for repo conventions, module/import rules, and the vendored agent skills under .agents/skills/ (updated by the update-skills workflow).
ISC