fp-validation

0.0.5 • Public • Published

FP-Validation

Build Status

Known Vulnerabilities

fp-validation is a FP like validation library, it can let you compose validation function. It's inspired by compose.

Install

npm install fp-validation

Test

npm test

Usage

Require fp-validation

import vailCompose from 'fp-validation';
import { isNumber, isRequired } from 'fp-validation/libs';

You can pass a single lib as parameter:

const isNum = vailCompose(isNumber("Is not a Number"));
vail('foo'); // => "Is not a Number"
vail(123); // => false

You can also pass multiple libs as parameters:

Will apply all libs from right to left.

const isNumIsReq = vailCompose(isNumber("Is not a Number"), isRequired('The value cannot empty'));
isNumIsReq(""); // => "The value cannot empty"
isNumIsReq("foo"); // => "Is not a Number"
isNumIsReq(123) // => false

API

vailCompose(libs)

libs

Type: function

Return: If all the validation of the libs are true will be false otherwise is string(reason).

The libs you want to compose.

libs

isRequired([reason])

Default: 欄位為必填

isNumber([reason])

Default: 輸入內容必須為數字

isEmail([reason])

Default: 電子信箱格式不正確

maxLength(length, [reason])

Default: 超過最大限制長度length字元

minLength(length, [reason])

Default: 小於最小限制長度length字元

maxNum(max, [reason])

Default: 數值超過max

LICENSE

MIT

Dependents (0)

Package Sidebar

Install

npm i fp-validation

Weekly Downloads

0

Version

0.0.5

License

MIT

Last publish

Collaborators

  • addhome2001