Skip to content

dalthonmh/WDSvalidation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebDevSimplified validations

A library of simple validators, numbers and strings, this is an enhancement of code from Kyle Cook based on validations.

Usage

install using a package manager

yarn add wdsvalidation

then required and use it.

const validation = require("wdsvalidation");

// rules
const validations = {
  name: {
    required: true,
    minLength: 3,
    maxLength: 50,
    type: "string",
  },
  categoryId: {
    required: true,
    minLength: 23, // id mongodb format
    maxLength: 25, // id mongodb format
    type: "string",
  },
  price: {
    minValue: 0,
    maxValue: 999,
    type: "number",
  },
};

// data to validate:
const product = {
  name: "ceviche",
  categoryId: "123",
  price: 10,
};

const errors = validation(validations, product);

//output from product validation
errors: {
  name: [],
  categoryId: ["must be min 23 or more characters"],
  price: [],
}

license MIT

About

Validate string and numbers length

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published