@mapbox/locale-utils

A helper library for finding an appropriate locale from a list of available locales given an input locale.

Stats

StarsIssuesVersionUpdatedCreatedSize
@mapbox/locale-utils
0.0.63 years ago4 years agoMinified + gzip package size for @mapbox/locale-utils in KB

Readme

Locale Utils

A helper library for finding an appropriate locale from a list of available locales given an input locale.

Build Status

Installation

npm install @mapbox/locale-utils --save

Usage

var locale = require('@mapbox/locale-utils');

var availableLocales = [
    'en-US',
    'en-GB',
    'es-ES',
    'pt-PT',
    'tr',
    'zh-Hans'
];

// Find the best fitting locale given an input locale
var newLocale = locale.bestMatchingLocale('es-MX', availableLocales));
// Returns `es-ES` since `es-MX` is not an available locale.


// Parse a locale into smaller, easier to understand pieces.
var codedLocale = locale.parseLocaleIntoCodes('es-MX');
// Returns:
// {
//     locale: 'es-MX',
//     language: 'es',
//     script: undefined,
//     region: 'MX'
// }

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.