npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cplotter-validator

v2.0.9

Published

Does several object validation. This was inspired by Laravel Validation

Downloads

28

Readme

cplotter-validator

Does several object validations. This was inspired by Laravel Validation

Instalation

npm install cplotter-validator

Use

Add cplotter-validator dependence const cplotterValidator=require("cplotter-validator)

Create a validation roles like this:

let validationRoles = [
	{
		param:"email",
		required:["required","E-mail is required"]
		type:["email","Invalid e-mail"]
	}
]

Call validation function

let validationErrors = await cplotterValidator.validate(validationRoles, req.body);
if(validationErrors){
	console.log(validationErrors) //Validation failed return a messages in array
} else {
	console.log("Validated")
}

the validate function validate(validationRoles[], targetObject{})

The function validate receive two parameters

  • validationRoles
    • Array of validationRoles objects, this object set the roles to validation.
  • targetObject
    • Object that will be validated according to validationRoles, this object can be any object like express.request.body, express.request.headers, express.request.params or any object, object target can have properties wtih others objects, but is not possible validate the child properties.

the function validate returns FALSE when validate is ok or returns an array of string with the messagens of role when validation failed

Understanding validation roles

The cplotter-validation needs an array of object (validatorRoles), this objects need to respect the following structure.

{
	param:"param_name", // REQUIRED
	required:["<command>","message"] // OPTIONAL
	type:["<type>","message"]  // OPTIONAL
	length:[number,"message"] // OPTIONAL
	minLength:[number,"message"] // OPTIONAL
	maxLength:[number,"message"] // OPTIONAL
	min:[number,"message"] // OPTIONAL
	max:[number,"message"] // OPTIONAL
	equal:[any,"message"] //OPTIONAL
	inList:[["opt","opt2",3],"message"] //OPTIONAL
}

validatorRoles object definition

####param:String Set the name of property will be validated on the target object, this property is required ###required:[] This property is optional. Set if property (seted in param property) is required in target object. This property receive a array as value, this array have must respect the following structure: [command,message]

  • command must be "required"
  • message is the message tha will added on return if the property not exists in target object

type:[]

This property is optional. Verify if value of property (seted in param property) is compatible with role. This property receive a array as value, this array have must respect the following structure: [type,message]

  • type must be one of the these string:
    • boolean - verify if a value is a boolean.
    • cep - verify if value is a brazilian CEP.
    • cnpj - verify if value is a brazilian CNPJ.
    • cpf - verify if value is a brazilian CPF.
    • doc - verify if value is a brazilian CPF or CNPJ.
    • email - verify if value is a valid e-mail.
    • number - verify if value is a number.
    • integer - verify if value is a integer.
    • array - verify if value is a array.
  • message is the message tha will added on return if the property value is not compatible with type.

length[]

This property is optional. Verify if length of value of property (seted in param property) contains the number of caracters according to the rule . This property receive a array as value, this array have must respect the following structure: [number,message]

  • number - must be a integer value
  • message - is the message tha will added on return if the property value is not compatible with the role.

minLength[]

This property is optional. Verify if length of value of property (seted in param property) contains the minimum of caracters according to the rule . This property receive a array as value, this array have must respect the following structure: [number,message]

  • number - must be a integer value
  • message - is the message tha will added on return if the property value is not compatible with the role.

maxLength[]

This property is optional. Verify if length of value of property (seted in param property) contains the maximum of caracters according to the rule . This property receive a array as value, this array have must respect the following structure: [number,message]

  • number - must be a integer value
  • message - is the message tha will added on return if the property value is not compatible with the role.

min[]

This property is optional. Verify if value of property (seted in param property) is greater than or equal to role. This property receive a array as value, this array have must respect the following structure: [number,message]

  • number - must be a number value
  • message - is the message tha will added on return if the property value is not compatible with the role.

max[]

This property is optional. Verify if value of property (seted in param property) is less than or equal to role. This property receive a array as value, this array have must respect the following structure: [number,message]

  • number - must be a number value
  • message - is the message tha will added on return if the property value is not compatible with the role.

equal[]

This property is optional. Verify if value of property (seted in param property) is equal to role. This property receive a array as value, this array have must respect the following structure: [number,message]

  • number - must be a number value
  • message - is the message tha will added on return if the property value is not compatible with the role.

inList[]

This property is optional. Verify if value of property (seted in param property) is in a list. This property receive a array as value, this array have must respect the following structure: [[list],message]

  • [list] - must be a array
  • message - is the message tha will added on return if the property value is not compatible with the role.

#Cplotter Team

http://cplotter.com.br