Collec
Simple JavaScript collections for database models
Install
npm install collec --save
Browser global
This library requires lodash.
<script src='scripts/lodash.js'></script>
<script src='scripts/collec.js'></script>
API
Id keys
All items in the collection must have an id key e.g. 'id'. By default Collect assumes 'id'. See setKey
below to change this.
new
var records = id: 1 label: 'Sam' id: 2 label: 'Tess';var col = ;
add
Add items to the collection. Takes one item or an array of items.
colcol
all
Get all items from the collection.
var items = colall
count
Get the size of the collection
col.count()
filter
Returns a filtered collection using a filtering function
var items = col.filter(function (item) {
return item.age > 20;
})
get
Get one item by id
var item = col
replace
Replaces one item or many. This discards any previous data from the replace items.
colcol
remove
Remove one item or many using the id.
colcol
update
Updates one item or many. This merges the given data with the existing one.
colcol
setKey
Set the key used for finding items e.g. '_id'. By default 'id' is assumed.
col
Test
npm test
Build
gulp