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

hasharray

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hasharray - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

2

package.json

@@ -5,3 +5,3 @@ {

"description": "A data structure that combines a hash and an array for CRUD operations by object keys or index.",
"version": "0.0.5",
"version": "0.0.6",
"main": "index.js",

@@ -8,0 +8,0 @@ "url": "https://github.com/joshjung/hash-array",

@@ -30,6 +30,7 @@ var HashArray = function(keyFields, callback) {

if (this._map[inst]) {
throw Error('HashArray key ' + obj[key] + ' already exists');
}
this._map[inst] = obj;
if (this._map[inst].indexOf(obj) != -1) {
continue;
}
this._map[inst].push(obj);
} else this._map[inst] = [obj];
}

@@ -54,3 +55,3 @@ }

get: function(key) {
return this._map[key];
return (!(this._map[key] instanceof Array) || this._map[key].length != 1) ? this._map[key] : this._map[key][0];
},

@@ -60,2 +61,5 @@ has: function(key) {

},
hasMultiple: function(key) {
return this._map[key] instanceof Array;
},
removeByKey: function() {

@@ -65,11 +69,21 @@ var removed = [];

var key = arguments[i];
var item = this._map[key];
if (item) {
removed.push(item);
for (var ix in this.keyFields) {
var key2 = this.find(item, this.keyFields[ix]);
if (key2)
delete this._map[key2];
var items = this._map[key];
if (items) {
removed = removed.concat(items);
for (var j in items) {
var item = items[j];
for (var ix in this.keyFields) {
var key2 = this.find(item, this.keyFields[ix]);
if (key2 && this._map[key2]) {
var ix = this._map[key2].indexOf(item);
if (ix != -1)
this._map[key2].splice(ix, 1);
if (this._map[key2].length == 0)
delete this._map[key2];
}
}
this._list.splice(this._list.indexOf(item), 1);
}
this._list.splice(this._list.indexOf(item), 1);
}

@@ -85,10 +99,16 @@ delete this._map[key];

for (var i = 0; i < arguments.length; i++) {
var item = arguments[i];
for (var ix in this.keyFields) {
var key = this.find(arguments[i], this.keyFields[ix]);
var key = this.find(item, this.keyFields[ix]);
if (key) {
delete this._map[key];
var ix = this._map[key].indexOf(item);
if (ix != -1)
this._map[key].splice(ix, 1);
if (this._map[key].length == 0)
delete this._map[key];
}
}
this._list.splice(this._list.indexOf(arguments[i]), 1);
this._list.splice(this._list.indexOf(item), 1);
}

@@ -95,0 +115,0 @@

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