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

set-component

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

set-component

Set container

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-53.3%
Maintainers
1
Weekly downloads
 
Created
Source

set

Generic Set container

Installation

$ component install component/set

Example

var Set = require('set');
var set = new Set;

set.add('foo');
set.add('foo');
set.add({ some: 'object' });
set.remove('foo');

set.values();
// => [{ some: 'object' }]

Equality

Set supports an .equals(other) method when present, for example you may then add two separate User instances that are identified as being the same via their name:

User.prototype.equals = function(user){
  return this.name == user.name;
};

API

Set()

Create a new Set.

Set(values)

Create a new Set with values array. Duplicates will be removed.

Set#add(value)

Add value to the set.

Set#remove(value)

Remove value from the set, returning true when present, otherwise returning false.

Set#has(value)

Check if value is present.

Set#values()

Return an array of values.

Aliased as .toJSON().

Set#each(fn)

Iterate each member and invoke fn(val).

Set#size()

Return the set size.

Set#clear()

Empty the set and return the old values array.

Set#isEmpty()

Check if the set is empty.

Set#union(set)

Perform a union with set and return a new Set.

Set#intersect(set)

Perform an intersection with set and return a new Set.

License

MIT

Keywords

FAQs

Package last updated on 07 Nov 2012

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