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

json-hash

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-hash - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

3

lib/browser.js

@@ -22,4 +22,5 @@ "use strict";

var crypto = _ref$crypto === undefined ? crypto_ : _ref$crypto;
var sets = _ref.sets;
return digest_(a, { algorithm: algorithm, inputEncoding: inputEncoding, outputEncoding: outputEncoding, crypto: crypto });
return digest_(a, { algorithm: algorithm, inputEncoding: inputEncoding, outputEncoding: outputEncoding, crypto: crypto, sets: sets });
}

@@ -26,0 +27,0 @@ Object.defineProperty(exports, "__esModule", {

@@ -15,2 +15,3 @@ "use strict";

var crypto = _ref.crypto;
var sets = _ref.sets;

@@ -26,3 +27,3 @@ var h = crypto.createHash(algorithm);

var d = function (a) {
return digest(a, { algorithm: algorithm, inputEncoding: inputEncoding, outputEncoding: outputEncoding, crypto: crypto });
return digest(a, { algorithm: algorithm, inputEncoding: inputEncoding, outputEncoding: outputEncoding, crypto: crypto, sets: sets });
};

@@ -82,7 +83,15 @@ switch (true) {

case Array.isArray(a):
u("[");
a.forEach(function (e) {
return u("a", d(e));
});
u("]");
if (sets) {
u("<");
a.map(d).sort().forEach(function (e) {
return u("A", e);
});
u(">");
} else {
u("[");
a.forEach(function (e) {
return u("a", d(e));
});
u("]");
}
break;

@@ -89,0 +98,0 @@

@@ -22,4 +22,5 @@ "use strict";

var crypto = _ref$crypto === undefined ? crypto_ : _ref$crypto;
var sets = _ref.sets;
return digest_(a, { algorithm: algorithm, inputEncoding: inputEncoding, outputEncoding: outputEncoding, crypto: crypto });
return digest_(a, { algorithm: algorithm, inputEncoding: inputEncoding, outputEncoding: outputEncoding, crypto: crypto, sets: sets });
}

@@ -26,0 +27,0 @@ Object.defineProperty(exports, "__esModule", {

{
"name": "json-hash",
"version": "1.1.0",
"version": "1.2.0",
"description": "Compute JSON hash.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -66,3 +66,3 @@

return it('should handle utf8', function () {
it('should handle utf8', function () {
let r = 'Dopóki nie skorzys­tałem z In­terne­tu, nie wie­działem, że na świecie jest ty­lu idiotów.'

@@ -69,0 +69,0 @@ for (let e in [ undefined, 'binary', 'ascii', 'utf8' ]) {

@@ -10,19 +10,19 @@

// Get digest from browser and crypto based versions.
function d (s) {
let a = null
let b = null
for (let e in [ undefined, 'binary', 'ascii', 'utf8' ]) {
a = browser.digest(s, e)
b = crypto.digest(s, e)
assert.equal(a, b)
function d(s, { sets } = {}) {
let a = null;
let b = null;
for (let inputEncoding in [ undefined, 'binary', 'ascii', 'utf8' ]) {
a = browser.digest(s, { inputEncoding, sets });
b = crypto.digest(s, { inputEncoding, sets });
assert.equal(a, b);
}
return a
return a;
}
function eq (a, b) {
assert.equal(d(a), d(b))
function eq(a, b, options) {
assert.equal(d(a, options), d(b, options));
}
function ne (a, b) {
assert.notEqual(d(a), d(b))
function ne(a, b, options) {
assert.notEqual(d(a, options), d(b, options));
}

@@ -42,2 +42,11 @@

it('should have different hashes for arrays with different order', function () {
ne(['foo', 'bar'], ['bar', 'foo']);
});
it('should have same hashes for arrays with different order with sets = true option', function () {
eq(['foo', 'bar'], ['bar', 'foo'], { sets: true });
eq({ foo: ['foo', 'bar'] }, { foo: ['bar', 'foo'] }, { sets: true });
});
it('should have different hashes for 1 as a number and "1" as a string', function() {

@@ -44,0 +53,0 @@ ne( 1, '1' )

@@ -5,4 +5,4 @@

export function digest (a, { algorithm = 'sha1', inputEncoding = 'utf8', outputEncoding = 'hex', crypto = crypto_ } = {}) {
return digest_(a, { algorithm, inputEncoding, outputEncoding, crypto })
export function digest (a, { algorithm = 'sha1', inputEncoding = 'utf8', outputEncoding = 'hex', crypto = crypto_, sets } = {}) {
return digest_(a, { algorithm, inputEncoding, outputEncoding, crypto, sets })
}
// Compute digest for JSON object.
export function digest (a, { algorithm = 'sha1', inputEncoding = 'utf8', outputEncoding = 'hex', crypto } = {}) {
export function digest (a, { algorithm = 'sha1', inputEncoding = 'utf8', outputEncoding = 'hex', crypto, sets } = {}) {
let h = crypto.createHash(algorithm)
let u = (...args) => h.update(args.join(':'), inputEncoding)
let d = a => digest(a, { algorithm, inputEncoding, outputEncoding, crypto })
let d = a => digest(a, { algorithm, inputEncoding, outputEncoding, crypto, sets })
switch (true) {

@@ -60,5 +60,11 @@

case Array.isArray(a):
u('[')
a.forEach(e => u('a', d(e)))
u(']')
if (sets) {
u('<')
a.map(d).sort().forEach(e => u('A', e))
u('>')
} else {
u('[')
a.forEach(e => u('a', d(e)))
u(']')
}
break

@@ -65,0 +71,0 @@

@@ -5,4 +5,4 @@

export function digest (a, { algorithm = 'sha1', inputEncoding = 'utf8', outputEncoding = 'hex', crypto = crypto_ } = {}) {
return digest_(a, { algorithm, inputEncoding, outputEncoding, crypto })
export function digest (a, { algorithm = 'sha1', inputEncoding = 'utf8', outputEncoding = 'hex', crypto = crypto_, sets } = {}) {
return digest_(a, { algorithm, inputEncoding, outputEncoding, crypto, sets })
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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