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

@saulx/utils

Package Overview
Dependencies
Maintainers
1
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@saulx/utils - npm Package Compare versions

Comparing version 1.0.4 to 1.0.5

55

dist/hash.js

@@ -18,10 +18,10 @@ "use strict";

if (type === 'string') {
hash = (exports.stringHash(field, hash) * 33) ^ exports.stringHash(key, hash);
hash = (exports.stringHash(field, hash) * 33) ^ (exports.stringHash(key, hash) * 33);
}
else if (type === 'number') {
hash = (((hash * 33) ^ field) * 33) ^ exports.stringHash(key, hash);
hash = (((hash * 33) ^ field) * 33) ^ (exports.stringHash(key, hash) * 33);
}
else if (type === 'object') {
if (field === null) {
hash = 5381 ^ exports.stringHash(key, hash);
hash = 5381 ^ (exports.stringHash(key, hash) * 33);
}

@@ -31,3 +31,3 @@ else {

(exports.hashObjectIgnoreKeyOrderNest(field, hash) * 33) ^
exports.stringHash(key, hash);
(exports.stringHash(key, hash) * 33);
}

@@ -38,3 +38,3 @@ }

(((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^
exports.stringHash(key, hash);
(exports.stringHash(key, hash) * 33);
}

@@ -51,10 +51,10 @@ }

if (type === 'string') {
hash = (exports.stringHash(field, hash) * 33) ^ exports.stringHash(key, hash);
hash = (exports.stringHash(field, hash) * 33) ^ (exports.stringHash(key, hash) * 33);
}
else if (type === 'number') {
hash = (((hash * 33) ^ field) * 33) ^ exports.stringHash(key, hash);
hash = (((hash * 33) ^ field) * 33) ^ (exports.stringHash(key, hash) * 33);
}
else if (type === 'object') {
if (field === null) {
hash = 5381 ^ exports.stringHash(key, hash);
hash = 5381 ^ (exports.stringHash(key, hash) * 33);
}

@@ -64,3 +64,3 @@ else {

(exports.hashObjectIgnoreKeyOrderNest(field, hash) * 33) ^
exports.stringHash(key, hash);
(exports.stringHash(key, hash) * 33);
}

@@ -71,3 +71,3 @@ }

(((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^
exports.stringHash(key, hash);
(exports.stringHash(key, hash) * 33);
}

@@ -79,3 +79,2 @@ }

exports.hashObjectNest = (obj, hash = 5381) => {
// if (obj.constructor === Array) {
for (let key in obj) {

@@ -85,13 +84,13 @@ const field = obj[key];

if (type === 'string') {
hash = (exports.stringHash(field, hash) * 33) ^ exports.stringHash(key, hash);
hash = (exports.stringHash(field, hash) * 33) ^ (exports.stringHash(key, hash) * 33);
}
else if (type === 'number') {
hash = (((hash * 33) ^ field) * 33) ^ exports.stringHash(key, hash);
hash = (((hash * 33) ^ field) * 33) ^ (exports.stringHash(key, hash) * 33);
}
else if (type === 'object') {
if (field === null) {
hash = 5381 ^ exports.stringHash(key, hash);
hash = 5381 ^ (exports.stringHash(key, hash) * 33);
}
else {
hash = (exports.hashObjectNest(field, hash) * 33) ^ exports.stringHash(key, hash);
hash = (exports.hashObjectNest(field, hash) * 33) ^ (exports.stringHash(key, hash) * 33);
}

@@ -101,28 +100,6 @@ }

hash =
(((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^ exports.stringHash(key, hash);
(((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^
(exports.stringHash(key, hash) * 33);
}
}
// } else {
// const keys = Object.keys(obj).sort()
// for (let i = 0; i < keys.length; i++) {
// const key = keys[i]
// const field = obj[key]
// const type = typeof field
// if (type === 'string') {
// hash = (stringHash(field, hash) * 33) ^ stringHash(key, hash)
// } else if (type === 'number') {
// hash = (((hash * 33) ^ field) * 33) ^ stringHash(key, hash)
// } else if (type === 'object') {
// if (field === null) {
// hash = 5381 ^ stringHash(key, hash)
// } else {
// hash = (hashObjectNest(field, hash) * 33) ^ stringHash(key, hash)
// }
// } else if (type === 'boolean') {
// hash =
// (((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^
// stringHash(key, hash)
// }
// }
// }
return hash;

@@ -129,0 +106,0 @@ };

{
"name": "@saulx/utils",
"main": "./dist/index.js",
"version": "1.0.4",
"version": "1.0.5",
"scripts": {

@@ -6,0 +6,0 @@ "build": "tsc",

@@ -17,12 +17,12 @@ export const stringHash = (str, hash = 5381): number => {

if (type === 'string') {
hash = (stringHash(field, hash) * 33) ^ stringHash(key, hash)
hash = (stringHash(field, hash) * 33) ^ (stringHash(key, hash) * 33)
} else if (type === 'number') {
hash = (((hash * 33) ^ field) * 33) ^ stringHash(key, hash)
hash = (((hash * 33) ^ field) * 33) ^ (stringHash(key, hash) * 33)
} else if (type === 'object') {
if (field === null) {
hash = 5381 ^ stringHash(key, hash)
hash = 5381 ^ (stringHash(key, hash) * 33)
} else {
hash =
(hashObjectIgnoreKeyOrderNest(field, hash) * 33) ^
stringHash(key, hash)
(stringHash(key, hash) * 33)
}

@@ -32,3 +32,3 @@ } else if (type === 'boolean') {

(((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^
stringHash(key, hash)
(stringHash(key, hash) * 33)
}

@@ -44,12 +44,12 @@ }

if (type === 'string') {
hash = (stringHash(field, hash) * 33) ^ stringHash(key, hash)
hash = (stringHash(field, hash) * 33) ^ (stringHash(key, hash) * 33)
} else if (type === 'number') {
hash = (((hash * 33) ^ field) * 33) ^ stringHash(key, hash)
hash = (((hash * 33) ^ field) * 33) ^ (stringHash(key, hash) * 33)
} else if (type === 'object') {
if (field === null) {
hash = 5381 ^ stringHash(key, hash)
hash = 5381 ^ (stringHash(key, hash) * 33)
} else {
hash =
(hashObjectIgnoreKeyOrderNest(field, hash) * 33) ^
stringHash(key, hash)
(stringHash(key, hash) * 33)
}

@@ -59,3 +59,3 @@ } else if (type === 'boolean') {

(((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^
stringHash(key, hash)
(stringHash(key, hash) * 33)
}

@@ -68,3 +68,2 @@ }

export const hashObjectNest = (obj, hash = 5381): number => {
// if (obj.constructor === Array) {
for (let key in obj) {

@@ -74,40 +73,17 @@ const field = obj[key]

if (type === 'string') {
hash = (stringHash(field, hash) * 33) ^ stringHash(key, hash)
hash = (stringHash(field, hash) * 33) ^ (stringHash(key, hash) * 33)
} else if (type === 'number') {
hash = (((hash * 33) ^ field) * 33) ^ stringHash(key, hash)
hash = (((hash * 33) ^ field) * 33) ^ (stringHash(key, hash) * 33)
} else if (type === 'object') {
if (field === null) {
hash = 5381 ^ stringHash(key, hash)
hash = 5381 ^ (stringHash(key, hash) * 33)
} else {
hash = (hashObjectNest(field, hash) * 33) ^ stringHash(key, hash)
hash = (hashObjectNest(field, hash) * 33) ^ (stringHash(key, hash) * 33)
}
} else if (type === 'boolean') {
hash =
(((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^ stringHash(key, hash)
(((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^
(stringHash(key, hash) * 33)
}
}
// } else {
// const keys = Object.keys(obj).sort()
// for (let i = 0; i < keys.length; i++) {
// const key = keys[i]
// const field = obj[key]
// const type = typeof field
// if (type === 'string') {
// hash = (stringHash(field, hash) * 33) ^ stringHash(key, hash)
// } else if (type === 'number') {
// hash = (((hash * 33) ^ field) * 33) ^ stringHash(key, hash)
// } else if (type === 'object') {
// if (field === null) {
// hash = 5381 ^ stringHash(key, hash)
// } else {
// hash = (hashObjectNest(field, hash) * 33) ^ stringHash(key, hash)
// }
// } else if (type === 'boolean') {
// hash =
// (((hash * 33) ^ (field === true ? 1 : 0)) * 33) ^
// stringHash(key, hash)
// }
// }
// }
return hash

@@ -114,0 +90,0 @@ }

@@ -72,1 +72,51 @@ import test from 'ava'

})
test('hash weird equality hashObjectIgnoreKeyOrder', async t => {
const a = {
type: 'folder',
title: '',
id: 'fo1',
name: '',
children: [
{
buttonText: 'my ballz',
type: 'match',
name: '',
id: 'ma1',
aliases: [],
published: false
}
],
aliases: []
}
const b = {
type: 'folder',
title: '',
id: 'fo1',
name: '',
children: [
{
buttonText: 'my ballzzzz',
type: 'match',
name: '',
id: 'ma1',
aliases: [],
published: false
}
],
aliases: []
}
const hashA1 = hashObject(a)
const hashB1 = hashObject(b)
const hashA = hashObjectIgnoreKeyOrder(a)
const hashB = hashObjectIgnoreKeyOrder(b)
const hashStrA = hash('my ballz')
const hashStrB = hash('my ballzzzz')
t.true(hashStrA !== hashStrB)
t.true(hashA1 !== hashB1)
t.true(hashA !== hashB)
})

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