@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.
- package/dist/__tests__/attribute.test.cjs +252 -12
- package/dist/__tests__/attribute.test.js +233 -2
- package/dist/__tests__/condition.test.cjs +21 -11
- package/dist/__tests__/condition.test.js +3 -2
- package/dist/__tests__/get-attribute-type.test.cjs +195 -0
- package/dist/__tests__/get-attribute-type.test.d.cts +2 -0
- package/dist/__tests__/get-attribute-type.test.d.ts +2 -0
- package/dist/__tests__/get-attribute-type.test.js +133 -0
- package/dist/attribute.cjs +111 -0
- package/dist/attribute.d.cts +5 -0
- package/dist/attribute.d.ts +5 -0
- package/dist/attribute.js +12 -0
- package/dist/chunk-EEYZG4JJ.js +78 -0
- package/dist/{chunk-E2APTIR7.js → chunk-KYDXF7SU.js} +16 -11
- package/dist/{chunk-YZQBWYCU.js → chunk-NVSDWUJP.js} +3 -3
- package/dist/conditions/attribute.cjs +21 -11
- package/dist/conditions/attribute.js +2 -1
- package/dist/conditions/condition.cjs +21 -11
- package/dist/conditions/condition.js +3 -2
- package/dist/conditions/index.cjs +21 -11
- package/dist/conditions/index.js +5 -4
- package/dist/index.cjs +87 -11
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +12 -4
- package/package.json +1 -1
|
@@ -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,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,
|
|
@@ -108,26 +112,27 @@ function evaluateStringCondition(logic, actualValue, expectedValue) {
|
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
114
|
function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
115
|
+
const numActualValue = Number(actualValue);
|
|
116
|
+
const numExpectedValue = Number(expectedValue);
|
|
117
|
+
const numExpectedValue2 = Number(expectedValue2);
|
|
118
|
+
if (Number.isNaN(numActualValue)) {
|
|
114
119
|
return false;
|
|
115
120
|
}
|
|
116
121
|
switch (logic) {
|
|
117
122
|
case "is":
|
|
118
|
-
return
|
|
123
|
+
return numActualValue === numExpectedValue;
|
|
119
124
|
case "not":
|
|
120
|
-
return
|
|
125
|
+
return numActualValue !== numExpectedValue;
|
|
121
126
|
case "isLessThan":
|
|
122
|
-
return
|
|
127
|
+
return numActualValue < numExpectedValue;
|
|
123
128
|
case "isLessThanOrEqualTo":
|
|
124
|
-
return
|
|
129
|
+
return numActualValue <= numExpectedValue;
|
|
125
130
|
case "isGreaterThan":
|
|
126
|
-
return
|
|
131
|
+
return numActualValue > numExpectedValue;
|
|
127
132
|
case "isGreaterThanOrEqualTo":
|
|
128
|
-
return
|
|
133
|
+
return numActualValue >= numExpectedValue;
|
|
129
134
|
case "between":
|
|
130
|
-
return
|
|
135
|
+
return numActualValue >= numExpectedValue && numActualValue <= numExpectedValue2;
|
|
131
136
|
case "empty":
|
|
132
137
|
return actualValue === null || actualValue === void 0 || actualValue === "";
|
|
133
138
|
case "any":
|
|
@@ -151,7 +156,7 @@ function evaluateBooleanCondition(logic, actualValue) {
|
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
158
|
function evaluateListCondition(logic, actualValue, expectedValues) {
|
|
154
|
-
const arrayValue =
|
|
159
|
+
const arrayValue = isArray(actualValue) ? actualValue : [];
|
|
155
160
|
if (logic === "empty" || logic === "any") {
|
|
156
161
|
switch (logic) {
|
|
157
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-E2APTIR7.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";
|