Natural Polyglot Machine

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

install

npm i fp-validation

Downloadsweekly downloads

5

version

0.0.5

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability