Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
collectionize
Advanced tools
A lightweight collection management library. Requires Lodash.
bower install collectionize
npm install collectionize
var Things = Collectionize('things');
Things.add({ id: 2, color: 'blue', shape: 'square' });
Things.add({ id: 3, color: 'red', shape: 'circle' });
Things.add({ id: 5, color: 'green', shape: 'polygon' });
Things.add({ id: 6, color: 'blue', shape: 'triangle' });
Things.size();
// 4
Things.search({ color: 'blue' });
// [{ id: 2, color: 'blue', shape: 'square' }, { id: 6, color: 'blue', shape: 'triangle' }]
Things.get({ color: 'blue' });
// [{ id: 2, color: 'blue', shape: 'square' }]
Things.index({ id: 3 });
// 1
Things.update({ id: 3, color: 'yellow' });
// [{ id: 3, color: 'yellow', shape: 'circle' }]
Add an object to the collection.
Things.add({ id: 2, color: 'blue', shape: 'square' });
// undefined
Save the collection to localStorage. Assumes localStorage exists, meaning there is no bundled polyfill. If the collection includes DOM elements, those are dropped, and functions are converted to strings.
Things.clientSave()
Load the collection from localStorage. Assumes localStorage exists, meaning there is no bundled polyfill.
Things.clientSave()
Things.flush()
Things.db = Things.clientLoad()
Flush out or replace the collection.
Things.flush()
Alias for the Lodash find
method.
Increments the property
number or sets it to zero if it doesn't exist.
Things.incr({ id: 2 }, 'id');
// undefined
Alias for the Lodash findIndex
method.
Returns true
if the filtered query returns empty, otherwise returns false
.
Things.isEmpty({ color: 'yellow' });
// true
Alias for the Lodash size
method.
Change the order of an object in the collection.
Things.move(1, 2);
If defined, onAdd
will decorate the object before adding it to the collection.
Things.onAdd = function (obj) {
obj.hello = true;
};
Things.add({ id: 123 });
// [{ id: 123, hello: true }]
Remove all matching elements from the collection.
// Remove object with id 3
Things.remove({ id: 3 });
// Remove all squares
Things.remove({ shape: 'square' });
Alias for the Lodash filter
method.
Updates all matching objects by property, or adds object if no matches are found.
// Change color to 'red' for object with id '2'
Things.update({ id: 2, color: 'red' });
// Change all squares to color 'red'
Things.update({ shape: 'square', color: 'red' }, 'shape');
// Change all 'blue' colors to 'green'
Things.update({ color: 'green' }, { color: 'blue' });
at
, each
, every
, filter
, find
, findIndex
, findLastIndex
, first
, last
, map
, max
, min
, pluck
, reduce
, reduceRight
, reject
, sample
, size
, shuffle
, some
, sortBy
, where
Collectionize simply decorates your collection with these methods, meaning instead of _.filter(Things, query)
you would write Things.filter(query)
.
First install bower and npm dependencies:
npm install
bower install
npm test
MIT. Copyright © 2014 Andrew Childs.
FAQs
A lightweight JS model/collection library.
The npm package collectionize receives a total of 260 weekly downloads. As such, collectionize popularity was classified as not popular.
We found that collectionize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.