@usertour/helpers 0.0.15 → 0.0.17

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.
Files changed (48) hide show
  1. package/dist/__tests__/attribute.test.cjs +1036 -0
  2. package/dist/__tests__/attribute.test.d.cts +2 -0
  3. package/dist/__tests__/attribute.test.d.ts +2 -0
  4. package/dist/__tests__/attribute.test.js +802 -0
  5. package/dist/__tests__/time.test.cjs +73 -0
  6. package/dist/__tests__/time.test.d.cts +2 -0
  7. package/dist/__tests__/time.test.d.ts +2 -0
  8. package/dist/__tests__/time.test.js +48 -0
  9. package/dist/__tests__/url.test.cjs +259 -0
  10. package/dist/__tests__/url.test.d.cts +2 -0
  11. package/dist/__tests__/url.test.d.ts +2 -0
  12. package/dist/__tests__/url.test.js +197 -0
  13. package/dist/{chunk-B4DTY6GN.js → chunk-4LLDSAHJ.js} +0 -12
  14. package/dist/chunk-7CC4WXB3.js +60 -0
  15. package/dist/chunk-7ODE2AIC.js +0 -0
  16. package/dist/{chunk-IZFZYGPU.js → chunk-BC7KXBMF.js} +5 -56
  17. package/dist/chunk-CEK3SCQO.js +31 -0
  18. package/dist/chunk-PBZSPV5R.js +239 -0
  19. package/dist/conditions/attribute.cjs +264 -0
  20. package/dist/conditions/attribute.d.cts +28 -0
  21. package/dist/conditions/attribute.d.ts +28 -0
  22. package/dist/conditions/attribute.js +9 -0
  23. package/dist/conditions/condition.cjs +95 -0
  24. package/dist/{conditions.d.ts → conditions/condition.d.cts} +1 -2
  25. package/dist/{conditions.d.cts → conditions/condition.d.ts} +1 -2
  26. package/dist/conditions/condition.js +9 -0
  27. package/dist/conditions/index.cjs +379 -0
  28. package/dist/conditions/index.d.cts +6 -0
  29. package/dist/conditions/index.d.ts +6 -0
  30. package/dist/conditions/index.js +24 -0
  31. package/dist/conditions/time.cjs +55 -0
  32. package/dist/conditions/time.d.cts +10 -0
  33. package/dist/conditions/time.d.ts +10 -0
  34. package/dist/conditions/time.js +7 -0
  35. package/dist/{conditions.cjs → conditions/url.cjs} +9 -71
  36. package/dist/conditions/url.d.cts +6 -0
  37. package/dist/conditions/url.d.ts +6 -0
  38. package/dist/conditions/url.js +9 -0
  39. package/dist/content.cjs +0 -13
  40. package/dist/content.d.cts +1 -2
  41. package/dist/content.d.ts +1 -2
  42. package/dist/content.js +1 -3
  43. package/dist/index.cjs +261 -54
  44. package/dist/index.d.cts +5 -2
  45. package/dist/index.d.ts +5 -2
  46. package/dist/index.js +19 -8
  47. package/package.json +15 -9
  48. package/dist/conditions.js +0 -11
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/conditions/condition.ts
31
+ var condition_exports = {};
32
+ __export(condition_exports, {
33
+ conditionsIsSame: () => conditionsIsSame,
34
+ isEqual: () => import_fast_deep_equal.default
35
+ });
36
+ module.exports = __toCommonJS(condition_exports);
37
+ var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
38
+ var compareConditionsItem = (item1, item2) => {
39
+ const { data = {}, ...others1 } = item1;
40
+ const { data: data2 = {}, ...others2 } = item2;
41
+ if (!(0, import_fast_deep_equal.default)(others2, others1)) {
42
+ return false;
43
+ }
44
+ for (const key in data) {
45
+ if (!(0, import_fast_deep_equal.default)(data[key], data2[key])) {
46
+ return false;
47
+ }
48
+ }
49
+ return true;
50
+ };
51
+ var conditionsIsSame = (rr1, rr2) => {
52
+ const r1 = [...rr1];
53
+ const r2 = [...rr2];
54
+ if (r1.length === 0 && r2.length === 0) {
55
+ return true;
56
+ }
57
+ if (r1.length !== r2.length) {
58
+ return false;
59
+ }
60
+ const group1 = r1.filter((item) => item.type === "group");
61
+ const group2 = r2.filter((item) => item.type === "group");
62
+ if (group1.length !== group2.length) {
63
+ return false;
64
+ }
65
+ for (let index = 0; index < r1.length; index++) {
66
+ const item1 = r1[index];
67
+ const item2 = r2[index];
68
+ if (!item1 || !item2) {
69
+ return false;
70
+ }
71
+ if (item1.type === "group") {
72
+ if (!item2.conditions) {
73
+ return false;
74
+ }
75
+ const c1 = item1.conditions;
76
+ const c2 = item2.conditions;
77
+ if (item1.operators !== item2.operators) {
78
+ return false;
79
+ }
80
+ if (!conditionsIsSame(c1, c2)) {
81
+ return false;
82
+ }
83
+ } else {
84
+ if (!compareConditionsItem(item1, item2)) {
85
+ return false;
86
+ }
87
+ }
88
+ }
89
+ return true;
90
+ };
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ conditionsIsSame,
94
+ isEqual
95
+ });
@@ -1,7 +1,6 @@
1
1
  import { RulesCondition } from '@usertour/types';
2
2
  export { default as isEqual } from 'fast-deep-equal';
3
3
 
4
- declare const isMatchUrlPattern: (_url: string, includes: string[], excludes: string[]) => boolean;
5
4
  declare const conditionsIsSame: (rr1: RulesCondition[], rr2: RulesCondition[]) => boolean;
6
5
 
7
- export { conditionsIsSame, isMatchUrlPattern };
6
+ export { conditionsIsSame };
@@ -1,7 +1,6 @@
1
1
  import { RulesCondition } from '@usertour/types';
2
2
  export { default as isEqual } from 'fast-deep-equal';
3
3
 
4
- declare const isMatchUrlPattern: (_url: string, includes: string[], excludes: string[]) => boolean;
5
4
  declare const conditionsIsSame: (rr1: RulesCondition[], rr2: RulesCondition[]) => boolean;
6
5
 
7
- export { conditionsIsSame, isMatchUrlPattern };
6
+ export { conditionsIsSame };
@@ -0,0 +1,9 @@
1
+ import {
2
+ conditionsIsSame,
3
+ isEqual
4
+ } from "../chunk-7CC4WXB3.js";
5
+ import "../chunk-XEO3YXBM.js";
6
+ export {
7
+ conditionsIsSame,
8
+ isEqual
9
+ };
@@ -0,0 +1,379 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/conditions/index.ts
31
+ var conditions_exports = {};
32
+ __export(conditions_exports, {
33
+ conditionsIsSame: () => conditionsIsSame,
34
+ evaluateAttributeCondition: () => evaluateAttributeCondition,
35
+ evaluateTimeCondition: () => evaluateTimeCondition,
36
+ evaluateUrlCondition: () => evaluateUrlCondition,
37
+ isEqual: () => import_fast_deep_equal.default,
38
+ isMatchUrlPattern: () => isMatchUrlPattern
39
+ });
40
+ module.exports = __toCommonJS(conditions_exports);
41
+
42
+ // src/conditions/condition.ts
43
+ var import_fast_deep_equal = __toESM(require("fast-deep-equal"), 1);
44
+ var compareConditionsItem = (item1, item2) => {
45
+ const { data = {}, ...others1 } = item1;
46
+ const { data: data2 = {}, ...others2 } = item2;
47
+ if (!(0, import_fast_deep_equal.default)(others2, others1)) {
48
+ return false;
49
+ }
50
+ for (const key in data) {
51
+ if (!(0, import_fast_deep_equal.default)(data[key], data2[key])) {
52
+ return false;
53
+ }
54
+ }
55
+ return true;
56
+ };
57
+ var conditionsIsSame = (rr1, rr2) => {
58
+ const r1 = [...rr1];
59
+ const r2 = [...rr2];
60
+ if (r1.length === 0 && r2.length === 0) {
61
+ return true;
62
+ }
63
+ if (r1.length !== r2.length) {
64
+ return false;
65
+ }
66
+ const group1 = r1.filter((item) => item.type === "group");
67
+ const group2 = r2.filter((item) => item.type === "group");
68
+ if (group1.length !== group2.length) {
69
+ return false;
70
+ }
71
+ for (let index = 0; index < r1.length; index++) {
72
+ const item1 = r1[index];
73
+ const item2 = r2[index];
74
+ if (!item1 || !item2) {
75
+ return false;
76
+ }
77
+ if (item1.type === "group") {
78
+ if (!item2.conditions) {
79
+ return false;
80
+ }
81
+ const c1 = item1.conditions;
82
+ const c2 = item2.conditions;
83
+ if (item1.operators !== item2.operators) {
84
+ return false;
85
+ }
86
+ if (!conditionsIsSame(c1, c2)) {
87
+ return false;
88
+ }
89
+ } else {
90
+ if (!compareConditionsItem(item1, item2)) {
91
+ return false;
92
+ }
93
+ }
94
+ }
95
+ return true;
96
+ };
97
+
98
+ // src/conditions/url.ts
99
+ var parseUrl = (url) => {
100
+ const urlPatterns = url.match(/^(([a-z\d]+):\/\/)?([^/?#]+)?(\/[^?#]*)?(\?([^#]*))?(#.*)?$/i);
101
+ if (!urlPatterns) {
102
+ return null;
103
+ }
104
+ const [, , scheme = "", domain = "", path = "", , query = "", fragment = ""] = urlPatterns;
105
+ return { scheme, domain, path, query, fragment };
106
+ };
107
+ var replaceWildcard = (input, s1, s2) => {
108
+ const withSpecialWords = replaceSpecialWords(input);
109
+ const withWildcard = withSpecialWords.replace(/\\\*/g, `${s1}*`);
110
+ if (!s2) {
111
+ return withWildcard;
112
+ }
113
+ return withWildcard.replace(/:[a-z0-9_]+/g, `[^${s2}]+`);
114
+ };
115
+ var replaceSpecialWords = (str) => {
116
+ return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
117
+ };
118
+ var parsePattern = (pattern) => {
119
+ if (!pattern || !pattern.trim()) {
120
+ return null;
121
+ }
122
+ const _pattern = parseUrl(pattern);
123
+ if (!_pattern) {
124
+ console.error("Invalid URL pattern:", pattern);
125
+ return null;
126
+ }
127
+ const { scheme, domain, path, query, fragment } = _pattern;
128
+ const _scheme = scheme ? replaceSpecialWords(scheme) : "[a-z\\d]+";
129
+ const _domain = domain ? replaceWildcard(domain, "[^/]", ".") : "[^/]*";
130
+ const _fragment = fragment ? replaceWildcard(fragment, ".", "/") : "(#.*)?";
131
+ const _path = path ? replaceWildcard(path, "[^?#]", "/") : "/[^?#]*";
132
+ let _query = "(\\?[^#]*)?";
133
+ if (query) {
134
+ new URLSearchParams(query).forEach((value, key) => {
135
+ const _str = value === "" ? "=?" : value === "*" ? "(=[^&#]*)?" : `=${replaceWildcard(value, "[^#]")}`;
136
+ _query += `(?=.*[?&]${replaceSpecialWords(key)}${_str}([&#]|$))`;
137
+ });
138
+ _query += "\\?[^#]*";
139
+ }
140
+ return new RegExp(`^${_scheme}://${_domain}(:\\d+)?${_path}${_query}${_fragment}$`);
141
+ };
142
+ var isMatchUrlPattern = (_url, includes, excludes) => {
143
+ const isMatchIncludesConditions = includes.length > 0 ? includes.some((_include) => {
144
+ const reg = parsePattern(_include);
145
+ if (reg) {
146
+ return reg.test(_url);
147
+ }
148
+ return false;
149
+ }) : true;
150
+ const isMatchExcludesConditions = excludes.length > 0 ? excludes.some((_exclude) => {
151
+ const reg = parsePattern(_exclude);
152
+ if (reg) {
153
+ return reg.test(_url);
154
+ }
155
+ return false;
156
+ }) : false;
157
+ return isMatchIncludesConditions && !isMatchExcludesConditions;
158
+ };
159
+ var evaluateUrlCondition = (rules, url) => {
160
+ const { excludes, includes } = rules.data;
161
+ return isMatchUrlPattern(url, includes, excludes);
162
+ };
163
+
164
+ // src/conditions/time.ts
165
+ var import_date_fns = require("date-fns");
166
+ var evaluateTimeCondition = (rules) => {
167
+ try {
168
+ const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data || {};
169
+ if (!startDate || !startDateHour || !startDateMinute) {
170
+ return false;
171
+ }
172
+ const startTimeString = `${startDate}T${startDateHour.padStart(2, "0")}:${startDateMinute.padStart(2, "0")}:00`;
173
+ const startTime = (0, import_date_fns.parseISO)(startTimeString);
174
+ if (!(0, import_date_fns.isValid)(startTime)) {
175
+ return false;
176
+ }
177
+ const now = /* @__PURE__ */ new Date();
178
+ if (!endDate || !endDateHour || !endDateMinute) {
179
+ return (0, import_date_fns.isAfter)(now, startTime);
180
+ }
181
+ const endTimeString = `${endDate}T${endDateHour.padStart(2, "0")}:${endDateMinute.padStart(2, "0")}:00`;
182
+ const endTime = (0, import_date_fns.parseISO)(endTimeString);
183
+ if (!(0, import_date_fns.isValid)(endTime)) {
184
+ return false;
185
+ }
186
+ return (0, import_date_fns.isAfter)(now, startTime) && (0, import_date_fns.isBefore)(now, endTime);
187
+ } catch {
188
+ return false;
189
+ }
190
+ };
191
+
192
+ // src/conditions/attribute.ts
193
+ var import_types = require("@usertour/types");
194
+ var import_date_fns2 = require("date-fns");
195
+ function evaluateAttributeCondition(condition, attributes, userAttributes) {
196
+ const { data } = condition;
197
+ if (!data) {
198
+ return false;
199
+ }
200
+ const { logic, value, attrId, value2, listValues = [] } = data;
201
+ if (!attrId) {
202
+ return false;
203
+ }
204
+ const attr = attributes.find((attr2) => attr2.id === attrId);
205
+ if (!attr) {
206
+ return false;
207
+ }
208
+ const actualValue = getAttributeValue(attr.codeName, userAttributes);
209
+ if (attr.dataType === import_types.BizAttributeTypes.String) {
210
+ return evaluateStringCondition(logic, actualValue, value);
211
+ }
212
+ if (attr.dataType === import_types.BizAttributeTypes.Number) {
213
+ return evaluateNumberCondition(logic, actualValue, value, value2);
214
+ }
215
+ if (attr.dataType === import_types.BizAttributeTypes.Boolean) {
216
+ return evaluateBooleanCondition(logic, actualValue);
217
+ }
218
+ if (attr.dataType === import_types.BizAttributeTypes.List) {
219
+ return evaluateListCondition(logic, actualValue, listValues);
220
+ }
221
+ if (attr.dataType === import_types.BizAttributeTypes.DateTime) {
222
+ return evaluateDateTimeCondition(logic, actualValue, value);
223
+ }
224
+ return false;
225
+ }
226
+ function getAttributeValue(codeName, userAttributes) {
227
+ return userAttributes == null ? void 0 : userAttributes[codeName];
228
+ }
229
+ function evaluateStringCondition(logic, actualValue, expectedValue) {
230
+ const stringValue = actualValue === null || actualValue === void 0 ? "" : String(actualValue);
231
+ switch (logic) {
232
+ case "is":
233
+ return stringValue === expectedValue;
234
+ case "not":
235
+ return stringValue !== expectedValue;
236
+ case "contains":
237
+ return stringValue.includes(expectedValue);
238
+ case "notContain":
239
+ return !stringValue.includes(expectedValue);
240
+ case "startsWith":
241
+ return stringValue.startsWith(expectedValue);
242
+ case "endsWith":
243
+ return stringValue.endsWith(expectedValue);
244
+ case "empty": {
245
+ const isEmpty = !stringValue || stringValue === "";
246
+ return isEmpty;
247
+ }
248
+ case "any":
249
+ return Boolean(stringValue && stringValue !== "");
250
+ default:
251
+ return false;
252
+ }
253
+ }
254
+ function evaluateNumberCondition(logic, actualValue, expectedValue, expectedValue2) {
255
+ const numValue = Number(actualValue);
256
+ const numValue2 = Number(expectedValue2);
257
+ if (Number.isNaN(numValue)) {
258
+ return false;
259
+ }
260
+ switch (logic) {
261
+ case "is":
262
+ return numValue === expectedValue;
263
+ case "not":
264
+ return numValue !== expectedValue;
265
+ case "isLessThan":
266
+ return numValue < expectedValue;
267
+ case "isLessThanOrEqualTo":
268
+ return numValue <= expectedValue;
269
+ case "isGreaterThan":
270
+ return numValue > expectedValue;
271
+ case "isGreaterThanOrEqualTo":
272
+ return numValue >= expectedValue;
273
+ case "between":
274
+ return numValue >= expectedValue && numValue <= numValue2;
275
+ case "empty":
276
+ return actualValue === null || actualValue === void 0 || actualValue === "";
277
+ case "any":
278
+ return actualValue !== null && actualValue !== void 0 && actualValue !== "";
279
+ default:
280
+ return false;
281
+ }
282
+ }
283
+ function evaluateBooleanCondition(logic, actualValue) {
284
+ switch (logic) {
285
+ case "true":
286
+ return actualValue === true;
287
+ case "false":
288
+ return actualValue === false;
289
+ case "empty":
290
+ return actualValue === null || actualValue === void 0 || actualValue === "";
291
+ case "any":
292
+ return actualValue !== null && actualValue !== void 0 && actualValue !== "";
293
+ default:
294
+ return false;
295
+ }
296
+ }
297
+ function evaluateListCondition(logic, actualValue, expectedValues) {
298
+ const arrayValue = Array.isArray(actualValue) ? actualValue : [];
299
+ if (logic === "empty" || logic === "any") {
300
+ switch (logic) {
301
+ case "empty":
302
+ return !arrayValue || arrayValue.length === 0;
303
+ case "any":
304
+ return arrayValue && arrayValue.length > 0;
305
+ default:
306
+ return false;
307
+ }
308
+ }
309
+ const filteredValues = expectedValues.filter(
310
+ (value) => value !== null && value !== void 0 && value !== ""
311
+ );
312
+ if (!filteredValues.length) {
313
+ return false;
314
+ }
315
+ switch (logic) {
316
+ case "includesAtLeastOne":
317
+ return filteredValues.some((value) => arrayValue.includes(value));
318
+ case "includesAll":
319
+ return filteredValues.every((value) => arrayValue.includes(value));
320
+ case "notIncludesAtLeastOne":
321
+ return !filteredValues.some((value) => arrayValue.includes(value));
322
+ case "notIncludesAll":
323
+ return !filteredValues.every((value) => arrayValue.includes(value));
324
+ default:
325
+ return false;
326
+ }
327
+ }
328
+ function evaluateDateTimeCondition(logic, actualValue, expectedValue) {
329
+ const actualDate = actualValue ? new Date(actualValue) : null;
330
+ const now = /* @__PURE__ */ new Date();
331
+ if (!actualDate || Number.isNaN(actualDate.getTime())) {
332
+ return false;
333
+ }
334
+ switch (logic) {
335
+ case "lessThan": {
336
+ const targetDate = (0, import_date_fns2.subDays)(now, Number(expectedValue));
337
+ return actualDate >= targetDate;
338
+ }
339
+ case "exactly": {
340
+ const targetDate = (0, import_date_fns2.subDays)(now, Number(expectedValue));
341
+ const start = (0, import_date_fns2.startOfDay)(targetDate);
342
+ const end = (0, import_date_fns2.endOfDay)(targetDate);
343
+ return actualDate >= start && actualDate <= end;
344
+ }
345
+ case "moreThan": {
346
+ const targetDate = (0, import_date_fns2.subDays)(now, Number(expectedValue));
347
+ return actualDate <= targetDate;
348
+ }
349
+ case "before": {
350
+ const expectedDate = new Date(expectedValue);
351
+ return actualDate <= expectedDate;
352
+ }
353
+ case "on": {
354
+ const expectedDateOn = new Date(expectedValue);
355
+ const start = (0, import_date_fns2.startOfDay)(expectedDateOn);
356
+ const end = (0, import_date_fns2.endOfDay)(expectedDateOn);
357
+ return actualDate >= start && actualDate <= end;
358
+ }
359
+ case "after": {
360
+ const expectedDateAfter = new Date(expectedValue);
361
+ return actualDate >= expectedDateAfter;
362
+ }
363
+ case "empty":
364
+ return !actualValue || actualValue === "";
365
+ case "any":
366
+ return actualValue && actualValue !== "";
367
+ default:
368
+ return false;
369
+ }
370
+ }
371
+ // Annotate the CommonJS export names for ESM import in node:
372
+ 0 && (module.exports = {
373
+ conditionsIsSame,
374
+ evaluateAttributeCondition,
375
+ evaluateTimeCondition,
376
+ evaluateUrlCondition,
377
+ isEqual,
378
+ isMatchUrlPattern
379
+ });
@@ -0,0 +1,6 @@
1
+ export { conditionsIsSame } from './condition.cjs';
2
+ export { evaluateUrlCondition, isMatchUrlPattern } from './url.cjs';
3
+ export { evaluateTimeCondition } from './time.cjs';
4
+ export { evaluateAttributeCondition } from './attribute.cjs';
5
+ export { default as isEqual } from 'fast-deep-equal';
6
+ import '@usertour/types';
@@ -0,0 +1,6 @@
1
+ export { conditionsIsSame } from './condition.js';
2
+ export { evaluateUrlCondition, isMatchUrlPattern } from './url.js';
3
+ export { evaluateTimeCondition } from './time.js';
4
+ export { evaluateAttributeCondition } from './attribute.js';
5
+ export { default as isEqual } from 'fast-deep-equal';
6
+ import '@usertour/types';
@@ -0,0 +1,24 @@
1
+ import "../chunk-7ODE2AIC.js";
2
+ import {
3
+ conditionsIsSame,
4
+ isEqual
5
+ } from "../chunk-7CC4WXB3.js";
6
+ import {
7
+ evaluateAttributeCondition
8
+ } from "../chunk-PBZSPV5R.js";
9
+ import {
10
+ evaluateTimeCondition
11
+ } from "../chunk-CEK3SCQO.js";
12
+ import {
13
+ evaluateUrlCondition,
14
+ isMatchUrlPattern
15
+ } from "../chunk-BC7KXBMF.js";
16
+ import "../chunk-XEO3YXBM.js";
17
+ export {
18
+ conditionsIsSame,
19
+ evaluateAttributeCondition,
20
+ evaluateTimeCondition,
21
+ evaluateUrlCondition,
22
+ isEqual,
23
+ isMatchUrlPattern
24
+ };
@@ -0,0 +1,55 @@
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/conditions/time.ts
21
+ var time_exports = {};
22
+ __export(time_exports, {
23
+ evaluateTimeCondition: () => evaluateTimeCondition
24
+ });
25
+ module.exports = __toCommonJS(time_exports);
26
+ var import_date_fns = require("date-fns");
27
+ var evaluateTimeCondition = (rules) => {
28
+ try {
29
+ const { endDate, endDateHour, endDateMinute, startDate, startDateHour, startDateMinute } = rules.data || {};
30
+ if (!startDate || !startDateHour || !startDateMinute) {
31
+ return false;
32
+ }
33
+ const startTimeString = `${startDate}T${startDateHour.padStart(2, "0")}:${startDateMinute.padStart(2, "0")}:00`;
34
+ const startTime = (0, import_date_fns.parseISO)(startTimeString);
35
+ if (!(0, import_date_fns.isValid)(startTime)) {
36
+ return false;
37
+ }
38
+ const now = /* @__PURE__ */ new Date();
39
+ if (!endDate || !endDateHour || !endDateMinute) {
40
+ return (0, import_date_fns.isAfter)(now, startTime);
41
+ }
42
+ const endTimeString = `${endDate}T${endDateHour.padStart(2, "0")}:${endDateMinute.padStart(2, "0")}:00`;
43
+ const endTime = (0, import_date_fns.parseISO)(endTimeString);
44
+ if (!(0, import_date_fns.isValid)(endTime)) {
45
+ return false;
46
+ }
47
+ return (0, import_date_fns.isAfter)(now, startTime) && (0, import_date_fns.isBefore)(now, endTime);
48
+ } catch {
49
+ return false;
50
+ }
51
+ };
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {
54
+ evaluateTimeCondition
55
+ });
@@ -0,0 +1,10 @@
1
+ import { RulesCondition } from '@usertour/types';
2
+
3
+ /**
4
+ * Evaluate time condition based on start and end time rules
5
+ * @param rules - Time condition rules
6
+ * @returns boolean indicating if current time matches the condition
7
+ */
8
+ declare const evaluateTimeCondition: (rules: RulesCondition) => boolean;
9
+
10
+ export { evaluateTimeCondition };
@@ -0,0 +1,10 @@
1
+ import { RulesCondition } from '@usertour/types';
2
+
3
+ /**
4
+ * Evaluate time condition based on start and end time rules
5
+ * @param rules - Time condition rules
6
+ * @returns boolean indicating if current time matches the condition
7
+ */
8
+ declare const evaluateTimeCondition: (rules: RulesCondition) => boolean;
9
+
10
+ export { evaluateTimeCondition };
@@ -0,0 +1,7 @@
1
+ import {
2
+ evaluateTimeCondition
3
+ } from "../chunk-CEK3SCQO.js";
4
+ import "../chunk-XEO3YXBM.js";
5
+ export {
6
+ evaluateTimeCondition
7
+ };