@ki2/utils
Write what you mean, not what the compiler needs. @ki2/utils wraps the idioms we use every day—checking existence, narrowing types, running async work in parallel—into tiny helpers that read like plain English while keeping TypeScript on your side.
Install
yarn add @ki2/utils
npm install @ki2/utils
The package exposes ESM, CJS, and UMD bundles plus .d.ts files. Tree-shaking works out of the box with modern bundlers.
Essentials in 30 seconds
exist(value) | Expresses “does this exist?” and narrows away null | undefined without losing the underlying type. |
isString(value), isNumber(value), isArray(value), … | Self-explanatory guards that replace noisy typeof / Array.isArray chains and work seamlessly with TypeScript’s control-flow analysis. |
runParallel(...promises), applyParallel(items, fn) | Compose async operations declaratively, keep tuple types intact, and make intent unmistakable. |
import { readFile } from "node:fs/promises";
import { exist, isString, runParallel, applyParallel } from "@ki2/utils";
async function greet(name: unknown) {
if (!exist(name) || !isString(name)) return;
const [shout, echo] = await runParallel(
fetch(`https://api.example.com/hello/${encodeURIComponent(name)}`).then((res) => res.text()),
fetch("https://api.example.com/motd").then((res) => res.text())
);
return `${echo} • ${shout.toUpperCase()}`;
}
const files = await applyParallel(paths, (path) => readFile(path, "utf8"));
These helpers frontload intent—you see the business logic immediately—and they still unlock TypeScript’s strongest narrowing.
Need the full toolbox?
Browse the dedicated documentation:
Each page is short and focused so you, or an agent, can find the right helper quickly.
Compatibility & scripts
- Runtime: Node.js ≥ 14.17 or any ES2018-compatible browser.
- TypeScript: developed against TS 4.x; declarations remain consumable by TS 5 projects.
- Dependencies: none at runtime—only the Node/DOM standard library.
Local commands:
yarn lint
yarn workspace @ki2/utils test --runInBand
yarn workspace @ki2/utils build
The repository uses Yarn 4 (PnP). For editor integration, run yarn sdks vscode (or the equivalent for your IDE).
Contributing
Pull requests are welcome. Keep them focused, run the commands above, and update docs whenever behaviour changes. The aim is simple, readable utilities that stay friendly to both humans and TypeScript.