@usertour/helpers 0.0.33 → 0.0.35

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.
@@ -26,6 +26,15 @@ __export(attribute_exports, {
26
26
  module.exports = __toCommonJS(attribute_exports);
27
27
  var import_types = require("@usertour/types");
28
28
  var import_date_fns = require("date-fns");
29
+
30
+ // src/type-utils.ts
31
+ var nativeIsArray = Array.isArray;
32
+ var ObjProto = Object.prototype;
33
+ var objToString = ObjProto.toString;
34
+ var objHasOwn = ObjProto.hasOwnProperty;
35
+ var isArray = nativeIsArray || ((obj) => objToString.call(obj) === "[object Array]");
36
+
37
+ // src/conditions/attribute.ts
29
38
  function evaluateFilterConditions(conditions, options) {
30
39
  if (!conditions || !conditions.length) {
31
40
  return true;
@@ -130,26 +139,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
130
139
  }
131
140
  }
132
141
  function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
133
- const numValue = Number(actualValue);
134
- const numValue2 = Number(expectedValue2);
135
- if (Number.isNaN(numValue)) {
142
+ const numActualValue = Number(actualValue);
143
+ const numExpectedValue = Number(expectedValue);
144
+ const numExpectedValue2 = Number(expectedValue2);
145
+ if (Number.isNaN(numActualValue)) {
136
146
  return false;
137
147
  }
138
148
  switch (logic) {
139
149
  case "is":
140
- return numValue === expectedValue;
150
+ return numActualValue === numExpectedValue;
141
151
  case "not":
142
- return numValue !== expectedValue;
152
+ return numActualValue !== numExpectedValue;
143
153
  case "isLessThan":
144
- return numValue < expectedValue;
154
+ return numActualValue < numExpectedValue;
145
155
  case "isLessThanOrEqualTo":
146
- return numValue <= expectedValue;
156
+ return numActualValue <= numExpectedValue;
147
157
  case "isGreaterThan":
148
- return numValue > expectedValue;
158
+ return numActualValue > numExpectedValue;
149
159
  case "isGreaterThanOrEqualTo":
150
- return numValue >= expectedValue;
160
+ return numActualValue >= numExpectedValue;
151
161
  case "between":
152
- return numValue >= expectedValue && numValue <= numValue2;
162
+ return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
153
163
  case "empty":
154
164
  return actualValue === null || actualValue === void 0 || actualValue === "";
155
165
  case "any":
@@ -173,7 +183,7 @@ function evaluateBooleanCondition(logic, actualValue) {
173
183
  }
174
184
  }
175
185
  function evaluateListCondition(logic, actualValue, expectedValues) {
176
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
186
+ const arrayValue = isArray(actualValue) ? actualValue : [];
177
187
  if (logic === "empty" || logic === "any") {
178
188
  switch (logic) {
179
189
  case "empty":
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  evaluateAttributeCondition,
3
3
  evaluateFilterConditions
4
- } from "../chunk-E2APTIR7.js";
4
+ } from "../chunk-KYDXF7SU.js";
5
+ import "../chunk-GFH3VWOC.js";
5
6
  import "../chunk-XEO3YXBM.js";
6
7
  export {
7
8
  evaluateAttributeCondition,
@@ -158,6 +158,15 @@ var evaluateTimeCondition = (rules) => {
158
158
  // src/conditions/attribute.ts
159
159
  var import_types = require("@usertour/types");
160
160
  var import_date_fns2 = require("date-fns");
161
+
162
+ // src/type-utils.ts
163
+ var nativeIsArray = Array.isArray;
164
+ var ObjProto = Object.prototype;
165
+ var objToString = ObjProto.toString;
166
+ var objHasOwn = ObjProto.hasOwnProperty;
167
+ var isArray = nativeIsArray || ((obj) => objToString.call(obj) === "[object Array]");
168
+
169
+ // src/conditions/attribute.ts
161
170
  function evaluateAttributeCondition(condition, options) {
162
171
  const { data } = condition;
163
172
  if (!data) {
@@ -225,26 +234,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
225
234
  }
226
235
  }
227
236
  function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
228
- const numValue = Number(actualValue);
229
- const numValue2 = Number(expectedValue2);
230
- if (Number.isNaN(numValue)) {
237
+ const numActualValue = Number(actualValue);
238
+ const numExpectedValue = Number(expectedValue);
239
+ const numExpectedValue2 = Number(expectedValue2);
240
+ if (Number.isNaN(numActualValue)) {
231
241
  return false;
232
242
  }
233
243
  switch (logic) {
234
244
  case "is":
235
- return numValue === expectedValue;
245
+ return numActualValue === numExpectedValue;
236
246
  case "not":
237
- return numValue !== expectedValue;
247
+ return numActualValue !== numExpectedValue;
238
248
  case "isLessThan":
239
- return numValue < expectedValue;
249
+ return numActualValue < numExpectedValue;
240
250
  case "isLessThanOrEqualTo":
241
- return numValue <= expectedValue;
251
+ return numActualValue <= numExpectedValue;
242
252
  case "isGreaterThan":
243
- return numValue > expectedValue;
253
+ return numActualValue > numExpectedValue;
244
254
  case "isGreaterThanOrEqualTo":
245
- return numValue >= expectedValue;
255
+ return numActualValue >= numExpectedValue;
246
256
  case "between":
247
- return numValue >= expectedValue && numValue <= numValue2;
257
+ return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
248
258
  case "empty":
249
259
  return actualValue === null || actualValue === void 0 || actualValue === "";
250
260
  case "any":
@@ -268,7 +278,7 @@ function evaluateBooleanCondition(logic, actualValue) {
268
278
  }
269
279
  }
270
280
  function evaluateListCondition(logic, actualValue, expectedValues) {
271
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
281
+ const arrayValue = isArray(actualValue) ? actualValue : [];
272
282
  if (logic === "empty" || logic === "any") {
273
283
  switch (logic) {
274
284
  case "empty":
@@ -8,11 +8,12 @@ import {
8
8
  isConditionsActived,
9
9
  isEqual,
10
10
  regenerateConditionIds
11
- } from "../chunk-YZQBWYCU.js";
11
+ } from "../chunk-NVSDWUJP.js";
12
12
  import "../chunk-YYIGUZNZ.js";
13
13
  import "../chunk-PAESAL23.js";
14
- import "../chunk-E2APTIR7.js";
15
14
  import "../chunk-CEK3SCQO.js";
15
+ import "../chunk-KYDXF7SU.js";
16
+ import "../chunk-GFH3VWOC.js";
16
17
  import "../chunk-3KG2HTZ3.js";
17
18
  import "../chunk-XEO3YXBM.js";
18
19
  export {
@@ -164,6 +164,15 @@ var evaluateTimeCondition = (rules) => {
164
164
  // src/conditions/attribute.ts
165
165
  var import_types = require("@usertour/types");
166
166
  var import_date_fns2 = require("date-fns");
167
+
168
+ // src/type-utils.ts
169
+ var nativeIsArray = Array.isArray;
170
+ var ObjProto = Object.prototype;
171
+ var objToString = ObjProto.toString;
172
+ var objHasOwn = ObjProto.hasOwnProperty;
173
+ var isArray = nativeIsArray || ((obj) => objToString.call(obj) === "[object Array]");
174
+
175
+ // src/conditions/attribute.ts
167
176
  function evaluateAttributeCondition(condition, options) {
168
177
  const { data } = condition;
169
178
  if (!data) {
@@ -231,26 +240,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
231
240
  }
232
241
  }
233
242
  function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
234
- const numValue = Number(actualValue);
235
- const numValue2 = Number(expectedValue2);
236
- if (Number.isNaN(numValue)) {
243
+ const numActualValue = Number(actualValue);
244
+ const numExpectedValue = Number(expectedValue);
245
+ const numExpectedValue2 = Number(expectedValue2);
246
+ if (Number.isNaN(numActualValue)) {
237
247
  return false;
238
248
  }
239
249
  switch (logic) {
240
250
  case "is":
241
- return numValue === expectedValue;
251
+ return numActualValue === numExpectedValue;
242
252
  case "not":
243
- return numValue !== expectedValue;
253
+ return numActualValue !== numExpectedValue;
244
254
  case "isLessThan":
245
- return numValue < expectedValue;
255
+ return numActualValue < numExpectedValue;
246
256
  case "isLessThanOrEqualTo":
247
- return numValue <= expectedValue;
257
+ return numActualValue <= numExpectedValue;
248
258
  case "isGreaterThan":
249
- return numValue > expectedValue;
259
+ return numActualValue > numExpectedValue;
250
260
  case "isGreaterThanOrEqualTo":
251
- return numValue >= expectedValue;
261
+ return numActualValue >= numExpectedValue;
252
262
  case "between":
253
- return numValue >= expectedValue && numValue <= numValue2;
263
+ return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
254
264
  case "empty":
255
265
  return actualValue === null || actualValue === void 0 || actualValue === "";
256
266
  case "any":
@@ -274,7 +284,7 @@ function evaluateBooleanCondition(logic, actualValue) {
274
284
  }
275
285
  }
276
286
  function evaluateListCondition(logic, actualValue, expectedValues) {
277
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
287
+ const arrayValue = isArray(actualValue) ? actualValue : [];
278
288
  if (logic === "empty" || logic === "any") {
279
289
  switch (logic) {
280
290
  case "empty":
@@ -9,18 +9,19 @@ import {
9
9
  isConditionsActived,
10
10
  isEqual,
11
11
  regenerateConditionIds
12
- } from "../chunk-YZQBWYCU.js";
12
+ } from "../chunk-NVSDWUJP.js";
13
13
  import {
14
14
  evaluateUrlCondition,
15
15
  isMatchUrlPattern
16
16
  } from "../chunk-YYIGUZNZ.js";
17
17
  import "../chunk-PAESAL23.js";
18
- import {
19
- evaluateAttributeCondition
20
- } from "../chunk-E2APTIR7.js";
21
18
  import {
22
19
  evaluateTimeCondition
23
20
  } from "../chunk-CEK3SCQO.js";
21
+ import {
22
+ evaluateAttributeCondition
23
+ } from "../chunk-KYDXF7SU.js";
24
+ import "../chunk-GFH3VWOC.js";
24
25
  import "../chunk-3KG2HTZ3.js";
25
26
  import "../chunk-XEO3YXBM.js";
26
27
  export {
package/dist/index.cjs CHANGED
@@ -43,6 +43,7 @@ __export(src_exports, {
43
43
  assignConditionIds: () => assignConditionIds,
44
44
  assignableWindow: () => assignableWindow,
45
45
  buildConfig: () => buildConfig,
46
+ capitalizeFirstLetter: () => capitalizeFirstLetter,
46
47
  cn: () => cn,
47
48
  conditionsIsSame: () => conditionsIsSame,
48
49
  convertSettings: () => convertSettings,
@@ -60,8 +61,10 @@ __export(src_exports, {
60
61
  evaluateUrlCondition: () => evaluateUrlCondition,
61
62
  fetch: () => fetch,
62
63
  filterConditionsByType: () => filterConditionsByType,
64
+ filterNullAttributes: () => filterNullAttributes,
63
65
  formatDate: () => formatDate,
64
66
  generateAutoStateColors: () => generateAutoStateColors,
67
+ getAttributeType: () => getAttributeType,
65
68
  getAuthToken: () => getAuthToken,
66
69
  getCodeError: () => getCodeError,
67
70
  getContentError: () => getContentError,
@@ -1196,26 +1199,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
1196
1199
  }
1197
1200
  }
1198
1201
  function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
1199
- const numValue = Number(actualValue);
1200
- const numValue2 = Number(expectedValue2);
1201
- if (Number.isNaN(numValue)) {
1202
+ const numActualValue = Number(actualValue);
1203
+ const numExpectedValue = Number(expectedValue);
1204
+ const numExpectedValue2 = Number(expectedValue2);
1205
+ if (Number.isNaN(numActualValue)) {
1202
1206
  return false;
1203
1207
  }
1204
1208
  switch (logic) {
1205
1209
  case "is":
1206
- return numValue === expectedValue;
1210
+ return numActualValue === numExpectedValue;
1207
1211
  case "not":
1208
- return numValue !== expectedValue;
1212
+ return numActualValue !== numExpectedValue;
1209
1213
  case "isLessThan":
1210
- return numValue < expectedValue;
1214
+ return numActualValue < numExpectedValue;
1211
1215
  case "isLessThanOrEqualTo":
1212
- return numValue <= expectedValue;
1216
+ return numActualValue <= numExpectedValue;
1213
1217
  case "isGreaterThan":
1214
- return numValue > expectedValue;
1218
+ return numActualValue > numExpectedValue;
1215
1219
  case "isGreaterThanOrEqualTo":
1216
- return numValue >= expectedValue;
1220
+ return numActualValue >= numExpectedValue;
1217
1221
  case "between":
1218
- return numValue >= expectedValue && numValue <= numValue2;
1222
+ return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
1219
1223
  case "empty":
1220
1224
  return actualValue === null || actualValue === void 0 || actualValue === "";
1221
1225
  case "any":
@@ -1239,7 +1243,7 @@ function evaluateBooleanCondition(logic, actualValue) {
1239
1243
  }
1240
1244
  }
1241
1245
  function evaluateListCondition(logic, actualValue, expectedValues) {
1242
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
1246
+ const arrayValue = isArray(actualValue) ? actualValue : [];
1243
1247
  if (logic === "empty" || logic === "any") {
1244
1248
  switch (logic) {
1245
1249
  case "empty":
@@ -1423,6 +1427,75 @@ var allConditionsHaveIds = (conditions) => {
1423
1427
  }
1424
1428
  return true;
1425
1429
  };
1430
+
1431
+ // src/attribute.ts
1432
+ var import_types6 = require("@usertour/types");
1433
+ var import_date_fns3 = require("date-fns");
1434
+ var isValidYear = (date) => {
1435
+ const year = date.getFullYear();
1436
+ return year >= 1900 && year <= 2100;
1437
+ };
1438
+ var tryParseDate = (parser) => {
1439
+ try {
1440
+ const date = parser();
1441
+ return (0, import_date_fns3.isValid)(date) && isValidYear(date);
1442
+ } catch {
1443
+ return false;
1444
+ }
1445
+ };
1446
+ function isDateString(dateStr) {
1447
+ if (!Number.isNaN(Number(dateStr)) || dateStr.length < 10) {
1448
+ return false;
1449
+ }
1450
+ const dateFormats = [
1451
+ "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
1452
+ "yyyy-MM-dd'T'HH:mm:ss'Z'",
1453
+ "yyyy-MM-dd'T'HH:mm:ss.SSS",
1454
+ "yyyy-MM-dd'T'HH:mm:ss",
1455
+ "yyyy-MM-dd",
1456
+ "MM/dd/yyyy",
1457
+ "dd/MM/yyyy",
1458
+ "yyyy/MM/dd",
1459
+ "MM-dd-yyyy",
1460
+ "dd-MM-yyyy"
1461
+ ];
1462
+ if (tryParseDate(() => (0, import_date_fns3.parseISO)(dateStr))) {
1463
+ return true;
1464
+ }
1465
+ return dateFormats.some((format) => tryParseDate(() => (0, import_date_fns3.parse)(dateStr, format, /* @__PURE__ */ new Date())));
1466
+ }
1467
+ var getAttributeType = (attribute) => {
1468
+ const t = typeof attribute;
1469
+ if (t === "number") {
1470
+ return import_types6.BizAttributeTypes.Number;
1471
+ }
1472
+ if (t === "string") {
1473
+ if (isDateString(attribute)) {
1474
+ return import_types6.BizAttributeTypes.DateTime;
1475
+ }
1476
+ return import_types6.BizAttributeTypes.String;
1477
+ }
1478
+ if (t === "boolean") {
1479
+ return import_types6.BizAttributeTypes.Boolean;
1480
+ }
1481
+ if (t === "object" && Array.isArray(attribute)) {
1482
+ return import_types6.BizAttributeTypes.List;
1483
+ }
1484
+ return import_types6.BizAttributeTypes.Nil;
1485
+ };
1486
+ var capitalizeFirstLetter = (string) => {
1487
+ return string.charAt(0).toUpperCase() + string.slice(1);
1488
+ };
1489
+ var filterNullAttributes = (attributes) => {
1490
+ const attrs = {};
1491
+ for (const key in attributes) {
1492
+ const v = attributes[key];
1493
+ if (!isNull(v)) {
1494
+ attrs[key] = v;
1495
+ }
1496
+ }
1497
+ return attrs;
1498
+ };
1426
1499
  // Annotate the CommonJS export names for ESM import in node:
1427
1500
  0 && (module.exports = {
1428
1501
  AbortController,
@@ -1433,6 +1506,7 @@ var allConditionsHaveIds = (conditions) => {
1433
1506
  assignConditionIds,
1434
1507
  assignableWindow,
1435
1508
  buildConfig,
1509
+ capitalizeFirstLetter,
1436
1510
  cn,
1437
1511
  conditionsIsSame,
1438
1512
  convertSettings,
@@ -1450,8 +1524,10 @@ var allConditionsHaveIds = (conditions) => {
1450
1524
  evaluateUrlCondition,
1451
1525
  fetch,
1452
1526
  filterConditionsByType,
1527
+ filterNullAttributes,
1453
1528
  formatDate,
1454
1529
  generateAutoStateColors,
1530
+ getAttributeType,
1455
1531
  getAuthToken,
1456
1532
  getCodeError,
1457
1533
  getContentError,
package/dist/index.d.cts CHANGED
@@ -13,6 +13,7 @@ export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRul
13
13
  export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.cjs';
14
14
  export { evaluateTimeCondition } from './conditions/time.cjs';
15
15
  export { evaluateAttributeCondition } from './conditions/attribute.cjs';
16
+ export { capitalizeFirstLetter, filterNullAttributes, getAttributeType } from './attribute.cjs';
16
17
  export { default as isEqual } from 'fast-deep-equal';
17
18
  import '@usertour/types';
18
19
  import './storage.cjs';
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export { allConditionsHaveIds, assignConditionIds, conditionsIsSame, evaluateRul
13
13
  export { evaluateUrlCondition, isMatchUrlPattern } from './conditions/url.js';
14
14
  export { evaluateTimeCondition } from './conditions/time.js';
15
15
  export { evaluateAttributeCondition } from './conditions/attribute.js';
16
+ export { capitalizeFirstLetter, filterNullAttributes, getAttributeType } from './attribute.js';
16
17
  export { default as isEqual } from 'fast-deep-equal';
17
18
  import '@usertour/types';
18
19
  import './storage.js';
package/dist/index.js CHANGED
@@ -20,18 +20,23 @@ import {
20
20
  isConditionsActived,
21
21
  isEqual,
22
22
  regenerateConditionIds
23
- } from "./chunk-YZQBWYCU.js";
23
+ } from "./chunk-NVSDWUJP.js";
24
24
  import {
25
25
  evaluateUrlCondition,
26
26
  isMatchUrlPattern
27
27
  } from "./chunk-YYIGUZNZ.js";
28
28
  import "./chunk-PAESAL23.js";
29
- import {
30
- evaluateAttributeCondition
31
- } from "./chunk-E2APTIR7.js";
32
29
  import {
33
30
  evaluateTimeCondition
34
31
  } from "./chunk-CEK3SCQO.js";
32
+ import {
33
+ evaluateAttributeCondition
34
+ } from "./chunk-KYDXF7SU.js";
35
+ import {
36
+ capitalizeFirstLetter,
37
+ filterNullAttributes,
38
+ getAttributeType
39
+ } from "./chunk-EEYZG4JJ.js";
35
40
  import {
36
41
  getAuthToken,
37
42
  removeAuthToken,
@@ -126,6 +131,7 @@ export {
126
131
  assignConditionIds,
127
132
  assignableWindow,
128
133
  buildConfig,
134
+ capitalizeFirstLetter,
129
135
  cn,
130
136
  conditionsIsSame,
131
137
  convertSettings,
@@ -143,8 +149,10 @@ export {
143
149
  evaluateUrlCondition,
144
150
  fetch,
145
151
  filterConditionsByType,
152
+ filterNullAttributes,
146
153
  formatDate,
147
154
  generateAutoStateColors,
155
+ getAttributeType,
148
156
  getAuthToken,
149
157
  getCodeError,
150
158
  getContentError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usertour/helpers",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "type": "module",
5
5
  "description": "Utility functions and helpers shared across the UserTour project",
6
6
  "homepage": "https://www.usertour.io",