Welcome to Powerful Javascript Collection
Jscollection is a powerful, easy searchable, easy enumerable javascript collection implements List, Stack, Queue, FixedQueue library for JavaScript and node.js.
Installation
npm install jscollection
Manipulating a collection is just easy
var myList = new List();
myList.add(item) // Add an item in collection
myList.addRange(arrayOfItems) // Add multiple items in collection
myList.insertAt(index, item); // Insert an item at a given position
myList.removeAt(index); // Remove an item from a given position also returns the deleted item
myList.remove(item) // Remove an item from collection also returns the deleted item
myList.removeLast() // Remove the last item from collection also returns the deleted item
myList.removeAt(index) // Remove an item at specific index from collection also returns the deleted item
myList.first() // Get the first item from the collection
myList.last() // Get the last item from the collection
myList.count() // Get the size of the collection
myList.any() // Is there any items present in collection?
myList.avg() // Calculate average of values present in collection
myList.sum() // Calculate sum of values present in collection
Traverse the collection asynchronously
eachAsync(function(item,index,nextCallback){}) - traverse the collection and perform asynchronous operations for each
Example:
myDataList.eachAsync(function(item, index, next) {
insertIntoMongoDb(item, function(){
next();
});
});
Execute asyncronus functions one after another
List.exeAsync(function insertIntomongo(next){
// Do operation in mongo
next(dataReturnedFromMongo); // once you are done call next
}, function insertIntoRedis(next, dataReturnedFromMongo){
// Do operation in redis
next(dataReturnedFromRedis); // // once you are done call next
}, function onDone(next, dataReturnedFromRedis){
// call the final callback here
});
Searching and Querying your Collection
select(selector function) // Select items from collection
selectMulti(selector function) // Select items from collections where selected item is a collection/array
where(selector function) // Where condition in query
groupby(selector function) // Groupby your logic in javascript
orderByAsc(comparator function) // Sort items Ascending order
orderByDesc(comparator function) // Sort items in descending order
unique() // Collect only unique items from collection
top(count) // Collect only top N items from collection
bottom(count) // Collect last N items from collection
range(fromIndex,toIndex) // Collect all items within a range
Authors and Contributors
@somnathpanja (somnathpanja@gmail.com)
Support or Contact
Having trouble with Pages? Check out our documentation or report issue and we’ll help you sort it out.