Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename simpleHash to cyrb53Hash #5644

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/userId/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions test/spec/utils_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
Expand Down