A set of general-purpose typescript functions for common tasks.
The toolbox is available via JSR. To install it, run:
npx jsr add @dovca/toolbox
The main goal of this package is to remedy the pain of writing readable linear functional code in TypeScript. This package was conceived as a workaround for these issues:
- Lodash's
chain()
breaks in production builds. (see issue) - TypeScript doesn't support the pipeline operator (yet). (see issue)
import {
add, flow, fromCharCode, grow, increment,
join, log, map, multiply, toArray,
} from '@dovca/toolbox';
const result = flow(
1, // 1
add(12), // 13
multiply(5), // 65
toArray, // [65]
grow(increment), // [65, 66]
map(fromCharCode), // ['A', 'B']
join(', '), // 'A, B'
log, // -> console.log('A, B')
);
result; // 'A, B'
-
flowing value - the value that is being passed through the
flow
andpipe
functions - to produce a value - a function produces a value that then becomes the flowing value
-
predicate - a unary function that "passes" when it returns
true
for a given value