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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ibrokhim/rbdv

v1.0.2

Published

Advanced Rule-Based Data Validator for NodeJS.

Downloads

31

Readme

RBDV for NodeJS

Advanced Rule-Based Data Validator for NodeJS. https://iiiniii.github.io/RBDV-NodeJS

Build Status Package Size Downloads Count Package Version Package License

About

Let's say you are receiving a JavaScript object in your application and for using the data without a problem you have to use something like if(data != null) or if(data != undefined) each time you want to access the data's value. I know it is so annoying. Well not anymore. Using this package you can now easily create rules for the data you receive and validate it. It is like a dream, I know but, not anymore.

Features

  • [NEW] Create rule out of an example object
  • Verbose validation results
  • Great, advanced, easy to use and flexible configuration
  • Useful in any project
  • Many useful functions
  • Supported data types: String, Number, Array, Function, Object, Null, Undefined, Boolean, RegExp, Error, Date, Symbol
  • User-friendly feedbacks
  • In case of invalid data user-friendly report

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js.

Installation is done using the npm install command:

npm install --save @ibrokhim/rbdv
# or
npm i --save @ibrokhim/rbdv

Check examples below on how to use this package in your project.

Quick Start

Install package using command below:

npm install --save @ibrokhim/rbdv

Add the following line to the top of your JavaScript file:

const RBDV = require('@ibrokhim/rbdv');

Create an instance of RBDV:

var rbdv = new RBDV();

Set your rules for validation:

rbdv.setRules(rules);

If you want verbose results, then:

rbdv.setVerbose(true); // dafault: false

And now it is time to validate our data:

rbdv.isValid(data, subRuleName); // Returns true if data is valid

If you prefer single-use validation, you can do something like this:

rbdv.validate(data, rule); // Returns true if data is valid

You can also create a rule out of an example object:

rbdv.makeRule({
    'name': 'Tom',
    'surname': 'Jerry',
    'isActive': true
});

Returns:

{
    type: 'object',
    props: {
        name: { type: 'string' },
        surname: { type: 'string' },
        isActive: { type: 'boolean' }
    }
}

How to Use

Rules Example

You can get an example configuration object in JSON format by running command below:

rbdv.exampleRule();

Returns:

{
    // A basic object configuration
    'chat_data': {
        type: 'object',
        props: {
            to: {type: 'string'},
            from: {type: 'string'},
            msg: {type: 'string'}
        }
    },

    // A basic string configuration
    'username': {
        type: 'string'
    },

    // A basic number configuration
    'age': {
        type: 'number'
    },

    // A little bit more complex configuration
    'user_data_complex': {
        type: 'object',
        props: {
            name: {type: 'string'},
            surname: {type: 'string'},
            isActive: {type: 'boolean'},
            contact_info: {
                type: 'object',
                props: {
                    email: {type: 'string'},
                    phone: {type: 'string'}
                }
            }
        }
    }
}

Usage Examples

Example using a simple configuration:

var RBDV = require("@ibrokhim/rbdv");
var rules = {
    // A basic string configuration
    'username': {
        type: 'string'
    },

    // A basic number configuration
    'id': {
        type: 'number'
    },
};

var rbdv = new RBDV(rules, true); // RBDV(rules, is_verbose)

console.log('Test #1:');
var data = "admin";
console.log(rbdv.isValid(data, 'username'));

console.log('\nTest #2:');
data = 123;
console.log(rbdv.isValid(data, 'id'));

console.log('\nTest #3:');
data = 321;
console.log(rbdv.isValid(data, 'username'));

console.log('\nTest #4:');
data = "asdf";
console.log(rbdv.isValid(data, 'id'));

Output:

Test #1:
true

Test #2:
true

Test #3:
-----------Validator Error-----------
Object Path: data
Expected: string
Got: number
Value: 321
-------------------------------------
false

Test #4:
-----------Validator Error-----------
Object Path: data
Expected: number
Got: string
Value: asdf
-------------------------------------
false

Example using much more complex configuration:

var RBDV = require("@ibrokhim/rbdv");
var rules = {
    'user_detail': {
        type: 'object',
            props: {
            name: {type: 'string'},
            surname: {type: 'string'},
            isActive: {type: 'boolean'},
            contact_info: {
                type: 'object',
                    props: {
                    email: {type: 'string'},
                    phone: {type: 'string'}
                }
            }
        }
    }
};

var rbdv = new RBDV(rules, true); // RBDV(rules, is_verbose)

console.log('Test #1:');
var data = {
    'name': 'Tom',
    'surname': 'Jerry'
};
console.log(rbdv.isValid(data, 'user_detail'));

console.log('\nTest #2:');
data = {
    'name': 'Tom',
    'surname': 'Jerry',
    'isActive': true,
    contact_info: '[email protected]'
};
console.log(rbdv.isValid(data, 'user_detail'));

console.log('\nTest #3:');
data = {
    'name': 'Tom',
    'surname': 'Jerry',
    'isActive': true,
    contact_info: {
        'email': '[email protected]'
    }
};
console.log(rbdv.isValid(data, 'user_detail'));

console.log('\nTest #4:');
data = {
    'name': 'Tom',
    'surname': 'Jerry',
    'isActive': true,
    contact_info: {
        'email': '[email protected]',
        'phone': '5556667777'
    }
};
console.log(rbdv.isValid(data, 'user_detail'));

Output:

Test #1:
-----------Validator Error-----------
Object Path: data.isActive
Expected: boolean
Got: undefined
Value: undefined
-------------------------------------
-----------Validator Error-----------
Object Path: data.contact_info
Expected: object
Got: undefined
Value: undefined
-------------------------------------
false

Test #2:
-----------Validator Error-----------
Object Path: data.contact_info
Expected: object
Got: string
Value: [email protected]
-------------------------------------
false

Test #3:
-----------Validator Error-----------
Object Path: data.contact_info.phone
Expected: string
Got: undefined
Value: undefined
-------------------------------------
false

Test #4:
true

Example using single-use configuration:

var RBDV = require("@ibrokhim/rbdv");
var rbdv = new RBDV();
var singleUseRule = {
    type: 'object',
    props: {
        name: {type: 'string'},
        surname: {type: 'string'},
        isActive: {type: 'boolean'},
        contact_info: {
            type: 'object',
            props: {
                email: {type: 'string'},
                phone: {type: 'string'}
            }
        }
    }
};
var data = {
    'name': 'Tom',
    'surname': 'Jerry',
    'isActive': true,
    contact_info: {
        'email': '[email protected]',
        'phone': '5556667777'
    }
};

rbdv.setVerbose(true);

console.log(rbdv.validate(data, singleUseRule));

Output:

true

License

MIT

Support or Contact

Having trouble with this package? Contact me and I’ll help you sort it out.