type-pipe contains a type-safe pipe()
function implementation, because you just can't wait for JS-native pipes.
// begin with a value
const result = pipe(() => "2")
// it is passed as the first argument to the next piped function
.pipe(parseInt)
// you may pass additional arguments, beyond the first piped argument
.pipe(add, 2)
// your functions must expect the same type as the prior function
.pipe((num: number) => num.toString())
// as your value changes, so does the required type of your piped functions
.pipe((num: string) => num.repeat(3))
const add = (num1: number, num2: number) => num1 + num2
- ⛓ Chaining functions via
pipe().pipe()
etc. - 🏭 Passing the return of one
pipe
to the first argument of the nextpipe
- 👾 Catching errors and returning them safely
- 🦺 Type safety between pipes
- Async functions
Contributions welcome! Feel free to fork the repo and open PRs.
Contributions will not be accepted without unit tests ❤️.
- Fork the repo
- Complete your change
- Create a changeset with
pnpm run changeset
describing your change - Open a PR to this repo at
main