@formatjs/intl-localematcher 0.10.0 → 0.10.2
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/README.md +22 -30
- package/index.d.ts +1 -8
- package/index.js +377 -190
- package/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,41 +1,33 @@
|
|
|
1
1
|
# Intl LocaleMatcher
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Documentation](https://formatjs.github.io/docs/polyfills/intl-localematcher).
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
This package implements a highly optimized three-tier locale matching algorithm that provides excellent performance even with large locale sets (700+ locales).
|
|
8
|
-
|
|
9
|
-
### Benchmark Results
|
|
10
|
-
|
|
11
|
-
Benchmarked with 725 CLDR locales on Node.js:
|
|
5
|
+
Best fit uses CLDR language distances, requested-locale ordering and supported
|
|
6
|
+
locale preferences. Lookup uses RFC 4647 prefix matching.
|
|
12
7
|
|
|
13
|
-
|
|
14
|
-
| ------------------------------------------------------- | ------- | ---------- | -------------------- |
|
|
15
|
-
| **Tier 1: Exact Match** (`en`) | 1.38ms | 730 ops/s | Baseline |
|
|
16
|
-
| **Tier 2: 1-level Fallback** (`en-US` → `en`) | 1.39ms | 725 ops/s | 1.01x slower |
|
|
17
|
-
| **Tier 2: Maximized Match** (`zh-TW` → `zh-Hant`) | 1.40ms | 720 ops/s | 1.02x slower |
|
|
18
|
-
| **Tier 3: CLDR Distance** (`sr-Latn-BA` → `sr-Latn-BA`) | 1.38ms | 730 ops/s | 1.00x slower |
|
|
19
|
-
| **Tier 3: Fuzzy Match** (`en-XZ` → `en`) | 1.50ms | 670 ops/s | 1.09x slower |
|
|
20
|
-
|
|
21
|
-
### Real-world Impact
|
|
22
|
-
|
|
23
|
-
The optimization in this package resolved [issue #4936](https://github.com/formatjs/formatjs/issues/4936), where `DurationFormat` instantiation was taking **610ms** on React Native/Hermes due to slow locale matching against 700+ auto-loaded locales.
|
|
8
|
+
## Performance
|
|
24
9
|
|
|
25
|
-
|
|
10
|
+
Canonical tags, maximized locales and supported-list indexes are cached for
|
|
11
|
+
repeated matches. Mutable best-fit arrays remain checked before cache reuse.
|
|
12
|
+
`ResolveLocale` checks Set contents and order before reusing its private snapshot;
|
|
13
|
+
matching that snapshot avoids a second validation scan. Later mutations retain
|
|
14
|
+
first-match ordering and locale-data selection.
|
|
26
15
|
|
|
27
|
-
|
|
28
|
-
- Chinese locales (`zh-TW`): **1.40ms** per instantiation
|
|
29
|
-
- Serbo-Croatian locales: **1.38ms** per instantiation
|
|
16
|
+
Keep cold preparation, matching, construction and formatting measurements separate.
|
|
30
17
|
|
|
31
|
-
|
|
18
|
+
## Current measurements
|
|
32
19
|
|
|
33
|
-
|
|
20
|
+
Measured 2026-10-31 on Apple M4 Max, macOS arm64, Node 24.14.0 / ICU 78.2; source `56d15e997`. Median of seven warmed rounds.
|
|
34
21
|
|
|
35
|
-
|
|
22
|
+
| Operation | TS ops/s | TS full helpers ops/s | Native JS ops/s |
|
|
23
|
+
| ------------------- | -------: | --------------------: | --------------: |
|
|
24
|
+
| best fit en | 917,471† | 62,277† | — |
|
|
25
|
+
| best fit en-US | 470,600 | 72,354 | — |
|
|
26
|
+
| best fit zh-TW | 455,547 | 71,873 | — |
|
|
27
|
+
| best fit sr-Latn-BA | 391,251 | 71,347 | — |
|
|
28
|
+
| best fit en-XZ | 456,567 | 72,177 | — |
|
|
29
|
+
| fresh array | 38,101 | 25,985 | — |
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
2. **Tier 2 (Maximization + Fallback)**: Progressive subtag removal with locale maximization
|
|
39
|
-
3. **Tier 3 (CLDR Distance)**: Full UTS #35 Enhanced Language Matching with memoization
|
|
31
|
+
[Methodology and raw results](../../benchmarks/polyfills/README.md).
|
|
40
32
|
|
|
41
|
-
|
|
33
|
+
Latest full Rust core coverage: [all-polyfill report](../../benchmarks/polyfills/README.md#rust-core-suite).
|
package/index.d.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
//#region packages/intl-localematcher/abstract/LookupSupportedLocales.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* https://tc39.es/ecma402/#sec-lookupsupportedlocales
|
|
4
3
|
* @param availableLocales
|
|
5
4
|
* @param requestedLocales
|
|
6
5
|
*/
|
|
7
6
|
export declare function LookupSupportedLocales(availableLocales: string[], requestedLocales: string[]): string[];
|
|
8
|
-
//#endregion
|
|
9
|
-
//#region packages/intl-localematcher/abstract/ResolveLocale.d.ts
|
|
10
7
|
interface ResolveLocaleResult {
|
|
11
8
|
locale: string;
|
|
12
9
|
dataLocale: string;
|
|
@@ -19,12 +16,8 @@ export declare function ResolveLocale<K extends string, D extends { [k in K]: an
|
|
|
19
16
|
localeMatcher: string;
|
|
20
17
|
[k: string]: string | null | undefined;
|
|
21
18
|
}, relevantExtensionKeys: K[], localeData: Record<string, D | undefined>, getDefaultLocale: () => string): ResolveLocaleResult;
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region packages/intl-localematcher/index.d.ts
|
|
24
19
|
export interface Opts {
|
|
25
20
|
algorithm: "lookup" | "best fit";
|
|
26
21
|
}
|
|
27
22
|
export declare function match(requestedLocales: readonly string[], availableLocales: readonly string[], defaultLocale: string, opts?: Opts): string;
|
|
28
|
-
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=index.d.ts.map
|
|
23
|
+
export {};
|