Validatorz

validatorz is...

a minimalistic data validation checker

fairly efficient (for js).

Usage

Pass in a list of requirements to the createStringValidator or createNumberValidator function:

createStringValidator requirements can have the following properties:

mustContain : Will return error if any of the required character types are not found. "symbols" : `!@#$%^&*()_-+=[{]}\|><.,?/"';:~`` "uppercase" : all uppercase letters "lowercase" : all lowercase letters "letters" : all letters o "digits" : all digits [0-9] "alphanumeric" : all digits and letters "spaces" : the character * any other character you want represented with a string "f29c" would be valid if it contains the characters f , 2 , 9 , and c

: Will return error if any of the required character types are not found. validChars : Will return error if any characters other than the ones specified are found. The list of characters if the same as the ones for mustContain

: Will return error if any characters other than the ones specified are found. min : the minimum length of the string

: the minimum length of the string max : the maximum length of the string

: the maximum length of the string regexp : a regular expression to test the value

createNumberValidator requirements can have the following properties:

min : minimum value

: minimum value max : maximum value

Then, you simply pass a string to validate. It will return an array of errors (empty array if no errors).

const passwordValidator = createStringValidator ( { mustContain : [ " symbols " , " uppercase " , " lowercase " , " digits " ] , validChars : [ " symbols " , " alphanumeric " ] , min : 8 , max : 45 , } ) passwordValidator ( " Password#1805 " ) passwordValidator ( " password#1805 " )

createNumberValidator works the same way:

passwordValidator ( " 19 " ) passwordValidator ( 3 )

Preset Validators

validatorz also comes with some preset validators. Please open an issue/pr if there are more that you need.

Installation

Yarn: yarn add validatorz

Npm: npm i validatorz

Dependencies

None