Skip to content

Ground-breaking objects and strings validation in typescript for Node applications

Notifications You must be signed in to change notification settings

beedyboy/data-hero

Repository files navigation

data-hero

Ground-breaking objects and strings validation in typescript for Node applications.

Version

1.6.1

Motto

Be your own data hero

License

MIT - See LICENSE.md

Install

yarn add data-hero

General usage

  • On node:
$ npm install -g data-hero

Validate an object

import dataHero from 'data-hero'

const schema = {
  email: {
    min: 14,
    email: true,
    message: 'Email is required'
  },
  password: {
    min: 8,
    max: 10,
    message: 'password is required'
  }
}
const data = {
  email: 'bolade@gmail.com',
  password: 'akin'
}
dataHero.validate(schema, data)

will return false if validation passes

Single Validation

import dataHero from 'data-hero';
  • Syntax dataHero.validator(field, rule, rule value)
  • Example 1
dataHero.validator('pp', 'min', 2)

  • Example 2
const schema = {
    email: {
      min: 14,
      email: true,
      message: 'Email is required'
    }
  }
  const data = {
    email: 'bolade@gmail.com'
  }
  dataHero.validate(schema, data);

  • Example 3
  const schema = {
           
          password: {
            compare: {
              to: 'cpaswword'
            }, 
            message: 'password does not match'
          }
        }
        const data = { 
          password: 'Bolade',
          cpaswword: 'Bolades', 
        }
dataHero.validate(schema, data)

Available rules

  • min to take integer value
  • max to take integer value
  • isEmpty to take boolean value
  • email to take boolean value
  • isNumeric to take boolean value
  • isBoolean takes a boolean value
  • isTrue takes a boolean value
  • isFalse takes a boolean value
  • compare use to compare two fields e.g. password

Note: Any rule applied above will return false is validation passes !

About

Ground-breaking objects and strings validation in typescript for Node applications

Resources

Stars

Watchers

Forks

Packages

No packages published