@zag-js/i18n-utils 1.34.1 → 1.35.1
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/cache.d.mts +4 -0
- package/dist/cache.d.ts +4 -0
- package/dist/cache.js +41 -0
- package/dist/cache.mjs +16 -0
- package/dist/collator.d.mts +3 -0
- package/dist/collator.d.ts +3 -0
- package/dist/collator.js +34 -0
- package/dist/collator.mjs +9 -0
- package/dist/filter.d.mts +11 -0
- package/dist/filter.d.ts +11 -0
- package/dist/filter.js +73 -0
- package/dist/filter.mjs +48 -0
- package/dist/format-bytes.d.mts +32 -0
- package/dist/format-bytes.d.ts +32 -0
- package/dist/format-bytes.js +54 -0
- package/dist/format-bytes.mjs +29 -0
- package/dist/format-date.d.mts +7 -0
- package/dist/format-date.d.ts +7 -0
- package/dist/format-date.js +262 -0
- package/dist/format-date.mjs +237 -0
- package/dist/format-list.d.mts +3 -0
- package/dist/format-list.d.ts +3 -0
- package/dist/format-list.js +35 -0
- package/dist/format-list.mjs +10 -0
- package/dist/format-number.d.mts +3 -0
- package/dist/format-number.d.ts +3 -0
- package/dist/format-number.js +35 -0
- package/dist/format-number.mjs +10 -0
- package/dist/format-relative-time.d.mts +3 -0
- package/dist/format-relative-time.d.ts +3 -0
- package/dist/format-relative-time.js +65 -0
- package/dist/format-relative-time.mjs +40 -0
- package/dist/format-time.d.mts +13 -0
- package/dist/format-time.d.ts +13 -0
- package/dist/format-time.js +77 -0
- package/dist/format-time.mjs +52 -0
- package/dist/index.d.mts +11 -90
- package/dist/index.d.ts +11 -90
- package/dist/index.js +53 -509
- package/dist/index.mjs +17 -497
- package/dist/is-rtl.d.mts +4 -0
- package/dist/is-rtl.d.ts +4 -0
- package/dist/is-rtl.js +77 -0
- package/dist/is-rtl.mjs +51 -0
- package/dist/locale.d.mts +13 -0
- package/dist/locale.d.ts +13 -0
- package/dist/locale.js +42 -0
- package/dist/locale.mjs +17 -0
- package/dist/track-locale.d.mts +10 -0
- package/dist/track-locale.d.ts +10 -0
- package/dist/track-locale.js +43 -0
- package/dist/track-locale.mjs +18 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,511 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const cacheKey = locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : "");
|
|
10
|
-
if (formatterCache.has(cacheKey)) {
|
|
11
|
-
return formatterCache.get(cacheKey);
|
|
12
|
-
}
|
|
13
|
-
let formatter = new Ins(locale, options);
|
|
14
|
-
formatterCache.set(cacheKey, formatter);
|
|
15
|
-
return formatter;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/collator.ts
|
|
20
|
-
var getCollator = i18nCache(Intl.Collator);
|
|
21
|
-
function createCollator(locale = "en-US", options = {}) {
|
|
22
|
-
return getCollator(locale, options);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/filter.ts
|
|
26
|
-
var collatorCache = i18nCache(Intl.Collator);
|
|
27
|
-
function createFilter(options) {
|
|
28
|
-
const { locale, ...rest } = options || {};
|
|
29
|
-
const collator = collatorCache(locale || "en-US", { usage: "search", ...rest });
|
|
30
|
-
function normalize(string) {
|
|
31
|
-
string = string.normalize("NFC");
|
|
32
|
-
if (collator.resolvedOptions().ignorePunctuation) {
|
|
33
|
-
string = string.replace(/\p{P}/gu, "");
|
|
34
|
-
}
|
|
35
|
-
return string;
|
|
36
|
-
}
|
|
37
|
-
function startsWith(string, substring) {
|
|
38
|
-
if (substring.length === 0) return true;
|
|
39
|
-
string = normalize(string);
|
|
40
|
-
substring = normalize(substring);
|
|
41
|
-
return collator.compare(string.slice(0, substring.length), substring) === 0;
|
|
42
|
-
}
|
|
43
|
-
function endsWith(string, substring) {
|
|
44
|
-
if (substring.length === 0) return true;
|
|
45
|
-
string = normalize(string);
|
|
46
|
-
substring = normalize(substring);
|
|
47
|
-
return collator.compare(string.slice(-substring.length), substring) === 0;
|
|
48
|
-
}
|
|
49
|
-
function contains(string, substring) {
|
|
50
|
-
if (substring.length === 0) return true;
|
|
51
|
-
string = normalize(string);
|
|
52
|
-
substring = normalize(substring);
|
|
53
|
-
let scan = 0;
|
|
54
|
-
let sliceLen = substring.length;
|
|
55
|
-
for (; scan + sliceLen <= string.length; scan++) {
|
|
56
|
-
let slice = string.slice(scan, scan + sliceLen);
|
|
57
|
-
if (collator.compare(substring, slice) === 0) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
startsWith,
|
|
65
|
-
endsWith,
|
|
66
|
-
contains
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/format-number.ts
|
|
71
|
-
var getNumberFormatter = i18nCache(Intl.NumberFormat);
|
|
72
|
-
function formatNumber(v, locale, options = {}) {
|
|
73
|
-
const formatter = getNumberFormatter(locale, options);
|
|
74
|
-
return formatter.format(v);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// src/format-bytes.ts
|
|
78
|
-
var bitPrefixes = ["", "kilo", "mega", "giga", "tera"];
|
|
79
|
-
var bytePrefixes = ["", "kilo", "mega", "giga", "tera", "peta"];
|
|
80
|
-
var formatBytes = (bytes, locale = "en-US", options = {}) => {
|
|
81
|
-
if (Number.isNaN(bytes)) return "";
|
|
82
|
-
if (bytes === 0) return "0 B";
|
|
83
|
-
const { unitSystem = "decimal", precision = 3, unit = "byte", unitDisplay = "short" } = options;
|
|
84
|
-
const factor = unitSystem === "binary" ? 1024 : 1e3;
|
|
85
|
-
const prefix = unit === "bit" ? bitPrefixes : bytePrefixes;
|
|
86
|
-
const isNegative = bytes < 0;
|
|
87
|
-
const absoluteBytes = Math.abs(bytes);
|
|
88
|
-
let value = absoluteBytes;
|
|
89
|
-
let index = 0;
|
|
90
|
-
while (value >= factor && index < prefix.length - 1) {
|
|
91
|
-
value /= factor;
|
|
92
|
-
index++;
|
|
93
|
-
}
|
|
94
|
-
const v = parseFloat(value.toPrecision(precision));
|
|
95
|
-
const finalValue = isNegative ? -v : v;
|
|
96
|
-
return formatNumber(finalValue, locale, {
|
|
97
|
-
style: "unit",
|
|
98
|
-
unit: prefix[index] + unit,
|
|
99
|
-
unitDisplay
|
|
100
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
101
9
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
var FORMATS = [
|
|
109
|
-
"G",
|
|
110
|
-
"GG",
|
|
111
|
-
"GGG",
|
|
112
|
-
"GGGG",
|
|
113
|
-
"GGGGG",
|
|
114
|
-
"y",
|
|
115
|
-
"yo",
|
|
116
|
-
"yy",
|
|
117
|
-
"yyy",
|
|
118
|
-
"yyyy",
|
|
119
|
-
"Y",
|
|
120
|
-
"Yo",
|
|
121
|
-
"YY",
|
|
122
|
-
"YYY",
|
|
123
|
-
"YYYY",
|
|
124
|
-
"Q",
|
|
125
|
-
"Qo",
|
|
126
|
-
"QQ",
|
|
127
|
-
"QQQ",
|
|
128
|
-
"QQQQ",
|
|
129
|
-
"QQQQQ",
|
|
130
|
-
"M",
|
|
131
|
-
"Mo",
|
|
132
|
-
"MM",
|
|
133
|
-
"MMM",
|
|
134
|
-
"MMMM",
|
|
135
|
-
"MMMMM",
|
|
136
|
-
"E",
|
|
137
|
-
"EE",
|
|
138
|
-
"EEE",
|
|
139
|
-
"EEEE",
|
|
140
|
-
"EEEEE",
|
|
141
|
-
"EEEEEE",
|
|
142
|
-
"a",
|
|
143
|
-
"aa",
|
|
144
|
-
"aaa",
|
|
145
|
-
"aaaa",
|
|
146
|
-
"aaaaa",
|
|
147
|
-
"d",
|
|
148
|
-
"do",
|
|
149
|
-
"dd",
|
|
150
|
-
"D",
|
|
151
|
-
"Do",
|
|
152
|
-
"DD",
|
|
153
|
-
"DDD",
|
|
154
|
-
"w",
|
|
155
|
-
"wo",
|
|
156
|
-
"ww",
|
|
157
|
-
"s",
|
|
158
|
-
"so",
|
|
159
|
-
"ss",
|
|
160
|
-
"m",
|
|
161
|
-
"mo",
|
|
162
|
-
"mm",
|
|
163
|
-
"h",
|
|
164
|
-
"ho",
|
|
165
|
-
"hh",
|
|
166
|
-
"H",
|
|
167
|
-
"Ho",
|
|
168
|
-
"HH",
|
|
169
|
-
"z",
|
|
170
|
-
"zz",
|
|
171
|
-
"zzz",
|
|
172
|
-
"zzzz",
|
|
173
|
-
"T"
|
|
174
|
-
];
|
|
175
|
-
function ordinal(num) {
|
|
176
|
-
const n = typeof num === "string" ? parseFloat(num) : num;
|
|
177
|
-
let suffix = "th";
|
|
178
|
-
if (n % 10 === 1 && n % 100 !== 11) {
|
|
179
|
-
suffix = "st";
|
|
180
|
-
} else if (n % 10 === 2 && n % 100 !== 12) {
|
|
181
|
-
suffix = "nd";
|
|
182
|
-
} else if (n % 10 === 3 && n % 100 !== 13) {
|
|
183
|
-
suffix = "rd";
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
184
15
|
}
|
|
185
|
-
return
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
case "Qo":
|
|
226
|
-
return ordinal(Math.ceil((date.getMonth() + 1) / 3));
|
|
227
|
-
case "QQ":
|
|
228
|
-
return pad(Math.ceil((date.getMonth() + 1) / 3), 2);
|
|
229
|
-
case "QQQ":
|
|
230
|
-
return `Q${Math.ceil((date.getMonth() + 1) / 3)}`;
|
|
231
|
-
case "QQQQ": {
|
|
232
|
-
const base = ordinal(String(Math.ceil((date.getMonth() + 1) / 3)));
|
|
233
|
-
return `${base} quarter`;
|
|
234
|
-
}
|
|
235
|
-
// month
|
|
236
|
-
case "M":
|
|
237
|
-
return date.getMonth() + 1;
|
|
238
|
-
case "Mo":
|
|
239
|
-
return ordinal(date.getMonth() + 1);
|
|
240
|
-
case "MM":
|
|
241
|
-
return date.toLocaleString(locale, { month: "2-digit" });
|
|
242
|
-
case "MMM":
|
|
243
|
-
return date.toLocaleString(locale, { month: "short" });
|
|
244
|
-
case "MMMM":
|
|
245
|
-
return date.toLocaleString(locale, { month: "long" });
|
|
246
|
-
case "MMMMM":
|
|
247
|
-
return date.toLocaleString(locale, { month: "narrow" });
|
|
248
|
-
// week
|
|
249
|
-
case "w":
|
|
250
|
-
return Math.ceil(date.getDate() / 7);
|
|
251
|
-
case "wo":
|
|
252
|
-
return ordinal(Math.ceil(date.getDate() / 7));
|
|
253
|
-
case "ww":
|
|
254
|
-
return pad(Math.ceil(date.getDate() / 7), 2);
|
|
255
|
-
// day
|
|
256
|
-
case "d":
|
|
257
|
-
case "D":
|
|
258
|
-
return date.getDate();
|
|
259
|
-
case "do":
|
|
260
|
-
case "Do":
|
|
261
|
-
return ordinal(date.getDate());
|
|
262
|
-
case "dd":
|
|
263
|
-
case "DD":
|
|
264
|
-
return date.toLocaleString(locale, { day: "2-digit" });
|
|
265
|
-
case "DDD":
|
|
266
|
-
return pad(date.getDate(), 3);
|
|
267
|
-
// weekday
|
|
268
|
-
case "E":
|
|
269
|
-
case "EE":
|
|
270
|
-
case "EEE":
|
|
271
|
-
return date.toLocaleString(locale, { weekday: "short" });
|
|
272
|
-
case "EEEE":
|
|
273
|
-
return date.toLocaleString(locale, { weekday: "long" });
|
|
274
|
-
case "EEEEE":
|
|
275
|
-
return date.toLocaleString(locale, { weekday: "narrow" });
|
|
276
|
-
case "EEEEEE":
|
|
277
|
-
return date.toLocaleString(locale, { weekday: "short" }).slice(0, 2);
|
|
278
|
-
// hour
|
|
279
|
-
case "h":
|
|
280
|
-
return date.toLocaleString(locale, { hour: "numeric", hour12: true });
|
|
281
|
-
case "ho":
|
|
282
|
-
return ordinal(date.toLocaleString(locale, { hour: "2-digit", hour12: true }));
|
|
283
|
-
case "hh":
|
|
284
|
-
return date.toLocaleString(locale, { hour: "2-digit", hour12: true });
|
|
285
|
-
case "H":
|
|
286
|
-
return date.toLocaleString(locale, { hour: "numeric", hour12: false });
|
|
287
|
-
case "Ho":
|
|
288
|
-
return ordinal(+date.toLocaleString(locale, { hour: "numeric", hour12: false }));
|
|
289
|
-
case "HH":
|
|
290
|
-
return date.toLocaleString(locale, { hour: "2-digit", hour12: false });
|
|
291
|
-
// minute
|
|
292
|
-
case "m":
|
|
293
|
-
return date.toLocaleString(locale, { minute: "numeric" });
|
|
294
|
-
case "mo":
|
|
295
|
-
return ordinal(date.toLocaleString(locale, { minute: "numeric" }));
|
|
296
|
-
case "mm":
|
|
297
|
-
return date.toLocaleString(locale, { minute: "2-digit" });
|
|
298
|
-
// second
|
|
299
|
-
case "s":
|
|
300
|
-
return date.toLocaleString(locale, { second: "numeric" });
|
|
301
|
-
case "so":
|
|
302
|
-
return ordinal(date.toLocaleString(locale, { second: "numeric" }));
|
|
303
|
-
case "ss":
|
|
304
|
-
return date.toLocaleString(locale, { second: "2-digit" });
|
|
305
|
-
// timestamp
|
|
306
|
-
case "T":
|
|
307
|
-
return date.getTime();
|
|
308
|
-
// day period
|
|
309
|
-
case "a":
|
|
310
|
-
case "aa":
|
|
311
|
-
case "aaa":
|
|
312
|
-
return date.toLocaleString(locale, { hour: "numeric", hour12: true }).toLocaleUpperCase();
|
|
313
|
-
case "aaaa":
|
|
314
|
-
return date.toLocaleString(locale, { hour: "numeric", hour12: true }).toLocaleLowerCase();
|
|
315
|
-
case "aaaaa":
|
|
316
|
-
return date.toLocaleString(locale, { hour: "numeric", hour12: true }).charAt(0);
|
|
317
|
-
// TODO:Revise this
|
|
318
|
-
case "z":
|
|
319
|
-
case "zz":
|
|
320
|
-
case "zzz": {
|
|
321
|
-
return zone(date.toLocaleString(locale, { timeZone, timeZoneName: "shortOffset" }));
|
|
322
|
-
}
|
|
323
|
-
case "zzzz":
|
|
324
|
-
return zone(date.toLocaleString(locale, { timeZone, timeZoneName: "longOffset" }));
|
|
325
|
-
default:
|
|
326
|
-
throw new Error(`Unknown format: ${format}`);
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
function formatDate(date, format, locale, timeZone) {
|
|
330
|
-
let result = format;
|
|
331
|
-
for (const key of FORMATS) {
|
|
332
|
-
const res = getFormat(date, { locale, format: key, timeZone });
|
|
333
|
-
result = result.replace(createRegEx(key), "$1" + res + "$3");
|
|
334
|
-
}
|
|
335
|
-
return result;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// src/format-list.ts
|
|
339
|
-
var getListFormatter = i18nCache(Intl.ListFormat);
|
|
340
|
-
function formatList(list, locale, options = {}) {
|
|
341
|
-
const formatter = getListFormatter(locale, options);
|
|
342
|
-
return formatter.format(list);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// src/format-relative-time.ts
|
|
346
|
-
var getRelativeTimeFormatter = i18nCache(Intl.RelativeTimeFormat);
|
|
347
|
-
function formatRelativeTime(value, locale, options = {}) {
|
|
348
|
-
const rtf = getRelativeTimeFormatter(locale, options);
|
|
349
|
-
const now = /* @__PURE__ */ new Date();
|
|
350
|
-
const diff = getDistance(now, value);
|
|
351
|
-
if (diff.years > 0) return rtf.format(diff.years * diff.sign, "year");
|
|
352
|
-
if (diff.months > 0) return rtf.format(diff.months * diff.sign, "month");
|
|
353
|
-
if (diff.weeks > 0) return rtf.format(diff.weeks * diff.sign, "week");
|
|
354
|
-
if (diff.days > 0) return rtf.format(diff.days * diff.sign, "day");
|
|
355
|
-
if (diff.hours > 0) return rtf.format(diff.hours * diff.sign, "hour");
|
|
356
|
-
if (diff.minutes > 0) return rtf.format(diff.minutes * diff.sign, "minute");
|
|
357
|
-
return rtf.format(diff.seconds * diff.sign, "second");
|
|
358
|
-
}
|
|
359
|
-
var SECOND_TO_MS = 1e3;
|
|
360
|
-
var MINUTE_TO_MS = 1e3 * 60;
|
|
361
|
-
var HOUR_TO_MS = 1e3 * 60 * 60;
|
|
362
|
-
var DAY_TO_MS = 1e3 * 60 * 60 * 24;
|
|
363
|
-
var WEEK_TO_MS = 1e3 * 60 * 60 * 24 * 7;
|
|
364
|
-
var MONTH_TO_MS = 1e3 * 60 * 60 * 24 * 30;
|
|
365
|
-
var YEAR_TO_MS = 1e3 * 60 * 60 * 24 * 365;
|
|
366
|
-
function getDistance(startDate, endDate) {
|
|
367
|
-
const endTime = endDate.getTime();
|
|
368
|
-
const startTime = startDate.getTime();
|
|
369
|
-
const distance = Math.abs(endTime - startTime);
|
|
370
|
-
return {
|
|
371
|
-
sign: Math.sign(endTime - startTime),
|
|
372
|
-
days: Math.floor(distance / DAY_TO_MS),
|
|
373
|
-
hours: Math.floor(distance % DAY_TO_MS / HOUR_TO_MS),
|
|
374
|
-
minutes: Math.floor(distance % HOUR_TO_MS / MINUTE_TO_MS),
|
|
375
|
-
seconds: Math.floor(distance % MINUTE_TO_MS / SECOND_TO_MS),
|
|
376
|
-
weeks: Math.floor(distance / WEEK_TO_MS),
|
|
377
|
-
months: Math.floor(distance / MONTH_TO_MS),
|
|
378
|
-
years: Math.floor(distance / YEAR_TO_MS)
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// src/format-time.ts
|
|
383
|
-
var getTimeFormatter = i18nCache(Intl.DateTimeFormat);
|
|
384
|
-
function splitTimeString(timeString) {
|
|
385
|
-
const [hours = null, minutes = null, seconds = null] = timeString.split(":");
|
|
386
|
-
const parsedHours = hours === null ? null : Number(hours);
|
|
387
|
-
const parsedMinutes = minutes === null ? null : Number(minutes);
|
|
388
|
-
const parsedSeconds = seconds === null ? null : Number(seconds);
|
|
389
|
-
return {
|
|
390
|
-
hours: Number.isNaN(parsedHours) ? null : parsedHours,
|
|
391
|
-
minutes: Number.isNaN(parsedMinutes) ? null : parsedMinutes,
|
|
392
|
-
seconds: Number.isNaN(parsedSeconds) ? null : parsedSeconds
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
function getTimeParts(value) {
|
|
396
|
-
if (value instanceof Date) {
|
|
397
|
-
if (Number.isNaN(value.getTime())) return null;
|
|
398
|
-
return {
|
|
399
|
-
date: value,
|
|
400
|
-
hours: value.getHours(),
|
|
401
|
-
minutes: value.getMinutes(),
|
|
402
|
-
seconds: value.getSeconds()
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
const { hours, minutes, seconds } = splitTimeString(value);
|
|
406
|
-
if (hours === null || minutes === null) return null;
|
|
407
|
-
if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59) return null;
|
|
408
|
-
if (seconds !== null && (seconds < 0 || seconds > 59)) return null;
|
|
409
|
-
const date = /* @__PURE__ */ new Date(0);
|
|
410
|
-
date.setHours(hours, minutes, seconds ?? 0, 0);
|
|
411
|
-
return { date, hours, minutes, seconds: seconds ?? 0 };
|
|
412
|
-
}
|
|
413
|
-
function formatTime(value, locale, options = {}) {
|
|
414
|
-
const { format = "24h", amPmLabels, withSeconds = false } = options;
|
|
415
|
-
const parts = getTimeParts(value);
|
|
416
|
-
if (!parts) return null;
|
|
417
|
-
const formatter = getTimeFormatter(locale, {
|
|
418
|
-
hour: format === "24h" ? "2-digit" : "numeric",
|
|
419
|
-
minute: "2-digit",
|
|
420
|
-
second: withSeconds ? "2-digit" : void 0,
|
|
421
|
-
hour12: format === "12h"
|
|
422
|
-
});
|
|
423
|
-
if (format !== "12h" || !amPmLabels) {
|
|
424
|
-
return formatter.format(parts.date);
|
|
425
|
-
}
|
|
426
|
-
const isPm = parts.hours >= 12;
|
|
427
|
-
const tokens = formatter.formatToParts(parts.date);
|
|
428
|
-
return tokens.map((token) => token.type === "dayPeriod" ? isPm ? amPmLabels.pm : amPmLabels.am : token.value).join("");
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
// src/is-rtl.ts
|
|
432
|
-
var RTL_SCRIPTS = /* @__PURE__ */ new Set([
|
|
433
|
-
"Avst",
|
|
434
|
-
"Arab",
|
|
435
|
-
"Armi",
|
|
436
|
-
"Syrc",
|
|
437
|
-
"Samr",
|
|
438
|
-
"Mand",
|
|
439
|
-
"Thaa",
|
|
440
|
-
"Mend",
|
|
441
|
-
"Nkoo",
|
|
442
|
-
"Adlm",
|
|
443
|
-
"Rohg",
|
|
444
|
-
"Hebr"
|
|
445
|
-
]);
|
|
446
|
-
var RTL_LANGS = /* @__PURE__ */ new Set([
|
|
447
|
-
"ae",
|
|
448
|
-
"ar",
|
|
449
|
-
"arc",
|
|
450
|
-
"bcc",
|
|
451
|
-
"bqi",
|
|
452
|
-
"ckb",
|
|
453
|
-
"dv",
|
|
454
|
-
"fa",
|
|
455
|
-
"glk",
|
|
456
|
-
"he",
|
|
457
|
-
"ku",
|
|
458
|
-
"mzn",
|
|
459
|
-
"nqo",
|
|
460
|
-
"pnb",
|
|
461
|
-
"ps",
|
|
462
|
-
"sd",
|
|
463
|
-
"ug",
|
|
464
|
-
"ur",
|
|
465
|
-
"yi"
|
|
466
|
-
]);
|
|
467
|
-
function isRTL(locale) {
|
|
468
|
-
if (Intl.Locale) {
|
|
469
|
-
const script = new Intl.Locale(locale).maximize().script ?? "";
|
|
470
|
-
return RTL_SCRIPTS.has(script);
|
|
471
|
-
}
|
|
472
|
-
const lang = locale.split("-")[0];
|
|
473
|
-
return RTL_LANGS.has(lang);
|
|
474
|
-
}
|
|
475
|
-
function getLocaleDir(locale) {
|
|
476
|
-
return isRTL(locale) ? "rtl" : "ltr";
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
// src/locale.ts
|
|
480
|
-
function getDefaultLocale() {
|
|
481
|
-
let locale = typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
|
|
482
|
-
return {
|
|
483
|
-
locale,
|
|
484
|
-
dir: isRTL(locale) ? "rtl" : "ltr"
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
function trackLocale(options = {}) {
|
|
488
|
-
const { getRootNode, onLocaleChange } = options;
|
|
489
|
-
onLocaleChange?.(getDefaultLocale());
|
|
490
|
-
const handleLocaleChange = () => {
|
|
491
|
-
onLocaleChange?.(getDefaultLocale());
|
|
492
|
-
};
|
|
493
|
-
const win = getRootNode ? domQuery.getWindow(getRootNode()) : window;
|
|
494
|
-
win.addEventListener("languagechange", handleLocaleChange);
|
|
495
|
-
return () => {
|
|
496
|
-
win.removeEventListener("languagechange", handleLocaleChange);
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
exports.createCollator = createCollator;
|
|
501
|
-
exports.createFilter = createFilter;
|
|
502
|
-
exports.formatBytes = formatBytes;
|
|
503
|
-
exports.formatDate = formatDate;
|
|
504
|
-
exports.formatList = formatList;
|
|
505
|
-
exports.formatNumber = formatNumber;
|
|
506
|
-
exports.formatRelativeTime = formatRelativeTime;
|
|
507
|
-
exports.formatTime = formatTime;
|
|
508
|
-
exports.getDefaultLocale = getDefaultLocale;
|
|
509
|
-
exports.getLocaleDir = getLocaleDir;
|
|
510
|
-
exports.isRTL = isRTL;
|
|
511
|
-
exports.trackLocale = trackLocale;
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/index.ts
|
|
22
|
+
var index_exports = {};
|
|
23
|
+
__export(index_exports, {
|
|
24
|
+
getDefaultLocale: () => import_locale.getDefaultLocale,
|
|
25
|
+
getLocaleDir: () => import_is_rtl.getLocaleDir,
|
|
26
|
+
isRTL: () => import_is_rtl.isRTL,
|
|
27
|
+
trackLocale: () => import_track_locale.trackLocale
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
__reExport(index_exports, require("./collator.cjs"), module.exports);
|
|
31
|
+
__reExport(index_exports, require("./filter.cjs"), module.exports);
|
|
32
|
+
__reExport(index_exports, require("./format-bytes.cjs"), module.exports);
|
|
33
|
+
__reExport(index_exports, require("./format-date.cjs"), module.exports);
|
|
34
|
+
__reExport(index_exports, require("./format-list.cjs"), module.exports);
|
|
35
|
+
__reExport(index_exports, require("./format-number.cjs"), module.exports);
|
|
36
|
+
__reExport(index_exports, require("./format-relative-time.cjs"), module.exports);
|
|
37
|
+
__reExport(index_exports, require("./format-time.cjs"), module.exports);
|
|
38
|
+
var import_is_rtl = require("./is-rtl.cjs");
|
|
39
|
+
var import_locale = require("./locale.cjs");
|
|
40
|
+
var import_track_locale = require("./track-locale.cjs");
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
getDefaultLocale,
|
|
44
|
+
getLocaleDir,
|
|
45
|
+
isRTL,
|
|
46
|
+
trackLocale,
|
|
47
|
+
...require("./collator.cjs"),
|
|
48
|
+
...require("./filter.cjs"),
|
|
49
|
+
...require("./format-bytes.cjs"),
|
|
50
|
+
...require("./format-date.cjs"),
|
|
51
|
+
...require("./format-list.cjs"),
|
|
52
|
+
...require("./format-number.cjs"),
|
|
53
|
+
...require("./format-relative-time.cjs"),
|
|
54
|
+
...require("./format-time.cjs")
|
|
55
|
+
});
|