If you're not sure that what kind of input you are getting and you want to validate it before doing further process this package help you with this. anything which is not as per requirement it returns error.
Installation and Usage
Server-side usage
Install the library with npm install --save variables-type-validator
let typeValidator = require('variables-type-validator');
const valid = typeValidator({ value:"dummy string", type:"String" })
this will check that if given value is string or not it return the object like below :-
console.log(valid)
{ valid:true, message:"all variables are valid" }
type
type parameter accept four valeus
- String
- Number
- Array
- Object
this module also help you with other characterstics of variable like
required : true
this parameter define is the value of given variable is required or not
length
you can also define the length of the value of and variable. The
length parameter accept an object. the length of the variable can be define as below
- gte (greater then or equal to)
- lte (lower then or equal to)
- eq ( equal to)
- gt (greater then)
- lt (lower then)
for example :-
const valid = typeValidator({ value:[1,2,3,4,5,6,7], type:"Array", required:true length:{ gte:5, lte:10 } })
validation ERROR messages
=> if type of given variable does not matched
- type of </your variable name> should be Array
- type of </your variable name> should be Object
- type of </your variable name> should be String
- type of </your variable name> should be Number
=> if required condition does not match
variable </your variable name> cannot be null
=> if length of given variable does not matched
- length of </your variable name> is must be greater then or equal to </ your condition>
- length of </your variable name> is must be lower then or equal to </ your condition>
- length of </your variable name> is must be equal to </ your condition>
- length of </your variable name> is must be greater then </ your condition>
- length of </your variable name> is must be lower then </ your condition>
ABOUT :-
this package is in its initial age so you may face some bugs and difficulties by using this but i am intresterd to know about your thoughts regarding this package so i can develop it more further and i hope that some of you may interested helping me with this package and give me new ideas that help me building this more further.
you can mail me your reviews and idea to my gmail account aliasgherbadshah128@gmail.com