@ripl/utilities
v1.0.0-beta.1
Published
Shared typed utility functions for Ripl
Downloads
26
Readme
@ripl/utilities
Shared typed utility functions for Ripl — a unified API for 2D graphics rendering in the browser.
Installation
npm install @ripl/utilitiesOverview
A collection of strictly-typed utility functions used across the Ripl ecosystem. Zero dependencies, fully tree-shakable.
API
Type Guards
typeIsArray(value); // value is unknown[]
typeIsFunction(value); // value is AnyFunction
typeIsNil(value); // value is null | undefined
typeIsNumber(value); // value is number
typeIsString(value); // value is string
typeIsObject(value); // value is object
typeIsDate(value); // value is Date
typeIsBoolean(value); // value is booleanCollection Helpers
arrayJoin(left, right, predicate); // left/inner/right join for data diffing (Map-optimized for key predicates)
arrayMapRange(length, callback); // map over a numeric range
arrayGroup(array, key); // group array items by key or function
arrayIntersection(left, right, predicate); // intersection of two arrays
arrayDifference(left, right, predicate); // difference of two arraysNote: Generic array wrappers (
arrayForEach,arrayMap,arrayFilter,arrayReduce,arrayFind,arrayFlatMap) have been removed in favour of native array methods for better performance.
Object Helpers
objectForEach(object, callback);
objectMap(object, callback);
objectMerge(target, ...sources);Common Types
OneOrMore<T>; // T | T[]
AnyFunction; // (...args: any[]) => any
AnyObject; // { [key: PropertyKey]: unknown }
Disposable; // { dispose: () => void }
Predicate<L, R>; // (left: L, right: R) => booleanValue Helpers
valueOr(value, fallback); // value ?? fallback with type narrowing
valueOrDefault(value, fallback); // nullish coalescing with defaultsDocumentation
Full documentation is available at ripl.rocks.
