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