1.1.0 • Published 6 years ago

simple-validator-request v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 years ago

Simple Validator Request

Npm Package for simple validator request body

Installation

npm i simple-validator-request

Dependencies

How To Use

const { simpleValidator } = require('simple-validator-request')

const validation = {
    requiredKey: {
        type: 'string',
        message: {
            required: '{customize message for required validation}',
            type: '{customize message for type validation}'
        }
    },
    anotherRequiredKey: {
        type: 'number',
        message: {
            required: '{customize message for required validation}',
            type: '{customize message for type validation}'
        }
    }
}

// JSON request body example 
const body = {
    code: "TEST",
    name: "asd",
    arrs: ["test","asd"]
}

let validator = simpleValidator(body, validation)
console.log(validator)
// validator.status = boolean
// validator.error = string (message error)

Explain

const validator = {
	requiredKey: <option>
}
simpleValidator(requestBody,validator)

/** 
*<option>
*	type:
*	- 'string' => string validator
*	- 'number' => number validator
*	- 'email' => email format validator
*	- 'array' => array format validator
*	
*	length : (int) <string len>
*	min : (int) <min number>
*	max : (int) <max number>
*/
1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago