Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

collections-x

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collections-x

ES6 collections fallback library: Map and Set.

  • 3.0.17
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
275
decreased by-48.02%
Maintainers
1
Weekly downloads
 
Created
Source

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score

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.

ParamTypeDescription
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.

ParamTypeDescription
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.

ParamTypeDescription
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.

ParamTypeDescription
callbackfunctionFunction 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.

ParamTypeDescription
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.

ParamTypeDescription
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.

ParamTypeDescription
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.

ParamTypeDescription
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.

ParamTypeDescription
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.

ParamTypeDescription
callbackfunctionFunction 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.

ParamTypeDescription
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

Keywords

FAQs

Package last updated on 05 Aug 2019

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc