@usertour/helpers 0.0.26 → 0.0.27

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.
@@ -351,50 +351,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
351
351
  return condition;
352
352
  });
353
353
  };
354
- var evaluateRule = async (rule, options) => {
354
+ var evaluateRule = async (condition, options) => {
355
355
  var _a;
356
356
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
357
- const ruleId = rule.id;
358
- if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
357
+ const conditionId = condition.id;
358
+ if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
359
359
  return true;
360
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
360
+ if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
361
361
  return false;
362
- const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
362
+ const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
363
363
  if (customEvaluator) {
364
- const result = customEvaluator(rule, options);
364
+ const result = customEvaluator(condition, options);
365
365
  return typeof result === "object" && result !== null && "then" in result ? await result : result;
366
366
  }
367
- if (typeControl[rule.type] !== true) {
368
- return rule.actived || false;
367
+ if (typeControl[condition.type] !== true) {
368
+ return condition.actived || false;
369
369
  }
370
- switch (rule.type) {
370
+ switch (condition.type) {
371
371
  case import_types2.RulesType.CURRENT_PAGE:
372
- return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
372
+ return evaluateUrlCondition(condition, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
373
373
  case import_types2.RulesType.TIME:
374
- return evaluateTimeCondition(rule);
374
+ return evaluateTimeCondition(condition);
375
375
  case import_types2.RulesType.USER_ATTR:
376
376
  case import_types2.RulesType.COMPANY_ATTR:
377
377
  return evaluateAttributeCondition(
378
- rule,
378
+ condition,
379
379
  options.attributes || [],
380
380
  options.userAttributes || {}
381
381
  );
382
382
  default:
383
- return rule.actived || false;
383
+ return condition.actived || false;
384
384
  }
385
385
  };
386
386
  var evaluateRulesConditions = async (conditions, options = {}) => {
387
387
  const results = [];
388
- for (const rule of conditions) {
389
- if (rule.type === "group" && rule.conditions) {
388
+ for (const condition of conditions) {
389
+ if (condition.type === "group" && condition.conditions) {
390
390
  results.push({
391
- ...rule,
392
- conditions: await evaluateRulesConditions(rule.conditions, options)
391
+ ...condition,
392
+ conditions: await evaluateRulesConditions(condition.conditions, options)
393
393
  });
394
394
  } else {
395
395
  results.push({
396
- ...rule,
397
- actived: await evaluateRule(rule, options)
396
+ ...condition,
397
+ actived: await evaluateRule(condition, options)
398
398
  });
399
399
  }
400
400
  }
@@ -2,7 +2,7 @@ import {
2
2
  evaluateRulesConditions,
3
3
  filterConditionsByType,
4
4
  isConditionsActived
5
- } from "../chunk-CCL2GU2M.js";
5
+ } from "../chunk-KQRO6BRK.js";
6
6
  import "../chunk-YYIGUZNZ.js";
7
7
  import "../chunk-PAESAL23.js";
8
8
  import "../chunk-PBZSPV5R.js";
@@ -0,0 +1,58 @@
1
+ // src/utils.ts
2
+ var deepClone = (obj) => {
3
+ try {
4
+ return structuredClone(obj);
5
+ } catch (error) {
6
+ console.warn("structuredClone failed, falling back to JSON method:", error);
7
+ return JSON.parse(JSON.stringify(obj));
8
+ }
9
+ };
10
+ var parseUrlParams = (url, paramName) => {
11
+ if (!url || !paramName) {
12
+ return null;
13
+ }
14
+ try {
15
+ const urlObj = new URL(url);
16
+ const searchParams = new URLSearchParams(urlObj.search);
17
+ if (searchParams.has(paramName)) {
18
+ return searchParams.get(paramName);
19
+ }
20
+ if (urlObj.hash) {
21
+ const hashSearch = urlObj.hash.split("?")[1];
22
+ if (hashSearch) {
23
+ const hashParams = new URLSearchParams(hashSearch);
24
+ if (hashParams.has(paramName)) {
25
+ return hashParams.get(paramName);
26
+ }
27
+ }
28
+ }
29
+ return null;
30
+ } catch (error) {
31
+ console.error("Error parsing URL:", error);
32
+ return null;
33
+ }
34
+ };
35
+ var wait = (seconds) => {
36
+ if (typeof seconds !== "number" || Number.isNaN(seconds)) {
37
+ return Promise.reject(new Error("Invalid wait time: must be a number"));
38
+ }
39
+ if (seconds < 0) {
40
+ return Promise.reject(new Error("Invalid wait time: cannot be negative"));
41
+ }
42
+ if (seconds === 0) {
43
+ return Promise.resolve();
44
+ }
45
+ return new Promise((resolve, reject) => {
46
+ try {
47
+ setTimeout(resolve, seconds * 1e3);
48
+ } catch (error) {
49
+ reject(error);
50
+ }
51
+ });
52
+ };
53
+
54
+ export {
55
+ deepClone,
56
+ parseUrlParams,
57
+ wait
58
+ };
@@ -44,50 +44,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
44
44
  return condition;
45
45
  });
46
46
  };
47
- var evaluateRule = async (rule, options) => {
47
+ var evaluateRule = async (condition, options) => {
48
48
  var _a;
49
49
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
50
- const ruleId = rule.id;
51
- if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
50
+ const conditionId = condition.id;
51
+ if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
52
52
  return true;
53
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
53
+ if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
54
54
  return false;
55
- const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
55
+ const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
56
56
  if (customEvaluator) {
57
- const result = customEvaluator(rule, options);
57
+ const result = customEvaluator(condition, options);
58
58
  return typeof result === "object" && result !== null && "then" in result ? await result : result;
59
59
  }
60
- if (typeControl[rule.type] !== true) {
61
- return rule.actived || false;
60
+ if (typeControl[condition.type] !== true) {
61
+ return condition.actived || false;
62
62
  }
63
- switch (rule.type) {
63
+ switch (condition.type) {
64
64
  case RulesType.CURRENT_PAGE:
65
- return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
65
+ return evaluateUrlCondition(condition, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
66
66
  case RulesType.TIME:
67
- return evaluateTimeCondition(rule);
67
+ return evaluateTimeCondition(condition);
68
68
  case RulesType.USER_ATTR:
69
69
  case RulesType.COMPANY_ATTR:
70
70
  return evaluateAttributeCondition(
71
- rule,
71
+ condition,
72
72
  options.attributes || [],
73
73
  options.userAttributes || {}
74
74
  );
75
75
  default:
76
- return rule.actived || false;
76
+ return condition.actived || false;
77
77
  }
78
78
  };
79
79
  var evaluateRulesConditions = async (conditions, options = {}) => {
80
80
  const results = [];
81
- for (const rule of conditions) {
82
- if (rule.type === "group" && rule.conditions) {
81
+ for (const condition of conditions) {
82
+ if (condition.type === "group" && condition.conditions) {
83
83
  results.push({
84
- ...rule,
85
- conditions: await evaluateRulesConditions(rule.conditions, options)
84
+ ...condition,
85
+ conditions: await evaluateRulesConditions(condition.conditions, options)
86
86
  });
87
87
  } else {
88
88
  results.push({
89
- ...rule,
90
- actived: await evaluateRule(rule, options)
89
+ ...condition,
90
+ actived: await evaluateRule(condition, options)
91
91
  });
92
92
  }
93
93
  }
@@ -366,50 +366,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
366
366
  return condition;
367
367
  });
368
368
  };
369
- var evaluateRule = async (rule, options) => {
369
+ var evaluateRule = async (condition, options) => {
370
370
  var _a;
371
371
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
372
- const ruleId = rule.id;
373
- if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
372
+ const conditionId = condition.id;
373
+ if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
374
374
  return true;
375
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
375
+ if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
376
376
  return false;
377
- const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
377
+ const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
378
378
  if (customEvaluator) {
379
- const result = customEvaluator(rule, options);
379
+ const result = customEvaluator(condition, options);
380
380
  return typeof result === "object" && result !== null && "then" in result ? await result : result;
381
381
  }
382
- if (typeControl[rule.type] !== true) {
383
- return rule.actived || false;
382
+ if (typeControl[condition.type] !== true) {
383
+ return condition.actived || false;
384
384
  }
385
- switch (rule.type) {
385
+ switch (condition.type) {
386
386
  case import_types2.RulesType.CURRENT_PAGE:
387
- return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
387
+ return evaluateUrlCondition(condition, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
388
388
  case import_types2.RulesType.TIME:
389
- return evaluateTimeCondition(rule);
389
+ return evaluateTimeCondition(condition);
390
390
  case import_types2.RulesType.USER_ATTR:
391
391
  case import_types2.RulesType.COMPANY_ATTR:
392
392
  return evaluateAttributeCondition(
393
- rule,
393
+ condition,
394
394
  options.attributes || [],
395
395
  options.userAttributes || {}
396
396
  );
397
397
  default:
398
- return rule.actived || false;
398
+ return condition.actived || false;
399
399
  }
400
400
  };
401
401
  var evaluateRulesConditions = async (conditions, options = {}) => {
402
402
  const results = [];
403
- for (const rule of conditions) {
404
- if (rule.type === "group" && rule.conditions) {
403
+ for (const condition of conditions) {
404
+ if (condition.type === "group" && condition.conditions) {
405
405
  results.push({
406
- ...rule,
407
- conditions: await evaluateRulesConditions(rule.conditions, options)
406
+ ...condition,
407
+ conditions: await evaluateRulesConditions(condition.conditions, options)
408
408
  });
409
409
  } else {
410
410
  results.push({
411
- ...rule,
412
- actived: await evaluateRule(rule, options)
411
+ ...condition,
412
+ actived: await evaluateRule(condition, options)
413
413
  });
414
414
  }
415
415
  }
@@ -34,7 +34,7 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
34
34
  * deactivatedIds: ['rule-3']
35
35
  * });
36
36
  */
37
- declare const evaluateRule: (rule: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
37
+ declare const evaluateRule: (condition: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
38
38
  declare const evaluateRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => Promise<RulesCondition[]>;
39
39
 
40
40
  export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived };
@@ -34,7 +34,7 @@ declare const filterConditionsByType: (conditions: RulesCondition[], allowedType
34
34
  * deactivatedIds: ['rule-3']
35
35
  * });
36
36
  */
37
- declare const evaluateRule: (rule: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
37
+ declare const evaluateRule: (condition: RulesCondition, options: RulesEvaluationOptions) => Promise<boolean>;
38
38
  declare const evaluateRulesConditions: (conditions: RulesCondition[], options?: RulesEvaluationOptions) => Promise<RulesCondition[]>;
39
39
 
40
40
  export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived };
@@ -5,7 +5,7 @@ import {
5
5
  filterConditionsByType,
6
6
  isConditionsActived,
7
7
  isEqual
8
- } from "../chunk-CCL2GU2M.js";
8
+ } from "../chunk-KQRO6BRK.js";
9
9
  import "../chunk-YYIGUZNZ.js";
10
10
  import "../chunk-PAESAL23.js";
11
11
  import "../chunk-PBZSPV5R.js";
@@ -372,50 +372,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
372
372
  return condition;
373
373
  });
374
374
  };
375
- var evaluateRule = async (rule, options) => {
375
+ var evaluateRule = async (condition, options) => {
376
376
  var _a;
377
377
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
378
- const ruleId = rule.id;
379
- if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
378
+ const conditionId = condition.id;
379
+ if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
380
380
  return true;
381
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
381
+ if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
382
382
  return false;
383
- const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
383
+ const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
384
384
  if (customEvaluator) {
385
- const result = customEvaluator(rule, options);
385
+ const result = customEvaluator(condition, options);
386
386
  return typeof result === "object" && result !== null && "then" in result ? await result : result;
387
387
  }
388
- if (typeControl[rule.type] !== true) {
389
- return rule.actived || false;
388
+ if (typeControl[condition.type] !== true) {
389
+ return condition.actived || false;
390
390
  }
391
- switch (rule.type) {
391
+ switch (condition.type) {
392
392
  case import_types2.RulesType.CURRENT_PAGE:
393
- return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
393
+ return evaluateUrlCondition(condition, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
394
394
  case import_types2.RulesType.TIME:
395
- return evaluateTimeCondition(rule);
395
+ return evaluateTimeCondition(condition);
396
396
  case import_types2.RulesType.USER_ATTR:
397
397
  case import_types2.RulesType.COMPANY_ATTR:
398
398
  return evaluateAttributeCondition(
399
- rule,
399
+ condition,
400
400
  options.attributes || [],
401
401
  options.userAttributes || {}
402
402
  );
403
403
  default:
404
- return rule.actived || false;
404
+ return condition.actived || false;
405
405
  }
406
406
  };
407
407
  var evaluateRulesConditions = async (conditions, options = {}) => {
408
408
  const results = [];
409
- for (const rule of conditions) {
410
- if (rule.type === "group" && rule.conditions) {
409
+ for (const condition of conditions) {
410
+ if (condition.type === "group" && condition.conditions) {
411
411
  results.push({
412
- ...rule,
413
- conditions: await evaluateRulesConditions(rule.conditions, options)
412
+ ...condition,
413
+ conditions: await evaluateRulesConditions(condition.conditions, options)
414
414
  });
415
415
  } else {
416
416
  results.push({
417
- ...rule,
418
- actived: await evaluateRule(rule, options)
417
+ ...condition,
418
+ actived: await evaluateRule(condition, options)
419
419
  });
420
420
  }
421
421
  }
@@ -6,7 +6,7 @@ import {
6
6
  filterConditionsByType,
7
7
  isConditionsActived,
8
8
  isEqual
9
- } from "../chunk-CCL2GU2M.js";
9
+ } from "../chunk-KQRO6BRK.js";
10
10
  import {
11
11
  evaluateUrlCondition,
12
12
  isMatchUrlPattern
package/dist/index.cjs CHANGED
@@ -109,11 +109,13 @@ __export(src_exports, {
109
109
  nativeForEach: () => nativeForEach,
110
110
  nativeIndexOf: () => nativeIndexOf,
111
111
  navigator: () => navigator,
112
+ parseUrlParams: () => parseUrlParams,
112
113
  removeAuthToken: () => removeAuthToken,
113
114
  setAuthToken: () => setAuthToken,
114
115
  storage: () => storage,
115
116
  userAgent: () => userAgent,
116
117
  uuidV4: () => uuidV4,
118
+ wait: () => wait,
117
119
  window: () => win
118
120
  });
119
121
  module.exports = __toCommonJS(src_exports);
@@ -895,6 +897,49 @@ var deepClone = (obj) => {
895
897
  return JSON.parse(JSON.stringify(obj));
896
898
  }
897
899
  };
900
+ var parseUrlParams = (url, paramName) => {
901
+ if (!url || !paramName) {
902
+ return null;
903
+ }
904
+ try {
905
+ const urlObj = new URL(url);
906
+ const searchParams = new URLSearchParams(urlObj.search);
907
+ if (searchParams.has(paramName)) {
908
+ return searchParams.get(paramName);
909
+ }
910
+ if (urlObj.hash) {
911
+ const hashSearch = urlObj.hash.split("?")[1];
912
+ if (hashSearch) {
913
+ const hashParams = new URLSearchParams(hashSearch);
914
+ if (hashParams.has(paramName)) {
915
+ return hashParams.get(paramName);
916
+ }
917
+ }
918
+ }
919
+ return null;
920
+ } catch (error) {
921
+ console.error("Error parsing URL:", error);
922
+ return null;
923
+ }
924
+ };
925
+ var wait = (seconds) => {
926
+ if (typeof seconds !== "number" || Number.isNaN(seconds)) {
927
+ return Promise.reject(new Error("Invalid wait time: must be a number"));
928
+ }
929
+ if (seconds < 0) {
930
+ return Promise.reject(new Error("Invalid wait time: cannot be negative"));
931
+ }
932
+ if (seconds === 0) {
933
+ return Promise.resolve();
934
+ }
935
+ return new Promise((resolve, reject) => {
936
+ try {
937
+ setTimeout(resolve, seconds * 1e3);
938
+ } catch (error) {
939
+ reject(error);
940
+ }
941
+ });
942
+ };
898
943
 
899
944
  // src/helper.ts
900
945
  var import_clsx = require("clsx");
@@ -1293,50 +1338,50 @@ var filterConditionsByType = (conditions, allowedTypes) => {
1293
1338
  return condition;
1294
1339
  });
1295
1340
  };
1296
- var evaluateRule = async (rule, options) => {
1341
+ var evaluateRule = async (condition, options) => {
1297
1342
  var _a;
1298
1343
  const { typeControl = {}, activatedIds, deactivatedIds, customEvaluators } = options;
1299
- const ruleId = rule.id;
1300
- if (activatedIds == null ? void 0 : activatedIds.includes(ruleId))
1344
+ const conditionId = condition.id;
1345
+ if (activatedIds == null ? void 0 : activatedIds.includes(conditionId))
1301
1346
  return true;
1302
- if (deactivatedIds == null ? void 0 : deactivatedIds.includes(ruleId))
1347
+ if (deactivatedIds == null ? void 0 : deactivatedIds.includes(conditionId))
1303
1348
  return false;
1304
- const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[rule.type];
1349
+ const customEvaluator = customEvaluators == null ? void 0 : customEvaluators[condition.type];
1305
1350
  if (customEvaluator) {
1306
- const result = customEvaluator(rule, options);
1351
+ const result = customEvaluator(condition, options);
1307
1352
  return typeof result === "object" && result !== null && "then" in result ? await result : result;
1308
1353
  }
1309
- if (typeControl[rule.type] !== true) {
1310
- return rule.actived || false;
1354
+ if (typeControl[condition.type] !== true) {
1355
+ return condition.actived || false;
1311
1356
  }
1312
- switch (rule.type) {
1357
+ switch (condition.type) {
1313
1358
  case import_types5.RulesType.CURRENT_PAGE:
1314
- return evaluateUrlCondition(rule, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
1359
+ return evaluateUrlCondition(condition, ((_a = options.clientContext) == null ? void 0 : _a.page_url) || "");
1315
1360
  case import_types5.RulesType.TIME:
1316
- return evaluateTimeCondition(rule);
1361
+ return evaluateTimeCondition(condition);
1317
1362
  case import_types5.RulesType.USER_ATTR:
1318
1363
  case import_types5.RulesType.COMPANY_ATTR:
1319
1364
  return evaluateAttributeCondition(
1320
- rule,
1365
+ condition,
1321
1366
  options.attributes || [],
1322
1367
  options.userAttributes || {}
1323
1368
  );
1324
1369
  default:
1325
- return rule.actived || false;
1370
+ return condition.actived || false;
1326
1371
  }
1327
1372
  };
1328
1373
  var evaluateRulesConditions = async (conditions, options = {}) => {
1329
1374
  const results = [];
1330
- for (const rule of conditions) {
1331
- if (rule.type === "group" && rule.conditions) {
1375
+ for (const condition of conditions) {
1376
+ if (condition.type === "group" && condition.conditions) {
1332
1377
  results.push({
1333
- ...rule,
1334
- conditions: await evaluateRulesConditions(rule.conditions, options)
1378
+ ...condition,
1379
+ conditions: await evaluateRulesConditions(condition.conditions, options)
1335
1380
  });
1336
1381
  } else {
1337
1382
  results.push({
1338
- ...rule,
1339
- actived: await evaluateRule(rule, options)
1383
+ ...condition,
1384
+ actived: await evaluateRule(condition, options)
1340
1385
  });
1341
1386
  }
1342
1387
  }
@@ -1418,10 +1463,12 @@ var evaluateRulesConditions = async (conditions, options = {}) => {
1418
1463
  nativeForEach,
1419
1464
  nativeIndexOf,
1420
1465
  navigator,
1466
+ parseUrlParams,
1421
1467
  removeAuthToken,
1422
1468
  setAuthToken,
1423
1469
  storage,
1424
1470
  userAgent,
1425
1471
  uuidV4,
1472
+ wait,
1426
1473
  window
1427
1474
  });
package/dist/index.d.cts CHANGED
@@ -6,7 +6,7 @@ export { defaultStep } from './settings.cjs';
6
6
  export { isUrl } from './is-url.cjs';
7
7
  export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.cjs';
8
8
  export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.cjs';
9
- export { deepClone } from './utils.cjs';
9
+ export { deepClone, parseUrlParams, wait } from './utils.cjs';
10
10
  export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.cjs';
11
11
  export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.cjs';
12
12
  export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './conditions/condition.cjs';
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@ export { defaultStep } from './settings.js';
6
6
  export { isUrl } from './is-url.js';
7
7
  export { AbortController, ArrayProto, XMLHttpRequest, assignableWindow, document, fetch, location, nativeForEach, nativeIndexOf, navigator, userAgent, window } from './globals.js';
8
8
  export { buildConfig, defaultContentConfig, isPublishedAtLeastOneEnvironment, isPublishedInAllEnvironments } from './content.js';
9
- export { deepClone } from './utils.js';
9
+ export { deepClone, parseUrlParams, wait } from './utils.js';
10
10
  export { generateAutoStateColors, hexToHSLString, hexToRGBStr } from './color.js';
11
11
  export { absoluteUrl, cn, cuid, evalCode, formatDate, getRandomColor, hexToRgb, isDark, uuidV4 } from './helper.js';
12
12
  export { conditionsIsSame, evaluateRule, evaluateRulesConditions, filterConditionsByType, isConditionsActived } from './conditions/condition.js';
package/dist/index.js CHANGED
@@ -6,8 +6,10 @@ import {
6
6
  defaultStep
7
7
  } from "./chunk-FW54TSA3.js";
8
8
  import {
9
- deepClone
10
- } from "./chunk-2AEGAICC.js";
9
+ deepClone,
10
+ parseUrlParams,
11
+ wait
12
+ } from "./chunk-5C3J4DM2.js";
11
13
  import {
12
14
  conditionsIsSame,
13
15
  evaluateRule,
@@ -15,7 +17,7 @@ import {
15
17
  filterConditionsByType,
16
18
  isConditionsActived,
17
19
  isEqual
18
- } from "./chunk-CCL2GU2M.js";
20
+ } from "./chunk-KQRO6BRK.js";
19
21
  import {
20
22
  evaluateUrlCondition,
21
23
  isMatchUrlPattern
@@ -187,10 +189,12 @@ export {
187
189
  nativeForEach,
188
190
  nativeIndexOf,
189
191
  navigator,
192
+ parseUrlParams,
190
193
  removeAuthToken,
191
194
  setAuthToken,
192
195
  storage,
193
196
  userAgent,
194
197
  uuidV4,
198
+ wait,
195
199
  win as window
196
200
  };
package/dist/utils.cjs CHANGED
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/utils.ts
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
- deepClone: () => deepClone
23
+ deepClone: () => deepClone,
24
+ parseUrlParams: () => parseUrlParams,
25
+ wait: () => wait
24
26
  });
25
27
  module.exports = __toCommonJS(utils_exports);
26
28
  var deepClone = (obj) => {
@@ -31,7 +33,52 @@ var deepClone = (obj) => {
31
33
  return JSON.parse(JSON.stringify(obj));
32
34
  }
33
35
  };
36
+ var parseUrlParams = (url, paramName) => {
37
+ if (!url || !paramName) {
38
+ return null;
39
+ }
40
+ try {
41
+ const urlObj = new URL(url);
42
+ const searchParams = new URLSearchParams(urlObj.search);
43
+ if (searchParams.has(paramName)) {
44
+ return searchParams.get(paramName);
45
+ }
46
+ if (urlObj.hash) {
47
+ const hashSearch = urlObj.hash.split("?")[1];
48
+ if (hashSearch) {
49
+ const hashParams = new URLSearchParams(hashSearch);
50
+ if (hashParams.has(paramName)) {
51
+ return hashParams.get(paramName);
52
+ }
53
+ }
54
+ }
55
+ return null;
56
+ } catch (error) {
57
+ console.error("Error parsing URL:", error);
58
+ return null;
59
+ }
60
+ };
61
+ var wait = (seconds) => {
62
+ if (typeof seconds !== "number" || Number.isNaN(seconds)) {
63
+ return Promise.reject(new Error("Invalid wait time: must be a number"));
64
+ }
65
+ if (seconds < 0) {
66
+ return Promise.reject(new Error("Invalid wait time: cannot be negative"));
67
+ }
68
+ if (seconds === 0) {
69
+ return Promise.resolve();
70
+ }
71
+ return new Promise((resolve, reject) => {
72
+ try {
73
+ setTimeout(resolve, seconds * 1e3);
74
+ } catch (error) {
75
+ reject(error);
76
+ }
77
+ });
78
+ };
34
79
  // Annotate the CommonJS export names for ESM import in node:
35
80
  0 && (module.exports = {
36
- deepClone
81
+ deepClone,
82
+ parseUrlParams,
83
+ wait
37
84
  });
package/dist/utils.d.cts CHANGED
@@ -4,5 +4,7 @@
4
4
  * @returns A deep copy of the object
5
5
  */
6
6
  declare const deepClone: <T>(obj: T) => T;
7
+ declare const parseUrlParams: (url: string, paramName: string) => string | null;
8
+ declare const wait: (seconds: number) => Promise<void>;
7
9
 
8
- export { deepClone };
10
+ export { deepClone, parseUrlParams, wait };
package/dist/utils.d.ts CHANGED
@@ -4,5 +4,7 @@
4
4
  * @returns A deep copy of the object
5
5
  */
6
6
  declare const deepClone: <T>(obj: T) => T;
7
+ declare const parseUrlParams: (url: string, paramName: string) => string | null;
8
+ declare const wait: (seconds: number) => Promise<void>;
7
9
 
8
- export { deepClone };
10
+ export { deepClone, parseUrlParams, wait };
package/dist/utils.js CHANGED
@@ -1,7 +1,11 @@
1
1
  import {
2
- deepClone
3
- } from "./chunk-2AEGAICC.js";
2
+ deepClone,
3
+ parseUrlParams,
4
+ wait
5
+ } from "./chunk-5C3J4DM2.js";
4
6
  import "./chunk-XEO3YXBM.js";
5
7
  export {
6
- deepClone
8
+ deepClone,
9
+ parseUrlParams,
10
+ wait
7
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "description": "Utility functions and helpers shared across the UserTour project",
6
6
  "homepage": "https://www.usertour.io",
@@ -1,13 +0,0 @@
1
- // src/utils.ts
2
- var deepClone = (obj) => {
3
- try {
4
- return structuredClone(obj);
5
- } catch (error) {
6
- console.warn("structuredClone failed, falling back to JSON method:", error);
7
- return JSON.parse(JSON.stringify(obj));
8
- }
9
- };
10
-
11
- export {
12
- deepClone
13
- };