lookup-closest-locale
Advanced tools
Comparing version 5.1.0 to 6.0.0-alpha.0
18
index.js
@@ -0,15 +1,15 @@ | ||
// @flow | ||
// "lookup" algorithm http://tools.ietf.org/html/rfc4647#section-3.4 | ||
module.exports = function lookupClosestLocale (locale, available) { | ||
if (available[locale]) return locale | ||
var locales = [].concat(locale || []) | ||
for (var l = 0, ll = locales.length; l < ll; ++l) { | ||
var current = locales[l].split('-') | ||
// assumes normalized language tags, and matches in a case sensitive manner | ||
module.exports = function lookupClosestLocale (locale/*: string | string[] | void */, available/*: { [string]: any } */)/*: ?string */ { | ||
if (typeof locale === 'string' && available[locale]) return locale | ||
const locales = [].concat(locale || []) | ||
for (let l = 0, ll = locales.length; l < ll; ++l) { | ||
const current = locales[l].split('-') | ||
while (current.length) { | ||
if (current.join('-') in available) { | ||
return current.join('-') | ||
} | ||
const candidate = current.join('-') | ||
if (available[candidate]) return candidate | ||
current.pop() | ||
} | ||
} | ||
return 'en' | ||
} |
{ | ||
"name": "lookup-closest-locale", | ||
"version": "5.1.0", | ||
"version": "6.0.0-alpha.0", | ||
"description": "Lookup the closest locale from among object keys", | ||
"author": "Andy VanWagoner <thetalecrafter@gmail.com> (https://thetalecrafter.com/)", | ||
"homepage": "https://github.com/format-message/format-message", | ||
"author": "Andy VanWagoner <andy@thetalecrafter.com> (https://thetalecrafter.com/)", | ||
"homepage": "https://github.com/format-message/format-message/tree/master/packages/lookup-closest-locale", | ||
"license": "MIT", | ||
@@ -11,4 +11,7 @@ "repository": "format-message/format-message", | ||
"keywords": [ | ||
"format-message" | ||
"i18n", | ||
"lookup", | ||
"BCP47", | ||
"language tag" | ||
] | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1200
2