Skip to content

gchudnov/bspec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

369f966 · Feb 11, 2015

History

63 Commits
Feb 8, 2015
Feb 9, 2015
Feb 11, 2015
Feb 11, 2015
Feb 8, 2015
Feb 8, 2015
Feb 8, 2015
Feb 8, 2015
Feb 7, 2015
Feb 9, 2015
Feb 8, 2015
Feb 8, 2015
Feb 7, 2015
Feb 8, 2015

Repository files navigation

bspec

Build Status

Sauce Test Status

bspec is a small JavaScript library for structuring business rules.

A specification is a predicate that determines if an object does or does not satisfy some criteria. Business rules can be expressed as predicates and combined using operators such as "AND", "OR" and "NOT" to express more complex rules.

Example

'use strict';

var bspec = require('bspec');

/**
 * Constraint that only a customer who has specified a first given name can specify a second given name
 */
var hasFirstName = bspec.makeSync(function(customer) {
  return !!(customer && customer.first_name);
});

var hasSecondName = bspec.makeSync(function(customer) {
  return !!(customer && customer.second_name);
});

var customer1 = { first_name: 'Bob' };
var customer2 = { second_name: 'Pablo' };
var customer3 = { first_name: 'Juan', second_name: 'Pablo' };

var isCustomerNameValid = (hasSecondName.not()).or(hasFirstName);

console.log(isCustomerNameValid.isSatisfiedBy(customer1)); // true
console.log(isCustomerNameValid.isSatisfiedBy(customer2)); // false
console.log(isCustomerNameValid.isSatisfiedBy(customer3)); // true

node.js | io.js

installing with npm:

$ npm install bspec --save

In browser

To use bspec in browser, use the bspec.js file in the /dist directory of this repository, or build it manually. To build a fresh version:

$ npm install
$ gulp script

installing with bower:

$ bower install bspec

Tests

To run the tests for bspec:

$ npm test

Contact

[Grigoriy Chudnov] (mailto:[email protected])

License

Distributed under the The MIT License (MIT).

About

A JavaScript library for structuring business rules

Resources

License

Stars

Watchers

Forks

Packages

No packages published