Glomb
Extended wrapper of the built-in Array for a MongoDB-like handling
Are there any improvements, hints or bug fixes? Let me know!
Introduction
This module is implemented in ECMAScript 6 (v2015). Therefore the development dependencies are based on babel
.
Additionally eslint
and mocha
are used to grant a high quality implementation. Furthermore there are used some experimental features:
- Function bind
::
- Decorators
- Class fields and static properties
- Object spread properties
Glomb ['glɔmb] is Swabian term for something that doesn't work well or is difficult to handle. Should be an oxymoron/paradox :)
Installation
For installation use the Node Package Manager:
// production version with ES5 syntax
$ npm install --save glomb
or clone the repository:
// development version with ES6 syntax
$ git clone https://github.com/felixheck/Glomb
Usage
Every method tagged with @immutable
returns a new instance of an array or object.
Contruct new instance
First you have to import the module:
// ES6 module syntax;// Node traditional syntaxvar Glomb = default;
Afterwards it is possible to create an empty instance:
const todos = ;
Alternatively pass single parameters of Object
type:
const todos = todoNo1 todoNo2;
Or make use of destructuring and pass an array of objects:
const todos = ...listOfTodos;
Glomb.all()
Get list of stored objects:
/*** @immutable** @returns {Array.<?Object>} List of stored data*/todosall;
Glomb.get()
Get stored object by MongoDB _id
:
/*** @immutable** @param* @returns*/const dataId = '507f191e810c19729de860ea';todos;
Glomb.find()
Get stored objects matching a MongoDB _id
or custom filter:
/*** @immutable** @param {String | Function} cond The conditions to be searched for* @returns {Array.<?Object>} List of matched items*/todos;
Glomb.has()
Check if stored data containing at least one matching object:
/*** @param {String | Function} cond The conditions to be searched for* @returns*/todos;
Glomb.insert()
Add new items to internal data storage:
/*** @immutable** @param {Array.<?Object>} items The items to be pushed* @returns*/todos;
Glomb.update()
Update matching items with passed fields:
/*** @immutable** @param {String | Function} cond The conditions to be searched for* @param* @returns {Array.<?Object>} List of data including the updated items*/;const increment decrement unset = Glomboperations;todos;
Glomb.remove()
Remove matching items from internal data storage:
/*** @immutable* @param {String | Function} cond The conditions to be searched for* @returns {Array.<?Object>} The updated stored data*/todos;
Glomb.reset()
Purge the internal data storage
/*** @immutable** @returns*/todos;
Testing
First you have to install all dependencies:
$ npm install
To execute all unit tests once, use:
$ npm test
or to run the tests after each update, use:
$ npm start
To get information about the test coverage, use:
$ npm run coverage
Contribution
Fork this repository and push in your ideas.
Do not forget to add corresponding tests to keep up 100% test coverage.
License
The MIT License
Copyright (c) 2016 Felix Heck
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.