Gathering detailed insights and metrics for @bardoui/validators
Gathering detailed insights and metrics for @bardoui/validators
Gathering detailed insights and metrics for @bardoui/validators
Gathering detailed insights and metrics for @bardoui/validators
npm install @bardoui/validators
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Extra validators for yup.
This package published as validators
module in umd.
1<script src="https://unpkg.com/@bardoui/validators"></script>
1npm i @bardoui/validators
1import { 2 registerAll, 3 registerCreditCardValidator, 4 registerUsernameValidator, 5} from "@bardoui/validators"; 6// Register all validators 7registerAll(); 8// Register custom validator only 9registerCreditCardValidator(); 10registerUsernameValidator();
Validate package contains following helper functions:
Get error rules from keyed error.
1// Signature: 2export function getErrorRules(errors: any): ErrorMap; 3 4// Example 5// Error Response => {"username": {"max": "username max is 20 char", "unique": "username must unique"}, "password": {"min" :"password must have 10 char at least"}} 6// result => {"username": ["max","unique"], "password": ["min"]}
Get error messages from keyed error.
1// Signature: 2export function getErrorMessages(errors: any): ErrorMap; 3 4// Example 5// Error Response => {"username": {"max": "username max is 20 char", "unique": "username must unique"}, "password": {"min" :"password must have 10 char at least"}} 6// result => {"username": ["username max is 20 char","username must unique"], "password": ["password must have 10 char at least"]}
Get first error rule from errors list.
1// Signature: 2export function getFirstRule(errors: any): ErrorField; 3 4// Example 5// Error Response => {"username": {"max": "username max is 20 char", "unique": "username must unique"}, "password": {"min" :"password must have 10 char at least"}} 6// result => {"username": "max", "password": "min"}
Get first error message from errors list.
1// Signature: 2export function getFirstMessage(errors: any): ErrorField; 3 4// Example 5// Error Response => {"username": {"max": "username max is 20 char", "unique": "username must unique"}, "password": {"min" :"password must have 10 char at least"}} 6// result => {"username": "username max is 20 char", "password": "password must have 10 char at least"}
This function override yup default translator and return error key as error message.
1// Signature: 2export function makeYupKeyedErrors(); 3 4// Example 5// instead of 'this field is required' message return 'required'
Validator contains following validators:
Note by default all validators return validator key as error message (in lowercase). you can pass error message on create time or use time to override this behavior.
Validate string contains alpha-numeric string. This validator accept a string to contains in check/
1yup.string().alnum("-"); // alnum and dash
Validate string contains alpha-numeric and persian characters string. This validator accept a string to contains in check/
1yup.string().alnumfa("");
Validate credit card number. this validator accept tow mode, long (20 digit) and short (16 digit) card number. Allowed formats:
xxxx-xxxx-xxxx-xxxx-xxxx
or xxxx-xxxx-xxxx-xxxx-xxxx
xxxx-xxxx-xxxx-xxxx
or xxxx-xxxx-xxxx-xxxx
x
represent one digit.
1// 20 digit 2yup.string().credit(true); 3// 16 digit 4yup.string().credit(false, "invalid credit card number");
Validate id number string (0 to 10 digit string).
1yup.string().idNumber();
Validate number greater than 1.
1yup.number().identifier();
Validate IPv4 string.
1yup.string().ip();
Validate IPv4 string with port.
1yup.string().ipPort();
Validate jalali date string by format.
1yup.string().jalali("YYYY/MM/DD");
Validate persian mobile number. accept (09xx) xxx-xxx and 09xxxxxxxx formats.
1yup.string().mobile();
Validate persian national code. accept xxx-xxxxxx-x and xxxxxxxxxx formats.
1yup.string().nationalCode();
Validate persian postal code. accept xxxxx-xxxxx and xxxxxxxxxx formats.
1yup.string().postalCode();
Validate persian tel. accept (0xx) xxxx-xxxx and 0xxxxxxxxxx formats for prefixed mode and xxxx-xxxx and xxxxxxxx for non-prefixed mode.
1// Prefixed mode (11 digit) 2yup.string().tel(true); 3// Non-prefixed mode (8 digit) 4yup.string().tel(false);
Validate unsigned number (0 or greater).
1yup.number().unsigned();
Validate username. username can contains numbers, alpha, dash, dot and underscore characters.
1yup.string().username();
Validate uuid string.
1yup.string().uuid();
No vulnerabilities found.
No security vulnerabilities found.