oc

oak-check

rule based model validator

Showing:

Popularity

Downloads/wk

13

GitHub Stars

0

Maintenance

Last Commit

6yrs ago

Contributors

1

Package

Dependencies

2

Size (min+gzip)

23.1KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

oak-check

rule based model validator

oak check allows you to run "queries" against a json object in order to validate something.

Built in logical operators

  • $or
  • $and
  • $not

Built in comparison operators

  • $eq - Equals
  • $gt - Greater than
  • $gte - Greater than or equal to
  • $lt - Less than
  • $lte - Less than or equal to

Examples

Simple

    var data = {'johnny': 5},
        condition = {'$eq' : {'johnny' : 5}};
    
    processor.check(condition, data, [], function (err, result) {
        if (result) {
            console.log('found him!');
        }else {
            console.log('johnny 5 is dead');
        }
    });

Deep

    var data = {robots : {'johnny': 5}},
        condition = {'$eq' : {'robots.johnny' : 5}};
    
    processor.check(condition, data, [], function (err, result) {
        if (!result) {
            console.log('found him!');
        } else {
            console.log('johnny 5 is dead');
        }
    });

Logical

    var data = {'johnny': 6},
        condition = {'$or' :
                [
                    {'$eq' : {'johnny': 5}},
                    {'$eq' : {'johnny': 6}}
                ]};
    
    processor.check(condition, data, [], function (err, result) {
        if (result) {
            console.log('found a robot!');
        } else {
            console.log('nothing to see here');
        }
    });

Custom Operators

You can pass in custom operator functions to do evaluation on data.

    var data = {'johnny': 6},
        condition = {'$or' :
                [
                    {'$eq' : {'johnny': 5}},
                    {'$hi' : {'johnny': 6}}
                ]},
        custom = {
            '$hi' : function (condition, data, customConditions, callback) {
                setTimeout(function () {
                    callback (null, true);
                }, 100);
            }
        };
    
    processor.check(condition, data, custom, function (err, result) {
        if (!result) {
            done();
        } else {
            done('failed should have passed');
        }
    });

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100