npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

collection-data

v1.0.1

Published

This module is an utility for managing data in the form of Map.

Readme

Collection

This module is an utility for managing data in the form of Map.

Getting Started

Prerequisites :

Node.js 12.0.0 or newer is required.

Instalation

With npm :

npm install collection-data

With yarn :

yarn add collection-data

Usage

Import the module from node_modules :

With CommonJS syntax :

const { Collection } = require("collection-data");

With module syntax :

import { Collection } = from 'collection-data';

Create a new Collection with optional data has a parameter.

Parameters :

  • data : Array of data to be added to the collection.
    • type : Array<Array<any, data>>
    • optional : Yes
const collection = new Collection([
  ["key1", value1],
  ["key2", value2],
  ["key3", value3],
]);

Collection#get(key)

Get a value from the collection by name of key.

Parameters :

  • key : The name of the key to get value from the collection (any).

Returns :

The value of the key in the collection (type : any | undefined).

collection.get("key1");

Collection#set(key, value)

Set a value in the collection.

Parameters :

  • key : The name of the key to add (any).
  • value : The value to set (any).

Returns :

The Collection (type : Collection).

collection.set("key2", value2);

Collection#has(key)

Check if a key exists in the collection.

Parameters :

  • key : The key to check (any).

Returns :

True if the key exists in the collection (type : boolean).

collection.has("key1"); // true

Collection#hasAllKeys(keys)

Check if all keys exists in the collection.

Parameters :

  • keys : The name of the keys to check (Array<any>).

Returns :

True if the keys exists in the collection (type : boolean).

collection.hasAllKeys(["key1", "key2"]);

Collection#hasAnyKey(key)

Check if at least one key exists in the collection.

Parameters :

  • keys : The name of the keys to check (Array<any>).

Returns :

True if one key exists in the collection (type : boolean).

collection.hasAnyKey(["key1", "key2"]);

Collection#delete(key)

Delete a value from the collection by name of key.

Parameters :

  • key : The name of the key to delete from the collection (any).

Returns :

True if the key was deleted (type : boolean).

collection.delete("key1");

Collection#clear()

Clear all values from the collection.

Parameters :

None

Returns :

Void (type : void).

collection.clear();

Collection#updateIf(data, filter)

Update value from the collection if the filter returns true for at least one item of collection.

Parameters :

  • data : Object with a key and value keys (key of item and newValue).
  • filter : Function with in parameters key and value.

Returns :

The collection if it was updated and null otherwise (type : Collection| null).

const filter = (k, v) => k === "key1";
collection.updateIf({ key: "key1", value: newValue }, filter);

Collection#deleteIf(key, filter)

Delete value from the collection if the filter returns true for at least one item of collection.

Parameters :

  • key : Object with a key and value keys (key of item and newValue) (any).
  • filter : Function with in parameters key and value (Function).

Returns :

The collection if data was deleted and null otherwise (type : Collection| null).

const filter = (k, v) => k === "key1";
collection.deleteIf("key1", filter);

Collection#isUnique(key)

Check if in the collection an othen element have the value of item of key.

Parameters :

  • key : The name of the key to check (any).

Returns :

True if value of this item is unique in the collection (type : boolean).

collection.isUnique("key1");

Collection#firstKey()

Get the key of first element of the collection.

Parameters :

None

Returns :

The key of the first element in the collection (type : any | null).

collection.firstKey();

Collection#first()

Get the first element of the collection.

Parameters :

None

Returns :

The value of the first element in the collection (type : any | null).

collection.first();

Collection#lastKey()

Get the key of last element of the collection.

Parameters :

None

Returns :

The key of the last element in the collection (type : any | null).

collection.lastKey();

Collection#last()

Get the last element of the collection.

Parameters :

None

Returns :

The value of the last element in the collection (type : any | null).

collection.last();

Collection#randomKey()

Get a random key from the collection.

Parameters :

None

Returns :

The random key of the collection (type : any | null).

collection.randomKey();

Collection#random()

Get a random value from the collection.

Parameters :

None

Returns :

The random value of the collection (type : any | null).

collection.random();

Collection#find(function)

Search value in collection.

Parameters :

  • function : The function to search with value and key as a parameter.

Returns :

The value found (type : any | null).

collection.find((v) => v.property == value);

Collection#isEmpty()

Check if the collection is empty.

Parameters :

None

Returns :

True if the collection is empty (type : boolean).

collection.isEmpty();

Collection#copy()

Get a copie of the collection.

Parameters :

None

Returns :

The collection copied (type : Collection).

collection.copy();

Collection#filter(function)

Return the values where the function returns true in the collection.

Parameters :

  • function : Function with in parameters the value and the key.

Returns :

A collection with the items filtered (type : Collection).

collection.filter((v, k) => {
  return v.property === other;
});

Collection#keysList()

Get a list of keys in the collection.

Parameters :

None

Returns :

An arrays of keys of the collection (type : Array<K> | null).

collection.keysList();

Collection#valuesList()

Get a list of values in the collection.

Parameters :

None

Returns :

An arrays of values of the collection (type : Array<V> | null).

collection.valuesList();

Collection#merge(other)

Merge an other collection or Map with this collection.

Parameters :

  • other : A collection or a Map

Returns :

The new collection merged (type : Collection).

collection.merge(other);

Collection#concat(other)

Concat map or collection to this collection.

Parameters :

  • other : A collection or a Map

None

Returns :

The collection (type : Collection)

collection.concat(other);

Collection#toArray()

Convert the collection to an array.

Parameters :

None

Returns :

An arrays of the collection (type : Array<{key:string, value:any}> | null).

collection.toArray();

Collection#toJSON()

Convert the collection to json.

Parameters :

None

Returns :

The collection as json (type : Object).

collection.toJSON();

Collection#each(function)

Convert the collection to json.

Parameters :

  • function : Function to execute for each element (Function).

Returns :

The collection (type : Collection).

collection.each((v) => console.log(v));