@usertour/helpers 0.0.34 → 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.
@@ -6,6 +6,15 @@ var import_types2 = require("@usertour/types");
6
6
  // src/conditions/attribute.ts
7
7
  var import_types = require("@usertour/types");
8
8
  var import_date_fns = require("date-fns");
9
+
10
+ // src/type-utils.ts
11
+ var nativeIsArray = Array.isArray;
12
+ var ObjProto = Object.prototype;
13
+ var objToString = ObjProto.toString;
14
+ var objHasOwn = ObjProto.hasOwnProperty;
15
+ var isArray = nativeIsArray || ((obj) => objToString.call(obj) === "[object Array]");
16
+
17
+ // src/conditions/attribute.ts
9
18
  function evaluateFilterConditions(conditions, options) {
10
19
  if (!conditions || !conditions.length) {
11
20
  return true;
@@ -154,7 +163,7 @@ function evaluateBooleanCondition(logic, actualValue) {
154
163
  }
155
164
  }
156
165
  function evaluateListCondition(logic, actualValue, expectedValues) {
157
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
166
+ const arrayValue = isArray(actualValue) ? actualValue : [];
158
167
  if (logic === "empty" || logic === "any") {
159
168
  switch (logic) {
160
169
  case "empty":
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  evaluateAttributeCondition,
3
3
  evaluateFilterConditions
4
- } from "../chunk-7JXEY4A2.js";
4
+ } from "../chunk-KYDXF7SU.js";
5
+ import "../chunk-GFH3VWOC.js";
5
6
  import "../chunk-XEO3YXBM.js";
6
7
 
7
8
  // src/__tests__/attribute.test.ts
@@ -143,6 +143,15 @@ var evaluateTimeCondition = (rules) => {
143
143
  // src/conditions/attribute.ts
144
144
  var import_types = require("@usertour/types");
145
145
  var import_date_fns2 = require("date-fns");
146
+
147
+ // src/type-utils.ts
148
+ var nativeIsArray = Array.isArray;
149
+ var ObjProto = Object.prototype;
150
+ var objToString = ObjProto.toString;
151
+ var objHasOwn = ObjProto.hasOwnProperty;
152
+ var isArray = nativeIsArray || ((obj) => objToString.call(obj) === "[object Array]");
153
+
154
+ // src/conditions/attribute.ts
146
155
  function evaluateAttributeCondition(condition, options) {
147
156
  const { data } = condition;
148
157
  if (!data) {
@@ -254,7 +263,7 @@ function evaluateBooleanCondition(logic, actualValue) {
254
263
  }
255
264
  }
256
265
  function evaluateListCondition(logic, actualValue, expectedValues) {
257
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
266
+ const arrayValue = isArray(actualValue) ? actualValue : [];
258
267
  if (logic === "empty" || logic === "any") {
259
268
  switch (logic) {
260
269
  case "empty":
@@ -2,11 +2,12 @@ import {
2
2
  evaluateRulesConditions,
3
3
  filterConditionsByType,
4
4
  isConditionsActived
5
- } from "../chunk-A4KMGXB3.js";
5
+ } from "../chunk-NVSDWUJP.js";
6
6
  import "../chunk-YYIGUZNZ.js";
7
7
  import "../chunk-PAESAL23.js";
8
- import "../chunk-7JXEY4A2.js";
9
8
  import "../chunk-CEK3SCQO.js";
9
+ import "../chunk-KYDXF7SU.js";
10
+ import "../chunk-GFH3VWOC.js";
10
11
  import "../chunk-3KG2HTZ3.js";
11
12
  import "../chunk-XEO3YXBM.js";
12
13
 
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+
3
+ // src/__tests__/get-attribute-type.test.ts
4
+ var import_types2 = require("@usertour/types");
5
+
6
+ // src/attribute.ts
7
+ var import_types = require("@usertour/types");
8
+ var import_date_fns = require("date-fns");
9
+
10
+ // src/type-utils.ts
11
+ var nativeIsArray = Array.isArray;
12
+ var ObjProto = Object.prototype;
13
+ var objToString = ObjProto.toString;
14
+ var objHasOwn = ObjProto.hasOwnProperty;
15
+
16
+ // src/attribute.ts
17
+ var isValidYear = (date) => {
18
+ const year = date.getFullYear();
19
+ return year >= 1900 && year <= 2100;
20
+ };
21
+ var tryParseDate = (parser) => {
22
+ try {
23
+ const date = parser();
24
+ return (0, import_date_fns.isValid)(date) && isValidYear(date);
25
+ } catch {
26
+ return false;
27
+ }
28
+ };
29
+ function isDateString(dateStr) {
30
+ if (!Number.isNaN(Number(dateStr)) || dateStr.length < 10) {
31
+ return false;
32
+ }
33
+ const dateFormats = [
34
+ "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
35
+ "yyyy-MM-dd'T'HH:mm:ss'Z'",
36
+ "yyyy-MM-dd'T'HH:mm:ss.SSS",
37
+ "yyyy-MM-dd'T'HH:mm:ss",
38
+ "yyyy-MM-dd",
39
+ "MM/dd/yyyy",
40
+ "dd/MM/yyyy",
41
+ "yyyy/MM/dd",
42
+ "MM-dd-yyyy",
43
+ "dd-MM-yyyy"
44
+ ];
45
+ if (tryParseDate(() => (0, import_date_fns.parseISO)(dateStr))) {
46
+ return true;
47
+ }
48
+ return dateFormats.some((format) => tryParseDate(() => (0, import_date_fns.parse)(dateStr, format, /* @__PURE__ */ new Date())));
49
+ }
50
+ var getAttributeType = (attribute) => {
51
+ const t = typeof attribute;
52
+ if (t === "number") {
53
+ return import_types.BizAttributeTypes.Number;
54
+ }
55
+ if (t === "string") {
56
+ if (isDateString(attribute)) {
57
+ return import_types.BizAttributeTypes.DateTime;
58
+ }
59
+ return import_types.BizAttributeTypes.String;
60
+ }
61
+ if (t === "boolean") {
62
+ return import_types.BizAttributeTypes.Boolean;
63
+ }
64
+ if (t === "object" && Array.isArray(attribute)) {
65
+ return import_types.BizAttributeTypes.List;
66
+ }
67
+ return import_types.BizAttributeTypes.Nil;
68
+ };
69
+
70
+ // src/__tests__/get-attribute-type.test.ts
71
+ describe("getAttributeType", () => {
72
+ describe("Number type", () => {
73
+ test("should return Number for integer", () => {
74
+ expect(getAttributeType(42)).toBe(import_types2.BizAttributeTypes.Number);
75
+ });
76
+ test("should return Number for float", () => {
77
+ expect(getAttributeType(3.14)).toBe(import_types2.BizAttributeTypes.Number);
78
+ });
79
+ test("should return Number for negative number", () => {
80
+ expect(getAttributeType(-10)).toBe(import_types2.BizAttributeTypes.Number);
81
+ });
82
+ test("should return Number for zero", () => {
83
+ expect(getAttributeType(0)).toBe(import_types2.BizAttributeTypes.Number);
84
+ });
85
+ });
86
+ describe("String type", () => {
87
+ test("should return String for regular string", () => {
88
+ expect(getAttributeType("hello")).toBe(import_types2.BizAttributeTypes.String);
89
+ });
90
+ test("should return String for string with special characters", () => {
91
+ expect(getAttributeType("Nanjing-user-189327")).toBe(import_types2.BizAttributeTypes.String);
92
+ });
93
+ test("should return String for email-like string", () => {
94
+ expect(getAttributeType("user@example.com")).toBe(import_types2.BizAttributeTypes.String);
95
+ });
96
+ test("should return String for short string (< 10 chars)", () => {
97
+ expect(getAttributeType("short")).toBe(import_types2.BizAttributeTypes.String);
98
+ });
99
+ test("should return String for string that looks like number but is not pure number", () => {
100
+ expect(getAttributeType("123abc")).toBe(import_types2.BizAttributeTypes.String);
101
+ });
102
+ });
103
+ describe("DateTime type", () => {
104
+ test("should return DateTime for ISO 8601 format with time", () => {
105
+ expect(getAttributeType("2024-12-11T16:00:00.000Z")).toBe(import_types2.BizAttributeTypes.DateTime);
106
+ });
107
+ test("should return DateTime for ISO 8601 format without milliseconds", () => {
108
+ expect(getAttributeType("2024-12-11T16:00:00Z")).toBe(import_types2.BizAttributeTypes.DateTime);
109
+ });
110
+ test("should return DateTime for ISO 8601 format without timezone", () => {
111
+ expect(getAttributeType("2024-12-11T16:00:00")).toBe(import_types2.BizAttributeTypes.DateTime);
112
+ });
113
+ test("should return DateTime for ISO 8601 date only", () => {
114
+ expect(getAttributeType("2024-12-11")).toBe(import_types2.BizAttributeTypes.DateTime);
115
+ });
116
+ test("should return DateTime for MM/DD/YYYY format", () => {
117
+ expect(getAttributeType("12/12/2024")).toBe(import_types2.BizAttributeTypes.DateTime);
118
+ });
119
+ test("should return DateTime for YYYY/MM/DD format", () => {
120
+ expect(getAttributeType("2024/12/11")).toBe(import_types2.BizAttributeTypes.DateTime);
121
+ });
122
+ test("should return DateTime for MM-DD-YYYY format", () => {
123
+ expect(getAttributeType("12-12-2024")).toBe(import_types2.BizAttributeTypes.DateTime);
124
+ });
125
+ test("should return DateTime for DD-MM-YYYY format", () => {
126
+ expect(getAttributeType("11-12-2024")).toBe(import_types2.BizAttributeTypes.DateTime);
127
+ });
128
+ test("should return String for invalid date string", () => {
129
+ expect(getAttributeType("2024-13-45")).toBe(import_types2.BizAttributeTypes.String);
130
+ });
131
+ test("should return String for date string with invalid year (< 1900)", () => {
132
+ expect(getAttributeType("1899-12-11")).toBe(import_types2.BizAttributeTypes.String);
133
+ });
134
+ test("should return String for date string with invalid year (> 2100)", () => {
135
+ expect(getAttributeType("2101-12-11")).toBe(import_types2.BizAttributeTypes.String);
136
+ });
137
+ });
138
+ describe("Boolean type", () => {
139
+ test("should return Boolean for true", () => {
140
+ expect(getAttributeType(true)).toBe(import_types2.BizAttributeTypes.Boolean);
141
+ });
142
+ test("should return Boolean for false", () => {
143
+ expect(getAttributeType(false)).toBe(import_types2.BizAttributeTypes.Boolean);
144
+ });
145
+ });
146
+ describe("List type", () => {
147
+ test("should return List for array of strings", () => {
148
+ expect(getAttributeType(["a", "b", "c"])).toBe(import_types2.BizAttributeTypes.List);
149
+ });
150
+ test("should return List for array of numbers", () => {
151
+ expect(getAttributeType([1, 2, 3])).toBe(import_types2.BizAttributeTypes.List);
152
+ });
153
+ test("should return List for array of mixed types", () => {
154
+ expect(getAttributeType([1, "a", true])).toBe(import_types2.BizAttributeTypes.List);
155
+ });
156
+ test("should return List for empty array", () => {
157
+ expect(getAttributeType([])).toBe(import_types2.BizAttributeTypes.List);
158
+ });
159
+ });
160
+ describe("Nil type", () => {
161
+ test("should return Nil for null", () => {
162
+ expect(getAttributeType(null)).toBe(import_types2.BizAttributeTypes.Nil);
163
+ });
164
+ test("should return Nil for undefined", () => {
165
+ expect(getAttributeType(void 0)).toBe(import_types2.BizAttributeTypes.Nil);
166
+ });
167
+ test("should return Nil for object (non-array)", () => {
168
+ expect(getAttributeType({ key: "value" })).toBe(import_types2.BizAttributeTypes.Nil);
169
+ });
170
+ test("should return Nil for function", () => {
171
+ expect(getAttributeType(() => {
172
+ })).toBe(import_types2.BizAttributeTypes.Nil);
173
+ });
174
+ test("should return Nil for Symbol", () => {
175
+ expect(getAttributeType(Symbol("test"))).toBe(import_types2.BizAttributeTypes.Nil);
176
+ });
177
+ });
178
+ describe("Edge cases", () => {
179
+ test("should return String for string that is a number but length < 10", () => {
180
+ expect(getAttributeType("12345")).toBe(import_types2.BizAttributeTypes.String);
181
+ });
182
+ test("should return String for string that is exactly 9 characters", () => {
183
+ expect(getAttributeType("123456789")).toBe(import_types2.BizAttributeTypes.String);
184
+ });
185
+ test("should return DateTime for string that is exactly 10 characters and valid date", () => {
186
+ expect(getAttributeType("2024-12-11")).toBe(import_types2.BizAttributeTypes.DateTime);
187
+ });
188
+ test("should return String for string that contains date-like pattern but invalid", () => {
189
+ expect(getAttributeType("2024-99-99")).toBe(import_types2.BizAttributeTypes.String);
190
+ });
191
+ test("should return String for string starting with numbers but not a date", () => {
192
+ expect(getAttributeType("2024abc-def-ghi")).toBe(import_types2.BizAttributeTypes.String);
193
+ });
194
+ });
195
+ });
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,133 @@
1
+ import {
2
+ getAttributeType
3
+ } from "../chunk-EEYZG4JJ.js";
4
+ import "../chunk-GFH3VWOC.js";
5
+ import "../chunk-XEO3YXBM.js";
6
+
7
+ // src/__tests__/get-attribute-type.test.ts
8
+ import { BizAttributeTypes } from "@usertour/types";
9
+ describe("getAttributeType", () => {
10
+ describe("Number type", () => {
11
+ test("should return Number for integer", () => {
12
+ expect(getAttributeType(42)).toBe(BizAttributeTypes.Number);
13
+ });
14
+ test("should return Number for float", () => {
15
+ expect(getAttributeType(3.14)).toBe(BizAttributeTypes.Number);
16
+ });
17
+ test("should return Number for negative number", () => {
18
+ expect(getAttributeType(-10)).toBe(BizAttributeTypes.Number);
19
+ });
20
+ test("should return Number for zero", () => {
21
+ expect(getAttributeType(0)).toBe(BizAttributeTypes.Number);
22
+ });
23
+ });
24
+ describe("String type", () => {
25
+ test("should return String for regular string", () => {
26
+ expect(getAttributeType("hello")).toBe(BizAttributeTypes.String);
27
+ });
28
+ test("should return String for string with special characters", () => {
29
+ expect(getAttributeType("Nanjing-user-189327")).toBe(BizAttributeTypes.String);
30
+ });
31
+ test("should return String for email-like string", () => {
32
+ expect(getAttributeType("user@example.com")).toBe(BizAttributeTypes.String);
33
+ });
34
+ test("should return String for short string (< 10 chars)", () => {
35
+ expect(getAttributeType("short")).toBe(BizAttributeTypes.String);
36
+ });
37
+ test("should return String for string that looks like number but is not pure number", () => {
38
+ expect(getAttributeType("123abc")).toBe(BizAttributeTypes.String);
39
+ });
40
+ });
41
+ describe("DateTime type", () => {
42
+ test("should return DateTime for ISO 8601 format with time", () => {
43
+ expect(getAttributeType("2024-12-11T16:00:00.000Z")).toBe(BizAttributeTypes.DateTime);
44
+ });
45
+ test("should return DateTime for ISO 8601 format without milliseconds", () => {
46
+ expect(getAttributeType("2024-12-11T16:00:00Z")).toBe(BizAttributeTypes.DateTime);
47
+ });
48
+ test("should return DateTime for ISO 8601 format without timezone", () => {
49
+ expect(getAttributeType("2024-12-11T16:00:00")).toBe(BizAttributeTypes.DateTime);
50
+ });
51
+ test("should return DateTime for ISO 8601 date only", () => {
52
+ expect(getAttributeType("2024-12-11")).toBe(BizAttributeTypes.DateTime);
53
+ });
54
+ test("should return DateTime for MM/DD/YYYY format", () => {
55
+ expect(getAttributeType("12/12/2024")).toBe(BizAttributeTypes.DateTime);
56
+ });
57
+ test("should return DateTime for YYYY/MM/DD format", () => {
58
+ expect(getAttributeType("2024/12/11")).toBe(BizAttributeTypes.DateTime);
59
+ });
60
+ test("should return DateTime for MM-DD-YYYY format", () => {
61
+ expect(getAttributeType("12-12-2024")).toBe(BizAttributeTypes.DateTime);
62
+ });
63
+ test("should return DateTime for DD-MM-YYYY format", () => {
64
+ expect(getAttributeType("11-12-2024")).toBe(BizAttributeTypes.DateTime);
65
+ });
66
+ test("should return String for invalid date string", () => {
67
+ expect(getAttributeType("2024-13-45")).toBe(BizAttributeTypes.String);
68
+ });
69
+ test("should return String for date string with invalid year (< 1900)", () => {
70
+ expect(getAttributeType("1899-12-11")).toBe(BizAttributeTypes.String);
71
+ });
72
+ test("should return String for date string with invalid year (> 2100)", () => {
73
+ expect(getAttributeType("2101-12-11")).toBe(BizAttributeTypes.String);
74
+ });
75
+ });
76
+ describe("Boolean type", () => {
77
+ test("should return Boolean for true", () => {
78
+ expect(getAttributeType(true)).toBe(BizAttributeTypes.Boolean);
79
+ });
80
+ test("should return Boolean for false", () => {
81
+ expect(getAttributeType(false)).toBe(BizAttributeTypes.Boolean);
82
+ });
83
+ });
84
+ describe("List type", () => {
85
+ test("should return List for array of strings", () => {
86
+ expect(getAttributeType(["a", "b", "c"])).toBe(BizAttributeTypes.List);
87
+ });
88
+ test("should return List for array of numbers", () => {
89
+ expect(getAttributeType([1, 2, 3])).toBe(BizAttributeTypes.List);
90
+ });
91
+ test("should return List for array of mixed types", () => {
92
+ expect(getAttributeType([1, "a", true])).toBe(BizAttributeTypes.List);
93
+ });
94
+ test("should return List for empty array", () => {
95
+ expect(getAttributeType([])).toBe(BizAttributeTypes.List);
96
+ });
97
+ });
98
+ describe("Nil type", () => {
99
+ test("should return Nil for null", () => {
100
+ expect(getAttributeType(null)).toBe(BizAttributeTypes.Nil);
101
+ });
102
+ test("should return Nil for undefined", () => {
103
+ expect(getAttributeType(void 0)).toBe(BizAttributeTypes.Nil);
104
+ });
105
+ test("should return Nil for object (non-array)", () => {
106
+ expect(getAttributeType({ key: "value" })).toBe(BizAttributeTypes.Nil);
107
+ });
108
+ test("should return Nil for function", () => {
109
+ expect(getAttributeType(() => {
110
+ })).toBe(BizAttributeTypes.Nil);
111
+ });
112
+ test("should return Nil for Symbol", () => {
113
+ expect(getAttributeType(Symbol("test"))).toBe(BizAttributeTypes.Nil);
114
+ });
115
+ });
116
+ describe("Edge cases", () => {
117
+ test("should return String for string that is a number but length < 10", () => {
118
+ expect(getAttributeType("12345")).toBe(BizAttributeTypes.String);
119
+ });
120
+ test("should return String for string that is exactly 9 characters", () => {
121
+ expect(getAttributeType("123456789")).toBe(BizAttributeTypes.String);
122
+ });
123
+ test("should return DateTime for string that is exactly 10 characters and valid date", () => {
124
+ expect(getAttributeType("2024-12-11")).toBe(BizAttributeTypes.DateTime);
125
+ });
126
+ test("should return String for string that contains date-like pattern but invalid", () => {
127
+ expect(getAttributeType("2024-99-99")).toBe(BizAttributeTypes.String);
128
+ });
129
+ test("should return String for string starting with numbers but not a date", () => {
130
+ expect(getAttributeType("2024abc-def-ghi")).toBe(BizAttributeTypes.String);
131
+ });
132
+ });
133
+ });
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/attribute.ts
21
+ var attribute_exports = {};
22
+ __export(attribute_exports, {
23
+ capitalizeFirstLetter: () => capitalizeFirstLetter,
24
+ filterNullAttributes: () => filterNullAttributes,
25
+ getAttributeType: () => getAttributeType
26
+ });
27
+ module.exports = __toCommonJS(attribute_exports);
28
+ var import_types = require("@usertour/types");
29
+ var import_date_fns = require("date-fns");
30
+
31
+ // src/type-utils.ts
32
+ var nativeIsArray = Array.isArray;
33
+ var ObjProto = Object.prototype;
34
+ var objToString = ObjProto.toString;
35
+ var objHasOwn = ObjProto.hasOwnProperty;
36
+ var isNull = (x) => {
37
+ return x === null;
38
+ };
39
+
40
+ // src/attribute.ts
41
+ var isValidYear = (date) => {
42
+ const year = date.getFullYear();
43
+ return year >= 1900 && year <= 2100;
44
+ };
45
+ var tryParseDate = (parser) => {
46
+ try {
47
+ const date = parser();
48
+ return (0, import_date_fns.isValid)(date) && isValidYear(date);
49
+ } catch {
50
+ return false;
51
+ }
52
+ };
53
+ function isDateString(dateStr) {
54
+ if (!Number.isNaN(Number(dateStr)) || dateStr.length < 10) {
55
+ return false;
56
+ }
57
+ const dateFormats = [
58
+ "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
59
+ "yyyy-MM-dd'T'HH:mm:ss'Z'",
60
+ "yyyy-MM-dd'T'HH:mm:ss.SSS",
61
+ "yyyy-MM-dd'T'HH:mm:ss",
62
+ "yyyy-MM-dd",
63
+ "MM/dd/yyyy",
64
+ "dd/MM/yyyy",
65
+ "yyyy/MM/dd",
66
+ "MM-dd-yyyy",
67
+ "dd-MM-yyyy"
68
+ ];
69
+ if (tryParseDate(() => (0, import_date_fns.parseISO)(dateStr))) {
70
+ return true;
71
+ }
72
+ return dateFormats.some((format) => tryParseDate(() => (0, import_date_fns.parse)(dateStr, format, /* @__PURE__ */ new Date())));
73
+ }
74
+ var getAttributeType = (attribute) => {
75
+ const t = typeof attribute;
76
+ if (t === "number") {
77
+ return import_types.BizAttributeTypes.Number;
78
+ }
79
+ if (t === "string") {
80
+ if (isDateString(attribute)) {
81
+ return import_types.BizAttributeTypes.DateTime;
82
+ }
83
+ return import_types.BizAttributeTypes.String;
84
+ }
85
+ if (t === "boolean") {
86
+ return import_types.BizAttributeTypes.Boolean;
87
+ }
88
+ if (t === "object" && Array.isArray(attribute)) {
89
+ return import_types.BizAttributeTypes.List;
90
+ }
91
+ return import_types.BizAttributeTypes.Nil;
92
+ };
93
+ var capitalizeFirstLetter = (string) => {
94
+ return string.charAt(0).toUpperCase() + string.slice(1);
95
+ };
96
+ var filterNullAttributes = (attributes) => {
97
+ const attrs = {};
98
+ for (const key in attributes) {
99
+ const v = attributes[key];
100
+ if (!isNull(v)) {
101
+ attrs[key] = v;
102
+ }
103
+ }
104
+ return attrs;
105
+ };
106
+ // Annotate the CommonJS export names for ESM import in node:
107
+ 0 && (module.exports = {
108
+ capitalizeFirstLetter,
109
+ filterNullAttributes,
110
+ getAttributeType
111
+ });
@@ -0,0 +1,5 @@
1
+ declare const getAttributeType: (attribute: any) => number;
2
+ declare const capitalizeFirstLetter: (string: string) => string;
3
+ declare const filterNullAttributes: (attributes: Record<string, any>) => Record<string, any>;
4
+
5
+ export { capitalizeFirstLetter, filterNullAttributes, getAttributeType };
@@ -0,0 +1,5 @@
1
+ declare const getAttributeType: (attribute: any) => number;
2
+ declare const capitalizeFirstLetter: (string: string) => string;
3
+ declare const filterNullAttributes: (attributes: Record<string, any>) => Record<string, any>;
4
+
5
+ export { capitalizeFirstLetter, filterNullAttributes, getAttributeType };
@@ -0,0 +1,12 @@
1
+ import {
2
+ capitalizeFirstLetter,
3
+ filterNullAttributes,
4
+ getAttributeType
5
+ } from "./chunk-EEYZG4JJ.js";
6
+ import "./chunk-GFH3VWOC.js";
7
+ import "./chunk-XEO3YXBM.js";
8
+ export {
9
+ capitalizeFirstLetter,
10
+ filterNullAttributes,
11
+ getAttributeType
12
+ };
@@ -0,0 +1,78 @@
1
+ import {
2
+ isNull
3
+ } from "./chunk-GFH3VWOC.js";
4
+
5
+ // src/attribute.ts
6
+ import { BizAttributeTypes } from "@usertour/types";
7
+ import { isValid, parseISO, parse } from "date-fns";
8
+ var isValidYear = (date) => {
9
+ const year = date.getFullYear();
10
+ return year >= 1900 && year <= 2100;
11
+ };
12
+ var tryParseDate = (parser) => {
13
+ try {
14
+ const date = parser();
15
+ return isValid(date) && isValidYear(date);
16
+ } catch {
17
+ return false;
18
+ }
19
+ };
20
+ function isDateString(dateStr) {
21
+ if (!Number.isNaN(Number(dateStr)) || dateStr.length < 10) {
22
+ return false;
23
+ }
24
+ const dateFormats = [
25
+ "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
26
+ "yyyy-MM-dd'T'HH:mm:ss'Z'",
27
+ "yyyy-MM-dd'T'HH:mm:ss.SSS",
28
+ "yyyy-MM-dd'T'HH:mm:ss",
29
+ "yyyy-MM-dd",
30
+ "MM/dd/yyyy",
31
+ "dd/MM/yyyy",
32
+ "yyyy/MM/dd",
33
+ "MM-dd-yyyy",
34
+ "dd-MM-yyyy"
35
+ ];
36
+ if (tryParseDate(() => parseISO(dateStr))) {
37
+ return true;
38
+ }
39
+ return dateFormats.some((format) => tryParseDate(() => parse(dateStr, format, /* @__PURE__ */ new Date())));
40
+ }
41
+ var getAttributeType = (attribute) => {
42
+ const t = typeof attribute;
43
+ if (t === "number") {
44
+ return BizAttributeTypes.Number;
45
+ }
46
+ if (t === "string") {
47
+ if (isDateString(attribute)) {
48
+ return BizAttributeTypes.DateTime;
49
+ }
50
+ return BizAttributeTypes.String;
51
+ }
52
+ if (t === "boolean") {
53
+ return BizAttributeTypes.Boolean;
54
+ }
55
+ if (t === "object" && Array.isArray(attribute)) {
56
+ return BizAttributeTypes.List;
57
+ }
58
+ return BizAttributeTypes.Nil;
59
+ };
60
+ var capitalizeFirstLetter = (string) => {
61
+ return string.charAt(0).toUpperCase() + string.slice(1);
62
+ };
63
+ var filterNullAttributes = (attributes) => {
64
+ const attrs = {};
65
+ for (const key in attributes) {
66
+ const v = attributes[key];
67
+ if (!isNull(v)) {
68
+ attrs[key] = v;
69
+ }
70
+ }
71
+ return attrs;
72
+ };
73
+
74
+ export {
75
+ getAttributeType,
76
+ capitalizeFirstLetter,
77
+ filterNullAttributes
78
+ };
@@ -1,3 +1,7 @@
1
+ import {
2
+ isArray
3
+ } from "./chunk-GFH3VWOC.js";
4
+
1
5
  // src/conditions/attribute.ts
2
6
  import {
3
7
  BizAttributeTypes,
@@ -152,7 +156,7 @@ function evaluateBooleanCondition(logic, actualValue) {
152
156
  }
153
157
  }
154
158
  function evaluateListCondition(logic, actualValue, expectedValues) {
155
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
159
+ const arrayValue = isArray(actualValue) ? actualValue : [];
156
160
  if (logic === "empty" || logic === "any") {
157
161
  switch (logic) {
158
162
  case "empty":
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  evaluateUrlCondition
3
3
  } from "./chunk-YYIGUZNZ.js";
4
- import {
5
- evaluateAttributeCondition
6
- } from "./chunk-7JXEY4A2.js";
7
4
  import {
8
5
  evaluateTimeCondition
9
6
  } from "./chunk-CEK3SCQO.js";
7
+ import {
8
+ evaluateAttributeCondition
9
+ } from "./chunk-KYDXF7SU.js";
10
10
  import {
11
11
  cuid
12
12
  } from "./chunk-3KG2HTZ3.js";
@@ -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;
@@ -174,7 +183,7 @@ function evaluateBooleanCondition(logic, actualValue) {
174
183
  }
175
184
  }
176
185
  function evaluateListCondition(logic, actualValue, expectedValues) {
177
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
186
+ const arrayValue = isArray(actualValue) ? actualValue : [];
178
187
  if (logic === "empty" || logic === "any") {
179
188
  switch (logic) {
180
189
  case "empty":
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  evaluateAttributeCondition,
3
3
  evaluateFilterConditions
4
- } from "../chunk-7JXEY4A2.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) {
@@ -269,7 +278,7 @@ function evaluateBooleanCondition(logic, actualValue) {
269
278
  }
270
279
  }
271
280
  function evaluateListCondition(logic, actualValue, expectedValues) {
272
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
281
+ const arrayValue = isArray(actualValue) ? actualValue : [];
273
282
  if (logic === "empty" || logic === "any") {
274
283
  switch (logic) {
275
284
  case "empty":
@@ -8,11 +8,12 @@ import {
8
8
  isConditionsActived,
9
9
  isEqual,
10
10
  regenerateConditionIds
11
- } from "../chunk-A4KMGXB3.js";
11
+ } from "../chunk-NVSDWUJP.js";
12
12
  import "../chunk-YYIGUZNZ.js";
13
13
  import "../chunk-PAESAL23.js";
14
- import "../chunk-7JXEY4A2.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) {
@@ -275,7 +284,7 @@ function evaluateBooleanCondition(logic, actualValue) {
275
284
  }
276
285
  }
277
286
  function evaluateListCondition(logic, actualValue, expectedValues) {
278
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
287
+ const arrayValue = isArray(actualValue) ? actualValue : [];
279
288
  if (logic === "empty" || logic === "any") {
280
289
  switch (logic) {
281
290
  case "empty":
@@ -9,18 +9,19 @@ import {
9
9
  isConditionsActived,
10
10
  isEqual,
11
11
  regenerateConditionIds
12
- } from "../chunk-A4KMGXB3.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-7JXEY4A2.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,
@@ -1240,7 +1243,7 @@ function evaluateBooleanCondition(logic, actualValue) {
1240
1243
  }
1241
1244
  }
1242
1245
  function evaluateListCondition(logic, actualValue, expectedValues) {
1243
- const arrayValue = Array.isArray(actualValue) ? actualValue : [];
1246
+ const arrayValue = isArray(actualValue) ? actualValue : [];
1244
1247
  if (logic === "empty" || logic === "any") {
1245
1248
  switch (logic) {
1246
1249
  case "empty":
@@ -1424,6 +1427,75 @@ var allConditionsHaveIds = (conditions) => {
1424
1427
  }
1425
1428
  return true;
1426
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
+ };
1427
1499
  // Annotate the CommonJS export names for ESM import in node:
1428
1500
  0 && (module.exports = {
1429
1501
  AbortController,
@@ -1434,6 +1506,7 @@ var allConditionsHaveIds = (conditions) => {
1434
1506
  assignConditionIds,
1435
1507
  assignableWindow,
1436
1508
  buildConfig,
1509
+ capitalizeFirstLetter,
1437
1510
  cn,
1438
1511
  conditionsIsSame,
1439
1512
  convertSettings,
@@ -1451,8 +1524,10 @@ var allConditionsHaveIds = (conditions) => {
1451
1524
  evaluateUrlCondition,
1452
1525
  fetch,
1453
1526
  filterConditionsByType,
1527
+ filterNullAttributes,
1454
1528
  formatDate,
1455
1529
  generateAutoStateColors,
1530
+ getAttributeType,
1456
1531
  getAuthToken,
1457
1532
  getCodeError,
1458
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-A4KMGXB3.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-7JXEY4A2.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.34",
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",