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

Set

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Set - npm Package Compare versions

Comparing version 0.3.1 to 0.4.0

2

package.json

@@ -9,3 +9,3 @@ {

],
"version": "0.3.1",
"version": "0.4.0",
"repository": {

@@ -12,0 +12,0 @@ "type": "git",

@@ -12,15 +12,11 @@ # Set

```
npm install Set
```
npm install Set
For the browser:
```
ender build Set
```
ender build Set
## Usage
```js
~~~ javascript
var Set = require('Set');

@@ -41,54 +37,65 @@

console.log(alpha.contains('c'));
```
~~~
## API
```js
Set(obj)
```
~~~ javascript
new Set(obj)
~~~
Create a set from an array or object.
```js
~~~ javascript
new Set(contains)
~~~
Create a set from a function.
This good for creating infinite sets. `contains` is a function that takes one
argument and returns `true` if it is in the set and `false` otherwise. It works
well together with `set.add()` and `set.remove()`, but not with `set.toArray()`
and `set.toString()`.
~~~ javascript
set.add(val, ...)
```
~~~
Add one or more elements to the set.
```js
~~~ javascript
set.addAll(array)
```
~~~
Add all elements from array to the set.
```js
~~~ javascript
set.remove(val, ...)
set.delete(val)
```
~~~
Remove one or more elements from the set.
```js
~~~ javascript
set.contains(val)
set.has(val)
```
~~~
Check if the set contains `val`.
```js
~~~ javascript
set.size()
```
~~~
Returns the size of the set.
```js
~~~ javascript
set.toArray()
set['*values']()
```
~~~
Returns the elements of the set as an Array.
```js
~~~ javascript
set.toString()
```
~~~

@@ -99,2 +106,3 @@ Serialize the set.

~~~
Copyright © 2012 Paul Vorbach

@@ -118,1 +126,2 @@

SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
~~~

@@ -5,2 +5,3 @@ module.exports = Set;

this.set = {};
this.infContains = function () { return true; };

@@ -13,2 +14,4 @@ if (typeof set == 'object') {

this.set = set;
} else if (typeof set == 'function') {
this.infContains = set;
} else if (typeof set != 'undefined')

@@ -19,3 +22,3 @@ throw new Error('set must be either an array or an object.');

Set.prototype.contains = function contains(val) {
return this.set[val] ? true : false;
return this.set[val] ? true : false && this.infContains(val);
};

@@ -22,0 +25,0 @@ Set.prototype.has = Set.prototype.contains;

var Set = require('./set.js');
var alpha = new Set([ 'a', 'b', 'c' ]);
var beta = new Set(function contains(val) { return val > 0; });

@@ -5,0 +6,0 @@ console.log(alpha.size());

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