Skip to content
On this page

Introduction

  • Author: MatchOvO
  • Repository: param-validator.js
  • Current Version: 1.4.0
  • An easy and lightweight way to validate params in Javascript Object. You can use it to validate the http request data in Node.js or the form data in web min.js is less than 10k, so that you can use it in your project without any burden. And ParamValidator.js can distinguish such as "Object","Array","null". All you need to do is to define a "dataModel" in a simple way like:
js
const dataModel = {
    anString: String,
    anNumber: Number,
    anObject: Object
}

Or more specific config like:

js
const dataModel = {
    anString:{
        type: String,
        regexp: /[A-Z]+/
    },
    anNumber:{
        type: Number,
        int: true,
        range: {
            "<=": 9,
            ">": 0
        }
    },
    anObject:{
        type: Object
    },
    anArray:{
        type: Array
    }
}