Socket
Book a DemoInstallSign in
Socket

locale-matcher

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locale-matcher

Super-fast and tiny locale matcher.

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
368
33.82%
Maintainers
1
Weekly downloads
 
Created
Source

locale-matcher build

Super-fast locale matcher and normalizer in just 2 kB gzipped.

npm install --save-prod locale-matcher

Usage

import {matchLocale, pickLocale, normalizeLocale} from 'locale-matcher';

matchLocale(/*requestedLocale*/ 'en-US', /*supportedLocale*/ ['en-AU', 'en-GB', 'en', 'ru']); // → 2

matchLocale(['en-GB', 'ru-RU'], ['pt', 'en', 'ru']); // → 1

pickLocale('__en-US__', ['en-AU', 'en-GB', 'en', 'ru']); // → 'en'

pickLocale(['es-ES', 'cz-CZ'], ['en', 'ru'], /*defaultLocale*/ 'en_US'); // → 'en_US'

pickLocale('aaa-bbb-ccc', ['aaa', 'aaa-bbb', 'aaa-ddd']); // → aaa-bbb

normalizeLocale('__EN__US__'); // → 'en-us'

Lookup algorithm tries to find a locale with the maximum number of matched subtags (en, US, etc.) and shortest overall length.

Matching is case-insensitive and ignores non-alpha-ASCII characters so mn-Cyrl-MN is not distinct from MN__cYRL--mn or ++mN__cYrL@Mn++.

Locales are expected start with ISO 639-1, ISO 639-2, ISO 639-3 or ISO 639-5 language code. These codes are interchangeable so chi-CN is not distinct from zh-CN.

locale-matcher doesn't depend on Intl and doesn't throw exceptions if locale is malformed or subtags aren't ordered properly.

Performance

Clone this repo and use npm ci && npm run perf to run the performance test suite.

Ops/sec
locale-matcher4,250,838
@formatjs/intl-localematcher20,089

Keywords

locale

FAQs

Package last updated on 10 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts