Created
November 18, 2012 22:47
-
-
Save gjohnson/4107930 to your computer and use it in GitHub Desktop.
constraints
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var constraint = require('constraint'); | |
var assert = require('assert'); | |
// create engine | |
var engine = constraint() | |
.contains('whatever', 'red') | |
.equals('some.thing.really.nested', 'works'); | |
// need a custom rule? | |
function gt(a, b){ | |
return a > b; | |
} | |
engine.rule(gt, 'age', 21); | |
// object to test | |
var mock = { | |
age: 26, | |
whatever: 'redventures' | |
some: { | |
thing: { | |
really: { | |
nested: 'works' | |
} | |
} | |
} | |
}; | |
// any of the rules match | |
var a = engine.any(mock); | |
// all of the rules match | |
var b = engine.all(mock); | |
// results | |
assert(a, true); | |
assert(b, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment