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.2 to 0.0.3

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.2",
"version": "0.0.3",
"main": "index.js",

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

@@ -1,4 +0,5 @@

var HashArray = function(keyFields) {
var HashArray = function(keyFields, callback) {
this._map = {};
this._list = [];
this.callback = callback;

@@ -14,2 +15,6 @@ this.keyFields = keyFields;

});
if (callback) {
callback('construct');
}
};

@@ -35,5 +40,14 @@

}
if (this.callback) {
this.callback('add', arguments);
}
},
addMap: function(key, obj) {
this._map[key] = obj;
if (this.callback) {
this.callback('addMap', {
key: key,
obj: obj
});
}
},

@@ -47,2 +61,3 @@ get: function(key) {

removeByKey: function() {
var removed = [];
for (var i = 0; i < arguments.length; i++) {

@@ -52,2 +67,3 @@ var key = arguments[i];

if (item) {
removed.push(item);
for (var ix in this.keyFields) {

@@ -62,2 +78,6 @@ var key2 = this.find(item, this.keyFields[ix]);

}
if (this.callback) {
this.callback('removeByKey', removed);
}
},

@@ -75,2 +95,6 @@ remove: function() {

}
if (this.callback) {
this.callback('remove', arguments);
}
},

@@ -80,2 +104,6 @@ removeAll: function() {

this._list = [];
if (this.callback) {
this.callback('removeAll');
}
},

@@ -82,0 +110,0 @@ find: function(obj, path) {

@@ -7,3 +7,7 @@ var assert = require('assert'),

describe('new HashArray(keys) should work', function() {
var ha = new HashArray(['key']);
var ha = new HashArray(['key'], function(type) {
it('Should callback with "construct"', function() {
assert.equal(type, 'construct');
});
});

@@ -25,2 +29,10 @@ it('Should have a all.length of 0.', function() {

};
ha.callback = function(type, what) {
it('Should have a "add" callback.', function() {
assert.equal(type, 'add');
assert.strictEqual(what[0], item);
});
};
ha.add(item);

@@ -42,2 +54,3 @@

]);
var item = {

@@ -75,2 +88,11 @@ key: 'whatever',

ha.callback = function(type, what) {
it('Should have a "add" callback.', function() {
assert.equal(type, 'add');
assert.strictEqual(what[0], item1);
assert.strictEqual(what[1], item2);
assert.strictEqual(what[2], item3);
});
};
ha.add(item1, item2, item3);

@@ -155,2 +177,8 @@

ha.add(item1, item2, item3);
ha.callback = function(type, what) {
it('Should have a "removeByKey" callback.', function() {
assert.equal(type, 'removeByKey');
assert.strictEqual(what[0], item1);
});
};
ha.removeByKey('whatever');

@@ -182,2 +210,8 @@

ha.add(item);
ha.callback = function(type, what) {
it('Should have a "remove" callback.', function() {
assert.equal(type, 'remove');
assert.strictEqual(what[0], item);
});
};
ha.remove(item);

@@ -208,2 +242,8 @@

ha.add(item1, item2, item3);
ha.callback = function(type, what) {
it('Should have a "remove" callback.', function() {
assert.equal(type, 'remove');
assert.strictEqual(what[0], item2);
});
};
ha.remove(item2);

@@ -228,2 +268,32 @@

});
describe('removeAll() should work', function() {
var ha = new HashArray(['key']);
var item1 = {
key: 'whatever'
},
item2 = {
key: 'whatever2'
},
item3 = {
key: 'whatever3'
};
ha.add(item1, item2, item3);
ha.callback = function(type, what) {
it('Should have a "remove" callback.', function() {
assert.equal(type, 'removeAll');
});
it('Should have 0 items after removeAll', function() {
assert.equal(ha.all.length, 0);
});
it('Should have a map with no keys.', function() {
for (var key in ha.map)
assert.equal(key, undefined);
});
};
ha.removeAll();
});
});
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