storaq
v1.0.0
Published
storage library with list/dictionary functionality
Downloads
3
Readme
storaq
Library for storing, querying and validating data in lists or dictionaries.
Simple:
const Lyst = require('storaq').Lyst;
var list = new Lyst();
list.add({
name: 'Steve',
type: 'Human',
items: [ 'apple', 'car', 'elephant' ],
pet: {
name: 'John',
type: 'Dog'
}
});
var steve = list.findOne({ pet: { name: 'John' }});
Optional item validation by custom structure definition:
const Diqt = require('storaq').Diqt;
var diqt = new Diqt({
type: 'object',
strict: false,
structure: {
name: 'string',
items: 'array',
pet: {
name: 'string',
type: 'any'
}
}
});
diqt.set('steve', steve); // works
diqt.set('john', steve.pet); // throws error
Item Definition Explanation:
/*
acceptable type strings:
* 'any'
* 'object'
* 'array' // uses Array.isArray() for validation
* 'number',
* 'string',
* 'boolean'
*/
itemDefinition = {
type: 'any',
strict: true, /* = ONLY given structure keys allowed.
false = structure keys required, but additional ones allowed */
structure: {
name: 'string',
something: 'any',
myArray: 'array', // array content will NOT be checked
someObject: 'object', // 'object' keys will just be validated with typeof, but
subStructure: { // sub structures like this will be recursively checked.
name: 'string',
number: 'number'
}
}
};