Speccy
Simple JavaScript specification pattern for NodeJS and Browserify apps.
Basic Use
npm install speccy
to install it.
function HasValue(attr){
this.attr = attr;
}
HasValue.prototype = Object.create(Specification);
HasValue.prototype.isSatisfiedBy = function(obj){
if (!obj){ return false; }
return obj[this.attr] !== undefined;
};
var hasFoo = new HasValue("foo");
var hasBar = new HasValue("Bar");
var hasBaz = new HasValue("Baz");
var mySpec = hasFoo.and(
(
hasBar.not(hasBaz)
).or(
hasBaz.not(hasBar)
)
);
console.log(mySpec.isSatisfiedBy({
foo: "something",
bar: "another thing"
}));
console.log(mySpec.isSatisfiedBy({
foo: "something",
baz: "third thing"
}));
console.log(mySpec.isSatisfiedBy({
foo: "something",
bar: "another thign",
baz: "third thing"
}));
For more examples, see the tests in the tests
folder.
Legal Junk
Copyright ©2014 Muted Solutions, LLC. All Rights Reserved.
Distributed under MIT License.