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

set

Package Overview
Dependencies
Maintainers
1
Versions
4
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 1.0.0 to 1.0.1

LICENSE

30

package.json
{
"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": "*"
}
}
}

18

README.md
# 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.

@@ -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;
}
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