@azlib/std
v0.5.0
Published
Language-level helpers for arrays, objects, strings, numbers, and functions. Pure functions by default, with an opt-in `Array.prototype` patch for method-style calls.
Readme
@azlib/std
Language-level helpers for arrays, objects, strings, numbers, and functions. Pure functions by default, with an opt-in Array.prototype patch for method-style calls.
Date/time belongs in @azlib/temporal. Validation belongs in @azlib/validator.
Install
pnpm add @azlib/stdPure functions
import {
shuffle,
unique,
difference,
intersection,
union,
sortBy,
countBy,
sum,
mean,
zip,
zipObject,
pick,
omit,
pickBy,
omitBy,
compactObject,
merge,
isEqual,
cloneDeep,
get,
set,
unset,
has,
flattenObject,
unflattenObject,
asRecord,
asArray,
asString,
asNumber,
asInteger,
asBoolean,
asError,
isNil,
isDefined,
isPrimitive,
isPromise,
isError,
isPlainObject,
capitalize,
kebabCase,
snakeCase,
camelCase,
pascalCase,
constantCase,
titleCase,
escapeRegExp,
escapeHtml,
unescapeHtml,
slugify,
template,
dedent,
mask,
clamp,
inRange,
round,
randomInt,
mapRange,
normalize,
debounce,
throttle,
retry,
timeout,
parallel,
memoize,
attempt,
tryOr,
pipe,
compose,
} from "@azlib/std";
// Objects
pick({ a: 1, b: 2 }, ["a"]);
omit({ a: 1, b: 2 }, ["b"]);
compactObject({ a: 1, b: null, c: undefined }); // { a: 1 }
isEqual({ a: [1, 2] }, { a: [1, 2] }); // true
cloneDeep({ a: new Set([1, 2]) });
get({ a: { b: 1 } }, "a.b");
set({ a: { b: 1 } }, "a.b", 2);
unset({ a: { b: 1 } }, "a.b");
has({ a: { b: 1 } }, "a.b"); // true
// Arrays
difference([1, 2, 3], [2]); // [1, 3]
intersection([1, 2, 3], [2, 3, 4]); // [2, 3]
union([1, 2], [2, 3]); // [1, 2, 3]
sortBy([{ age: 30 }, { age: 20 }], (x) => x.age);
countBy(["apple", "banana", "avocado"], (s) => s[0]); // { a: 2, b: 1 }
sum([1, 2, 3, 4]); // 10
mean([2, 4, 6]); // 4
// Strings & Numbers
slugify("Café & Restaurant — NY!"); // "cafe-restaurant-ny"
escapeHtml("<script>"); // "<script>"
template("Hello {user.name}", { user: { name: "Alex" } }); // "Hello Alex"
randomInt(1, 10); // 1..10
mapRange(5, 0, 10, 100, 200); // 150
// Functions & Async
const [err, data] = attempt(() => JSON.parse('{"a":1}'));
await retry(async () => fetchData(), { retries: 3 });
await parallel([1, 2, 3, 4], 2, async (id) => process(id));Importing @azlib/std never mutates built-in prototypes.
Opt-in array patch
import { patchArray } from "@azlib/std/array/patch";
patchArray();
[1, 2, 3, 4].take(2);
[1, 2, 3].difference([2]); // [1, 3]
[1, 2, 3, 4].sum(); // 10AI Agent Quick Reference
| Export | Description |
| --- | --- |
| shuffle / chunk / unique / groupBy / countBy | Array transforms & groupings |
| difference / differenceBy / intersection / union / symmetricDifference | Set operations on arrays |
| sortBy / take / drop / takeWhile / dropWhile / compact / partition | Array slicing, ordering & filtering |
| sum / sumBy / mean / meanBy / minBy / maxBy | Collection math aggregations |
| zip / unzip / zipObject / intersperse / range / sample | Array structuring & sampling |
| pick / omit / pickBy / omitBy / compactObject | Object selection & sanitization |
| merge / cloneDeep / isEqual / invert / defaults | Deep object merging, cloning & equality |
| get / set / unset / has / flattenObject / unflattenObject | Path-based access & nesting transforms |
| asRecord / asArray / asString / asNumber / asInteger / asFloat / asBoolean / asError | Unknown → typed coercion (JSON/API mapping) |
| isNil / isDefined / isPrimitive / isPromise / isError / isPlainObject | Type guards & runtime checks |
| capitalize / truncate / words / titleCase / dedent | String basics & formatting |
| kebabCase / snakeCase / camelCase / pascalCase / constantCase | Case converters |
| escapeRegExp / escapeHtml / unescapeHtml / slugify / template / mask | String escaping, slugification & templating |
| clamp / lerp / inRange / round / random / randomInt / mapRange / normalize / isEven / isOdd | Number & range helpers |
| debounce / throttle / once / noop / identity / sleep | Core function utilities |
| retry / timeout / parallel / deferred / memoize / attempt / tryOr / tryOrAsync / pipe / compose / negate / times | Async & functional flow helpers |
| patchArray / unpatchArray | From @azlib/std/array/patch |
