@zelgadis87/utils-core 5.2.9 → 5.2.11

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/esbuild/index.cjs CHANGED
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
6
  var __export = (target, all) => {
12
7
  for (var name in all)
13
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -20,154 +15,8 @@ var __copyProps = (to, from, except, desc) => {
20
15
  }
21
16
  return to;
22
17
  };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
19
 
33
- // ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js
34
- var require_format = __commonJS({
35
- "../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/format.js"(exports2) {
36
- "use strict";
37
- Object.defineProperty(exports2, "__esModule", {
38
- value: true
39
- });
40
- exports2["default"] = format2;
41
- function ownKeys(object, enumerableOnly) {
42
- var keys = Object.keys(object);
43
- if (Object.getOwnPropertySymbols) {
44
- var symbols = Object.getOwnPropertySymbols(object);
45
- if (enumerableOnly) {
46
- symbols = symbols.filter(function(sym) {
47
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
48
- });
49
- }
50
- keys.push.apply(keys, symbols);
51
- }
52
- return keys;
53
- }
54
- function _objectSpread(target) {
55
- for (var i = 1; i < arguments.length; i++) {
56
- var source = arguments[i] != null ? arguments[i] : {};
57
- if (i % 2) {
58
- ownKeys(Object(source), true).forEach(function(key) {
59
- _defineProperty(target, key, source[key]);
60
- });
61
- } else if (Object.getOwnPropertyDescriptors) {
62
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
63
- } else {
64
- ownKeys(Object(source)).forEach(function(key) {
65
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
66
- });
67
- }
68
- }
69
- return target;
70
- }
71
- function _defineProperty(obj, key, value) {
72
- if (key in obj) {
73
- Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true });
74
- } else {
75
- obj[key] = value;
76
- }
77
- return obj;
78
- }
79
- var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
80
- var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"|(\+)/g;
81
- var optionNames = {
82
- y: "year",
83
- M: "month",
84
- d: "day",
85
- D: "weekday",
86
- S: "fractionalSecondDigits",
87
- G: "era",
88
- Z: "timeZoneName",
89
- P: "dayPeriod",
90
- a: "hour12",
91
- h: "hour",
92
- H: "hour",
93
- m: "minute",
94
- s: "second"
95
- };
96
- var values = {
97
- y: ["numeric", "2-digit", void 0, "numeric"],
98
- M: ["narrow", "2-digit", "short", "long"],
99
- d: ["numeric", "2-digit"],
100
- D: ["narrow", "short", "long"],
101
- S: [1, 2, 3],
102
- G: ["narrow", "short", "long"],
103
- Z: ["short", "long"],
104
- P: ["narrow", "short", "long"],
105
- a: [true],
106
- h: ["numeric", "2-digit"],
107
- H: ["numeric", "2-digit"],
108
- m: ["numeric", "2-digit"],
109
- s: ["numeric", "2-digit"]
110
- };
111
- function padIf(condition, value, length) {
112
- return condition && length === 2 && value / 10 < 1 ? "0" + value : value;
113
- }
114
- function formatType(date, type, length) {
115
- var _options;
116
- var _ref = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {}, locale = _ref.locale, timeZone = _ref.timeZone;
117
- var option = optionNames[type];
118
- var value = values[type][length - 1];
119
- if (!value) {
120
- return;
121
- }
122
- var options = (_options = {}, _defineProperty(_options, option, value), _defineProperty(_options, "timeZone", timeZone), _options);
123
- if (type === "a") {
124
- return Intl.DateTimeFormat(locale, _objectSpread(_objectSpread({}, options), {}, {
125
- hour: "numeric"
126
- })).formatToParts(date).pop().value;
127
- }
128
- if (type === "G" || type === "Z") {
129
- return Intl.DateTimeFormat(locale, options).formatToParts(date).pop().value;
130
- }
131
- if (type === "H" || type === "h") {
132
- return Intl.DateTimeFormat("en-GB", _objectSpread(_objectSpread({}, options), {}, {
133
- hourCycle: type === "H" ? "h23" : "h11"
134
- })).format(date).toLocaleLowerCase().replace(" am", "").replace(" pm", "");
135
- }
136
- return padIf(["m", "s"].includes(type) && value === "2-digit", Intl.DateTimeFormat(locale, options).format(date), 2);
137
- }
138
- function format2(date, pattern, config) {
139
- return pattern.split(ESCAPE_REGEX).filter(function(sub) {
140
- return sub !== void 0;
141
- }).map(function(sub, index) {
142
- if (index % 2 !== 0) {
143
- return sub;
144
- }
145
- return sub.replace(PATTERN_REGEX, function(match) {
146
- var type = match.charAt(0);
147
- return formatType(date, type, match.length, config) || match;
148
- });
149
- }).join("");
150
- }
151
- }
152
- });
153
-
154
- // ../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js
155
- var require_lib = __commonJS({
156
- "../../node_modules/.pnpm/small-date@2.0.1/node_modules/small-date/lib/index.js"(exports2) {
157
- "use strict";
158
- Object.defineProperty(exports2, "__esModule", {
159
- value: true
160
- });
161
- exports2.format = void 0;
162
- var _format = require_format();
163
- var _format2 = _interopRequireDefault(_format);
164
- function _interopRequireDefault(obj) {
165
- return obj && obj.__esModule ? obj : { "default": obj };
166
- }
167
- exports2.format = _format2["default"];
168
- }
169
- });
170
-
171
20
  // src/index.ts
172
21
  var index_exports = {};
173
22
  __export(index_exports, {
@@ -1720,9 +1569,6 @@ var LazyDictionary = class _LazyDictionary {
1720
1569
  }
1721
1570
  };
1722
1571
 
1723
- // src/time/TimeInstant.ts
1724
- var import_small_date = __toESM(require_lib());
1725
-
1726
1572
  // src/time/TimeUnit.ts
1727
1573
  var TimeUnit = class _TimeUnit {
1728
1574
  constructor(multiplier) {
@@ -1889,13 +1735,13 @@ var TimeDuration = class _TimeDuration extends TimeBase {
1889
1735
  * @returns the duration, with only the most significant units displayed as a human readable string, eg: 1d 20h, 10m 30s.
1890
1736
  */
1891
1737
  get formatted() {
1892
- const format2 = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1738
+ const format = (x, u1, y, u2) => `${x}${u1} ${pad(y.toString(), 2, "0")}${u2}`;
1893
1739
  const units = this.toUnits();
1894
- if (units.days >= 1) return format2(units.days, "d", units.hours, "h");
1740
+ if (units.days >= 1) return format(units.days, "d", units.hours, "h");
1895
1741
  else if (units.hours >= 1)
1896
- return format2(units.hours, "h", units.minutes, "m");
1742
+ return format(units.hours, "h", units.minutes, "m");
1897
1743
  else if (units.minutes >= 1)
1898
- return format2(units.minutes, "m", units.seconds, "s");
1744
+ return format(units.minutes, "m", units.seconds, "s");
1899
1745
  else if (units.seconds >= 0)
1900
1746
  return units.seconds.toString() + "s";
1901
1747
  else if (units.seconds > -60)
@@ -2141,7 +1987,7 @@ var timeInstantResolveValue = (getFromDate2, referenceDate, x) => {
2141
1987
  };
2142
1988
  var getFromDate = {
2143
1989
  year: (d) => d.getFullYear(),
2144
- month: (d) => d.getMonth(),
1990
+ month: (d) => d.getMonth() + 1,
2145
1991
  date: (d) => d.getDate(),
2146
1992
  hours: (d) => d.getHours(),
2147
1993
  minutes: (d) => d.getMinutes(),
@@ -2158,7 +2004,8 @@ function createTimeInstantFromParameters(aParameters, aReferenceDate = TimeInsta
2158
2004
  const referenceDate = toReferenceDate(aReferenceDate);
2159
2005
  const timestamp2 = Date.UTC(
2160
2006
  timeInstantResolveValue(getFromDate.year, referenceDate, year),
2161
- timeInstantResolveValue(getFromDate.month, referenceDate, month),
2007
+ timeInstantResolveValue(getFromDate.month, referenceDate, month) - 1,
2008
+ // Convert from 1-based to 0-based for Date.UTC()
2162
2009
  timeInstantResolveValue(getFromDate.date, referenceDate, date),
2163
2010
  timeInstantResolveValue(getFromDate.hours, referenceDate, hours),
2164
2011
  timeInstantResolveValue(getFromDate.minutes, referenceDate, minutes),
@@ -2246,13 +2093,18 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2246
2093
  return TimeDuration_default.fromMs(Math.max(distance, 0));
2247
2094
  }
2248
2095
  distanceFromStartOfDay() {
2249
- return this.distanceFrom(this.atStartOfDay());
2096
+ const params = this.toParameters();
2097
+ const msInDay = params.hours * 36e5 + params.minutes * 6e4 + params.seconds * 1e3 + params.milliseconds;
2098
+ return TimeDuration_default.fromMs(msInDay);
2250
2099
  }
2251
2100
  atStartOfDay() {
2252
2101
  return this.atTime({ hours: 0, minutes: 0, seconds: 0, milliseconds: 0 });
2253
2102
  }
2254
2103
  distanceFromEndOfDay() {
2255
- return this.distanceFrom(this.atEndOfDay());
2104
+ const params = this.toParameters();
2105
+ const msInDay = params.hours * 36e5 + params.minutes * 6e4 + params.seconds * 1e3 + params.milliseconds;
2106
+ const msUntilEndOfDay = 86399999 - msInDay;
2107
+ return TimeDuration_default.fromMs(msUntilEndOfDay);
2256
2108
  }
2257
2109
  atEndOfDay() {
2258
2110
  return this.atTime({ hours: 23, minutes: 59, seconds: 59, milliseconds: 999 });
@@ -2278,11 +2130,13 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2278
2130
  throw new Error("Instant is not in the past");
2279
2131
  }
2280
2132
  isToday() {
2281
- return Math.floor(this.days) === Math.floor(_TimeInstant.now().days);
2133
+ return Math.floor(this.ms / 864e5) === Math.floor(Date.now() / 864e5);
2282
2134
  }
2283
2135
  /**
2284
2136
  * Formats this instant using the given pattern. The pattern can contain the following tokens:
2285
2137
  *
2138
+ * Note: Implementation inspired by the small-date library (https://github.com/robinweser/small-date).
2139
+ *
2286
2140
  * | Token | Description | Example |
2287
2141
  * |:------|:--------------------------------|:------------------------------|
2288
2142
  * | D | Weekday, 1 letter | W |
@@ -2322,7 +2176,32 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2322
2176
  * @returns a string, formatted using the given pattern, at the given timeZone with the given locale.
2323
2177
  */
2324
2178
  format(pattern, config = {}) {
2325
- return (0, import_small_date.format)(this.toDate(), pattern, config);
2179
+ return formatTimeInstant(this, pattern, config);
2180
+ }
2181
+ /**
2182
+ * Parses a date string using the given pattern and creates a TimeInstant.
2183
+ * This method is the inverse of format() - parsing a formatted string should recreate the original instant.
2184
+ *
2185
+ * For partial patterns (e.g., time-only or date-only), the missing components are taken from the base instant.
2186
+ * For example, parsing "14:30" with base set to yesterday at midnight will result in yesterday at 14:30.
2187
+ *
2188
+ * Note: Currently performs basic validation (e.g., month 1-12, day 1-31) but does not validate
2189
+ * calendar-specific constraints (e.g., February 30th, April 31st). Invalid dates may be
2190
+ * normalized by the underlying Date constructor.
2191
+ *
2192
+ * @param dateString The date string to parse
2193
+ * @param pattern The pattern used to parse the string (same tokens as format())
2194
+ * @param base The base TimeInstant to use for partial patterns (defaults to now)
2195
+ * @param config An optional locale and timeZone definition to use during parsing
2196
+ * @returns A TimeInstant parsed from the string
2197
+ * @throws Error if the string doesn't match the pattern or contains invalid basic values
2198
+ * @todo Add calendar-aware validation to reject dates like February 30th, April 31st
2199
+ */
2200
+ static fromString(dateString, pattern, base = _TimeInstant.now(), config = {}) {
2201
+ return parseTimeInstant(dateString, pattern, base, config);
2202
+ }
2203
+ static parse(dateString, pattern, config = {}) {
2204
+ return parseTimeInstantComponents(dateString, pattern, config);
2326
2205
  }
2327
2206
  /**
2328
2207
  * @returns this instant, in ISO 8601 format (eg, 2024-11-01T15:49:22.024Z). The format is meant to always be realiable.
@@ -2342,8 +2221,17 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2342
2221
  toDate() {
2343
2222
  return new Date(this.ms);
2344
2223
  }
2345
- toDateUTC() {
2346
- return new Date(this.ms + (/* @__PURE__ */ new Date()).getTimezoneOffset() * 60 * 1e3);
2224
+ toParameters() {
2225
+ const d = this.toDate();
2226
+ return {
2227
+ year: d.getUTCFullYear(),
2228
+ month: d.getUTCMonth() + 1,
2229
+ date: d.getUTCDate(),
2230
+ hours: d.getUTCHours(),
2231
+ minutes: d.getUTCMinutes(),
2232
+ seconds: d.getUTCSeconds(),
2233
+ milliseconds: d.getUTCMilliseconds()
2234
+ };
2347
2235
  }
2348
2236
  /**
2349
2237
  * @returns true if the instant is in the past, false otherwise
@@ -2406,13 +2294,47 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2406
2294
  return timeInstantBuilder();
2407
2295
  }
2408
2296
  static fromIso8601(str) {
2409
- return _TimeInstant.fromUnixTimestamp(new Date(str).getTime());
2410
- }
2411
- static tryFromIso8601(str) {
2412
- if (!str.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:.\d{3}|)(?:Z|[+-]\d{2}:\d{2})?$/))
2413
- throw new Error("Invalid date given: " + str);
2414
- return _TimeInstant.fromUnixTimestamp(new Date(str).getTime());
2297
+ const iso8601Regex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d{3})(Z|[+-]\d{2}:\d{2})?$/;
2298
+ const match = str.match(iso8601Regex);
2299
+ if (!match) {
2300
+ throw new Error("Invalid ISO 8601 date format: " + str);
2301
+ }
2302
+ const [, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr, millisecondStr] = match;
2303
+ const year = parseInt(yearStr, 10);
2304
+ const month = parseInt(monthStr, 10);
2305
+ const date = parseInt(dayStr, 10);
2306
+ const hours = parseInt(hourStr, 10);
2307
+ const minutes = parseInt(minuteStr, 10);
2308
+ const seconds = parseInt(secondStr, 10);
2309
+ const milliseconds = parseInt(millisecondStr, 10);
2310
+ if (!isValidYear(year))
2311
+ throw new Error("Invalid year in: " + str);
2312
+ if (!isValidMonth(month))
2313
+ throw new Error("Invalid month in: " + str);
2314
+ if (!isValidDayOfMonth(date))
2315
+ throw new Error("Invalid day in: " + str);
2316
+ if (!isValidHour(hours))
2317
+ throw new Error("Invalid hour in: " + str);
2318
+ if (!isValidMinute(minutes))
2319
+ throw new Error("Invalid minute in: " + str);
2320
+ if (!isValidSecond(seconds))
2321
+ throw new Error("Invalid second in: " + str);
2322
+ if (!isValidMillisecond(milliseconds))
2323
+ throw new Error("Invalid millisecond in: " + str);
2324
+ return _TimeInstant.fromParameters({
2325
+ year,
2326
+ month,
2327
+ date,
2328
+ hours,
2329
+ minutes,
2330
+ seconds,
2331
+ milliseconds
2332
+ });
2415
2333
  }
2334
+ /**
2335
+ * @deprecated [2025.10.19]: Use fromIso8601 instead.
2336
+ */
2337
+ static tryFromIso8601 = this.fromIso8601;
2416
2338
  static now() {
2417
2339
  return _TimeInstant.fromUnixTimestamp(Date.now());
2418
2340
  }
@@ -2440,30 +2362,21 @@ var TimeInstant = class _TimeInstant extends TimeBase {
2440
2362
  const timestamp2 = Math.round(this.ms / unitMs) * unitMs;
2441
2363
  return _TimeInstant.fromUnixTimestamp(timestamp2);
2442
2364
  }
2443
- get dayOfMonth() {
2444
- return this.toDate().getDate();
2445
- }
2446
- get dayOfWeek() {
2447
- return this.toDate().getDay() + 1;
2448
- }
2449
- get month() {
2450
- return this.toDate().getMonth() + 1;
2451
- }
2452
- get year() {
2453
- return this.toDate().getFullYear();
2454
- }
2455
2365
  /**
2456
2366
  * Returns the week number represented by this instant, according to the ISO 8601 standard.
2457
- * Please note that the instant and the week number could be of two different years, eg the friday 1st january is actually part of week 52 of the previous year.
2367
+ * Please note that the instant and the week number could be of two different years, eg the friday 1st january is actually part of week 52 of the previous year.
2458
2368
  */
2459
2369
  get weekNumber() {
2460
2370
  const date = this.toDate();
2461
2371
  const oneDay = 1e3 * 60 * 60 * 24;
2462
- const thursdayOfThisWeek = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 4 - (date.getDay() || 7), 14, 0, 0);
2463
- const firstOfJanuary = new Date(thursdayOfThisWeek.getFullYear(), 0, 1, 14, 0, 0);
2464
- const dayOfTheYear = Math.round((thursdayOfThisWeek.getTime() - firstOfJanuary.getTime()) / oneDay);
2372
+ const dayOfWeek = date.getUTCDay() || 7;
2373
+ const thursdayMs = this.ms + (4 - dayOfWeek) * oneDay;
2374
+ const thursdayDate = new Date(thursdayMs);
2375
+ const thursdayYear = thursdayDate.getUTCFullYear();
2376
+ const firstOfJanMs = Date.UTC(thursdayYear, 0, 1, 12, 0, 0);
2377
+ const dayOfTheYear = Math.round((thursdayMs - firstOfJanMs) / oneDay);
2465
2378
  const weekNumber = Math.floor(dayOfTheYear / 7) + 1;
2466
- return { weekNumber, year: thursdayOfThisWeek.getFullYear() };
2379
+ return { weekNumber, year: thursdayYear };
2467
2380
  }
2468
2381
  /**
2469
2382
  * This method is used to provide a better DX when inspecting a TimeInstant object in DevTools.
@@ -2483,6 +2396,297 @@ function isTimeInstant(x) {
2483
2396
  return x !== null && x !== void 0 && x instanceof TimeInstant;
2484
2397
  }
2485
2398
  var TimeInstant_default = TimeInstant;
2399
+ function isValidYear(num) {
2400
+ return num >= 0 && num <= 9999;
2401
+ }
2402
+ function isValidMonth(num) {
2403
+ return num >= 1 && num <= 12;
2404
+ }
2405
+ function isValidDayOfMonth(num) {
2406
+ return num >= 1 && num <= 31;
2407
+ }
2408
+ function isValidHour(num) {
2409
+ return num >= 0 && num <= 23;
2410
+ }
2411
+ function isValidMinute(num) {
2412
+ return num >= 0 && num <= 59;
2413
+ }
2414
+ function isValidSecond(num) {
2415
+ return num >= 0 && num <= 59;
2416
+ }
2417
+ function isValidMillisecond(num) {
2418
+ return num >= 0 && num <= 999;
2419
+ }
2420
+ var monthNamesCache = /* @__PURE__ */ new Map();
2421
+ function getMonthNames(locale = "en") {
2422
+ const cached = monthNamesCache.get(locale);
2423
+ if (cached) {
2424
+ return cached;
2425
+ }
2426
+ const shortFormatter = new Intl.DateTimeFormat(locale, { month: "short" });
2427
+ const longFormatter = new Intl.DateTimeFormat(locale, { month: "long" });
2428
+ const short = [];
2429
+ const long = [];
2430
+ for (let month = 0; month < 12; month++) {
2431
+ const date = new Date(2e3, month, 1);
2432
+ short.push(normalizeMonthName(shortFormatter.format(date)));
2433
+ long.push(normalizeMonthName(longFormatter.format(date)));
2434
+ }
2435
+ const result = { short, long };
2436
+ monthNamesCache.set(locale, result);
2437
+ return result;
2438
+ }
2439
+ function normalizeMonthName(name) {
2440
+ return name.replace(/[.,;:!?]/g, "").normalize("NFD").replace(/[\u0300-\u036f]/g, "").trim();
2441
+ }
2442
+ var PATTERN_REGEX = /(M|y|d|D|h|H|m|s|S|G|Z|P|a)+/g;
2443
+ var ESCAPE_REGEX = /\\"|"((?:\\"|[^"])*)"/g;
2444
+ var formatterConfigs = {
2445
+ // Year
2446
+ "y": { options: { year: "numeric" } },
2447
+ "yy": { options: { year: "2-digit" } },
2448
+ "yyyy": { options: { year: "numeric" } },
2449
+ // Month
2450
+ "M": { options: { month: "numeric" } },
2451
+ "MM": { options: { month: "2-digit" } },
2452
+ "MMM": { options: { month: "short" } },
2453
+ "MMMM": { options: { month: "long" } },
2454
+ // Day
2455
+ "d": { options: { day: "numeric" } },
2456
+ "dd": { options: { day: "2-digit" } },
2457
+ // Hours (24-hour) - extract and pad manually due to Intl quirk
2458
+ "H": { options: { hour: "numeric", hour12: false }, extract: { partType: "hour" } },
2459
+ "HH": { options: { hour: "2-digit", hour12: false }, extract: { partType: "hour", transform: (v) => v.padStart(2, "0") } },
2460
+ // Hours (12-hour) - extract and pad manually due to Intl quirk
2461
+ "h": { options: { hour: "numeric", hour12: true }, extract: { partType: "hour" } },
2462
+ "hh": { options: { hour: "2-digit", hour12: true }, extract: { partType: "hour", transform: (v) => v.padStart(2, "0") } },
2463
+ // Minutes - extract and pad manually due to Intl quirk
2464
+ "m": { options: { minute: "numeric" }, extract: { partType: "minute" } },
2465
+ "mm": { options: { minute: "2-digit" }, extract: { partType: "minute", transform: (v) => v.padStart(2, "0") } },
2466
+ // Seconds - extract and pad manually due to Intl quirk
2467
+ "s": { options: { second: "numeric" }, extract: { partType: "second" } },
2468
+ "ss": { options: { second: "2-digit" }, extract: { partType: "second", transform: (v) => v.padStart(2, "0") } },
2469
+ // Milliseconds - extract manually
2470
+ "S": { options: { fractionalSecondDigits: 1 }, extract: { partType: "fractionalSecond" } },
2471
+ "SS": { options: { fractionalSecondDigits: 2 }, extract: { partType: "fractionalSecond" } },
2472
+ "SSS": { options: { fractionalSecondDigits: 3 }, extract: { partType: "fractionalSecond" } },
2473
+ // Weekday
2474
+ "D": { options: { weekday: "narrow" } },
2475
+ "DD": { options: { weekday: "short" } },
2476
+ "DDD": { options: { weekday: "long" } },
2477
+ // Era
2478
+ "G": { options: { era: "narrow" } },
2479
+ "GG": { options: { era: "short" } },
2480
+ "GGG": { options: { era: "long" } },
2481
+ // Timezone
2482
+ "Z": { options: { timeZoneName: "short" } },
2483
+ "ZZ": { options: { timeZoneName: "long" } },
2484
+ // Day period
2485
+ "P": { options: { dayPeriod: "narrow" } },
2486
+ "PP": { options: { dayPeriod: "short" } },
2487
+ "PPP": { options: { dayPeriod: "long" } },
2488
+ // Meridiem - extract dayPeriod and lowercase it
2489
+ "a": { options: { hour: "numeric", hour12: true }, extract: { partType: "dayPeriod", transform: (v) => v.toLowerCase() } }
2490
+ };
2491
+ function formatType(type, length, date, locale = "en", timeZone = "UTC") {
2492
+ const tokenKey = type.repeat(length);
2493
+ const config = formatterConfigs[tokenKey];
2494
+ if (!config) {
2495
+ return void 0;
2496
+ }
2497
+ const formatter = new Intl.DateTimeFormat(locale, { ...config.options, timeZone });
2498
+ if (config.extract) {
2499
+ const part = formatter.formatToParts(date).find((p) => p.type === config.extract.partType);
2500
+ const value = part?.value;
2501
+ if (!value) {
2502
+ return void 0;
2503
+ }
2504
+ return config.extract.transform ? config.extract.transform(value) : value;
2505
+ }
2506
+ return formatter.format(date);
2507
+ }
2508
+ function formatTimeInstant(instant, pattern, config = {}) {
2509
+ const date = instant.toDate();
2510
+ const locale = config.locale || "en";
2511
+ const timeZone = config.timeZone || "UTC";
2512
+ return pattern.split(ESCAPE_REGEX).filter((sub) => sub !== void 0).map((sub, index) => {
2513
+ if (index % 2 !== 0) {
2514
+ return sub;
2515
+ }
2516
+ return sub.replace(PATTERN_REGEX, (match) => {
2517
+ const type = match.charAt(0);
2518
+ const length = match.length;
2519
+ return formatType(type, length, date, locale, timeZone) || match;
2520
+ });
2521
+ }).join("");
2522
+ }
2523
+ function parseTimeInstant(dateString, pattern, base, config = {}) {
2524
+ const parsed = parseTimeInstantComponents(dateString, pattern, config);
2525
+ const params = {
2526
+ ...base.toParameters(),
2527
+ ...parsed
2528
+ };
2529
+ return TimeInstant.fromParameters(params);
2530
+ }
2531
+ function parseTimeInstantComponents(dateString, pattern, config = {}) {
2532
+ let regexPattern = pattern;
2533
+ const tokens = [];
2534
+ let position = 0;
2535
+ const parts = pattern.split(ESCAPE_REGEX).filter((sub) => sub !== void 0);
2536
+ regexPattern = parts.map((sub, index) => {
2537
+ if (index % 2 !== 0) {
2538
+ return sub.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2539
+ }
2540
+ return sub.replace(PATTERN_REGEX, (match) => {
2541
+ const type = match.charAt(0);
2542
+ tokens.push({ type, length: match.length, position: position++ });
2543
+ switch (type) {
2544
+ case "y":
2545
+ return match.length === 2 ? "(\\d{2})" : "(\\d{4})";
2546
+ case "M":
2547
+ if (match.length === 1) return "(\\d{1,2})";
2548
+ if (match.length === 2) return "(\\d{2})";
2549
+ if (match.length === 3) return "([A-Za-z.]{1,7})";
2550
+ return "([A-Za-z]+)";
2551
+ case "d":
2552
+ return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
2553
+ case "H":
2554
+ case "h":
2555
+ return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
2556
+ case "m":
2557
+ case "s":
2558
+ return match.length === 1 ? "(\\d{1,2})" : "(\\d{2})";
2559
+ case "S":
2560
+ return `(\\d{${match.length}})`;
2561
+ case "a":
2562
+ return "([aApP][mM])";
2563
+ case "D":
2564
+ if (match.length === 1) return "([A-Za-z])";
2565
+ if (match.length === 2) return "([A-Za-z]{3})";
2566
+ return "([A-Za-z]+)";
2567
+ case "G":
2568
+ if (match.length === 1) return "([A-Za-z])";
2569
+ if (match.length === 2) return "([A-Za-z]{2})";
2570
+ return "([A-Za-z\\s]+)";
2571
+ case "Z":
2572
+ return match.length === 1 ? "([A-Za-z0-9+\\-:]+)" : "([A-Za-z\\s]+)";
2573
+ case "P":
2574
+ return "([A-Za-z\\s]+)";
2575
+ default:
2576
+ return match;
2577
+ }
2578
+ });
2579
+ }).join("");
2580
+ const regex = new RegExp("^" + regexPattern + "$");
2581
+ const matches = dateString.match(regex);
2582
+ if (!matches) {
2583
+ throw new Error(`Date string "${dateString}" does not match pattern "${pattern}"`);
2584
+ }
2585
+ const result = {};
2586
+ const locale = config.locale || "en";
2587
+ let isPM = false;
2588
+ let is12Hour = false;
2589
+ let hourValue;
2590
+ tokens.forEach((token, index) => {
2591
+ const value = matches[index + 1];
2592
+ switch (token.type) {
2593
+ case "y":
2594
+ if (token.length === 2) {
2595
+ const shortYear = parseInt(value, 10);
2596
+ result.year = shortYear < 50 ? 2e3 + shortYear : 1900 + shortYear;
2597
+ } else {
2598
+ result.year = parseInt(value, 10);
2599
+ }
2600
+ break;
2601
+ case "M":
2602
+ switch (token.length) {
2603
+ case 1:
2604
+ case 2:
2605
+ result.month = parseInt(value, 10);
2606
+ break;
2607
+ case 3: {
2608
+ const normalizedValue = normalizeMonthName(value);
2609
+ const monthIndex = getMonthNames(locale).short.findIndex(
2610
+ (name) => name.toLowerCase() === normalizedValue.toLowerCase()
2611
+ );
2612
+ if (monthIndex === -1)
2613
+ throw new Error(`Invalid short month name in date string: ${dateString}`);
2614
+ result.month = monthIndex + 1;
2615
+ break;
2616
+ }
2617
+ case 4: {
2618
+ const normalizedValue = normalizeMonthName(value);
2619
+ const monthIndex = getMonthNames(locale).long.findIndex(
2620
+ (name) => name.toLowerCase() === normalizedValue.toLowerCase()
2621
+ );
2622
+ if (monthIndex === -1)
2623
+ throw new Error(`Invalid full month name in date string: ${dateString}`);
2624
+ result.month = monthIndex + 1;
2625
+ break;
2626
+ }
2627
+ default:
2628
+ throw new Error(`Invalid month pattern: ${token}`);
2629
+ }
2630
+ break;
2631
+ case "d":
2632
+ result.date = parseInt(value, 10);
2633
+ break;
2634
+ case "H":
2635
+ result.hours = parseInt(value, 10);
2636
+ break;
2637
+ case "h":
2638
+ hourValue = parseInt(value, 10);
2639
+ is12Hour = true;
2640
+ break;
2641
+ case "m":
2642
+ result.minutes = parseInt(value, 10);
2643
+ break;
2644
+ case "s":
2645
+ result.seconds = parseInt(value, 10);
2646
+ break;
2647
+ case "S":
2648
+ let ms = parseInt(value, 10);
2649
+ if (token.length === 1) ms *= 100;
2650
+ else if (token.length === 2) ms *= 10;
2651
+ result.milliseconds = ms;
2652
+ break;
2653
+ case "a":
2654
+ isPM = value.toLowerCase().includes("p");
2655
+ break;
2656
+ }
2657
+ });
2658
+ if (is12Hour && hourValue !== void 0) {
2659
+ if (isPM && hourValue < 12) {
2660
+ result.hours = hourValue + 12;
2661
+ } else if (!isPM && hourValue === 12) {
2662
+ result.hours = 0;
2663
+ } else {
2664
+ result.hours = hourValue;
2665
+ }
2666
+ }
2667
+ if (typeof result.year === "number" && !isValidYear(result.year)) {
2668
+ throw new Error(`Invalid year in date string: ${dateString}`);
2669
+ }
2670
+ if (typeof result.month === "number" && !isValidMonth(result.month)) {
2671
+ throw new Error(`Invalid month in date string: ${dateString}`);
2672
+ }
2673
+ if (typeof result.date === "number" && !isValidDayOfMonth(result.date)) {
2674
+ throw new Error(`Invalid day in date string: ${dateString}`);
2675
+ }
2676
+ if (typeof result.hours === "number" && !isValidHour(result.hours)) {
2677
+ throw new Error(`Invalid hour in date string: ${dateString}`);
2678
+ }
2679
+ if (typeof result.minutes === "number" && !isValidMinute(result.minutes)) {
2680
+ throw new Error(`Invalid minute in date string: ${dateString}`);
2681
+ }
2682
+ if (typeof result.seconds === "number" && !isValidSecond(result.seconds)) {
2683
+ throw new Error(`Invalid second in date string: ${dateString}`);
2684
+ }
2685
+ if (typeof result.milliseconds === "number" && !isValidMillisecond(result.milliseconds)) {
2686
+ throw new Error(`Invalid millisecond in date string: ${dateString}`);
2687
+ }
2688
+ return result;
2689
+ }
2486
2690
 
2487
2691
  // src/Logger.ts
2488
2692
  var LEVELS = ["trace", "log", "debug", "info", "warn", "error"];