A package that makes json validation easier
npm install validatit> Validatit helps you to validate JSON objects.
``sh`
npm i validatit@latest
`node`
import {validatit} from 'validatit'
Call validatit function
`node
let json = {
first_name:"jamie",
phone:"+18889203388",
address:{
street:""
}
};
let params=[
{name:"*first_name:STRING"},
{name:"*phone:PHONE"} ,
{
name:"address",
params:[
{name:"*street"}
]
}
];
let res = await validatit(json,params);
`
Parameter name | description | example | notes
--- | --- | --- | ---
name | name of the parameter to ve validated | name:"first_name" |
required | indicates that the parameter is mandatory | {name:"first_name" ,required:true} | you can use {name:"*first_name"} instead to have smaller validators
type | parameter type. Current types are :ARRAY, OBJECT, BOOLEAN, STRING, NUMBER, FUNCTION, DATE, CREDIT_CARD, EMAIL, PHONE, ANY | {name:"first_name" ,type:"STRING"} | you can use {name:"first_name:STRING"} instead to have smaller validators
pattern | custom regular expression | {name:"first_name",pattern:/^[A-Z][a-z]+(?:[A-Z][a-z]+)*$/} |
dynamicValidation | used for custom runtime validations | {name:"first_name",dynamicValidation:asyc(body)=>return {success:true,error_message:""}} |
`sh``
npm run test
š¤ Bahram Ghahari
* Github: @bahram-ghahari
Contributions, issues and feature requests are welcome!
Feel free to check issues page. You can also take a look at the contributing guide.
Give a āļø if this project helped you!
Copyright © 2021 Bahram Ghahari.
This project is MIT licensed.
*
_This README was generated with ā¤ļø by readme-md-generator_