Easy Start
Install (安装)
shell
> npm install param-validator.js
Import (导入)
js
// CommonJS
const ParamValidator = require('param-validator.js')
// ES module
import ParamValidator from 'param-validator.js'
Construct validator model (构建校验模型)
js
const dataModel = {
name: String,
age: Number
}
const validator = new ParamValidator(dataModel)
Quick validate(快速校验)
js
const data = {
name: 'match',
age: 20
}
const result = validator.test(data)
console.log(result)// return 'true' when data is matched with dataModel