📅 You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP
Socket
Sign inDemoInstall
Socket

validate-data

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

validate-data

Sanitize and validate data with the given set of rules.

0.1.1
latest
Source
npm
Version published
Weekly downloads
24
50%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status npm license

NPM

Validate Data

NodeJs backend library for validate data against the rules provided.

Usage

Install the library with npm install validate-data

const validate = require('validate-data');

// Validation rules 
const rules = {
        required: "email name age",
        email: "email",
        string: "email name",
        number: "age",
        array: "options",
        boolean: "status"
    };

// Data to be validated
const data = {
    email: "example@sample.com",
    name: "John",
    age: 25,
    options: [1,2,3],
    status: true
};

// Using the package
let error = validate(data, rules);

console.log(error);   

Error will be null if all the validation rules passs, otherwise will get the following error

[
    {
        rule: 'required', // Failed rule
        errorOn: ['sample'] // Failed data fields
    },
    {
        rule: 'email',
        errorOn: ['email']
    },
    {
        rule: 'number',
        errorOn: ['age']
    },
    {
        rule: 'array',
        errorOn: ['options']
    },
    {
        rule: 'boolean',
        errorOn: ['status']
    }
]

Validators

Module ensure that the given data will be validated against the following strategies.

  • Required
  • String
  • Number
  • Email
  • Array
  • Boolean

Feature requests

Feature requests are welcome. But take a moment to find out whether your idea fits with the scope and aims of the project. Please provide as much detail and context as possible. Click here to add feature requests and issues.

Change Log

CHANGELOG.md

Tests

 yarn run test

License

MIT

Keywords

data

FAQs

Package last updated on 19 Jul 2017

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