0.9.3 • Published 4 years ago

wdsvalidation v0.9.3

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago