@formatjs/intl-localematcher 0.9.0 → 0.10.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/LICENSE.md CHANGED
File without changes
package/README.md CHANGED
@@ -1,41 +1,18 @@
1
1
  # Intl LocaleMatcher
2
2
 
3
- We've migrated the docs to https://formatjs.github.io/docs/polyfills/intl-localematcher.
3
+ [Documentation](https://formatjs.github.io/docs/polyfills/intl-localematcher).
4
4
 
5
- ## Performance
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:
12
-
13
- | Scenario | Latency | Throughput | Relative Performance |
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
5
+ Best fit uses CLDR language distances, requested-locale ordering and supported
6
+ locale preferences. Lookup uses RFC 4647 prefix matching.
22
7
 
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.
24
-
25
- **After optimization:**
26
-
27
- - Common case (`en-US`): **1.39ms** per instantiation
28
- - Chinese locales (`zh-TW`): **1.40ms** per instantiation
29
- - Serbo-Croatian locales: **1.38ms** per instantiation
30
-
31
- **Performance improvement: 439x faster** 🚀
32
-
33
- ### Three-Tier Optimization
34
-
35
- The algorithm uses three tiers for maximum performance:
8
+ ## Performance
36
9
 
37
- 1. **Tier 1 (Exact Match)**: O(1) Set lookup for exact locale matches
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
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.
40
15
 
41
- This design ensures that common cases (exact matches and simple fallbacks) are extremely fast, while complex scenarios (script/region matching, language distances) still perform well.
16
+ [Constructor measurements](../../knowledge-base/audits/2026-10-31-numberformat-constructor-snapshots.md)
17
+ compare warm construction with the same supported locales. Keep cold preparation,
18
+ matching, construction and formatting measurements separate.
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,11 +16,9 @@ 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
- //#endregion
23
+ export {};
29
24
  //# sourceMappingURL=index.d.ts.map