@rh-support/utils 2.4.2 → 2.4.3-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,8 @@ type AddToDate = {
12
12
  };
13
13
  export declare const addDaysToDate: (params: AddToDate) => moment.Moment;
14
14
  export declare const isValidDate: (dateString: string) => boolean;
15
- export declare const trafficSplit: (testVariationWeight: number, dateString: string) => "A" | "B";
15
+ export declare const generateUniqueIdBasedOnNowDate: () => string;
16
+ export declare const ABTestSplitSplitBasedOnDate: (testVariationWeight: number, dateString: string) => "A" | "B";
17
+ export declare const ABTestSplitBasedOnAccountNumber: (testVariationWeight: number, accountNumber: string) => "A" | "B";
16
18
  export {};
17
19
  //# sourceMappingURL=dateUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dateUtils.d.ts","sourceRoot":"","sources":["../../src/dateUtils.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,eAAO,MAAM,UAAU,wCAGX,IAAI,CAAC,qBAAqB,WASrC,CAAC;AAEF,eAAO,MAAM,cAAc,wCAGf,IAAI,CAAC,qBAAqB,WAerC,CAAC;AAEF,eAAO,MAAM,OAAO,SAAU,MAAM,KAAG,MAAmC,CAAC;AAE3E,eAAO,MAAM,2BAA2B,WAAY,MAAM,WAEzD,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAAc,MAAM,KAAG,MAExD,CAAC;AAEF,eAAO,MAAM,+BAA+B,SAClC,MAAM,gBACC,MAAM,CAAC,UAAU,CAAC,OAAO,KACvC,OAEF,CAAC;AAEF,eAAO,MAAM,YAAY,SAAU,MAAM,gBAAe,MAAM,CAAC,UAAU,CAAC,OAAO,YAEhF,CAAC;AAEF,KAAK,SAAS,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,aAAa,WAAY,SAAS,kBAG9C,CAAC;AAEF,eAAO,MAAM,WAAW,eAAgB,MAAM,YAI7C,CAAC;AAQF,eAAO,MAAM,YAAY,wBAAyB,MAAM,cAAc,MAAM,cAe3E,CAAC"}
1
+ {"version":3,"file":"dateUtils.d.ts","sourceRoot":"","sources":["../../src/dateUtils.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,eAAO,MAAM,UAAU,wCAGX,IAAI,CAAC,qBAAqB,WASrC,CAAC;AAEF,eAAO,MAAM,cAAc,wCAGf,IAAI,CAAC,qBAAqB,WAerC,CAAC;AAEF,eAAO,MAAM,OAAO,SAAU,MAAM,KAAG,MAAmC,CAAC;AAE3E,eAAO,MAAM,2BAA2B,WAAY,MAAM,WAEzD,CAAC;AAEF,eAAO,MAAM,qBAAqB,aAAc,MAAM,KAAG,MAExD,CAAC;AAEF,eAAO,MAAM,+BAA+B,SAClC,MAAM,gBACC,MAAM,CAAC,UAAU,CAAC,OAAO,KACvC,OAEF,CAAC;AAEF,eAAO,MAAM,YAAY,SAAU,MAAM,gBAAe,MAAM,CAAC,UAAU,CAAC,OAAO,YAEhF,CAAC;AAEF,KAAK,SAAS,GAAG;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,aAAa,WAAY,SAAS,kBAG9C,CAAC;AAEF,eAAO,MAAM,WAAW,eAAgB,MAAM,YAI7C,CAAC;AAEF,eAAO,MAAM,8BAA8B,cAE1C,CAAC;AAQF,eAAO,MAAM,2BAA2B,wBAAyB,MAAM,cAAc,MAAM,cAe1F,CAAC;AASF,eAAO,MAAM,+BAA+B,wBAAyB,MAAM,iBAAiB,MAAM,cAkBjG,CAAC"}
@@ -45,12 +45,16 @@ export const isValidDate = (dateString) => {
45
45
  const parsedDate = parseISO(dateString);
46
46
  return isValid(parsedDate);
47
47
  };
48
+ export const generateUniqueIdBasedOnNowDate = () => {
49
+ return Date.now().toString(36) + Math.random().toString(36).substring(2);
50
+ };
48
51
  // split traffic based on time and weight
49
52
  // for example, if testVariationWeight is 2 and the current time in seconds modulo 10 is less than 2,
50
53
  // redirect to test version (20% of the time), else redirect to control version (80% of the time)
51
54
  // @wieght: a number between 0 and 10
52
- // @dateString: date string
53
- export const trafficSplit = (testVariationWeight, dateString) => {
55
+ // @dateString: date string - to get consistent variant for a user during experiece, pass a fix date
56
+ // for example in case craetion, we can pass sessionItem.session.createdDate as dateString
57
+ export const ABTestSplitSplitBasedOnDate = (testVariationWeight, dateString) => {
54
58
  if (testVariationWeight === 10)
55
59
  return 'A'; // test
56
60
  if (testVariationWeight === 0 || !testVariationWeight || isNaN(testVariationWeight))
@@ -66,3 +70,29 @@ export const trafficSplit = (testVariationWeight, dateString) => {
66
70
  return 'B';
67
71
  }
68
72
  };
73
+ /*
74
+ Without prime number Generates a hash value for the given account number.
75
+ The hash is calculated by multiplying the ASCII value of each character
76
+ by its position in the string (1-based), and then returning the result modulo 100.
77
+ @param {string} accountNumber - The account number to hash.
78
+ @return {number} The hash value in the range 0-99.
79
+ */
80
+ export const ABTestSplitBasedOnAccountNumber = (testVariationWeight, accountNumber) => {
81
+ if (testVariationWeight === 100)
82
+ return 'A'; // test
83
+ if (testVariationWeight === 0 || !testVariationWeight || isNaN(testVariationWeight) || !accountNumber)
84
+ return 'B'; // control
85
+ let hash = 0;
86
+ // Loop through each character in the account number
87
+ for (let i = 0; i < (accountNumber || '').length; i++) {
88
+ // Multiply the ASCII value of the character by its position (index + 1)
89
+ hash += accountNumber.charCodeAt(i) * (i + 1);
90
+ }
91
+ const moduloResult = hash % 100;
92
+ if (moduloResult < testVariationWeight) {
93
+ return 'A';
94
+ }
95
+ else {
96
+ return 'B';
97
+ }
98
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/utils",
3
- "version": "2.4.2",
3
+ "version": "2.4.3-beta.3",
4
4
  "description": "> TODO: description",
5
5
  "author": "Vikas Rathee <vrathee@redhat.com>",
6
6
  "license": "ISC",
@@ -41,14 +41,14 @@
41
41
  "prepublishOnly": "npm run build"
42
42
  },
43
43
  "peerDependencies": {
44
- "@cee-eng/hydrajs": "4.17.33",
44
+ "@cee-eng/hydrajs": "4.17.34",
45
45
  "localforage": "^1.10.0",
46
46
  "lodash": "^4.17.21",
47
47
  "qs": "^6.7.0",
48
48
  "solr-query-builder": "1.0.1"
49
49
  },
50
50
  "dependencies": {
51
- "@cee-eng/hydrajs": "4.17.33",
51
+ "@cee-eng/hydrajs": "4.17.34",
52
52
  "@rh-support/types": "2.0.4",
53
53
  "date-fns": "3.6.0",
54
54
  "dompurify": "^2.2.6",
@@ -75,5 +75,5 @@
75
75
  "defaults and supports es6-module",
76
76
  "maintained node versions"
77
77
  ],
78
- "gitHead": "908b440e3c6cd625c77178c3205f4e2908630446"
78
+ "gitHead": "3f3896032774c8fb5cd4fd01d4854b4594881c3c"
79
79
  }