Comparing version 0.3.1 to 0.4.0
@@ -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()); |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
6466
71
124
0