Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "set", | ||
"version": "1.0.1", | ||
"description": "An implementation of Sets in JavaScript", | ||
"version": "1.0.0", | ||
"repository": "git://github.com/gkatsev/set.js.git", | ||
"author": "Gary Katsevman <me@gkatsev.com> (gkatsev.com)", | ||
"main": "set", | ||
"scripts": { | ||
"test": "vows" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gkatsev/set.js" | ||
}, | ||
"bugs": "https://github.com/gkatev/set.js/issues", | ||
"directories": { | ||
"lib": "." | ||
}, | ||
"scripts": { | ||
"test": "vows tests.js" | ||
"keywords": [ | ||
"set", | ||
"intersect", | ||
"union", | ||
"difference" | ||
], | ||
"author": "Gary Katsevman <me@gkatsev.com> (gkatsev.com)", | ||
"license": { | ||
"type": "MIT", | ||
"url": "http://gkatsev.mit-license.org/" | ||
}, | ||
"readmeFilename": "README.md", | ||
"devDependencies": { | ||
"vows": "*" | ||
}, | ||
"engines": { | ||
"node": "*" | ||
} | ||
} | ||
} |
# Set.js | ||
[![Dependency Status](https://david-dm.org/gkatsev/set.js.png)](https://david-dm.org/gkatsev/set.js) | ||
[![devDependency Status](https://david-dm.org/gkatsev/set.js/dev-status.png)](https://david-dm.org/gkatsev/set.js#info=devDependencies) | ||
[![NPM](https://nodei.co/npm/set.png)](https://nodei.co/npm/set/) | ||
I created this because I noticed that there were no actual set object implementations in JavaScript and also to learn a bit more about creating node modules. | ||
I created this because I could not find any actual set object implementations in JavaScript that included functions such as union and intersect. Also, I wanted to learn a bit more about creating node modules. | ||
This uses [vows](http://vowsjs.org/) | ||
@@ -34,1 +38,13 @@ ## Usage | ||
`Set#find` return an array with all items that match the predicate. | ||
## License | ||
The MIT License (MIT) | ||
Copyright (c) 2011 George "Gary" Katsevman | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
197
set.js
@@ -0,4 +1,29 @@ | ||
/* The MIT License (MIT) | ||
Copyright (c) 2011-2012 George "Gary" Katsevman | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE S | ||
OFTWARE. | ||
*/ | ||
var Set = function () { | ||
var value = true | ||
, unique = function(iset){ | ||
var set = {} | ||
var set = Object.create(null) | ||
, i = 0 | ||
@@ -15,105 +40,103 @@ , l = iset.length | ||
var Set = function(input){ | ||
var set | ||
this._set = unique(input || []) | ||
} | ||
this.contains = function(prop){ | ||
return !!set[prop] | ||
} | ||
Set.prototype.contains = function(prop){ | ||
return !!this._set[prop] | ||
} | ||
this.empty = function(){ | ||
return Object.keys(set).length == 0 | ||
} | ||
Set.prototype.empty = function(){ | ||
return Object.keys(this._set).length == 0 | ||
} | ||
this.size = function(){ | ||
return Object.keys(set).length | ||
} | ||
Set.prototype.size = function(){ | ||
return Object.keys(this._set).length | ||
} | ||
this.get = function(){ | ||
return Object.keys(set) | ||
} | ||
Set.prototype.get = function(){ | ||
return Object.keys(this._set) | ||
} | ||
this.add = function(prop){ | ||
set[prop] = value | ||
} | ||
Set.prototype.add = function(prop){ | ||
this._set[prop] = value | ||
} | ||
this.remove = function(prop){ | ||
delete set[prop] | ||
} | ||
Set.prototype.remove = function(prop){ | ||
delete this._set[prop] | ||
} | ||
this.union = function(iset){ | ||
return new Set(this.get().concat(iset.get())) | ||
} | ||
Set.prototype.union = function(iset){ | ||
return new Set(this.get().concat(iset.get())) | ||
} | ||
this.intersect = function(iset){ | ||
var items = iset.get() | ||
, i = 0 | ||
, l = items.length | ||
, oset = new Set() | ||
, prop | ||
for(; i < l; i++){ | ||
prop = items[i] | ||
if(this.contains(prop)){ | ||
oset.add(prop) | ||
} | ||
Set.prototype.intersect = function(iset){ | ||
var items = iset.get() | ||
, i = 0 | ||
, l = items.length | ||
, oset = new Set() | ||
, prop | ||
for(; i < l; i++){ | ||
prop = items[i] | ||
if(this.contains(prop)){ | ||
oset.add(prop) | ||
} | ||
items = this.get() | ||
for(i = 0, l = items.length; i < l; i++){ | ||
prop = items[i] | ||
if(iset.contains(prop)){ | ||
oset.add(prop) | ||
} | ||
} | ||
items = this.get() | ||
for(i = 0, l = items.length; i < l; i++){ | ||
prop = items[i] | ||
if(iset.contains(prop)){ | ||
oset.add(prop) | ||
} | ||
return oset | ||
} | ||
return oset | ||
} | ||
this.difference = function(iset){ | ||
var items = iset.get() | ||
, i = 0 | ||
, l = items.length | ||
, oset = this.union(iset) | ||
, prop | ||
for(; i < l; i++){ | ||
prop = items[i] | ||
if(this.contains(prop)){ | ||
oset.remove(prop) | ||
} | ||
Set.prototype.difference = function(iset){ | ||
var items = iset.get() | ||
, i = 0 | ||
, l = items.length | ||
, oset = this.union(iset) | ||
, prop | ||
for(; i < l; i++){ | ||
prop = items[i] | ||
if(this.contains(prop)){ | ||
oset.remove(prop) | ||
} | ||
return oset | ||
} | ||
return oset | ||
} | ||
this.subset = function(iset){ | ||
var items = iset.get() | ||
, subset = false | ||
, i = 0 | ||
, l = items.length | ||
for(; i < l; i++){ | ||
prop = items[i] | ||
if(this.contains(prop)){ | ||
subset = true | ||
} | ||
else{ | ||
subset = false | ||
break | ||
} | ||
Set.prototype.subset = function(iset){ | ||
var items = iset.get() | ||
, subset = false | ||
, i = 0 | ||
, l = items.length | ||
for(; i < l; i++){ | ||
prop = items[i] | ||
if(this.contains(prop)){ | ||
subset = true | ||
} | ||
return subset | ||
else{ | ||
subset = false | ||
break | ||
} | ||
} | ||
return subset | ||
} | ||
this.find = function(pred){ | ||
return this.get().filter(pred) | ||
} | ||
Set.prototype.find = function(pred){ | ||
return this.get().filter(pred) | ||
} | ||
this.clear = function(){ | ||
set = {} | ||
} | ||
set = unique(input || []) || {} | ||
Set.prototype.clear = function(){ | ||
this._set = Object.create(null) | ||
} | ||
@@ -125,4 +148,8 @@ | ||
return Set | ||
}() | ||
module.exports = Set; | ||
if(typeof module === 'object' && module.hasOwnProperty('exports')){ | ||
module.exports = Set; | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
0
256
50
0
0
12398
1
5
2