fp-validation
v0.0.5
Published
A FP style validation library
Maintainers
Readme
FP-Validation
fp-validation is a FP like validation library, it can let you compose validation function. It's inspired by compose.
Install
npm install fp-validationTest
npm testUsage
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); // => falseYou 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) // => falseAPI
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
