Pipe is a library for handle values, It completes the validate and conversion of values by combining handler functions.
Pipe 是一个处理值的库,它通过组合处理函数来完成对值的验证和转换。
import { pipe, int, min, max } from '@unicreators/pipe';
let fn = pipe(int(), min(2), max(10));
console.log(fn(8) == 8);
// true
console.log(fn(1) === undefined);
// true
fn = pipe(int({tryConvert: true}), min(2), max(10));
console.log(fn('8') == 8);
// true
Install
$ npm install @unicreators/pipe
Handlers
- string
- int
- float
- date
- boolean
- regex
- array
- min
- max
- minLength
- maxLength
- def
- required
- throwError
- tap
- invalid
- path
- project