@ethisyscore/core-utils 1.94.1 → 1.95.0
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/chunk-2F5FENXB.js +84 -0
- package/dist/chunk-2F5FENXB.js.map +1 -0
- package/dist/chunk-3LIIUXBE.js +14 -0
- package/dist/chunk-3LIIUXBE.js.map +1 -0
- package/dist/chunk-G2XGZH7P.cjs +16 -0
- package/dist/chunk-G2XGZH7P.cjs.map +1 -0
- package/dist/chunk-GAZLFZEL.js +105 -0
- package/dist/chunk-GAZLFZEL.js.map +1 -0
- package/dist/chunk-LT7I4JVK.cjs +121 -0
- package/dist/chunk-LT7I4JVK.cjs.map +1 -0
- package/dist/chunk-OEDAX6WN.js +121 -0
- package/dist/chunk-OEDAX6WN.js.map +1 -0
- package/dist/chunk-P5FSVRZO.cjs +127 -0
- package/dist/chunk-P5FSVRZO.cjs.map +1 -0
- package/dist/chunk-RLPXYKSM.cjs +23 -0
- package/dist/chunk-RLPXYKSM.cjs.map +1 -0
- package/dist/chunk-TN6DXBVD.js +252 -0
- package/dist/chunk-TN6DXBVD.js.map +1 -0
- package/dist/chunk-YNBKRMK3.cjs +290 -0
- package/dist/chunk-YNBKRMK3.cjs.map +1 -0
- package/dist/chunk-ZQCGDT7D.js +19 -0
- package/dist/chunk-ZQCGDT7D.js.map +1 -0
- package/dist/chunk-ZR7TABGT.cjs +94 -0
- package/dist/chunk-ZR7TABGT.cjs.map +1 -0
- package/dist/date/index.cjs +210 -397
- package/dist/date/index.cjs.map +1 -1
- package/dist/date/index.js +2 -349
- package/dist/date/index.js.map +1 -1
- package/dist/date/org-format.cjs +13 -151
- package/dist/date/org-format.cjs.map +1 -1
- package/dist/date/org-format.js +3 -141
- package/dist/date/org-format.js.map +1 -1
- package/dist/index.cjs +286 -600
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -539
- package/dist/index.js.map +1 -1
- package/dist/list/index.cjs +7 -11
- package/dist/list/index.cjs.map +1 -1
- package/dist/list/index.js +1 -12
- package/dist/list/index.js.map +1 -1
- package/dist/money/index.cjs +39 -51
- package/dist/money/index.cjs.map +1 -1
- package/dist/money/index.d.cts +129 -8
- package/dist/money/index.d.ts +129 -8
- package/dist/money/index.js +1 -49
- package/dist/money/index.js.map +1 -1
- package/dist/number/index.cjs +15 -18
- package/dist/number/index.cjs.map +1 -1
- package/dist/number/index.js +1 -17
- package/dist/number/index.js.map +1 -1
- package/dist/patch/index.cjs +22 -121
- package/dist/patch/index.cjs.map +1 -1
- package/dist/patch/index.js +1 -119
- package/dist/patch/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,541 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var DISPLAY_DATE_FORMAT = "d MMM yyyy";
|
|
8
|
-
var DAY_DATE_FORMAT = "EEEE, d MMMM";
|
|
9
|
-
var DAY_MONTH_FORMAT = "MMM d";
|
|
10
|
-
var DAY_MONTH_YEAR_FORMAT = "MMM d, yyyy";
|
|
11
|
-
var TIME_FORMAT = "h:mm a";
|
|
12
|
-
var SHORT_DATETIME_FORMAT = "MMM d, h:mm a";
|
|
13
|
-
var MS_PER_DAY = 864e5;
|
|
14
|
-
var MS_PER_HOUR = 36e5;
|
|
15
|
-
var MS_PER_MINUTE = 6e4;
|
|
16
|
-
var DISPLAY_DATE_SLASH_FORMAT = "dd/MM/yyyy";
|
|
17
|
-
var DISPLAY_DATETIME_SLASH_FORMAT = "dd/MM/yyyy HH:mm";
|
|
18
|
-
var DISPLAY_SHORT_DATE_FORMAT = "EEE d MMM";
|
|
19
|
-
var isDateOnlyString = (value) => {
|
|
20
|
-
return typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value);
|
|
21
|
-
};
|
|
22
|
-
var formatDate = (date, dateFormat = DATE_FORMAT) => {
|
|
23
|
-
return format(date, dateFormat);
|
|
24
|
-
};
|
|
25
|
-
var getTodayIsoDate = () => {
|
|
26
|
-
return formatDate(/* @__PURE__ */ new Date());
|
|
27
|
-
};
|
|
28
|
-
var toIsoDate = (date) => formatDate(date);
|
|
29
|
-
var startOfMonthOffset = (date, months) => {
|
|
30
|
-
if (!date || !isValid(date)) {
|
|
31
|
-
return /* @__PURE__ */ new Date(NaN);
|
|
32
|
-
}
|
|
33
|
-
return new Date(date.getFullYear(), date.getMonth() + months, 1);
|
|
34
|
-
};
|
|
35
|
-
var daysBetweenIso = (fromIso, toIso) => {
|
|
36
|
-
const from = parseIsoDateLocal(fromIso);
|
|
37
|
-
const to = parseIsoDateLocal(toIso);
|
|
38
|
-
if (!from || !to) return NaN;
|
|
39
|
-
return Math.round((to.getTime() - from.getTime()) / MS_PER_DAY);
|
|
40
|
-
};
|
|
41
|
-
var getMonthStartIso = (date) => formatDate(new Date(date.getFullYear(), date.getMonth(), 1));
|
|
42
|
-
var getMonthEndIso = (date) => formatDate(new Date(date.getFullYear(), date.getMonth() + 1, 0));
|
|
43
|
-
var parseIsoDateLocal = (value) => {
|
|
44
|
-
if (!value || !isDateOnlyString(value)) return null;
|
|
45
|
-
const [year, month, day] = value.split("-").map(Number);
|
|
46
|
-
const d = new Date(year, month - 1, day);
|
|
47
|
-
return isValid(d) ? d : null;
|
|
48
|
-
};
|
|
49
|
-
var addDaysToIsoDate = (isoDate, days) => {
|
|
50
|
-
const base = parseIsoDateLocal(isoDate);
|
|
51
|
-
if (!base) return isoDate;
|
|
52
|
-
base.setDate(base.getDate() + days);
|
|
53
|
-
return formatDate(base);
|
|
54
|
-
};
|
|
55
|
-
var addYearsToIsoDate = (isoDate, years) => {
|
|
56
|
-
const base = parseIsoDateLocal(isoDate);
|
|
57
|
-
if (!base) return isoDate;
|
|
58
|
-
base.setFullYear(base.getFullYear() + years);
|
|
59
|
-
return formatDate(base);
|
|
60
|
-
};
|
|
61
|
-
var toDateOnlyString = (value) => {
|
|
62
|
-
if (!value) return "";
|
|
63
|
-
const datepart = value.split("T")[0];
|
|
64
|
-
return isDateOnlyString(datepart) ? datepart : "";
|
|
65
|
-
};
|
|
66
|
-
var EM_DASH = "\u2014";
|
|
67
|
-
var formatFixedDateTime = (value, fmt) => {
|
|
68
|
-
if (!value) return EM_DASH;
|
|
69
|
-
const date = new Date(value);
|
|
70
|
-
return Number.isNaN(date.getTime()) ? EM_DASH : format(date, fmt);
|
|
71
|
-
};
|
|
72
|
-
var relativeTimePhrase = (diffMinutes) => {
|
|
73
|
-
if (diffMinutes < 1) return "Just now";
|
|
74
|
-
if (diffMinutes < 60) return `${diffMinutes}m ago`;
|
|
75
|
-
const hours = Math.floor(diffMinutes / 60);
|
|
76
|
-
if (hours < 24) return `${hours}h ago`;
|
|
77
|
-
const days = Math.floor(hours / 24);
|
|
78
|
-
if (days < 7) return `${days}d ago`;
|
|
79
|
-
return null;
|
|
80
|
-
};
|
|
81
|
-
var formatSlashDate = (dateString) => {
|
|
82
|
-
const parsed = parseIsoDateLocal(dateString);
|
|
83
|
-
return parsed ? format(parsed, DISPLAY_DATE_SLASH_FORMAT) : dateString;
|
|
84
|
-
};
|
|
85
|
-
var formatCompactDateTime = (value) => formatFixedDateTime(value, DISPLAY_DATETIME_SLASH_FORMAT);
|
|
86
|
-
var formatShortDate = (value) => formatFixedDateTime(value, DISPLAY_SHORT_DATE_FORMAT);
|
|
87
|
-
var formatMonthDay = (value) => formatFixedDateTime(value, DAY_MONTH_FORMAT);
|
|
88
|
-
var formatDateSafe = (date, formatStr = DATE_FORMAT, fallback = "\u2014") => {
|
|
89
|
-
if (!date) return fallback;
|
|
90
|
-
try {
|
|
91
|
-
const dateObj = typeof date === "string" ? parseISO(date) : date;
|
|
92
|
-
if (!isValid(dateObj)) return fallback;
|
|
93
|
-
return format(dateObj, formatStr);
|
|
94
|
-
} catch {
|
|
95
|
-
return fallback;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
var getOrdinalSuffix = (day) => {
|
|
99
|
-
if (day > 3 && day < 21) return "th";
|
|
100
|
-
switch (day % 10) {
|
|
101
|
-
case 1:
|
|
102
|
-
return "st";
|
|
103
|
-
case 2:
|
|
104
|
-
return "nd";
|
|
105
|
-
case 3:
|
|
106
|
-
return "rd";
|
|
107
|
-
default:
|
|
108
|
-
return "th";
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
var formatDateWithOrdinal = (date) => {
|
|
112
|
-
if (!date) return "Not specified";
|
|
113
|
-
let dateObj;
|
|
114
|
-
if (typeof date === "string") {
|
|
115
|
-
if (isDateOnlyString(date)) {
|
|
116
|
-
const [year2, month2, day2] = date.split("-").map(Number);
|
|
117
|
-
dateObj = new Date(year2, month2 - 1, day2);
|
|
118
|
-
} else {
|
|
119
|
-
dateObj = parseISO(date);
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
dateObj = date;
|
|
123
|
-
}
|
|
124
|
-
if (!isValid(dateObj)) return "Invalid date";
|
|
125
|
-
const day = dateObj.getDate();
|
|
126
|
-
const month = format(dateObj, "MMM");
|
|
127
|
-
const year = dateObj.getFullYear();
|
|
128
|
-
return `${day}${getOrdinalSuffix(day)} ${month} ${year}`;
|
|
129
|
-
};
|
|
130
|
-
var formatTimeAgo = (date) => {
|
|
131
|
-
if (!date) return "";
|
|
132
|
-
const dateObj = typeof date === "string" ? parseISO(date) : date;
|
|
133
|
-
if (!isValid(dateObj)) return "";
|
|
134
|
-
const diffMinutes = Math.floor(((/* @__PURE__ */ new Date()).getTime() - dateObj.getTime()) / MS_PER_MINUTE);
|
|
135
|
-
return relativeTimePhrase(diffMinutes) ?? formatDate(dateObj);
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// src/date/formatValidation.ts
|
|
139
|
-
var SEPARATOR_CHARS = " ,./-:()";
|
|
140
|
-
var DAY_TOKENS = /* @__PURE__ */ new Set(["d", "dd", "do"]);
|
|
141
|
-
var WEEKDAY_TOKENS = /* @__PURE__ */ new Set(["EEE", "EEEE"]);
|
|
142
|
-
var MONTH_TOKENS = /* @__PURE__ */ new Set(["M", "MM", "MMM", "MMMM"]);
|
|
143
|
-
var YEAR_TOKENS = /* @__PURE__ */ new Set(["yy", "yyyy"]);
|
|
144
|
-
var HOUR12_TOKENS = /* @__PURE__ */ new Set(["h", "hh"]);
|
|
145
|
-
var HOUR24_TOKENS = /* @__PURE__ */ new Set(["H", "HH"]);
|
|
146
|
-
var MINUTE_TOKENS = /* @__PURE__ */ new Set(["m", "mm"]);
|
|
147
|
-
var SECOND_TOKENS = /* @__PURE__ */ new Set(["s", "ss"]);
|
|
148
|
-
var MERIDIEM_TOKEN = "a";
|
|
149
|
-
var DATE_HINTS = {
|
|
150
|
-
D: "d",
|
|
151
|
-
DD: "dd",
|
|
152
|
-
Y: "yyyy",
|
|
153
|
-
YY: "yy",
|
|
154
|
-
YYYY: "yyyy",
|
|
155
|
-
E: "EEE",
|
|
156
|
-
EE: "EEE",
|
|
157
|
-
m: "M",
|
|
158
|
-
mm: "MM"
|
|
159
|
-
};
|
|
160
|
-
var TIME_HINTS = {
|
|
161
|
-
t: "a",
|
|
162
|
-
tt: "a",
|
|
163
|
-
A: "a",
|
|
164
|
-
M: "m",
|
|
165
|
-
MM: "mm"
|
|
166
|
-
};
|
|
167
|
-
var invalid = (error) => ({ valid: false, error });
|
|
168
|
-
var isLetter = (c) => /[a-zA-Z]/.test(c);
|
|
169
|
-
function tokenize(value, isKnownToken, hints) {
|
|
170
|
-
const tokens = [];
|
|
171
|
-
let i = 0;
|
|
172
|
-
while (i < value.length) {
|
|
173
|
-
const c = value[i];
|
|
174
|
-
if (c === "'") {
|
|
175
|
-
i++;
|
|
176
|
-
let closed = false;
|
|
177
|
-
while (i < value.length) {
|
|
178
|
-
if (value[i] === "'") {
|
|
179
|
-
if (i + 1 < value.length && value[i + 1] === "'") {
|
|
180
|
-
i += 2;
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
closed = true;
|
|
184
|
-
i++;
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
i++;
|
|
188
|
-
}
|
|
189
|
-
if (!closed) return { result: invalid("Unterminated quoted literal."), tokens };
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
if (isLetter(c)) {
|
|
193
|
-
const start = i;
|
|
194
|
-
while (i < value.length && value[i] === c) i++;
|
|
195
|
-
let run = value.slice(start, i);
|
|
196
|
-
if (run === "d" && value[i] === "o") {
|
|
197
|
-
run = "do";
|
|
198
|
-
i++;
|
|
199
|
-
}
|
|
200
|
-
if (!isKnownToken(run)) {
|
|
201
|
-
const hint = hints[run];
|
|
202
|
-
return {
|
|
203
|
-
result: invalid(hint ? `Unknown token '${run}' \u2014 use '${hint}' instead.` : `Unknown token '${run}'.`),
|
|
204
|
-
tokens
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
tokens.push(run);
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
if (SEPARATOR_CHARS.includes(c)) {
|
|
211
|
-
i++;
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
return { result: invalid(`Unsupported character '${c}'.`), tokens };
|
|
215
|
-
}
|
|
216
|
-
return { result: { valid: true }, tokens };
|
|
217
|
-
}
|
|
218
|
-
function validateDateFormat(value) {
|
|
219
|
-
if (!value) return { valid: true };
|
|
220
|
-
const { result, tokens } = tokenize(
|
|
221
|
-
value,
|
|
222
|
-
(t) => DAY_TOKENS.has(t) || WEEKDAY_TOKENS.has(t) || MONTH_TOKENS.has(t) || YEAR_TOKENS.has(t),
|
|
223
|
-
DATE_HINTS
|
|
224
|
-
);
|
|
225
|
-
if (!result.valid) return result;
|
|
226
|
-
if (!tokens.some((t) => DAY_TOKENS.has(t))) return invalid("Date format must include a day token (d, dd or do).");
|
|
227
|
-
if (!tokens.some((t) => MONTH_TOKENS.has(t))) {
|
|
228
|
-
return invalid("Date format must include a month token (M, MM, MMM or MMMM).");
|
|
229
|
-
}
|
|
230
|
-
if (!tokens.some((t) => YEAR_TOKENS.has(t))) return invalid("Date format must include a year token (yy or yyyy).");
|
|
231
|
-
return { valid: true };
|
|
232
|
-
}
|
|
233
|
-
function validateTimeFormat(value) {
|
|
234
|
-
if (!value) return { valid: true };
|
|
235
|
-
const { result, tokens } = tokenize(
|
|
236
|
-
value,
|
|
237
|
-
(t) => HOUR12_TOKENS.has(t) || HOUR24_TOKENS.has(t) || MINUTE_TOKENS.has(t) || SECOND_TOKENS.has(t) || t === MERIDIEM_TOKEN,
|
|
238
|
-
TIME_HINTS
|
|
239
|
-
);
|
|
240
|
-
if (!result.valid) return result;
|
|
241
|
-
const hasHour12 = tokens.some((t) => HOUR12_TOKENS.has(t));
|
|
242
|
-
const hasHour24 = tokens.some((t) => HOUR24_TOKENS.has(t));
|
|
243
|
-
if (!hasHour12 && !hasHour24) return invalid("Time format must include an hour token (h, hh, H or HH).");
|
|
244
|
-
if (!tokens.some((t) => MINUTE_TOKENS.has(t))) return invalid("Time format must include a minute token (m or mm).");
|
|
245
|
-
const hasMeridiem = tokens.includes(MERIDIEM_TOKEN);
|
|
246
|
-
if (hasHour12 && !hasMeridiem) return invalid("12-hour time format requires the meridiem token 'a'.");
|
|
247
|
-
if (hasMeridiem && !hasHour12) return invalid("Meridiem token 'a' requires a 12-hour hour token (h or hh).");
|
|
248
|
-
return { valid: true };
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// src/date/duration.ts
|
|
252
|
-
var timespanToMilliseconds = (timespan) => {
|
|
253
|
-
if (!timespan) return 0;
|
|
254
|
-
const [h = "0", m = "0", s = "0"] = timespan.split(":");
|
|
255
|
-
const hours = parseInt(h || "0", 10);
|
|
256
|
-
const minutes = parseInt(m || "0", 10);
|
|
257
|
-
const seconds = parseInt(s || "0", 10);
|
|
258
|
-
return (isNaN(hours) ? 0 : hours) * 60 * 60 * 1e3 + (isNaN(minutes) ? 0 : minutes) * 60 * 1e3 + (isNaN(seconds) ? 0 : seconds) * 1e3;
|
|
259
|
-
};
|
|
260
|
-
var millisecondsToHours = (ms) => ms / MS_PER_HOUR;
|
|
261
|
-
var hoursToMilliseconds = (hours) => hours * MS_PER_HOUR;
|
|
262
|
-
var formatDuration = (ms) => {
|
|
263
|
-
if (ms == null || Number.isNaN(ms) || ms < 0) return "\u2014";
|
|
264
|
-
if (ms < MS_PER_MINUTE) return "0m";
|
|
265
|
-
const days = Math.floor(ms / MS_PER_DAY);
|
|
266
|
-
const hours = Math.floor(ms % MS_PER_DAY / MS_PER_HOUR);
|
|
267
|
-
const minutes = Math.floor(ms % MS_PER_HOUR / MS_PER_MINUTE);
|
|
268
|
-
const parts = [];
|
|
269
|
-
if (days) parts.push(`${days}d`);
|
|
270
|
-
if (hours) parts.push(`${hours}h`);
|
|
271
|
-
if (minutes) parts.push(`${minutes}m`);
|
|
272
|
-
return parts.join(" ");
|
|
273
|
-
};
|
|
274
|
-
function toHHmm(value, fallback) {
|
|
275
|
-
if (!value || value.length < 5) return fallback;
|
|
276
|
-
return value.slice(0, 5);
|
|
277
|
-
}
|
|
278
|
-
function toHHmmss(value) {
|
|
279
|
-
const trimmed = value.trim();
|
|
280
|
-
if (!trimmed) return null;
|
|
281
|
-
return trimmed.length === 5 ? `${trimmed}:00` : trimmed;
|
|
282
|
-
}
|
|
283
|
-
function dateOnlyToIsoUtc(value) {
|
|
284
|
-
if (!value) return void 0;
|
|
285
|
-
const parsed = value.includes("T") ? new Date(value) : /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
286
|
-
return Number.isNaN(parsed.getTime()) ? void 0 : parsed.toISOString();
|
|
287
|
-
}
|
|
288
|
-
function nowLocalDateTimeInputValue() {
|
|
289
|
-
return format(/* @__PURE__ */ new Date(), "yyyy-MM-dd'T'HH:mm");
|
|
290
|
-
}
|
|
291
|
-
function localDateTimeInputToIsoUtc(value) {
|
|
292
|
-
if (!value) return void 0;
|
|
293
|
-
const parsed = new Date(value);
|
|
294
|
-
if (!isValid(parsed)) return void 0;
|
|
295
|
-
return parsed.toISOString();
|
|
296
|
-
}
|
|
297
|
-
function ensureUtcIso(value) {
|
|
298
|
-
return /[Zz]|[+-]\d{2}:?\d{2}$/.test(value) ? value : value + "Z";
|
|
299
|
-
}
|
|
300
|
-
function isoUtcToLocalDateTimeInput(value, fallback = "") {
|
|
301
|
-
if (!value) return fallback;
|
|
302
|
-
const parsed = new Date(ensureUtcIso(value));
|
|
303
|
-
if (!isValid(parsed)) return fallback;
|
|
304
|
-
return format(parsed, "yyyy-MM-dd'T'HH:mm");
|
|
305
|
-
}
|
|
306
|
-
var getDateRange = (timePeriod, dateFormat = DATE_FORMAT) => {
|
|
307
|
-
const today = /* @__PURE__ */ new Date();
|
|
308
|
-
switch (timePeriod) {
|
|
309
|
-
case "month":
|
|
310
|
-
return { startDate: format(subMonths(today, 1), dateFormat), endDate: format(today, dateFormat) };
|
|
311
|
-
case "quarter":
|
|
312
|
-
return { startDate: format(subMonths(today, 3), dateFormat), endDate: format(today, dateFormat) };
|
|
313
|
-
case "year":
|
|
314
|
-
return { startDate: format(subYears(today, 1), dateFormat), endDate: format(today, dateFormat) };
|
|
315
|
-
case "week":
|
|
316
|
-
default:
|
|
317
|
-
return { startDate: format(subDays(today, 7), dateFormat), endDate: format(today, dateFormat) };
|
|
318
|
-
}
|
|
319
|
-
};
|
|
320
|
-
function computeDateRange(days) {
|
|
321
|
-
const to = (/* @__PURE__ */ new Date()).toISOString();
|
|
322
|
-
const from = new Date(Date.now() - days * 864e5).toISOString();
|
|
323
|
-
return { from, to };
|
|
324
|
-
}
|
|
325
|
-
function currentMonthRangeUtc(today = /* @__PURE__ */ new Date()) {
|
|
326
|
-
const year = today.getUTCFullYear();
|
|
327
|
-
const month = today.getUTCMonth();
|
|
328
|
-
return {
|
|
329
|
-
fromUtc: new Date(Date.UTC(year, month, 1)).toISOString(),
|
|
330
|
-
beforeUtc: new Date(Date.UTC(year, month + 1, 1)).toISOString()
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
function getCurrentOffsetMinutes(iana) {
|
|
334
|
-
try {
|
|
335
|
-
const parts = new Intl.DateTimeFormat("en", {
|
|
336
|
-
timeZone: iana,
|
|
337
|
-
timeZoneName: "longOffset"
|
|
338
|
-
}).formatToParts(/* @__PURE__ */ new Date());
|
|
339
|
-
const label = parts.find((p) => p.type === "timeZoneName")?.value ?? "";
|
|
340
|
-
if (label === "GMT" || label === "UTC") return 0;
|
|
341
|
-
const m = label.match(/GMT([+-])(\d{2}):(\d{2})/);
|
|
342
|
-
if (!m) return null;
|
|
343
|
-
const sign = m[1] === "+" ? 1 : -1;
|
|
344
|
-
return sign * (parseInt(m[2], 10) * 60 + parseInt(m[3], 10));
|
|
345
|
-
} catch {
|
|
346
|
-
return null;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
function generateJsonPatch(original, modified) {
|
|
350
|
-
if (!isSameType(original, modified)) {
|
|
351
|
-
if (original === modified) return [];
|
|
352
|
-
return [{ op: "replace", path: "", value: modified }];
|
|
353
|
-
}
|
|
354
|
-
const [, patches] = create(
|
|
355
|
-
original,
|
|
356
|
-
(draft) => {
|
|
357
|
-
applyChanges(draft, modified);
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
enablePatches: {
|
|
361
|
-
pathAsArray: false
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
);
|
|
365
|
-
return patches.map(
|
|
366
|
-
(patch) => ({
|
|
367
|
-
op: patch.op,
|
|
368
|
-
path: patch.path,
|
|
369
|
-
// explicitly check for value existence to satisfy strict null checks if needed
|
|
370
|
-
...patch.op !== "remove" ? { value: patch.value } : {}
|
|
371
|
-
})
|
|
372
|
-
);
|
|
373
|
-
}
|
|
374
|
-
function applyChanges(draft, modified) {
|
|
375
|
-
if (isDeepEqual(draft, modified)) {
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
if (Array.isArray(draft) && Array.isArray(modified)) {
|
|
379
|
-
const draftArray = draft;
|
|
380
|
-
draftArray.length = 0;
|
|
381
|
-
draftArray.push(...modified);
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
if (isPlainObject(draft) && isPlainObject(modified)) {
|
|
385
|
-
const draftObj = draft;
|
|
386
|
-
const modifiedObj = modified;
|
|
387
|
-
for (const key of Object.keys(draftObj)) {
|
|
388
|
-
if (!Object.prototype.hasOwnProperty.call(modifiedObj, key)) {
|
|
389
|
-
delete draftObj[key];
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
for (const key of Object.keys(modifiedObj)) {
|
|
393
|
-
if (!isDeepEqual(draftObj[key], modifiedObj[key])) {
|
|
394
|
-
draftObj[key] = modifiedObj[key];
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
function isDeepEqual(a, b) {
|
|
401
|
-
if (a === b) return true;
|
|
402
|
-
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
403
|
-
return a === b;
|
|
404
|
-
}
|
|
405
|
-
if (typeof a !== typeof b) return false;
|
|
406
|
-
if (a instanceof Date && b instanceof Date) {
|
|
407
|
-
return a.getTime() === b.getTime();
|
|
408
|
-
}
|
|
409
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
|
410
|
-
if (a.length !== b.length) return false;
|
|
411
|
-
for (let i = 0; i < a.length; i++) {
|
|
412
|
-
if (!isDeepEqual(a[i], b[i])) return false;
|
|
413
|
-
}
|
|
414
|
-
return true;
|
|
415
|
-
}
|
|
416
|
-
if (typeof a === "object" && typeof b === "object") {
|
|
417
|
-
const objA = a;
|
|
418
|
-
const objB = b;
|
|
419
|
-
const keysA = Object.keys(objA);
|
|
420
|
-
const keysB = Object.keys(objB);
|
|
421
|
-
if (keysA.length !== keysB.length) return false;
|
|
422
|
-
for (const key of keysA) {
|
|
423
|
-
if (!Object.prototype.hasOwnProperty.call(objB, key)) return false;
|
|
424
|
-
if (!isDeepEqual(objA[key], objB[key])) return false;
|
|
425
|
-
}
|
|
426
|
-
return true;
|
|
427
|
-
}
|
|
428
|
-
return false;
|
|
429
|
-
}
|
|
430
|
-
function isPlainObject(value) {
|
|
431
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date);
|
|
432
|
-
}
|
|
433
|
-
function isSameType(a, b) {
|
|
434
|
-
if (Array.isArray(a)) return Array.isArray(b);
|
|
435
|
-
if (Array.isArray(b)) return false;
|
|
436
|
-
if (a instanceof Date) return b instanceof Date;
|
|
437
|
-
if (a && typeof a === "object" && b && typeof b === "object") return true;
|
|
438
|
-
return typeof a === typeof b;
|
|
439
|
-
}
|
|
440
|
-
function applyJsonPatch(original, patches) {
|
|
441
|
-
const rootReplacement = patches.find((patch) => patch.path === "" && patch.op === "replace");
|
|
442
|
-
if (rootReplacement) {
|
|
443
|
-
return rootReplacement.value;
|
|
444
|
-
}
|
|
445
|
-
const nonRootPatches = patches.filter((patch) => patch.path !== "");
|
|
446
|
-
if (nonRootPatches.length === 0) {
|
|
447
|
-
return original;
|
|
448
|
-
}
|
|
449
|
-
return apply(original, nonRootPatches);
|
|
450
|
-
}
|
|
451
|
-
function isNullOrEmpty(patches) {
|
|
452
|
-
return !patches || patches.length === 0;
|
|
453
|
-
}
|
|
454
|
-
function hasPatches(patches) {
|
|
455
|
-
return patches.length > 0;
|
|
456
|
-
}
|
|
457
|
-
function deepClone(obj) {
|
|
458
|
-
if (typeof structuredClone === "function") {
|
|
459
|
-
return structuredClone(obj);
|
|
460
|
-
}
|
|
461
|
-
return JSON.parse(JSON.stringify(obj));
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// src/list/index.ts
|
|
465
|
-
function unwrapList(response) {
|
|
466
|
-
if (response == null) {
|
|
467
|
-
return [];
|
|
468
|
-
}
|
|
469
|
-
if (Array.isArray(response)) {
|
|
470
|
-
return response;
|
|
471
|
-
}
|
|
472
|
-
return response.items ?? response.rows ?? [];
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
// src/money/format.ts
|
|
476
|
-
var MONEY_FALLBACK_LOCALE = "en-GB";
|
|
477
|
-
function formatMoney(amount, options) {
|
|
478
|
-
const { currencyCode, decimalPlaces, locale = MONEY_FALLBACK_LOCALE, symbol } = options;
|
|
479
|
-
const normalizedCode = currencyCode.toUpperCase();
|
|
480
|
-
try {
|
|
481
|
-
const formatter = new Intl.NumberFormat(locale, {
|
|
482
|
-
style: "currency",
|
|
483
|
-
currency: normalizedCode,
|
|
484
|
-
// Narrow symbol so a clear currency context renders "$100", not "US$100".
|
|
485
|
-
currencyDisplay: "narrowSymbol",
|
|
486
|
-
...decimalPlaces != null ? { minimumFractionDigits: decimalPlaces, maximumFractionDigits: decimalPlaces } : {}
|
|
487
|
-
});
|
|
488
|
-
return formatter.format(amount);
|
|
489
|
-
} catch {
|
|
490
|
-
const fractionDigits = decimalPlaces ?? 2;
|
|
491
|
-
const prefix = symbol ?? normalizedCode;
|
|
492
|
-
const sign = amount < 0 ? "-" : "";
|
|
493
|
-
return `${sign}${prefix}${Math.abs(amount).toFixed(fractionDigits)}`;
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
function formatCompactMoney(amount, options) {
|
|
497
|
-
const { currencyCode, symbol, locale = MONEY_FALLBACK_LOCALE } = options;
|
|
498
|
-
const sym = getCurrencySymbol(currencyCode, locale, symbol);
|
|
499
|
-
const sign = amount < 0 ? "-" : "";
|
|
500
|
-
const abs = Math.abs(amount);
|
|
501
|
-
if (abs >= 1e6) {
|
|
502
|
-
return `${sign}${sym}${(abs / 1e6).toFixed(1)}m`;
|
|
503
|
-
}
|
|
504
|
-
if (abs >= 1e3) {
|
|
505
|
-
return `${sign}${sym}${(abs / 1e3).toFixed(0)}k`;
|
|
506
|
-
}
|
|
507
|
-
return `${sign}${sym}${abs.toFixed(0)}`;
|
|
508
|
-
}
|
|
509
|
-
function getCurrencySymbol(currencyCode, locale = MONEY_FALLBACK_LOCALE, symbol) {
|
|
510
|
-
const normalizedCode = currencyCode.toUpperCase();
|
|
511
|
-
try {
|
|
512
|
-
const parts = new Intl.NumberFormat(locale, {
|
|
513
|
-
style: "currency",
|
|
514
|
-
currency: normalizedCode,
|
|
515
|
-
currencyDisplay: "narrowSymbol"
|
|
516
|
-
}).formatToParts(0);
|
|
517
|
-
return parts.find((part) => part.type === "currency")?.value ?? symbol ?? normalizedCode;
|
|
518
|
-
} catch {
|
|
519
|
-
return symbol ?? normalizedCode;
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
// src/number/format.ts
|
|
524
|
-
var NUMBER_FALLBACK_LOCALE = "en-GB";
|
|
525
|
-
function formatNumber(value, options) {
|
|
526
|
-
if (value == null) {
|
|
527
|
-
return "\u2014";
|
|
528
|
-
}
|
|
529
|
-
const dp = options?.decimalPlaces ?? 2;
|
|
530
|
-
return new Intl.NumberFormat(options?.locale ?? NUMBER_FALLBACK_LOCALE, {
|
|
531
|
-
minimumFractionDigits: dp,
|
|
532
|
-
maximumFractionDigits: dp
|
|
533
|
-
}).format(value);
|
|
534
|
-
}
|
|
535
|
-
function formatPercent(ratio, options) {
|
|
536
|
-
return `${(ratio * 100).toFixed(options?.decimalPlaces ?? 2)}%`;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
export { AUDIT_DATE_FORMAT, DATE_FORMAT, DAY_DATE_FORMAT, DAY_MONTH_FORMAT, DAY_MONTH_YEAR_FORMAT, DISPLAY_DATETIME_SLASH_FORMAT, DISPLAY_DATE_FORMAT, DISPLAY_DATE_SLASH_FORMAT, DISPLAY_SHORT_DATE_FORMAT, EM_DASH, MONEY_FALLBACK_LOCALE, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, NUMBER_FALLBACK_LOCALE, SHORT_DATETIME_FORMAT, TIME_FORMAT, addDaysToIsoDate, addYearsToIsoDate, applyJsonPatch, computeDateRange, currentMonthRangeUtc, dateOnlyToIsoUtc, daysBetweenIso, deepClone, ensureUtcIso, formatCompactDateTime, formatCompactMoney, formatDate, formatDateSafe, formatDateWithOrdinal, formatDuration, formatMoney, formatMonthDay, formatNumber, formatPercent, formatShortDate, formatSlashDate, formatTimeAgo, generateJsonPatch, getCurrencySymbol, getCurrentOffsetMinutes, getDateRange, getMonthEndIso, getMonthStartIso, getTodayIsoDate, hasPatches, hoursToMilliseconds, isDateOnlyString, isNullOrEmpty, isoUtcToLocalDateTimeInput, localDateTimeInputToIsoUtc, millisecondsToHours, nowLocalDateTimeInputValue, parseIsoDateLocal, relativeTimePhrase, startOfMonthOffset, timespanToMilliseconds, toDateOnlyString, toHHmm, toHHmmss, toIsoDate, unwrapList, validateDateFormat, validateTimeFormat };
|
|
1
|
+
export { computeDateRange, currentMonthRangeUtc, dateOnlyToIsoUtc, ensureUtcIso, formatDuration, getCurrentOffsetMinutes, getDateRange, hoursToMilliseconds, isoUtcToLocalDateTimeInput, localDateTimeInputToIsoUtc, millisecondsToHours, nowLocalDateTimeInputValue, timespanToMilliseconds, toHHmm, toHHmmss } from './chunk-GAZLFZEL.js';
|
|
2
|
+
export { AUDIT_DATE_FORMAT, DATE_FORMAT, DAY_DATE_FORMAT, DAY_MONTH_FORMAT, DAY_MONTH_YEAR_FORMAT, DISPLAY_DATETIME_SLASH_FORMAT, DISPLAY_DATE_FORMAT, DISPLAY_DATE_SLASH_FORMAT, DISPLAY_SHORT_DATE_FORMAT, EM_DASH, MS_PER_DAY, MS_PER_HOUR, MS_PER_MINUTE, SHORT_DATETIME_FORMAT, TIME_FORMAT, addDaysToIsoDate, addYearsToIsoDate, daysBetweenIso, formatCompactDateTime, formatDate, formatDateSafe, formatDateWithOrdinal, formatMonthDay, formatShortDate, formatSlashDate, formatTimeAgo, getMonthEndIso, getMonthStartIso, getTodayIsoDate, isDateOnlyString, parseIsoDateLocal, relativeTimePhrase, startOfMonthOffset, toDateOnlyString, toIsoDate, validateDateFormat, validateTimeFormat } from './chunk-TN6DXBVD.js';
|
|
3
|
+
export { applyJsonPatch, deepClone, generateJsonPatch, hasPatches, isNullOrEmpty } from './chunk-OEDAX6WN.js';
|
|
4
|
+
export { unwrapList } from './chunk-3LIIUXBE.js';
|
|
5
|
+
export { MONEY_FALLBACK_CURRENCY, MONEY_FALLBACK_LOCALE, formatCompactMoney, formatMoney, getCurrencySymbol, getOrgReportingCurrency, parseMoney, resolveOrgReportingCurrencyCode, setOrgReportingCurrency } from './chunk-2F5FENXB.js';
|
|
6
|
+
export { NUMBER_FALLBACK_LOCALE, formatNumber, formatPercent } from './chunk-ZQCGDT7D.js';
|
|
540
7
|
//# sourceMappingURL=index.js.map
|
|
541
8
|
//# sourceMappingURL=index.js.map
|