@phensley/locale-matcher
TypeScript icon, indicating that this package has built-in type declarations

1.8.0 • Public • Published

@phensley/locale-matcher

@phensley/locale-matcher min+gzip

Implements distance based locale matching using the CLDR enhanced language matching algorithm.

Installation

NPM:

npm install --save @phensley/locale-matcher

Yarn:

yarn add @phensley/locale-matcher

Examples

import { LocaleMatch, LocaleMatcher } from '@phensley/locale-matcher';

// Add supported locales to matcher
const matcher = new LocaleMatcher('en, en_GB, zh, pt_AR, es-419');
let m: LocaleMatch;

// Query desired locales to find the nearest match
m = matcher.match('en-AU');
console.log(`distance ${m.distance} locale ${m.locale.id}`);

m = matcher.match('es-MX');
console.log(`distance ${m.distance} locale ${m.locale.id}`);
distance 3 locale en_GB
distance 4 locale es-419

Readme

Keywords

none

Package Sidebar

Install

npm i @phensley/locale-matcher

Weekly Downloads

2,035

Version

1.8.0

License

Apache-2.0

Unpacked Size

309 kB

Total Files

39

Last publish

Collaborators

  • phensley