Skip to content

Commit c11022e

Browse files
author
Guillermo Tamanaha
committed
Refactor hostname extraction and hashString function to improve clarity and consistency in Rokt-Kit
1 parent 713d7f4 commit c11022e

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/Rokt-Kit.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ var constructor = function () {
425425

426426
function isPartnerInLocalLauncherTestGroup() {
427427
var url = new URL(window.location.href);
428-
var { hostname } = url;
428+
var hostname = url.hostname;
429429
var hash = hashString(hostname);
430430

431431
return self.testGroup.includes(hash);
@@ -437,13 +437,13 @@ var constructor = function () {
437437
* @returns {bigint} A 64-bit BigInt representing the hash of the string.
438438
*/
439439
function hashString(str) {
440-
var hash = 5381n;
441-
442-
for (let i = 0; i < str.length; i++) {
440+
var hash = BigInt(5381);
441+
442+
for (var i = 0; i < str.length; i++) {
443443
var charCode = BigInt(str.charCodeAt(i));
444-
hash = (hash << 5n) + hash + charCode;
444+
hash = (hash << BigInt(5)) + hash + charCode;
445445
}
446-
446+
447447
return hash;
448448
}
449449
};

test/src/tests.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-env es6, mocha */
22
/* eslint-parser babel-eslint */
3+
/* global BigInt */
34

45
const packageVersion = require('../../package.json').version;
56
const sdkVersion = 'mParticle_wsdkv_1.2.3';
@@ -583,7 +584,9 @@ describe('Rokt Forwarder', () => {
583584
});
584585

585586
it('should create a local launcher if the partner is in the local launcher test group', async () => {
586-
window.mParticle.forwarder.testGroup = [BigInt('249896952128253326')];
587+
window.mParticle.forwarder.testGroup = [
588+
BigInt('249896952128253326'),
589+
];
587590

588591
await window.mParticle.forwarder.init(
589592
{ accountId: '123456' },

0 commit comments

Comments
 (0)