lv-ts-utils
v0.0.2
Published
Lightweight TypeScript utility kit with small, focused helpers for type guards, strings, arrays, and timing helpers. Published as ESM with bundled type definitions.
Readme
lv-ts-utils
Lightweight TypeScript utility kit with small, focused helpers for type guards, strings, arrays, and timing helpers. Published as ESM with bundled type definitions.
Installation
npm install lv-ts-utils
# or
yarn add lv-ts-utils
# or
pnpm add lv-ts-utilsQuick start
import { isString, debounce, capitalize } from "lv-ts-utils";
const logTyped = debounce((value: unknown) => {
if (isString(value)) {
console.log(capitalize(value));
}
}, 300);
logTyped("hello world"); // → "Hello World"API
Types
AnyFunction: alias for(...args: unknown[]) => unknown, used by timing helpers.
Check
isEmpty(value: unknown): boolean— returnstruefor non-objects and for objects with no enumerable entries.isNullOrUndefined(value): value is null | undefined— narrow to nullable values.isObject(value): value is object— plain object guard (excludesnull, arrays,Date,RegExp).isString(value): value is string— string guard.
Strings
capitalize(string): string— capitalizes the first letter of each space-separated word; if input is not a string, returns it unchanged.includes(string, substring): boolean— safe wrapper aroundString.prototype.includes; returnsfalseif either argument is not a string.
Arrays
arraylable(value): T[]— ensures an array; returns[]when input isnullor not an array.map(array, fn): U[]— thin wrapper overArray.prototype.mapfor consistent import style.
Timing
debounce(fn, delay = 200)— returns a debounced function that runs after inactivity for the given delay (default 200 ms).throttle(fn, delay = 500)— returns a throttled function that runs at most once per delay window (default 500 ms).
Test helpers
hello()— logsHello, world!.
Project scripts
npm run build— type-check withtscand build withvite.npm run lint— lint with Biome.npm run format— format with Biome.npm run check:types— Biome check plustsc --noEmit.npm test— run Vitest with coverage.npm run test:mutation— run Stryker mutation tests.
Output
- Entry point:
dist/ts-utils.js. - Types:
dist/types/index.d.ts.
