specs

modular specs compilation framework

npm install specs
1 downloads in the last week
4 downloads in the last month

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 operators
  • specs-logic : basic logic operators
  • specs-list : basic list operators (contains, any, none of, ...)

Module usage is then like so

var engine = specs.engine('comp', 'logic', 'list');
npm loves you