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

object-hash

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-hash - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

86

index.js

@@ -113,2 +113,7 @@ 'use strict';

}
if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(object)) {
hashFn.update('buffer:');
return hashFn.update(object);
}

@@ -122,2 +127,3 @@ if(objType !== 'object') {

}else{
hashFn.update('object:');
// TODO, add option for enumerating, for key in obj includePrototypeChain

@@ -134,2 +140,3 @@ var keys = Object.keys(object).sort();

_array: function(arr){
hashFn.update('array:' + arr.length + ':');
return arr.forEach(function(el){

@@ -140,18 +147,21 @@ typeHasher(hashFn, options, context).dispatch(el);

_date: function(date){
return hashFn.update(date.toJSON());
return hashFn.update('date:' + date.toJSON());
},
_error: function(err){
return hashFn.update('error:' + err.toString());
},
_boolean: function(bool){
return hashFn.update(bool.toString());
return hashFn.update('bool:' + bool.toString());
},
_string: function(string){
return hashFn.update(string);
return hashFn.update('string:' + string);
},
_function: function(fn){
return hashFn.update(fn.toString());
return hashFn.update('fn:' + fn.toString());
},
_number: function(number){
return hashFn.update(number.toString());
return hashFn.update('number:' + number.toString());
},
_xml: function(xml){
return hashFn.update(xml.toString());
return hashFn.update('xml:' + xml.toString());
},

@@ -165,8 +175,64 @@ _null: function(){

_regexp: function(regex){
return hashFn.update(regex.toString());
return hashFn.update('regex:' + regex.toString());
},
_domwindow: function(){
return hashFn.update('domwindow');
}
_uint8array: function(arr){
hashFn.update('uint8array:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_uint8clampedarray: function(arr){
hashFn.update('uint8clampedarray:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_int8array: function(arr){
hashFn.update('uint8array:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_uint16array: function(arr){
hashFn.update('uint16array:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_int16array: function(arr){
hashFn.update('uint16array:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_uint32array: function(arr){
hashFn.update('uint32array:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_int32array: function(arr){
hashFn.update('uint32array:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_float32array: function(arr){
hashFn.update('float32array:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_float64array: function(arr){
hashFn.update('float64array:');
return typeHasher(hashFn, options, context).dispatch(Array.prototype.slice.call(arr));
},
_arraybuffer: function(arr){
hashFn.update('arraybuffer:');
return typeHasher(hashFn, options, context).dispatch(new Uint8Array(arr));
},
_domwindow: function(){ return hashFn.update('domwindow'); },
/* Node.js standard native objects */
_process: function(){ return hashFn.update('process'); },
_timer: function(){ return hashFn.update('timer'); },
_pipe: function(){ return hashFn.update('pipe'); },
_tcp: function(){ return hashFn.update('tcp'); },
_udp: function(){ return hashFn.update('udp'); },
_tty: function(){ return hashFn.update('tty'); },
_statwatcher: function(){ return hashFn.update('statwatcher'); },
_securecontext: function(){ return hashFn.update('securecontext'); },
_connection: function(){ return hashFn.update('connection'); },
_zlib: function(){ return hashFn.update('zlib'); },
_context: function(){ return hashFn.update('context'); },
_nodescript: function(){ return hashFn.update('nodescript'); },
_httpparser: function(){ return hashFn.update('httpparser'); },
_dataview: function(){ return hashFn.update('dataview'); },
_signal: function(){ return hashFn.update('signal'); },
_fsevent: function(){ return hashFn.update('fsevent'); },
_tlswrap: function(){ return hashFn.update('tlswrap'); }
};
}

2

package.json
{
"name": "object-hash",
"version": "0.4.0",
"version": "0.5.0",
"description": "Generate hashes from javascript objects in node and the browser.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/puleos/object-hash",

@@ -33,3 +33,3 @@ var test = require('tape');

test('hashes special object types', function(assert){
assert.plan(8);
assert.plan(9);
var dt = new Date();

@@ -46,2 +46,3 @@ dt.setDate(dt.getDate() + 1);

assert.ok(validSha1.test(hash(new RegExp())), 'hash regex');
assert.ok(validSha1.test(hash(new Error())), 'hash error');
});

@@ -63,3 +64,3 @@

test('only hashes object keys when excludeValues option is set', function(assert){
test('hashes only object keys when excludeValues option is set', function(assert){
assert.plan(2);

@@ -132,1 +133,39 @@ var hash1 = hash({foo: false, bar: 'OK'}, { excludeValues: true });

});
test("null and 'Null' string produce different hashes", function(assert) {
assert.plan(1);
var hash1 = hash({foo: null});
var hash2 = hash({foo: 'Null'});
assert.notEqual(hash1, hash2, "null and 'Null' should not produce identical hashes");
});
test("object types are hashed", function(assert) {
assert.plan(1);
var hash1 = hash({foo: 'bar'});
var hash2 = hash(['foo', 'bar']);
assert.notEqual(hash1, hash2, "arrays and objects should not produce identical hashes");
});
if (typeof Buffer !== 'undefined') {
test("Buffers can be hashed", function(assert) {
assert.plan(1);
assert.ok(validSha1.test(hash(new Buffer('Banana'))), 'hashes Buffers');
});
}
if (typeof Uint8Array !== 'undefined') {
test("Typed arrays can be hashed", function(assert) {
assert.plan(10);
assert.ok(validSha1.test(hash(new Uint8Array([1,2,3,4]))), 'hashes Uint8Array');
assert.ok(validSha1.test(hash(new Int8Array([1,2,3,4]))), 'hashes Int8Array');
assert.ok(validSha1.test(hash(new Uint16Array([1,2,3,4]))), 'hashes Uint16Array');
assert.ok(validSha1.test(hash(new Int16Array([1,2,3,4]))), 'hashes Int16Array');
assert.ok(validSha1.test(hash(new Uint32Array([1,2,3,4]))), 'hashes Uint32Array');
assert.ok(validSha1.test(hash(new Int32Array([1,2,3,4]))), 'hashes Int32Array');
assert.ok(validSha1.test(hash(new Float32Array([1,2,3,4]))), 'hashes Float32Array');
assert.ok(validSha1.test(hash(new Float64Array([1,2,3,4]))), 'hashes Float64Array');
assert.ok(validSha1.test(hash(new Uint8ClampedArray([1,2,3,4]))), 'hashes Uint8ClampedArray');
assert.ok(validSha1.test(hash(new Uint8Array([1,2,3,4]).buffer)), 'hashes ArrayBuffer');
});
}
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