@pisell/utils 3.0.5 → 3.0.7

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 (157) hide show
  1. package/es/arrayUtils.d.ts +72 -0
  2. package/es/arrayUtils.js +142 -3
  3. package/es/common/index.d.ts +5 -0
  4. package/es/common/index.js +5 -0
  5. package/es/common/stateHelper.d.ts +18 -0
  6. package/es/common/stateHelper.js +25 -0
  7. package/es/common/types.d.ts +28 -0
  8. package/es/common/types.js +1 -0
  9. package/es/componentStorage.d.ts +36 -0
  10. package/es/componentStorage.js +142 -0
  11. package/es/format.d.ts +5 -1
  12. package/es/format.js +53 -8
  13. package/es/index.d.ts +6 -0
  14. package/es/index.js +6 -0
  15. package/es/jsBridge/index.d.ts +9 -105
  16. package/es/jsBridge/index.js +28 -12
  17. package/es/jsBridge/types.d.ts +149 -0
  18. package/es/jsBridge/types.js +1 -0
  19. package/es/locales.d.ts +2 -5
  20. package/es/locales.js +36 -7
  21. package/es/miniRedux.js +7 -2
  22. package/es/number-input/hooks/index.d.ts +4 -0
  23. package/es/number-input/hooks/index.js +5 -0
  24. package/es/number-input/hooks/useNumberInputState.d.ts +25 -0
  25. package/es/number-input/hooks/useNumberInputState.js +129 -0
  26. package/es/number-input/index.d.ts +14 -0
  27. package/es/number-input/index.js +21 -0
  28. package/es/number-input/types.d.ts +96 -0
  29. package/es/number-input/types.js +1 -0
  30. package/es/number-input/utils/formatter.d.ts +53 -0
  31. package/es/number-input/utils/formatter.js +82 -0
  32. package/es/number-input/utils/index.d.ts +7 -0
  33. package/es/number-input/utils/index.js +8 -0
  34. package/es/number-input/utils/validation.d.ts +27 -0
  35. package/es/number-input/utils/validation.js +67 -0
  36. package/es/otherUtils.d.ts +48 -0
  37. package/es/select/hooks/index.d.ts +5 -0
  38. package/es/select/hooks/index.js +6 -0
  39. package/es/select/hooks/useDebouncedSearch.d.ts +20 -0
  40. package/es/select/hooks/useDebouncedSearch.js +55 -0
  41. package/es/select/hooks/useSelectState.d.ts +19 -0
  42. package/es/select/hooks/useSelectState.js +117 -0
  43. package/es/select/index.d.ts +8 -0
  44. package/es/select/index.js +13 -0
  45. package/es/select/types.d.ts +256 -0
  46. package/es/select/types.js +1 -0
  47. package/es/select/utils/filterOptions.d.ts +22 -0
  48. package/es/select/utils/filterOptions.js +34 -0
  49. package/es/select/utils/helpers.d.ts +42 -0
  50. package/es/select/utils/helpers.js +61 -0
  51. package/es/select/utils/index.d.ts +7 -0
  52. package/es/select/utils/index.js +8 -0
  53. package/es/select/utils/sortOptions.d.ts +12 -0
  54. package/es/select/utils/sortOptions.js +32 -0
  55. package/es/select/utils/tagAggregation.d.ts +25 -0
  56. package/es/select/utils/tagAggregation.js +48 -0
  57. package/es/text-input/hooks/index.d.ts +4 -0
  58. package/es/text-input/hooks/index.js +5 -0
  59. package/es/text-input/hooks/useTextInputState.d.ts +24 -0
  60. package/es/text-input/hooks/useTextInputState.js +127 -0
  61. package/es/text-input/index.d.ts +14 -0
  62. package/es/text-input/index.js +20 -0
  63. package/es/text-input/types.d.ts +56 -0
  64. package/es/text-input/types.js +1 -0
  65. package/es/text-input/utils/index.d.ts +5 -0
  66. package/es/text-input/utils/index.js +7 -0
  67. package/es/text-input/utils/validation.d.ts +23 -0
  68. package/es/text-input/utils/validation.js +71 -0
  69. package/es/walletValidity.d.ts +55 -0
  70. package/es/walletValidity.js +143 -38
  71. package/es/weighing.d.ts +62 -0
  72. package/es/weighing.js +119 -0
  73. package/lib/arrayUtils.d.ts +72 -0
  74. package/lib/arrayUtils.js +75 -0
  75. package/lib/common/index.d.ts +5 -0
  76. package/lib/common/index.js +29 -0
  77. package/lib/common/stateHelper.d.ts +18 -0
  78. package/lib/common/stateHelper.js +34 -0
  79. package/lib/common/types.d.ts +28 -0
  80. package/lib/common/types.js +17 -0
  81. package/lib/componentStorage.d.ts +36 -0
  82. package/lib/componentStorage.js +144 -0
  83. package/lib/format.d.ts +5 -1
  84. package/lib/format.js +45 -5
  85. package/lib/index.d.ts +6 -0
  86. package/lib/index.js +13 -1
  87. package/lib/jsBridge/index.d.ts +9 -105
  88. package/lib/jsBridge/index.js +20 -1
  89. package/lib/jsBridge/types.d.ts +149 -0
  90. package/lib/jsBridge/types.js +17 -0
  91. package/lib/locales.d.ts +2 -5
  92. package/lib/locales.js +34 -7
  93. package/lib/miniRedux.js +5 -7
  94. package/lib/number-input/hooks/index.d.ts +4 -0
  95. package/lib/number-input/hooks/index.js +29 -0
  96. package/lib/number-input/hooks/useNumberInputState.d.ts +25 -0
  97. package/lib/number-input/hooks/useNumberInputState.js +83 -0
  98. package/lib/number-input/index.d.ts +14 -0
  99. package/lib/number-input/index.js +41 -0
  100. package/lib/number-input/types.d.ts +96 -0
  101. package/lib/number-input/types.js +17 -0
  102. package/lib/number-input/utils/formatter.d.ts +53 -0
  103. package/lib/number-input/utils/formatter.js +55 -0
  104. package/lib/number-input/utils/index.d.ts +7 -0
  105. package/lib/number-input/utils/index.js +39 -0
  106. package/lib/number-input/utils/validation.d.ts +27 -0
  107. package/lib/number-input/utils/validation.js +54 -0
  108. package/lib/otherUtils.d.ts +48 -0
  109. package/lib/select/hooks/index.d.ts +5 -0
  110. package/lib/select/hooks/index.js +34 -0
  111. package/lib/select/hooks/useDebouncedSearch.d.ts +20 -0
  112. package/lib/select/hooks/useDebouncedSearch.js +43 -0
  113. package/lib/select/hooks/useSelectState.d.ts +19 -0
  114. package/lib/select/hooks/useSelectState.js +97 -0
  115. package/lib/select/index.d.ts +8 -0
  116. package/lib/select/index.js +53 -0
  117. package/lib/select/types.d.ts +256 -0
  118. package/lib/select/types.js +17 -0
  119. package/lib/select/utils/filterOptions.d.ts +22 -0
  120. package/lib/select/utils/filterOptions.js +41 -0
  121. package/lib/select/utils/helpers.d.ts +42 -0
  122. package/lib/select/utils/helpers.js +51 -0
  123. package/lib/select/utils/index.d.ts +7 -0
  124. package/lib/select/utils/index.js +48 -0
  125. package/lib/select/utils/sortOptions.d.ts +12 -0
  126. package/lib/select/utils/sortOptions.js +41 -0
  127. package/lib/select/utils/tagAggregation.d.ts +25 -0
  128. package/lib/select/utils/tagAggregation.js +43 -0
  129. package/lib/text-input/hooks/index.d.ts +4 -0
  130. package/lib/text-input/hooks/index.js +29 -0
  131. package/lib/text-input/hooks/useTextInputState.d.ts +24 -0
  132. package/lib/text-input/hooks/useTextInputState.js +81 -0
  133. package/lib/text-input/index.d.ts +14 -0
  134. package/lib/text-input/index.js +35 -0
  135. package/lib/text-input/types.d.ts +56 -0
  136. package/lib/text-input/types.js +17 -0
  137. package/lib/text-input/utils/index.d.ts +5 -0
  138. package/lib/text-input/utils/index.js +32 -0
  139. package/lib/text-input/utils/validation.d.ts +23 -0
  140. package/lib/text-input/utils/validation.js +60 -0
  141. package/lib/walletValidity.d.ts +55 -0
  142. package/lib/walletValidity.js +120 -40
  143. package/lib/weighing.d.ts +62 -0
  144. package/lib/weighing.js +159 -0
  145. package/package.json +1 -1
  146. package/es/date.d.ts +0 -28
  147. package/es/document.d.ts +0 -13
  148. package/es/firebase/config/index.d.ts +0 -13
  149. package/es/firebase/index.d.ts +0 -28
  150. package/es/image.d.ts +0 -11
  151. package/es/typeUtils.d.ts +0 -42
  152. package/lib/date.d.ts +0 -28
  153. package/lib/document.d.ts +0 -13
  154. package/lib/firebase/config/index.d.ts +0 -13
  155. package/lib/firebase/index.d.ts +0 -28
  156. package/lib/image.d.ts +0 -11
  157. package/lib/typeUtils.d.ts +0 -42
@@ -29,16 +29,36 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/walletValidity.ts
30
30
  var walletValidity_exports = {};
31
31
  __export(walletValidity_exports, {
32
- getScheduleSummary: () => getScheduleSummary
32
+ getScheduleSummary: () => getScheduleSummary,
33
+ getWalletValidityRange: () => getWalletValidityRange
33
34
  });
34
35
  module.exports = __toCommonJS(walletValidity_exports);
35
36
  var import_dayjs = __toESM(require("dayjs"));
36
37
  var CONSTANTS = {
37
38
  ALL_DAY_START: "00:00",
38
39
  ALL_DAY_END: "23:59",
39
- DEFAULT_FUTURE_YEARS: 10,
40
40
  SECONDS_SUFFIX: ":59"
41
41
  };
42
+ function getValidityDate(value) {
43
+ if (typeof value !== "string") return null;
44
+ const match = value.match(/^(\d{4}-\d{2}-\d{2})(?:$|[ T])/);
45
+ if (!match) return null;
46
+ const date = (0, import_dayjs.default)(match[1]);
47
+ return date.isValid() && date.format("YYYY-MM-DD") === match[1] ? match[1] : null;
48
+ }
49
+ function getWalletValidityRange(start, end, validity) {
50
+ const scheduleStart = getValidityDate(start);
51
+ const scheduleEnd = getValidityDate(end);
52
+ const passStart = getValidityDate(validity == null ? void 0 : validity.start_date);
53
+ const passEnd = getValidityDate(validity == null ? void 0 : validity.expire_date) || getValidityDate(validity == null ? void 0 : validity.expire_time);
54
+ const startDate = passStart && (!scheduleStart || passStart > scheduleStart) ? passStart : scheduleStart;
55
+ const endDate = passEnd && (!scheduleEnd || passEnd < scheduleEnd) ? passEnd : scheduleEnd;
56
+ return {
57
+ startDate,
58
+ endDate,
59
+ isEmpty: Boolean(startDate && endDate && startDate > endDate)
60
+ };
61
+ }
42
62
  var textConfig = {
43
63
  "zh-HK": {
44
64
  weekdays: ["日", "一", "二", "三", "四", "五", "六"],
@@ -54,6 +74,7 @@ var textConfig = {
54
74
  year: "年",
55
75
  available: "可用",
56
76
  unlimited: "无限期",
77
+ noAvailableDates: "無可用日期",
57
78
  multipleRules: "多規則,點詳情",
58
79
  multipleSlots: ",多時段",
59
80
  until: "至",
@@ -82,6 +103,7 @@ var textConfig = {
82
103
  year: "年",
83
104
  available: "可用",
84
105
  unlimited: "无限期",
106
+ noAvailableDates: "无可用日期",
85
107
  multipleRules: "多规则,点详情",
86
108
  multipleSlots: ",多时段",
87
109
  until: "至",
@@ -110,6 +132,7 @@ var textConfig = {
110
132
  year: "year",
111
133
  available: "available",
112
134
  unlimited: "unlimited",
135
+ noAvailableDates: "No available dates",
113
136
  multipleRules: "Multiple rules, see details",
114
137
  multipleSlots: ", multiple slots",
115
138
  until: "Until ",
@@ -127,7 +150,7 @@ var textConfig = {
127
150
  };
128
151
  function getWeekdayText(dayNumbers, locale, separator) {
129
152
  const config = textConfig[locale];
130
- return dayNumbers.map((day) => config.weekdays[day]).join(separator || config.separator);
153
+ return [...new Set(dayNumbers)].sort((a, b) => a - b).map((day) => config.weekdays[day]).join(separator || config.separator);
131
154
  }
132
155
  function getText(locale, key) {
133
156
  return textConfig[locale][key];
@@ -168,24 +191,38 @@ function formatDateTime(dateTime, isAll = false, locale = "zh-CN") {
168
191
  function isAllDaySchedule(startTime, endTime) {
169
192
  return startTime === CONSTANTS.ALL_DAY_START && endTime === CONSTANTS.ALL_DAY_END;
170
193
  }
171
- function formatDateRange(startDate, endDate, isStarted, locale, isAllDay = false) {
194
+ function formatDateRange(startDate, endDate, isStarted, locale, isAllDay = false, validity) {
172
195
  const config = getConfig(locale);
173
- if (isStarted) {
174
- const endDateStr = formatDateTime(endDate, isAllDay, locale);
196
+ const range = getWalletValidityRange(startDate, endDate, validity);
197
+ if (range.isEmpty) return config.noAvailableDates;
198
+ const effectiveStart = range.startDate === getValidityDate(startDate) ? startDate : `${range.startDate} 00:00:00`;
199
+ const effectiveEnd = range.endDate === getValidityDate(endDate) ? endDate : `${range.endDate} 23:59:59`;
200
+ if (!range.endDate) return config.unlimited;
201
+ const hasStarted = range.startDate ? (0, import_dayjs.default)(effectiveStart).isBefore((0, import_dayjs.default)()) : isStarted;
202
+ if (hasStarted || !range.startDate) {
203
+ const endDateStr = formatDateTime(effectiveEnd, isAllDay, locale);
175
204
  return `${config.until}${endDateStr}`;
176
205
  } else {
177
- const startDateStr = formatDateTime(startDate, isAllDay, locale);
178
- const endDateStr = formatDateTime(endDate, isAllDay, locale);
206
+ const startDateStr = formatDateTime(effectiveStart, isAllDay, locale);
207
+ const endDateStr = formatDateTime(effectiveEnd, isAllDay, locale);
179
208
  return `${startDateStr}${config.rangeSeparator}${endDateStr}`;
180
209
  }
181
210
  }
182
- function getScheduleSummary(scheduleList, locale = "zh-CN") {
211
+ function getScheduleSummary(scheduleList, locale = "zh-CN", validity) {
212
+ var _a, _b;
183
213
  try {
214
+ locale = textConfig[locale] ? locale : "en";
184
215
  if (!scheduleList || !Array.isArray(scheduleList)) {
185
216
  return "";
186
217
  }
187
218
  if (scheduleList.length > 1) {
188
- return getText(locale, "multipleRules");
219
+ const range = getWalletValidityRange(null, null, validity);
220
+ if (!range.startDate && !range.endDate) return getText(locale, "multipleRules");
221
+ const summaries = scheduleList.map((schedule2) => getScheduleSummary([schedule2], locale, validity)).filter((summary2) => summary2 !== getText(locale, "noAvailableDates"));
222
+ if (summaries.length === 0) return getText(locale, "noAvailableDates");
223
+ if (summaries.length === 1 && summaries[0]) return summaries[0];
224
+ const prefix = range.endDate ? `${formatDateRange(range.startDate || "", range.endDate, false, locale, true)}${getText(locale, "periodSeparator")}` : "";
225
+ return `${prefix}${getText(locale, "multipleRules")}`;
189
226
  }
190
227
  if (scheduleList.length === 0) {
191
228
  return "";
@@ -204,8 +241,35 @@ function getScheduleSummary(scheduleList, locale = "zh-CN") {
204
241
  startTime = (0, import_dayjs.default)(`${firstDesignation.start_date} ${firstDesignation.start_time}`);
205
242
  }
206
243
  }
244
+ const passStart = getValidityDate(validity == null ? void 0 : validity.start_date);
245
+ if (passStart && (!startTime || (0, import_dayjs.default)(passStart).isAfter(startTime))) {
246
+ startTime = (0, import_dayjs.default)(passStart);
247
+ }
207
248
  const isStarted = startTime ? isTimeStarted(now, startTime) : false;
208
- return generateSummaryText(schedule, isStarted, locale);
249
+ const summary = generateSummaryText(schedule, isStarted, locale, validity);
250
+ if (summary === getText(locale, "noAvailableDates")) {
251
+ const included = (_b = (_a = schedule.repeat_rule) == null ? void 0 : _a.included_date) == null ? void 0 : _b.filter(
252
+ (item) => !getWalletValidityRange(item.start, item.end, validity).isEmpty
253
+ );
254
+ if (included == null ? void 0 : included.length) {
255
+ return getScheduleSummary([{
256
+ ...schedule,
257
+ start_time: null,
258
+ end_time: null,
259
+ type: "designation",
260
+ repeat_type: "none",
261
+ repeat_rule: null,
262
+ is_all: 1,
263
+ designation: included.map((item) => ({
264
+ start_date: item.start,
265
+ end_date: item.end,
266
+ start_time: "00:00",
267
+ end_time: "23:59"
268
+ }))
269
+ }], locale, validity);
270
+ }
271
+ }
272
+ return summary;
209
273
  } catch (error) {
210
274
  console.warn("Error in getScheduleSummary:", error);
211
275
  return "";
@@ -214,53 +278,69 @@ function getScheduleSummary(scheduleList, locale = "zh-CN") {
214
278
  function isTimeStarted(now, startTime) {
215
279
  return startTime.isBefore(now);
216
280
  }
217
- function generateSummaryText(schedule, isStarted, locale) {
281
+ function generateSummaryText(schedule, isStarted, locale, validity) {
218
282
  if (schedule.type === "designation" && schedule.designation && schedule.designation.length > 1) {
219
- return getText(locale, "multipleRules");
283
+ const passRange = getWalletValidityRange(null, null, validity);
284
+ if (!passRange.startDate && !passRange.endDate) return getText(locale, "multipleRules");
285
+ const designation = schedule.designation.filter(
286
+ (item) => !getWalletValidityRange(item.start_date, item.end_date, validity).isEmpty
287
+ );
288
+ if (!designation.length) return getText(locale, "noAvailableDates");
289
+ if (designation.length === 1) {
290
+ return generateSingleScheduleSummary({ ...schedule, designation }, isStarted, locale, validity);
291
+ }
292
+ const range = getWalletValidityRange(
293
+ designation.map((item) => item.start_date).sort()[0],
294
+ designation.map((item) => item.end_date).sort().pop(),
295
+ validity
296
+ );
297
+ const prefix = range.endDate ? `${formatDateRange(range.startDate || "", range.endDate, isStarted, locale, true)}${getText(locale, "periodSeparator")}` : "";
298
+ return `${prefix}${getText(locale, "multipleRules")}`;
220
299
  }
221
300
  if (schedule.type === "time-slots") {
222
- const endDate = getScheduleEndDate(schedule);
223
- if (!endDate) return "";
224
- const endDateStr = formatDateTime(endDate, true, locale);
225
- const prefix = "";
301
+ const range = getWalletValidityRange(schedule.start_time, getScheduleEndDate(schedule), validity);
302
+ if (range.isEmpty) return getText(locale, "noAvailableDates");
303
+ const endDateStr = range.endDate ? formatDateTime(range.endDate, true, locale) : getText(locale, "unlimited");
226
304
  const suffix = getText(locale, "multipleSlots");
227
- return `${prefix}${endDateStr}${suffix}`;
305
+ return `${endDateStr}${suffix}`;
228
306
  }
229
307
  if (schedule.repeat_type !== "none" && schedule.repeat_rule) {
230
- return generateRecurringSummary(schedule, isStarted, locale);
308
+ return generateRecurringSummary(schedule, isStarted, locale, validity);
231
309
  }
232
- return generateSingleScheduleSummary(schedule, isStarted, locale);
310
+ return generateSingleScheduleSummary(schedule, isStarted, locale, validity);
233
311
  }
234
- function generateRecurringSummary(schedule, isStarted, locale) {
312
+ function generateRecurringSummary(schedule, isStarted, locale, validity) {
235
313
  const { repeat_type, repeat_rule } = schedule;
236
314
  if (!repeat_rule) return "";
237
315
  const { frequency, frequency_date, end } = repeat_rule;
238
- if (end.type === "never") {
239
- return generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeat_type, frequency, frequency_date);
316
+ const range = getWalletValidityRange(schedule.start_time, getScheduleEndDate(schedule), validity);
317
+ if (range.isEmpty) return getText(locale, "noAvailableDates");
318
+ if (end.type === "never" && !range.endDate) {
319
+ return generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeat_type, frequency, frequency_date, validity);
240
320
  }
241
- const endDate = getScheduleEndDate(schedule);
321
+ const endDate = range.endDate;
242
322
  if (!endDate) return "";
243
- const endDateStr = formatDateTime(endDate, true, locale);
244
323
  if (repeat_type === "daily") {
245
324
  const frequencyText = getDailyFrequencyText(frequency, locale);
246
- const dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
247
- return `${dateRange},${frequencyText}`;
325
+ const dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true, validity);
326
+ return `${dateRange}${getText(locale, "timeSlotSeparator")}${frequencyText}`;
248
327
  }
249
328
  if (repeat_type === "weekly") {
250
329
  const weekdaysText = getWeekdayText(frequency_date, locale, "/");
251
330
  const frequencyPrefix = getWeeklyFrequencyPrefix(frequency, locale);
252
331
  const config = getConfig(locale);
253
- const dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
254
- return `${dateRange},${frequencyPrefix}${config.weekPrefix}${weekdaysText}`;
332
+ const dateRange = formatDateRange(schedule.start_time, endDate, isStarted, locale, true, validity);
333
+ return `${dateRange}${config.timeSlotSeparator}${frequencyPrefix}${config.weekPrefix}${weekdaysText}`;
255
334
  }
256
335
  return "";
257
336
  }
258
- function generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeatType, frequency, frequencyDate) {
337
+ function generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeatType, frequency, frequencyDate, validity) {
259
338
  const config = getConfig(locale);
260
339
  if (repeatType === "daily") {
261
340
  if (frequency === 1) {
262
- if (schedule.start_time) {
263
- const startDateStr = formatDateTime(schedule.start_time, true, locale);
341
+ const range = getWalletValidityRange(schedule.start_time, null, validity);
342
+ if (range.startDate) {
343
+ const startDateStr = formatDateTime(range.startDate, true, locale);
264
344
  return `${config.longTermValidFrom}${startDateStr}${config.noExpiry}`;
265
345
  }
266
346
  return "";
@@ -292,7 +372,7 @@ function generateNeverEndingRecurringSummary(schedule, isStarted, locale, repeat
292
372
  }
293
373
  return "";
294
374
  }
295
- function generateSingleScheduleSummary(schedule, isStarted, locale) {
375
+ function generateSingleScheduleSummary(schedule, isStarted, locale, validity) {
296
376
  const isAllDay = schedule.is_all === 1;
297
377
  if (schedule.type === "designation" && schedule.designation && schedule.designation.length === 1) {
298
378
  const designation = schedule.designation[0];
@@ -302,27 +382,26 @@ function generateSingleScheduleSummary(schedule, isStarted, locale) {
302
382
  const endTime = designation.end_time;
303
383
  const isDesignationAllDay = isAllDaySchedule(startTime, endTime);
304
384
  if (isDesignationAllDay || isAllDay) {
305
- return formatDateRange(startDate, endDate, isStarted, locale, true);
385
+ return formatDateRange(startDate, endDate, isStarted, locale, true, validity);
306
386
  } else {
307
387
  const startDateTime = `${startDate} ${startTime}${CONSTANTS.SECONDS_SUFFIX}`;
308
388
  const endDateTime = `${endDate} ${endTime}${CONSTANTS.SECONDS_SUFFIX}`;
309
- return formatDateRange(startDateTime, endDateTime, isStarted, locale, false);
389
+ return formatDateRange(startDateTime, endDateTime, isStarted, locale, false, validity);
310
390
  }
311
391
  }
312
392
  if (isAllDay) {
313
393
  const endDate = getScheduleEndDate(schedule);
314
394
  if (!endDate) return "";
315
- return formatDateRange(schedule.start_time, endDate, isStarted, locale, true);
395
+ return formatDateRange(schedule.start_time, endDate, isStarted, locale, true, validity);
316
396
  } else {
317
- return formatDateRange(schedule.start_time, schedule.end_time, isStarted, locale, false);
397
+ return formatDateRange(schedule.start_time, schedule.end_time, isStarted, locale, false, validity);
318
398
  }
319
399
  }
320
400
  function getScheduleEndDate(schedule) {
321
401
  try {
322
402
  if (schedule.repeat_rule) {
323
403
  if (schedule.repeat_rule.end.type === "never") {
324
- const futureDate = (0, import_dayjs.default)().add(CONSTANTS.DEFAULT_FUTURE_YEARS, "year");
325
- return `${futureDate.format("YYYY-MM-DD")} ${CONSTANTS.ALL_DAY_END}${CONSTANTS.SECONDS_SUFFIX}`;
404
+ return null;
326
405
  } else if (schedule.repeat_rule.end.end_date) {
327
406
  return `${schedule.repeat_rule.end.end_date} ${CONSTANTS.ALL_DAY_END}${CONSTANTS.SECONDS_SUFFIX}`;
328
407
  }
@@ -345,5 +424,6 @@ function getScheduleEndDate(schedule) {
345
424
  }
346
425
  // Annotate the CommonJS export names for ESM import in node:
347
426
  0 && (module.exports = {
348
- getScheduleSummary
427
+ getScheduleSummary,
428
+ getWalletValidityRange
349
429
  });
@@ -0,0 +1,62 @@
1
+ /** 商品配置与 NativeScale 使用的重量单位。 */
2
+ export declare type WeightUnitName = 'KILOGRAMS' | 'GRAMS' | 'POUNDS' | 'OUNCES';
3
+ /** 订单快照与 UI 使用的标准单位符号。 */
4
+ export declare type WeightUnitSymbol = 'kg' | 'g' | 'lb' | 'oz';
5
+ export declare type WeightUnit = WeightUnitName | WeightUnitSymbol;
6
+ /**
7
+ * Pisell 的标准重量单位。目录单价、缺省秤单位和缺省展示均以它为准。
8
+ * 后续标准单位变化时,应优先只修改此处。
9
+ */
10
+ export declare const STANDARD_WEIGHT_UNIT: WeightUnitName;
11
+ export declare const WEIGHT_PRECISION = 3;
12
+ export declare const UNIT_PRICE_PRECISION = 2;
13
+ export declare const MAX_RETAIL_SCALE_WEIGHT_KG = 1000;
14
+ export declare const WEIGHT_UNIT_SYMBOLS: Record<WeightUnitName, WeightUnitSymbol>;
15
+ export declare const WEIGHT_UNIT_NAMES: Record<WeightUnitSymbol, WeightUnitName>;
16
+ /** 单位对应的克数,作为不依赖 NativeScale 的目录价格换算基准。 */
17
+ export declare const WEIGHT_UNIT_GRAMS: Record<WeightUnit, number>;
18
+ export declare const STANDARD_WEIGHT_UNIT_SYMBOL: WeightUnitSymbol;
19
+ export declare const normalizeWeightUnit: (unit?: string | null, fallback?: WeightUnitName) => WeightUnitName;
20
+ export declare const getWeightUnitSymbol: (unit?: string | null) => string;
21
+ export declare const getWeightUnitGrams: (unit?: string | null) => number | undefined;
22
+ /**
23
+ * 将“每 sourceUnitValue 个 sourceUnit 的价格”换算到每 1 个目标单位的倍率。
24
+ * 这里只处理目录单价的单位关系;实际秤读数计价仍应使用 NativeScale。
25
+ */
26
+ export declare const getWeightUnitPriceConversionFactor: (params: {
27
+ sourceUnit?: string | null;
28
+ sourceUnitValue?: string | number | null;
29
+ targetUnit?: string | null;
30
+ }) => number | undefined;
31
+ export declare const isSupportedWeightUnit: (unit?: unknown) => unit is WeightUnit;
32
+ export declare const formatWeightValue: (value: unknown, precision?: number) => string;
33
+ export declare const formatUnitPriceValue: (value: unknown, precision?: number) => string;
34
+ export declare type ScaleReadingStatus = 'stable' | 'unstable' | 'overload' | 'negative' | string | null;
35
+ export declare const INVALID_SCALE_READING_STATUSES: readonly ["overload", "negative"];
36
+ export declare const isInvalidScaleReadingStatus: (status?: ScaleReadingStatus) => boolean;
37
+ export declare const getUsableScaleWeight: (status: ScaleReadingStatus | undefined, weight: number) => number;
38
+ export interface WeighingSnapshot {
39
+ open_sold_weight?: number | string | boolean;
40
+ mode?: 'auto' | 'manual' | string;
41
+ weight_source?: 'auto' | 'manual' | string;
42
+ weight?: string | number;
43
+ tare?: {
44
+ id?: string;
45
+ label?: string;
46
+ value?: string | number;
47
+ unit?: WeightUnit | string;
48
+ };
49
+ tare_name?: string;
50
+ tare_weight?: string | number;
51
+ net_weight?: string | number;
52
+ unit_price?: string | number;
53
+ unit?: WeightUnit | string;
54
+ unit_weight?: string | number;
55
+ unit_data_snapshot?: unknown;
56
+ scalePriceProduct?: unknown;
57
+ total_amount?: string | number;
58
+ }
59
+ /**
60
+ * 解析订单行称重快照:product_sku 是权威源,_extend.weighing 仅用于旧流程兼容。
61
+ */
62
+ export declare const resolveWeighingSnapshot: (dataSource?: Record<string, any> | null) => WeighingSnapshot | undefined;
@@ -0,0 +1,159 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/weighing.ts
20
+ var weighing_exports = {};
21
+ __export(weighing_exports, {
22
+ INVALID_SCALE_READING_STATUSES: () => INVALID_SCALE_READING_STATUSES,
23
+ MAX_RETAIL_SCALE_WEIGHT_KG: () => MAX_RETAIL_SCALE_WEIGHT_KG,
24
+ STANDARD_WEIGHT_UNIT: () => STANDARD_WEIGHT_UNIT,
25
+ STANDARD_WEIGHT_UNIT_SYMBOL: () => STANDARD_WEIGHT_UNIT_SYMBOL,
26
+ UNIT_PRICE_PRECISION: () => UNIT_PRICE_PRECISION,
27
+ WEIGHT_PRECISION: () => WEIGHT_PRECISION,
28
+ WEIGHT_UNIT_GRAMS: () => WEIGHT_UNIT_GRAMS,
29
+ WEIGHT_UNIT_NAMES: () => WEIGHT_UNIT_NAMES,
30
+ WEIGHT_UNIT_SYMBOLS: () => WEIGHT_UNIT_SYMBOLS,
31
+ formatUnitPriceValue: () => formatUnitPriceValue,
32
+ formatWeightValue: () => formatWeightValue,
33
+ getUsableScaleWeight: () => getUsableScaleWeight,
34
+ getWeightUnitGrams: () => getWeightUnitGrams,
35
+ getWeightUnitPriceConversionFactor: () => getWeightUnitPriceConversionFactor,
36
+ getWeightUnitSymbol: () => getWeightUnitSymbol,
37
+ isInvalidScaleReadingStatus: () => isInvalidScaleReadingStatus,
38
+ isSupportedWeightUnit: () => isSupportedWeightUnit,
39
+ normalizeWeightUnit: () => normalizeWeightUnit,
40
+ resolveWeighingSnapshot: () => resolveWeighingSnapshot
41
+ });
42
+ module.exports = __toCommonJS(weighing_exports);
43
+ var STANDARD_WEIGHT_UNIT = "KILOGRAMS";
44
+ var WEIGHT_PRECISION = 3;
45
+ var UNIT_PRICE_PRECISION = 2;
46
+ var MAX_RETAIL_SCALE_WEIGHT_KG = 1e3;
47
+ var WEIGHT_UNIT_SYMBOLS = {
48
+ KILOGRAMS: "kg",
49
+ GRAMS: "g",
50
+ POUNDS: "lb",
51
+ OUNCES: "oz"
52
+ };
53
+ var WEIGHT_UNIT_NAMES = {
54
+ kg: "KILOGRAMS",
55
+ g: "GRAMS",
56
+ lb: "POUNDS",
57
+ oz: "OUNCES"
58
+ };
59
+ var WEIGHT_UNIT_GRAMS = {
60
+ KILOGRAMS: 1e3,
61
+ GRAMS: 1,
62
+ POUNDS: 453.59237,
63
+ OUNCES: 28.349523125,
64
+ kg: 1e3,
65
+ g: 1,
66
+ lb: 453.59237,
67
+ oz: 28.349523125
68
+ };
69
+ var STANDARD_WEIGHT_UNIT_SYMBOL = WEIGHT_UNIT_SYMBOLS[STANDARD_WEIGHT_UNIT];
70
+ var normalizeWeightUnit = (unit, fallback = STANDARD_WEIGHT_UNIT) => {
71
+ if (unit && unit in WEIGHT_UNIT_SYMBOLS) {
72
+ return unit;
73
+ }
74
+ if (unit && unit in WEIGHT_UNIT_NAMES) {
75
+ return WEIGHT_UNIT_NAMES[unit];
76
+ }
77
+ return fallback;
78
+ };
79
+ var getWeightUnitSymbol = (unit) => {
80
+ if (unit && unit in WEIGHT_UNIT_SYMBOLS) {
81
+ return WEIGHT_UNIT_SYMBOLS[unit];
82
+ }
83
+ if (unit && unit in WEIGHT_UNIT_NAMES) {
84
+ return unit;
85
+ }
86
+ return unit || STANDARD_WEIGHT_UNIT_SYMBOL;
87
+ };
88
+ var getWeightUnitGrams = (unit) => unit ? WEIGHT_UNIT_GRAMS[unit] : WEIGHT_UNIT_GRAMS[STANDARD_WEIGHT_UNIT];
89
+ var getWeightUnitPriceConversionFactor = (params) => {
90
+ const sourceGrams = getWeightUnitGrams(
91
+ params.sourceUnit || STANDARD_WEIGHT_UNIT
92
+ );
93
+ const targetGrams = getWeightUnitGrams(
94
+ params.targetUnit || STANDARD_WEIGHT_UNIT
95
+ );
96
+ const sourceUnitValue = Number(params.sourceUnitValue ?? 1);
97
+ if (!sourceGrams || !targetGrams || !Number.isFinite(sourceUnitValue) || sourceUnitValue <= 0) {
98
+ return void 0;
99
+ }
100
+ return targetGrams / (sourceGrams * sourceUnitValue);
101
+ };
102
+ var isSupportedWeightUnit = (unit) => typeof unit === "string" && unit in WEIGHT_UNIT_GRAMS;
103
+ var formatWeightValue = (value, precision = WEIGHT_PRECISION) => {
104
+ const parsedValue = Number(value);
105
+ return (Number.isFinite(parsedValue) ? parsedValue : 0).toFixed(precision);
106
+ };
107
+ var formatUnitPriceValue = (value, precision = UNIT_PRICE_PRECISION) => {
108
+ const parsedValue = Number(value);
109
+ return (Number.isFinite(parsedValue) ? parsedValue : 0).toFixed(precision);
110
+ };
111
+ var INVALID_SCALE_READING_STATUSES = ["overload", "negative"];
112
+ var isInvalidScaleReadingStatus = (status) => INVALID_SCALE_READING_STATUSES.includes(status);
113
+ var getUsableScaleWeight = (status, weight) => isInvalidScaleReadingStatus(status) ? 0 : weight;
114
+ var hasDisplayWeight = (value) => Boolean(value && (Number(value.weight) > 0 || Number(value.net_weight) > 0));
115
+ var resolveProductSkuSnapshot = (value) => {
116
+ const snapshot = value;
117
+ return Number(snapshot == null ? void 0 : snapshot.open_sold_weight) === 1 && hasDisplayWeight(snapshot) ? snapshot : void 0;
118
+ };
119
+ var resolveWeighingSnapshot = (dataSource) => {
120
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
121
+ if (!dataSource) return void 0;
122
+ const productSkuCandidates = [
123
+ dataSource.product_sku,
124
+ (_a = dataSource._origin) == null ? void 0 : _a.product_sku,
125
+ (_c = (_b = dataSource.metadata) == null ? void 0 : _b.origin) == null ? void 0 : _c.product_sku
126
+ ];
127
+ for (const candidate of productSkuCandidates) {
128
+ const snapshot = resolveProductSkuSnapshot(candidate);
129
+ if (snapshot) return snapshot;
130
+ }
131
+ const legacyCandidates = [
132
+ (_e = (_d = dataSource._origin) == null ? void 0 : _d._extend) == null ? void 0 : _e.weighing,
133
+ (_f = dataSource._extend) == null ? void 0 : _f.weighing,
134
+ (_i = (_h = (_g = dataSource.metadata) == null ? void 0 : _g.origin) == null ? void 0 : _h._extend) == null ? void 0 : _i.weighing
135
+ ];
136
+ return legacyCandidates.find((candidate) => hasDisplayWeight(candidate));
137
+ };
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ INVALID_SCALE_READING_STATUSES,
141
+ MAX_RETAIL_SCALE_WEIGHT_KG,
142
+ STANDARD_WEIGHT_UNIT,
143
+ STANDARD_WEIGHT_UNIT_SYMBOL,
144
+ UNIT_PRICE_PRECISION,
145
+ WEIGHT_PRECISION,
146
+ WEIGHT_UNIT_GRAMS,
147
+ WEIGHT_UNIT_NAMES,
148
+ WEIGHT_UNIT_SYMBOLS,
149
+ formatUnitPriceValue,
150
+ formatWeightValue,
151
+ getUsableScaleWeight,
152
+ getWeightUnitGrams,
153
+ getWeightUnitPriceConversionFactor,
154
+ getWeightUnitSymbol,
155
+ isInvalidScaleReadingStatus,
156
+ isSupportedWeightUnit,
157
+ normalizeWeightUnit,
158
+ resolveWeighingSnapshot
159
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/utils",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "sideEffects": false,
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",
package/es/date.d.ts DELETED
@@ -1,28 +0,0 @@
1
- /**
2
- * @title: 格式化日期
3
- * @description:
4
- * @param {string} date
5
- * @param {string} format
6
- * @return {*}
7
- * @Author: zhiwei.Wang
8
- * @Date: 2023-07-21 10:49
9
- */
10
- export declare const formatDate: (date: string | Date, format?: string) => string;
11
- /**
12
- * @title: excel日期 转 js日期
13
- * @description:
14
- * @param {number} excelDate
15
- * @return {*}
16
- * @Author: zhiwei.Wang
17
- * @Date: 2023-07-21 10:49
18
- */
19
- export declare const excelDateToJSDate: (excelDate: number) => string;
20
- /**
21
- * @title: js日期 转 excel日期
22
- * @description:
23
- * @param {string} jsDate
24
- * @return {*}
25
- * @Author: zhiwei.Wang
26
- * @Date: 2023-07-21 10:49
27
- */
28
- export declare const jsDateToExcelDate: (jsDate: string) => number;
package/es/document.d.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * @Title: 设置主题
3
- * @Describe: 传入字符串键值对
4
- * @Author: Wzw
5
- */
6
- export declare const setTheme: (themes: {
7
- [key: string]: string;
8
- }) => void;
9
- /**
10
- * 复制到剪切板
11
- * @param text
12
- */
13
- export declare const copyToClipboard: (text: string) => Promise<void>;
@@ -1,13 +0,0 @@
1
- declare type InjectedConfigType = {
2
- apiKey: string;
3
- authDomain: string;
4
- projectId: string;
5
- storageBucket: string;
6
- messagingSenderId: string;
7
- appId: string;
8
- databaseURL: string;
9
- };
10
- export declare const injectConfig: (context: InjectedConfigType) => void;
11
- export declare const firebaseConfig: any;
12
- declare const _default: any;
13
- export default _default;
@@ -1,28 +0,0 @@
1
- import { FirebaseApp } from 'firebase/app';
2
- import { Auth } from 'firebase/auth';
3
- import { ref, Database, goOnline, goOffline } from 'firebase/database';
4
- declare let firebaseApp: FirebaseApp;
5
- declare let auth: Auth;
6
- declare let database: Database;
7
- export declare const initFirebase: (config?: any) => void;
8
- export { database, firebaseApp, auth, ref, goOnline, goOffline };
9
- export declare const getPath: (path: string) => string;
10
- export declare const setAuthStateChangeCallback: (callback: (user: any) => void) => void;
11
- export declare const signUp: (email: string, password: string) => Promise<import("firebase/auth").User>;
12
- export declare const signInUser: (email: string, password: string) => Promise<import("firebase/auth").User>;
13
- export declare const signOutUser: () => Promise<void>;
14
- export declare const readData: (path: string) => Promise<any>;
15
- export declare const writeData: (path: string, data: any) => Promise<void>;
16
- export declare const onDataChange: (path: string, callback: (snapshot: any) => void) => import("firebase/database").Unsubscribe;
17
- export declare const onDataChanged: (path: string, callback: (snapshot: any) => void) => import("firebase/database").Unsubscribe;
18
- export declare const removeDataListener: (listener: any) => void;
19
- declare const _default: {
20
- signInUser: (email: string, password: string) => Promise<import("firebase/auth").User>;
21
- signOutUser: () => Promise<void>;
22
- readData: (path: string) => Promise<any>;
23
- writeData: (path: string, data: any) => Promise<void>;
24
- onDataChange: (path: string, callback: (snapshot: any) => void) => import("firebase/database").Unsubscribe;
25
- removeDataListener: (listener: any) => void;
26
- onDataChanged: (path: string, callback: (snapshot: any) => void) => import("firebase/database").Unsubscribe;
27
- };
28
- export default _default;
package/es/image.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export declare const image: {
2
- ali: (url: string, w: number) => string;
3
- getImageSize: (url: string) => {
4
- width: number;
5
- height: number;
6
- ratio: number;
7
- success: boolean;
8
- widthRatio: number;
9
- originRatio: number;
10
- };
11
- };
package/es/typeUtils.d.ts DELETED
@@ -1,42 +0,0 @@
1
- /**
2
- * 判断是否是函数
3
- * @param obj
4
- */
5
- export declare const isFunction: (obj: any) => obj is Function;
6
- /**
7
- * 判断是否是数组
8
- * @param obj
9
- */
10
- export declare const isArr: (obj: any) => obj is any[];
11
- /**
12
- * 判断是否是字符串
13
- * @param obj
14
- */
15
- export declare const isString: (obj: any) => obj is string;
16
- /**
17
- * 判断是否是数字
18
- * @param obj
19
- */
20
- export declare const isNumber: (obj: any) => obj is number;
21
- /**
22
- * 判断是否是undefined
23
- * @param obj
24
- */
25
- export declare const isUndefined: (obj: any) => obj is undefined;
26
- /**
27
- * 判断是否是boolean
28
- * @param obj
29
- */
30
- export declare const isBoolean: (obj: any) => obj is boolean;
31
- /**
32
- * 判断是否是json字符串
33
- * @param v
34
- */
35
- export declare const isJson: (v: any) => boolean;
36
- /**
37
- * @Title: 判断是否为对象
38
- * @Describe:
39
- * @Author: Wzw
40
- * @param {any} obj
41
- */
42
- export declare const isPlainObject: (obj: any) => boolean;