Socket
Book a DemoInstallSign in
Socket

collo

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collo

A simple npm utility package for managing collection functions

1.5.5
latest
Source
npmnpm
Version published
Weekly downloads
18
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Collo | An npm package for managing collection functions

(Pronounced Call-O)! Super lightweight (No dependencies) utility package for dealing with in memory collections. It's like Mongoose and Lodash in one. It's like Collections Lodash [Col Lo].

Getting started

  • From Command Line run npm i -S collo
import Collo from 'collo';

const myCollection = [
    {
        id: 1,
        name: 'pigeon'
    },
    {
        id: 2,
        name: 'badger'
    },
    {
        id: 3,
        name: 'squirrel'
    }
];

const collection = new Collo(myCollection);

Usage

To Promisify the response : After you instantiate Collo, and before you use the api, trigger promisification. You can use chaining or you can call collection.promisify() by itself. The same is true of unpromisify.

const collection = new Collo(myCollection);

collection
    .promisify()
    .list()
    .then(items=>console.log(items))
    .catch(err=>console.log(err));

New collections are Observable.

There is a next and error fn on the instance that streams results on change or on error respectively.

collection
	.subscribe(
		res=>console.log('NEXT ',res),
		err=>console.log('ERROR ',err)
	);
	
	
collection
	.next(res=>console.log(res))
	.error(err=>console.log(err));

collection.promisify

Promisify the responses

collection.promisify()

collection.unPromisify

Un promisify the responses. So normal returns are triggered on api calls

collection.unPromisify()

collection.getTheIndexOf

Get the index of an item by key/value

const response = collection.getTheIndexOf({id:1})

collection.list

List all the items in the collection instance

const response = collection.list()

collection.findWhere

Pluck an item by key/value

const response = collection.findWhere({id:1})

collection.exists

Return a Boolean true if the item is in the collection, or false if not

const response = collection.exists({id:1})

collection.insert

Insert an item at the end of the stack. Returns the collection after mutation.

const response = collection.insert({
    id: 3,
    name: 'Paki Paki'
})

collection.insertAtIndex

Splice in an item at a certain index. Returns the collection after mutation

const response = collection.insertAtIndex({
    id: 3,
    name: 'Paki Paki'
},index)

collection.upsert

Super handy upsert function. If the key/value is found then the data is updated, otherwise it's pushed into the stack. Returns the collection after mutation.

const response = collection.upsert({id:3},{
    id: 3,
    name: 'Paki Paki'
})

collection.updateWhere

Update an item where the key/value match an item in the collection. Returns the collection after mutation.

const response = collection.updateWhere({id:2},{
    id: 2,
    name: 'Mama Chiggy'
})

collection.removeWhere

Remove an item where the key/value matches an item in the collection. Returns the collection after mutation.

const response = collection.removeWhere({id:3})

Contributions

If you would like to contribute, find an issue, or have a feature request, create an Issue. Also, see CONTRIBUTORS.md for contribution instructions

Keywords

npm-package

FAQs

Package last updated on 18 Aug 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.