@vielzeug/arsenal
v26.10.17
Published
Non-trivial TypeScript utilities: retry, cancellation, cache, safe-path, serialization, prototype-pollution-guarded collections
Readme
@vielzeug/arsenal
Non-trivial TypeScript utilities: retry, cancellation, cache, safe-path, serialization, prototype-pollution-guarded collections
Installation
pnpm add @vielzeug/arsenal
npm install @vielzeug/arsenal
yarn add @vielzeug/arsenalQuick Start
import { groupBy, retry } from '@vielzeug/arsenal';
import { fuzzyFilter } from '@vielzeug/arsenal/array';
import { taskPool } from '@vielzeug/arsenal/async';
import { cache } from '@vielzeug/arsenal/cache';
import { tryParseJson } from '@vielzeug/arsenal/object';
const parsed = tryParseJson('{"users":[{"name":"Alice"}]}');
const users = parsed.ok ? (parsed.value as { users: { name: string }[] }).users : [];
const matches = fuzzyFilter(users, 'ali', { select: (user) => user.name });
const pool = taskPool({ concurrency: 2 });
const data = await pool.run((signal) => retry(() => fetch('/api', { signal }).then((response) => response.json())));
const responses = cache<string, unknown>({ ttlMs: 60_000 });
const profile = await responses.getOrLoad('/profile', () => fetch('/profile').then((response) => response.json()));
const cachedResponses = responses.entries();
console.log(groupBy(matches, (user) => user.name), data, profile, cachedResponses);
pool.dispose();Features
compressBytes/decompressBytes: native compression streams with a required decompressed-byte limit, available from the root and/encodingentry points.paginate: cut one page and its totals out of a list in a one- or zero-based page base, available from the root and/arrayentry points.sort: one entry point for a selector, a{ key: direction }object, or ordered grid criteria with safe nested paths, available from the root and/arrayentry points.
Documentation
License
MIT © Helmuth Saatkamp: part of the Vielzeug monorepo.
