🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

variables-type-validator

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

variables-type-validator

this package help to varify the type and characterstics of any variable provided

Source
npmnpm
Version
1.0.3
Version published
Weekly downloads
3
200%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

validator

FAQs

Package last updated on 29 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts