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

collections-x

v3.1.2

Published

ES6 collections fallback library: Map and Set.

Readme

collections-x

ES6 collections fallback library: Map and Set.

collections-x.isMapboolean

Determine if an object is a Map.

Kind: static property of collections-x
Returns: boolean - true if the object is a Map, else false.

| Param | Type | Description | | ------ | --------------- | ------------------- | | object | * | The object to test. |

Example

import {isMap} from 'collections-x';

const m = new MapConstructor();

console.log(isMap([])); // false
console.log(isMap(true)); // false
console.log(isMap(m)); // true

collections-x.isSetboolean

Determine if an object is a Set.

Kind: static property of collections-x
Returns: boolean - true if the object is a Set, else false.

| Param | Type | Description | | ------ | --------------- | ------------------- | | object | * | The object to test. |

Example

import {isSet} from 'collections-x';

const s = new SetConstructor();

console.log(isSet([])); // false
console.log(isSet(true)); // false
console.log(isSet(s)); // true

collections-x.MapConstructor

Kind: static property of collections-x

map.clearObject

The clear() method removes all elements from a Map object.

Kind: instance property of Map
Returns: Object - The Map object.
Example

import {MapConstructor} from 'collections-x';

const myMap = new MapConstructor();
myMap.set('bar', 'baz');
myMap.set(1, 'foo');

console.log(myMap.size); // 2
console.log(myMap.has('bar')); // true

myMap.clear();

console.log(myMap.size); // 0
console.log(myMap.has('bar')); // false

map.deleteboolean

The delete() method removes the specified element from a Map object.

Kind: instance property of Map
Returns: boolean - Returns true if an element in the Map object has been removed successfully.

| Param | Type | Description | | ----- | --------------- | ----------------------------------------------------- | | key | * | The key of the element to remove from the Map object. |

Example

import {MapConstructor} from 'collections-x';

const myMap = new MapConstructor();
myMap.set('bar', 'foo');

myMap.delete('bar'); // Returns true. Successfully removed.
myMap.has('bar'); // Returns false.
// The "bar" element is no longer present.

map.entriesObject

The entries() method returns a new Iterator object that contains the [key, value] pairs for each element in the Map object in insertion order.

Kind: instance property of Map
Returns: Object - A new Iterator object.
Example

import {MapConstructor} from 'collections-x';
const myMap = new MapConstructor();
myMap.set('0', 'foo');
myMap.set(1, 'bar');
myMap.set({}, 'baz');

const mapIter = myMap.entries();

console.log(mapIter.next().value); // ["0", "foo"]
console.log(mapIter.next().value); // [1, "bar"]
console.log(mapIter.next().value); // [Object, "baz"]

map.forEachObject

The forEach() method executes a provided function once per each key/value pair in the Map object, in insertion order.

Kind: instance property of Map
Returns: Object - The Map object.

| Param | Type | Description | | --------- | --------------------- | --------------------------------------------- | | callback | function | Function to execute for each element. | | [thisArg] | * | Value to use as this when executing callback. |

Example

import {MapConstructor} from 'collections-x';

function logElements(value, key, map) {
  console.log('m[' + key + '] = ' + value);
}

const myMap = new MapConstructor([['foo', 3], ['bar', {}], ['baz', undefined]]);
myMap.forEach(logElements);
// logs:
// "m[foo] = 3"
// "m[bar] = [object Object]"
// "m[baz] = undefined"

map.get*

The get() method returns a specified element from a Map object.

Kind: instance property of Map
Returns: * - Returns the element associated with the specified key or undefined if the key can't be found in the Map object.

| Param | Type | Description | | ----- | --------------- | ----------------------------------------------------- | | key | * | The key of the element to return from the Map object. |

Example

import {MapConstructor} from 'collections-x';

const myMap = new MapConstructor();
myMap.set('bar', 'foo');

myMap.get('bar'); // Returns "foo".
myMap.get('baz'); // Returns undefined.

map.keysObject

The keys() method returns a new Iterator object that contains the keys for each element in the Map object in insertion order.

Kind: instance property of Map
Returns: Object - A new Iterator object.
Example

import {MapConstructor} from 'collections-x';

const myMap = new MapConstructor();
myMap.set('0', 'foo');
myMap.set(1, 'bar');
myMap.set({}, 'baz');

const mapIter = myMap.keys();

console.log(mapIter.next().value); // "0"
console.log(mapIter.next().value); // 1
console.log(mapIter.next().value); // Object

map.setObject

The set() method adds a new element with a specified key and value to a Map object.

Kind: instance property of Map
Returns: Object - The Map object.

| Param | Type | Description | | ----- | --------------- | -------------------------------------------------- | | key | * | The key of the element to add to the Map object. | | value | * | The value of the element to add to the Map object. |

Example

import {MapConstructor} from 'collections-x';

const myMap = new MapConstructor();

// Add new elements to the map
myMap.set('bar', 'foo');
myMap.set(1, 'foobar');

// Update an element in the map
myMap.set('bar', 'fuuu');

map.size : number

The value of size is an integer representing how many entries the Map object has.

Kind: instance property of Map
Example

import {MapConstructor} from 'collections-x';

const myMap = new MapConstructor();
myMap.set(1, true);
myMap.set(5, false);
myMap.set('some text', 1);

console.log(myMap.size); // 3

map.valuesObject

The values() method returns a new Iterator object that contains the values for each element in the Map object in insertion order.

Kind: instance property of Map
Returns: Object - A new Iterator object.
Example

import {MapConstructor} from 'collections-x';

const myMap = new MapConstructor();
myMap.set('0', 'foo');
myMap.set(1, 'bar');
myMap.set({}, 'baz');

const mapIter = myMap.values();

console.log(mapIter.next().value); // "foo"
console.log(mapIter.next().value); // "bar"
console.log(mapIter.next().value); // "baz"

map.has(key)boolean

The has() method returns a boolean indicating whether an element with the specified key exists or not.

Kind: instance method of Map
Returns: boolean - Returns true if an element with the specified key exists in the Map object; otherwise false.

| Param | Type | Description | | ----- | --------------- | -------------------------------------------------------------- | | key | * | The key of the element to test for presence in the Map object. |

Example

import {MapConstructor} from 'collections-x';

const myMap = new MapConstructor();
myMap.set('bar', 'foo');

myMap.has('bar'); // returns true
myMap.has('baz'); // returns false

map.symIt()Object

The initial value of the @@iterator property is the same function object as the initial value of the entries property.

Kind: instance method of Map
Returns: Object - A new Iterator object.
Example

import {MapConstructor, symIt} from 'collections-x';

const myMap = new MapConstructor();
myMap.set('0', 'foo');
myMap.set(1, 'bar');
myMap.set({}, 'baz');

var mapIter = myMap[symIt]();

console.log(mapIter.next().value); // ["0", "foo"]
console.log(mapIter.next().value); // [1, "bar"]
console.log(mapIter.next().value); // [Object, "baz"]

collections-x.SetConstructor

Kind: static property of collections-x

set.addObject

The add() method appends a new element with a specified value to the end of a Set object.

Kind: instance property of Set
Returns: Object - The Set object.

| Param | Type | Description | | ----- | --------------- | ------------------------------------------------------------ | | value | * | Required. The value of the element to add to the Set object. |

Example

import {SetConstructor} from 'collections-x';

const mySet = new SetConstructor();

mySet.add(1);
mySet.add(5).add('some text'); // chainable

console.log(mySet);
// Set [1, 5, "some text"]

set.clearObject

The clear() method removes all elements from a Set object.

Kind: instance property of Set
Returns: Object - The Set object.
Example

import {SetConstructor} from 'collections-x';

const mySet = new SetConstructor();
mySet.add(1);
mySet.add('foo');

console.log(mySet.size); // 2
mySet.has('foo'); // true

mySet.clear();

console.log(mySet.size); // 0
mySet.has('bar'); // false

set.deleteboolean

The delete() method removes the specified element from a Set object.

Kind: instance property of Set
Returns: boolean - Returns true if an element in the Set object has been removed successfully; otherwise false.

| Param | Type | Description | | ----- | --------------- | ------------------------------------------------------- | | value | * | The value of the element to remove from the Set object. |

Example

import {SetConstructor} from 'collections-x';

const mySet = new SetConstructor();
mySet.add('foo');

mySet.delete('bar'); // Returns false. No "bar" element found
//to be deleted.
mySet.delete('foo'); // Returns true.  Successfully removed.

mySet.has('foo'); // Returns false. The "foo" element is no
//longer present.

set.forEachObject

The forEach() method executes a provided function once per each value in the Set object, in insertion order.

Kind: instance property of Set
Returns: Object - The Set object.

| Param | Type | Description | | --------- | --------------------- | --------------------------------------------- | | callback | function | Function to execute for each element. | | [thisArg] | * | Value to use as this when executing callback. |

Example

function logSetElements(value1, value2, set) {
  console.log('s[' + value1 + '] = ' + value2);
}

new SetConstructor(['foo', 'bar', undefined]).forEach(logSetElements);

// logs:
// "s[foo] = foo"
// "s[bar] = bar"
// "s[undefined] = undefined"

set.size : number

The value of size is an integer representing how many entries the Set object has.

Kind: instance property of Set
Example

import {SetConstructor} from 'collections-x';

const mySet = new SetConstructor();
mySet.add(1);
mySet.add(5);
mySet.add('some text');

console.log(mySet.size); // 3

set.entries()Object

The entries() method returns a new Iterator object that contains an array of [value, value] for each element in the Set object, in insertion order. For Set objects there is no key like in Map objects. However, to keep the API similar to the Map object, each entry has the same value for its key and value here, so that an array [value, value] is returned.

Kind: instance method of Set
Returns: Object - A new Iterator object.
Example

import {SetConstructor} from 'collections-x';

const mySet = new SetConstructor();
mySet.add('foobar');
mySet.add(1);
mySet.add('baz');

const setIter = mySet.entries();

console.log(setIter.next().value); // ["foobar", "foobar"]
console.log(setIter.next().value); // [1, 1]
console.log(setIter.next().value); // ["baz", "baz"]

set.has(value)boolean

The has() method returns a boolean indicating whether an element with the specified value exists in a Set object or not.

Kind: instance method of Set
Returns: boolean - Returns true if an element with the specified value exists in the Set object; otherwise false.

| Param | Type | Description | | ----- | --------------- | ------------------------------------------------- | | value | * | The value to test for presence in the Set object. |

Example

import {SetConstructor} from 'collections-x';

const mySet = new SetConstructor();
mySet.add('foo');

mySet.has('foo'); // returns true
mySet.has('bar'); // returns false

set.keys()Object

The keys() method is an alias for the values method (for similarity with Map objects); it behaves exactly the same and returns values of Set elements.

Kind: instance method of Set
Returns: Object - A new Iterator object.
Example

import {SetConstructor} from 'collections-x';

const mySet = new SetConstructor();
mySet.add('foo');
mySet.add('bar');
mySet.add('baz');

const setIter = mySet.keys();

console.log(setIter.next().value); // "foo"
console.log(setIter.next().value); // "bar"
console.log(setIter.next().value); // "baz"

set.values()Object

The values() method returns a new Iterator object that contains the values for each element in the Set object in insertion order.

Kind: instance method of Set
Returns: Object - A new Iterator object.
Example

import {SetConstructor} from 'collections-x';

const mySet = new SetConstructor();
mySet.add('foo');
mySet.add('bar');
mySet.add('baz');

const setIter = mySet.values();

console.log(setIter.next().value); // "foo"
console.log(setIter.next().value); // "bar"
console.log(setIter.next().value); // "baz"

set.symIt()Object

The initial value of the @@iterator property is the same function object as the initial value of the values property.

Kind: instance method of Set
Returns: Object - A new Iterator object.
Example

import {SetConstructor, symIt} from 'collections-x';

const mySet = new SetConstructor();
mySet.add('0');
mySet.add(1);
mySet.add({});

const setIter = mySet[symIt]();

console.log(setIter.next().value); // "0"
console.log(setIter.next().value); // 1
console.log(setIter.next().value); // Object

collections-x.symIt

The iterator identifier that is in use.

type {Symbol|string}

Kind: static property of collections-x