From 4601c78f79185704f6934800bd2be0d916d71dfd Mon Sep 17 00:00:00 2001 From: Scott Menzer Date: Thu, 20 Aug 2020 18:56:49 +0200 Subject: [PATCH] rename simpleHash to cyrb53Hash to make it clearer which hash function is actually used. --- modules/userId/index.js | 2 +- src/utils.js | 2 +- test/spec/utils_spec.js | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/userId/index.js b/modules/userId/index.js index bcc0f68b2b0..14f7ad3599b 100644 --- a/modules/userId/index.js +++ b/modules/userId/index.js @@ -244,7 +244,7 @@ function makeStoredConsentDataHash(consentData) { storedConsentData.gdprApplies = consentData.gdprApplies; storedConsentData.apiVersion = consentData.apiVersion; } - return utils.simpleHash(JSON.stringify(storedConsentData)); + return utils.cyrb53Hash(JSON.stringify(storedConsentData)); } /** diff --git a/src/utils.js b/src/utils.js index 6801a7dc1d1..591c1d1bb2b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1223,7 +1223,7 @@ export function mergeDeep(target, ...sources) { * @param seed (optional) * @returns {string} */ -export function simpleHash(str, seed = 0) { +export function cyrb53Hash(str, seed = 0) { // IE doesn't support imul // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/imul#Polyfill let imul = function(opA, opB) { diff --git a/test/spec/utils_spec.js b/test/spec/utils_spec.js index dbaad919bd3..6494ead78e7 100644 --- a/test/spec/utils_spec.js +++ b/test/spec/utils_spec.js @@ -1178,23 +1178,23 @@ describe('Utils', function () { expect(utils.deepEqual(obj1, obj2)).to.equal(false); }); - describe('simpleHash', function() { + describe('cyrb53Hash', function() { it('should return the same hash for the same string', function() { const stringOne = 'string1'; - expect(utils.simpleHash(stringOne)).to.equal(utils.simpleHash(stringOne)); + expect(utils.cyrb53Hash(stringOne)).to.equal(utils.cyrb53Hash(stringOne)); }); it('should return a different hash for the same string with different seeds', function() { const stringOne = 'string1'; - expect(utils.simpleHash(stringOne, 1)).to.not.equal(utils.simpleHash(stringOne, 2)); + expect(utils.cyrb53Hash(stringOne, 1)).to.not.equal(utils.cyrb53Hash(stringOne, 2)); }); it('should return a different hash for different strings with the same seed', function() { const stringOne = 'string1'; const stringTwo = 'string2'; - expect(utils.simpleHash(stringOne)).to.not.equal(utils.simpleHash(stringTwo)); + expect(utils.cyrb53Hash(stringOne)).to.not.equal(utils.cyrb53Hash(stringTwo)); }); it('should return a string value, not a number', function() { const stringOne = 'string1'; - expect(typeof utils.simpleHash(stringOne)).to.equal('string'); + expect(typeof utils.cyrb53Hash(stringOne)).to.equal('string'); }); }); });