Skip to content
On this page

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

Usage Example