specs
v0.1.0
Published
modular specs compilation framework
Downloads
1,341
Readme
Specs
specs
is a modular framework to compile specification models into javascript
functions.
Install
npm install specs
Usage
var assert = require('assert');
var specs = require('specs');
var engine = specs.engine();
var spec = engine.compile({
foo: 42,
bar: /foo+bar/
});
assert(spec({
foo: 42,
bar: 'foooooooobar'
});
Directives
Directives allow you to extend the grammar of your specification engine
engine.directive('lt', function (model) {
return function (x) { return x < model; };
});
and use them in specification models
var spec = engine.compile({ $lt: 43 });
assert(spec(42));
Modules
A module is a set of directives.
You can write your own modules or reuse existing ones.
Below are officially supported modules to come
specs-comp
: basic scalar comparison operatorsspecs-logic
: basic logic operatorsspecs-list
: basic list operators (contains, any, none of, ...)
Module usage is then like so
var engine = specs.engine('comp', 'logic', 'list');