Associate arbitrary data with a context (a simple plain JavaScript object)


Associate arbitrary data with a context (a simple plain JavaScript object).

Via npm on Node:

npm install simplecontext

Reference in your program:

var sc = require('simplecontext');

Create an space to store the data and contexts:

var space = sc.createSpace();

Add an item to a context:

space.assert('John', { country: 'UK' });
space.assert('Mary', { country: 'UK' });
space.assert('Ann', { country: 'UK', category: 'Beverages' });

A context is a simple JavaScript object, like { country: 'UK' } or { country: 'UK', category: 'Dairy' }. Internally, { country: 'UK', category: 'Dairy' } and { category: 'Dairy', country: 'UK' } are the same context.

Retrieve the items associated to a context:

var result = space.retrieve({ country: 'UK' }); // [ 'John', 'Mary' ] 
var result = space.retrieve({ country: 'Japan' }); // [ ] 
var result = space.retrieve({ country: 'UK', category: 'Beverages' }); // [ 'John', 'Mary', 'Ann' ] 

Notice the use of inheritance in the last retrieve.

Retract an item from a context:

space.retract('John', { country: 'UK' });

Remove a context:

space.remove({ category: 'Beverages', country: 'UK' });
git clone git://
cd SimpleContext
npm install
npm test



Feel free to file issues and submit pull requests � contributions are welcome<

If you submit a pull request, please be sure to add or update corresponding test cases, and ensure that npm test continues to pass.