intl-pluralrules
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "intl-pluralrules", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Intl.PluralRules polyfill", | ||
@@ -39,6 +39,6 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.3.3", | ||
"@babel/preset-env": "^7.3.1", | ||
"jest": "^24.1.0" | ||
"@babel/cli": "^7.4.3", | ||
"@babel/core": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"jest": "^24.7.1" | ||
}, | ||
@@ -45,0 +45,0 @@ "scripts": { |
@@ -32,27 +32,30 @@ "use strict"; | ||
if (!Array.isArray(locales)) locales = [locales]; | ||
return locales.map(function (tag) { | ||
// Requiring tag to be a String or Object means that the Number value | ||
// NaN will not be interpreted as the language tag "nan", which stands | ||
// for Min Nan Chinese. | ||
switch (_typeof(tag)) { | ||
case 'string': | ||
break; | ||
var res = {}; | ||
case 'object': | ||
tag = tag.toString(); | ||
break; | ||
for (var i = 0; i < locales.length; ++i) { | ||
var tag = locales[i]; | ||
if (tag && _typeof(tag) === 'object') tag = String(tag); | ||
default: | ||
throw new TypeError('Locales should be strings, ' + JSON.stringify(tag) + " isn't."); | ||
if (typeof tag !== 'string') { | ||
// Requiring tag to be a String or Object means that the Number value | ||
// NaN will not be interpreted as the language tag "nan", which stands | ||
// for Min Nan Chinese. | ||
var msg = "Locales should be strings, ".concat(JSON.stringify(tag), " isn't."); | ||
throw new TypeError(msg); | ||
} | ||
if (tag[0] === '*') continue; | ||
if (!isStructurallyValidLanguageTag(tag)) { | ||
throw new RangeError('The locale ' + JSON.stringify(tag) + ' is not a structurally valid BCP 47 language tag.'); | ||
var strTag = JSON.stringify(tag); | ||
var _msg = "The locale ".concat(strTag, " is not a structurally valid BCP 47 language tag."); | ||
throw new RangeError(_msg); | ||
} | ||
return tag; | ||
}).reduce(function (seen, tag) { | ||
if (seen.indexOf(tag) < 0) seen.push(tag); | ||
return seen; | ||
}, []); | ||
res[tag] = true; | ||
} | ||
return Object.keys(res); | ||
}; | ||
@@ -90,8 +93,2 @@ | ||
var handleLocaleMatcher = function handleLocaleMatcher(localeMatcher) { | ||
if (localeMatcher && localeMatcher !== 'best fit' && typeof console !== 'undefined') { | ||
console.warn('intl-polyfill only supports `best fit` localeMatcher'); | ||
} | ||
}; | ||
var PluralRules = | ||
@@ -103,6 +100,2 @@ /*#__PURE__*/ | ||
value: function supportedLocalesOf(locales) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
localeMatcher = _ref.localeMatcher; | ||
handleLocaleMatcher(localeMatcher); | ||
return canonicalizeLocaleList(locales).filter(findLocale); | ||
@@ -117,3 +110,2 @@ } | ||
handleLocaleMatcher(opt.localeMatcher); | ||
this._locale = resolveLocale(locales); | ||
@@ -120,0 +112,0 @@ this._type = getType(opt.type); |
@@ -29,7 +29,7 @@ # intl-pluralrules | ||
The implementation itself is available as | ||
`intl-polyfill/plural-rules`, if you'd prefer using it without modifying your | ||
`intl-pluralrules/plural-rules`, if you'd prefer using it without modifying your | ||
`Intl` object, or if you wish to use it rather than your environment's own: | ||
```js | ||
import PluralRules from 'intl-polyfill/plural-rules' | ||
import PluralRules from 'intl-pluralrules/plural-rules' | ||
@@ -36,0 +36,0 @@ new PluralRules('en').select(1) // 'one' |
10340
172