fast-plural-rules
Advanced tools
Comparing version
@@ -7,73 +7,59 @@ (function (global, factory) { | ||
var cardinals = { | ||
const cardinals = { | ||
rules: [ | ||
function () { | ||
return 0; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : 1; | ||
}, | ||
function (n) { | ||
return n <= 1 ? 0 : 1; | ||
}, | ||
function (n) { | ||
return n % 10 === 1 && n % 100 !== 11 ? 1 : n % 10 !== 0 ? 2 : 0; | ||
}, | ||
function (n) { | ||
return n === 1 || n === 11 ? 0 : n === 2 || n === 12 ? 1 : n > 2 && n < 20 ? 2 : 3; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : n === 0 || n % 100 > 0 && n % 100 < 20 ? 1 : 2; | ||
}, | ||
function (n) { | ||
return n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 2 : 1; | ||
}, | ||
function (n) { | ||
return n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; | ||
}, | ||
function (n) { | ||
return n % 100 === 1 ? 0 : n % 100 === 2 ? 1 : n % 100 === 3 || n % 100 === 4 ? 2 : 3; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : n === 2 ? 1 : n > 2 && n < 7 ? 2 : n > 6 && n < 11 ? 3 : 4; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : n === 2 ? 1 : n % 100 >= 3 && n % 100 <= 10 ? 2 : n % 100 >= 11 ? 3 : n !== 0 ? 4 : 5; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : n === 0 || n % 100 > 0 && n % 100 < 11 ? 1 : n % 100 > 10 && n % 100 < 20 ? 2 : 3; | ||
}, | ||
function (n) { | ||
return n % 10 === 1 ? 0 : n % 10 === 2 ? 1 : 2; | ||
}, | ||
function (n) { | ||
return n % 10 === 1 && n % 100 !== 11 ? 0 : 1; | ||
}, | ||
function (n) { | ||
return n % 10 === 1 && n % 100 !== 11 && n % 100 !== 71 && n % 100 !== 91 ? 0 : n % 10 === 2 && n % 100 !== 12 && n % 100 !== 72 && n % 100 !== 92 ? 1 : (n % 10 === 3 || n % 10 === 4 || n % 10 === 9) && n % 100 !== 13 && n % 100 !== 73 && n % 100 !== 93 && n % 100 !== 14 && n % 100 !== 74 && n % 100 !== 94 && n % 100 !== 19 && n % 100 !== 79 && n % 100 !== 99 ? 2 : n !== 0 && n % 1000000 === 0 ? 3 : 4; | ||
}, | ||
function (n) { | ||
return n !== 0 ? 1 : 0; | ||
}, | ||
function (n) { | ||
return n === 1 ? 1 : n === 2 ? 2 : n === 3 ? 3 : n === 6 ? 4 : n !== 0 ? 5 : 0; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; | ||
}, | ||
function (n) { | ||
return n === 1 ? 0 : n === 2 ? 1 : n === 3 ? 2 : 3; | ||
}, | ||
function (n) { | ||
return n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2; | ||
}, | ||
function (n) { | ||
return n === 0 ? 0 : n === 1 ? 1 : 2; | ||
}], | ||
() => 0, | ||
n => n === 1 ? 0 : 1, | ||
n => n <= 1 ? 0 : 1, | ||
n => n % 10 === 1 && n % 100 !== 11 ? 1 : n % 10 !== 0 ? 2 : 0, | ||
n => n === 1 || n === 11 ? 0 : n === 2 || n === 12 ? 1 : n > 2 && n < 20 ? 2 : 3, | ||
n => n === 1 ? 0 : n === 0 || (n % 100 > 0 && n % 100 < 20) ? 1 : 2, | ||
n => n % 10 === 1 && n % 100 !== 11 | ||
? 0 | ||
: n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 2 : 1, | ||
n => n % 10 === 1 && n % 100 !== 11 | ||
? 0 | ||
: n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2, | ||
n => n === 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2, | ||
n => n === 1 | ||
? 0 | ||
: n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2, | ||
n => n % 100 === 1 ? 0 : n % 100 === 2 ? 1 : n % 100 === 3 || n % 100 === 4 ? 2 : 3, | ||
n => n === 1 ? 0 : n === 2 ? 1 : n > 2 && n < 7 ? 2 : n > 6 && n < 11 ? 3 : 4, | ||
n => n === 1 | ||
? 0 | ||
: n === 2 | ||
? 1 | ||
: n % 100 >= 3 && n % 100 <= 10 | ||
? 2 | ||
: n % 100 >= 11 ? 3 : n !== 0 ? 4 : 5, | ||
n => n === 1 | ||
? 0 | ||
: n === 0 || (n % 100 > 0 && n % 100 < 11) | ||
? 1 | ||
: n % 100 > 10 && n % 100 < 20 ? 2 : 3, | ||
n => n % 10 === 1 ? 0 : n % 10 === 2 ? 1 : 2, | ||
n => n % 10 === 1 && n % 100 !== 11 ? 0 : 1, | ||
n => n % 10 === 1 && n % 100 !== 11 && n % 100 !== 71 && n % 100 !== 91 | ||
? 0 | ||
: n % 10 === 2 && n % 100 !== 12 && n % 100 !== 72 && n % 100 !== 92 | ||
? 1 | ||
: (n % 10 === 3 || n % 10 === 4 || n % 10 === 9) && | ||
n % 100 !== 13 && n % 100 !== 73 && n % 100 !== 93 && | ||
n % 100 !== 14 && n % 100 !== 74 && n % 100 !== 94 && | ||
n % 100 !== 19 && n % 100 !== 79 && n % 100 !== 99 | ||
? 2 | ||
: n !== 0 && n % 1000000 === 0 | ||
? 3 | ||
: 4, | ||
n => n !== 0 ? 1 : 0, | ||
n => n === 1 ? 1 : n === 2 ? 2 : n === 3 ? 3 : n === 6 ? 4 : n !== 0 ? 5 : 0, | ||
n => n === 1 | ||
? 0 | ||
: n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2, | ||
n => n === 1 ? 0 : n === 2 ? 1 : n === 3 ? 2 : 3, | ||
n => n % 10 === 1 && n % 100 !== 11 | ||
? 0 | ||
: n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2, | ||
n => n === 0 ? 0 : n === 1 ? 1 : 2 | ||
], | ||
rulesByLocale: { | ||
@@ -225,95 +211,110 @@ ach: 2, | ||
}, | ||
formsByIndex: [['other'], | ||
['one', 'other'], | ||
['one', 'other'], | ||
['zero', 'one', 'other'], | ||
['one', 'two', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'two', 'few', 'other'], | ||
['one', 'two', 'few', 'many', 'other'], | ||
['one', 'two', 'few', 'many', 'other', 'zero'], | ||
['one', 'few', 'many', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'other'], | ||
['one', 'two', 'few', 'many', 'other'], | ||
['zero', 'other'], | ||
['zero', 'one', 'two', 'few', 'many', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'two', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['zero', 'one', 'other'] | ||
formsByIndex: [ | ||
['other'], | ||
['one', 'other'], | ||
['one', 'other'], | ||
['zero', 'one', 'other'], | ||
['one', 'two', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'two', 'few', 'other'], | ||
['one', 'two', 'few', 'many', 'other'], | ||
['one', 'two', 'few', 'many', 'other', 'zero'], | ||
['one', 'few', 'many', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'other'], | ||
['one', 'two', 'few', 'many', 'other'], | ||
['zero', 'other'], | ||
['zero', 'one', 'two', 'few', 'many', 'other'], | ||
['one', 'few', 'other'], | ||
['one', 'two', 'few', 'other'], | ||
['one', 'few', 'other'], | ||
['zero', 'one', 'other'] | ||
] | ||
}; | ||
var rules = cardinals.rules, | ||
rulesByLocale = cardinals.rulesByLocale, | ||
formsByIndex = cardinals.formsByIndex; | ||
function normalizeLocale(locale) { | ||
return locale.toLowerCase().replace('_', '-'); | ||
const { rules, rulesByLocale, formsByIndex } = cardinals; | ||
function normalizeLocale (locale) { | ||
return locale.toLowerCase().replace('_', '-') | ||
} | ||
function getLanguage(locale) { | ||
var separator = locale.indexOf('-'); | ||
return separator > 0 ? locale.substr(0, separator) : locale; | ||
function getLanguage (locale) { | ||
const separator = locale.indexOf('-'); | ||
return separator > 0 ? locale.substr(0, separator) : locale | ||
} | ||
function getPluralRuleIndexForCardinalsByLocale(locale) { | ||
function getPluralRuleIndexForCardinalsByLocale (locale) { | ||
locale = normalizeLocale(locale); | ||
var index = rulesByLocale[locale]; | ||
let index = rulesByLocale[locale]; | ||
if (index === undefined) { | ||
var language = getLanguage(locale); | ||
const language = getLanguage(locale); | ||
index = rulesByLocale[language]; | ||
} | ||
if (index === undefined) { | ||
throw new Error("Unrecognized locale: \"" + locale + "\"."); | ||
throw new Error(`Unrecognized locale: "${locale}".`) | ||
} | ||
return index; | ||
return index | ||
} | ||
function adaptPluralRuleForFormName(rule, index) { | ||
var forms = formsByIndex[index]; | ||
function adaptPluralRuleForFormName (rule, index) { | ||
const forms = formsByIndex[index]; | ||
return function (count) { | ||
return forms[rule(count)]; | ||
}; | ||
return forms[rule(count)] | ||
} | ||
} | ||
function getPluralRuleForCardinalsByLocale(locale) { | ||
var index = getPluralRuleIndexForCardinalsByLocale(locale); | ||
return rules[index]; | ||
function getPluralRuleForCardinalsByLocale (locale) { | ||
const index = getPluralRuleIndexForCardinalsByLocale(locale); | ||
return rules[index] | ||
} | ||
function getPluralRuleForCardinalsByIndex(index) { | ||
var rule = rules[index]; | ||
function getPluralRuleForCardinalsByIndex (index) { | ||
const rule = rules[index]; | ||
if (rule === undefined) { | ||
throw new Error("Invalid index: \"" + index + "\"."); | ||
throw new Error(`Invalid index: "${index}".`) | ||
} | ||
return rule; | ||
return rule | ||
} | ||
function getPluralRuleForNamedFormsForCardinalsByLocale(locale) { | ||
var index = getPluralRuleIndexForCardinalsByLocale(locale); | ||
return adaptPluralRuleForFormName(rules[index], index); | ||
function getPluralRuleForNamedFormsForCardinalsByLocale (locale) { | ||
const index = getPluralRuleIndexForCardinalsByLocale(locale); | ||
return adaptPluralRuleForFormName(rules[index], index) | ||
} | ||
function getPluralRuleForNamedFormsForCardinalsByIndex(index) { | ||
var rule = rules[index]; | ||
function getPluralRuleForNamedFormsForCardinalsByIndex (index) { | ||
const rule = rules[index]; | ||
if (rule === undefined) { | ||
throw new Error("Invalid index: \"" + index + "\"."); | ||
throw new Error(`Invalid index: "${index}".`) | ||
} | ||
return adaptPluralRuleForFormName(rules[index], index); | ||
return adaptPluralRuleForFormName(rules[index], index) | ||
} | ||
function getPluralFormForCardinalByLocale(locale, count) { | ||
var rule = getPluralRuleForCardinalsByLocale(locale); | ||
return rule(count); | ||
function getPluralFormForCardinalByLocale (locale, count) { | ||
const rule = getPluralRuleForCardinalsByLocale(locale); | ||
return rule(count) | ||
} | ||
function getPluralFormForCardinalByIndex(index, count) { | ||
var rule = getPluralRuleForCardinalsByIndex(index); | ||
return rule(count); | ||
function getPluralFormForCardinalByIndex (index, count) { | ||
const rule = getPluralRuleForCardinalsByIndex(index); | ||
return rule(count) | ||
} | ||
function getPluralFormNameForCardinalByLocale(locale, count) { | ||
var rule = getPluralRuleForNamedFormsForCardinalsByLocale(locale); | ||
return rule(count); | ||
function getPluralFormNameForCardinalByLocale (locale, count) { | ||
const rule = getPluralRuleForNamedFormsForCardinalsByLocale(locale); | ||
return rule(count) | ||
} | ||
function getPluralFormNameForCardinalByIndex(index, count) { | ||
var rule = getPluralRuleForNamedFormsForCardinalsByIndex(index); | ||
return rule(count); | ||
function getPluralFormNameForCardinalByIndex (index, count) { | ||
const rule = getPluralRuleForNamedFormsForCardinalsByIndex(index); | ||
return rule(count) | ||
} | ||
let supportedLocales; | ||
function getSupportedLocales() { | ||
if (!supportedLocales) supportedLocales = Object.keys(rulesByLocale); | ||
return supportedLocales | ||
} | ||
function getPluralFormCountForLocale(locale) { | ||
const index = rulesByLocale[locale]; | ||
if (index === undefined) return | ||
return formsByIndex[index].length | ||
} | ||
function getPluralFormNamesForLocale(locale) { | ||
const index = rulesByLocale[locale]; | ||
if (index === undefined) return | ||
return formsByIndex[index] | ||
} | ||
exports.getPluralFormCountForLocale = getPluralFormCountForLocale; | ||
exports.getPluralFormForCardinalByIndex = getPluralFormForCardinalByIndex; | ||
@@ -323,2 +324,3 @@ exports.getPluralFormForCardinalByLocale = getPluralFormForCardinalByLocale; | ||
exports.getPluralFormNameForCardinalByLocale = getPluralFormNameForCardinalByLocale; | ||
exports.getPluralFormNamesForLocale = getPluralFormNamesForLocale; | ||
exports.getPluralRuleForCardinalsByIndex = getPluralRuleForCardinalsByIndex; | ||
@@ -328,2 +330,3 @@ exports.getPluralRuleForCardinalsByLocale = getPluralRuleForCardinalsByLocale; | ||
exports.getPluralRuleForNamedFormsForCardinalsByLocale = getPluralRuleForNamedFormsForCardinalsByLocale; | ||
exports.getSupportedLocales = getSupportedLocales; | ||
@@ -330,0 +333,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,2 +0,2 @@ | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((n="undefined"!=typeof globalThis?globalThis:n||self).fastPluralRules={})}(this,(function(n){"use strict";var e=[function(){return 0},function(n){return 1===n?0:1},function(n){return n<=1?0:1},function(n){return n%10==1&&n%100!=11?1:n%10!=0?2:0},function(n){return 1===n||11===n?0:2===n||12===n?1:n>2&&n<20?2:3},function(n){return 1===n?0:0===n||n%100>0&&n%100<20?1:2},function(n){return n%10==1&&n%100!=11?0:n%10>=2&&(n%100<10||n%100>=20)?2:1},function(n){return n%10==1&&n%100!=11?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2},function(n){return 1===n?0:n>=2&&n<=4?1:2},function(n){return 1===n?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2},function(n){return n%100==1?0:n%100==2?1:n%100==3||n%100==4?2:3},function(n){return 1===n?0:2===n?1:n>2&&n<7?2:n>6&&n<11?3:4},function(n){return 1===n?0:2===n?1:n%100>=3&&n%100<=10?2:n%100>=11?3:0!==n?4:5},function(n){return 1===n?0:0===n||n%100>0&&n%100<11?1:n%100>10&&n%100<20?2:3},function(n){return n%10==1?0:n%10==2?1:2},function(n){return n%10==1&&n%100!=11?0:1},function(n){return n%10==1&&n%100!=11&&n%100!=71&&n%100!=91?0:n%10==2&&n%100!=12&&n%100!=72&&n%100!=92?1:n%10!=3&&n%10!=4&&n%10!=9||n%100==13||n%100==73||n%100==93||n%100==14||n%100==74||n%100==94||n%100==19||n%100==79||n%100==99?0!==n&&n%1e6==0?3:4:2},function(n){return 0!==n?1:0},function(n){return 1===n?1:2===n?2:3===n?3:6===n?4:0!==n?5:0},function(n){return 1===n?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2},function(n){return 1===n?0:2===n?1:3===n?2:3},function(n){return n%10==1&&n%100!=11?0:n%10>=2&&n%10<=4&&(n%100<10||n%100>=20)?1:2},function(n){return 0===n?0:1===n?1:2}],r={ach:2,af:1,ak:2,am:2,an:1,anp:1,ar:12,arn:2,as:1,ast:1,ay:0,az:1,be:7,bg:1,bn:1,bo:0,br:2,brx:1,bs:7,ca:1,cgg:0,cs:8,csb:19,cy:18,da:1,de:1,doi:1,dz:0,el:1,en:1,eo:1,es:1,"es-ar":1,et:1,eu:1,fa:2,ff:1,fi:1,fil:2,fo:1,fr:2,fur:1,fy:1,ga:11,gd:4,gl:1,gu:1,gun:2,ha:1,he:1,hi:1,hne:1,hr:7,hu:1,hy:1,ia:1,id:0,is:15,it:1,ja:0,jbo:0,jv:17,ka:0,kk:1,kl:1,km:0,kn:1,ko:0,ku:1,kw:20,ky:1,lb:1,ln:2,lo:0,lt:6,lv:3,mai:1,me:21,mfe:2,mg:2,mi:2,mk:15,ml:1,mn:1,mni:1,mnk:22,mr:1,ms:0,mt:13,my:0,nah:1,nap:1,nb:1,ne:1,nl:1,nn:1,no:1,nso:1,oc:2,or:1,pa:1,pap:1,pl:9,pms:1,ps:1,pt:1,"pt-br":2,rm:1,ro:5,ru:7,rw:1,sah:0,sat:1,sco:1,sd:1,se:1,si:1,sk:8,sl:10,so:1,son:1,sq:1,sr:7,su:0,sv:1,sw:1,ta:1,te:1,tg:2,th:0,ti:2,tk:1,tr:2,tt:0,ug:0,uk:7,ur:1,uz:2,vi:0,wa:2,wo:0,yo:1,"zh-cn":0,"zh-tw":2},o=[["other"],["one","other"],["one","other"],["zero","one","other"],["one","two","few","other"],["one","few","other"],["one","few","other"],["one","few","other"],["one","few","other"],["one","few","other"],["one","two","few","other"],["one","two","few","many","other"],["one","two","few","many","other","zero"],["one","few","many","other"],["one","few","other"],["one","other"],["one","two","few","many","other"],["zero","other"],["zero","one","two","few","many","other"],["one","few","other"],["one","two","few","other"],["one","few","other"],["zero","one","other"]];function t(n){n=function(n){return n.toLowerCase().replace("_","-")}(n);var e=r[n];if(void 0===e){var o=function(n){var e=n.indexOf("-");return e>0?n.substr(0,e):n}(n);e=r[o]}if(void 0===e)throw new Error('Unrecognized locale: "'+n+'".');return e}function u(n,e){var r=o[e];return function(e){return r[n(e)]}}function a(n){var r=t(n);return e[r]}function i(n){var r=e[n];if(void 0===r)throw new Error('Invalid index: "'+n+'".');return r}function f(n){var r=t(n);return u(e[r],r)}function l(n){if(void 0===e[n])throw new Error('Invalid index: "'+n+'".');return u(e[n],n)}n.getPluralFormForCardinalByIndex=function(n,e){return i(n)(e)},n.getPluralFormForCardinalByLocale=function(n,e){return a(n)(e)},n.getPluralFormNameForCardinalByIndex=function(n,e){return l(n)(e)},n.getPluralFormNameForCardinalByLocale=function(n,e){return f(n)(e)},n.getPluralRuleForCardinalsByIndex=i,n.getPluralRuleForCardinalsByLocale=a,n.getPluralRuleForNamedFormsForCardinalsByIndex=l,n.getPluralRuleForNamedFormsForCardinalsByLocale=f,Object.defineProperty(n,"__esModule",{value:!0})})); | ||
!function(_,$){"object"==typeof exports&&"undefined"!=typeof module?$(exports):"function"==typeof define&&define.amd?define(["exports"],$):$((_="undefined"!=typeof globalThis?globalThis:_||self).fastPluralRules={})}(this,function(_){"use strict";let{rules:$,rulesByLocale:e,formsByIndex:r}={rules:[()=>0,_=>1===_?0:1,_=>_<=1?0:1,_=>_%10==1&&_%100!=11?1:_%10!=0?2:0,_=>1===_||11===_?0:2===_||12===_?1:_>2&&_<20?2:3,_=>1===_?0:0===_||_%100>0&&_%100<20?1:2,_=>_%10==1&&_%100!=11?0:_%10>=2&&(_%100<10||_%100>=20)?2:1,_=>_%10==1&&_%100!=11?0:_%10>=2&&_%10<=4&&(_%100<10||_%100>=20)?1:2,_=>1===_?0:_>=2&&_<=4?1:2,_=>1===_?0:_%10>=2&&_%10<=4&&(_%100<10||_%100>=20)?1:2,_=>_%100==1?0:_%100==2?1:_%100==3||_%100==4?2:3,_=>1===_?0:2===_?1:_>2&&_<7?2:_>6&&_<11?3:4,_=>1===_?0:2===_?1:_%100>=3&&_%100<=10?2:_%100>=11?3:0!==_?4:5,_=>1===_?0:0===_||_%100>0&&_%100<11?1:_%100>10&&_%100<20?2:3,_=>_%10==1?0:_%10==2?1:2,_=>_%10==1&&_%100!=11?0:1,_=>_%10==1&&_%100!=11&&_%100!=71&&_%100!=91?0:_%10==2&&_%100!=12&&_%100!=72&&_%100!=92?1:(_%10==3||_%10==4||_%10==9)&&_%100!=13&&_%100!=73&&_%100!=93&&_%100!=14&&_%100!=74&&_%100!=94&&_%100!=19&&_%100!=79&&_%100!=99?2:0!==_&&_%1e6==0?3:4,_=>0!==_?1:0,_=>1===_?1:2===_?2:3===_?3:6===_?4:0!==_?5:0,_=>1===_?0:_%10>=2&&_%10<=4&&(_%100<10||_%100>=20)?1:2,_=>1===_?0:2===_?1:3===_?2:3,_=>_%10==1&&_%100!=11?0:_%10>=2&&_%10<=4&&(_%100<10||_%100>=20)?1:2,_=>0===_?0:1===_?1:2],rulesByLocale:{ach:2,af:1,ak:2,am:2,an:1,anp:1,ar:12,arn:2,as:1,ast:1,ay:0,az:1,be:7,bg:1,bn:1,bo:0,br:2,brx:1,bs:7,ca:1,cgg:0,cs:8,csb:19,cy:18,da:1,de:1,doi:1,dz:0,el:1,en:1,eo:1,es:1,"es-ar":1,et:1,eu:1,fa:2,ff:1,fi:1,fil:2,fo:1,fr:2,fur:1,fy:1,ga:11,gd:4,gl:1,gu:1,gun:2,ha:1,he:1,hi:1,hne:1,hr:7,hu:1,hy:1,ia:1,id:0,is:15,it:1,ja:0,jbo:0,jv:17,ka:0,kk:1,kl:1,km:0,kn:1,ko:0,ku:1,kw:20,ky:1,lb:1,ln:2,lo:0,lt:6,lv:3,mai:1,me:21,mfe:2,mg:2,mi:2,mk:15,ml:1,mn:1,mni:1,mnk:22,mr:1,ms:0,mt:13,my:0,nah:1,nap:1,nb:1,ne:1,nl:1,nn:1,no:1,nso:1,oc:2,or:1,pa:1,pap:1,pl:9,pms:1,ps:1,pt:1,"pt-br":2,rm:1,ro:5,ru:7,rw:1,sah:0,sat:1,sco:1,sd:1,se:1,si:1,sk:8,sl:10,so:1,son:1,sq:1,sr:7,su:0,sv:1,sw:1,ta:1,te:1,tg:2,th:0,ti:2,tk:1,tr:2,tt:0,ug:0,uk:7,ur:1,uz:2,vi:0,wa:2,wo:0,yo:1,"zh-cn":0,"zh-tw":2},formsByIndex:[["other"],["one","other"],["one","other"],["zero","one","other"],["one","two","few","other"],["one","few","other"],["one","few","other"],["one","few","other"],["one","few","other"],["one","few","other"],["one","two","few","other"],["one","two","few","many","other"],["one","two","few","many","other","zero"],["one","few","many","other"],["one","few","other"],["one","other"],["one","two","few","many","other"],["zero","other"],["zero","one","two","few","many","other"],["one","few","other"],["one","two","few","other"],["one","few","other"],["zero","one","other"]]};function n(_){var $;let r=e[_=($=_).toLowerCase().replace("_","-")];if(void 0===r){let n=function(_){let $=_.indexOf("-");return $>0?_.substr(0,$):_}(_);r=e[n]}if(void 0===r)throw Error(`Unrecognized locale: "${_}".`);return r}function t(_,$){let e=r[$];return function($){return e[_($)]}}function o(_){let e=n(_);return $[e]}function l(_){let e=$[_];if(void 0===e)throw Error(`Invalid index: "${_}".`);return e}function a(_){let e=n(_);return t($[e],e)}function u(_){let e=$[_];if(void 0===e)throw Error(`Invalid index: "${_}".`);return t($[_],_)}let i;_.getPluralFormCountForLocale=function(_){let $=e[_];if(void 0!==$)return r[$].length},_.getPluralFormForCardinalByIndex=function(_,$){let e=l(_);return e($)},_.getPluralFormForCardinalByLocale=function(_,$){let e=o(_);return e($)},_.getPluralFormNameForCardinalByIndex=function(_,$){let e=u(_);return e($)},_.getPluralFormNameForCardinalByLocale=function(_,$){let e=a(_);return e($)},_.getPluralFormNamesForLocale=function(_){let $=e[_];if(void 0!==$)return r[$]},_.getPluralRuleForCardinalsByIndex=l,_.getPluralRuleForCardinalsByLocale=o,_.getPluralRuleForNamedFormsForCardinalsByIndex=u,_.getPluralRuleForNamedFormsForCardinalsByLocale=a,_.getSupportedLocales=function(){return i||(i=Object.keys(e)),i},Object.defineProperty(_,"__esModule",{value:!0})}) | ||
//# sourceMappingURL=index.umd.min.js.map |
{ | ||
"name": "fast-plural-rules", | ||
"version": "1.0.2", | ||
"version": "2.0.0", | ||
"description": "Evaluates locale-specific plural rules to identify the right plural form for a cardinal number, which represents an item count.", | ||
@@ -26,27 +26,27 @@ "author": { | ||
"engines": { | ||
"node": ">=6" | ||
"node": ">=14.8" | ||
}, | ||
"main": "dist/index.js", | ||
"typings": "dist/index.d.ts", | ||
"type": "module", | ||
"module": "dist/index.mjs", | ||
"main": "dist/index.cjs", | ||
"browser": "dist/index.umd.min.js", | ||
"types": "lib/index.d.ts", | ||
"exports": { | ||
"require": "./dist/index.cjs", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
"lib/index.d.ts" | ||
], | ||
"scripts": { | ||
"prepare": "npm run build", | ||
"lint": "run-s lint:js lint:ts", | ||
"lint:fix": "standard --verbose --fix", | ||
"lint:js": "standard --verbose", | ||
"lint:ts": "eslint -c .eslintrc.ts.yml src/*.ts test/*.ts", | ||
"prepare": "rollup -c", | ||
"lint": "denolint && tsc --noEmit test/types.test.ts", | ||
"generate:plural-rule-definitions": "node util/generate-plural-rule-definitions", | ||
"generate:browser-tests": "node util/generate-browser-tests", | ||
"compile": "rollup -c", | ||
"copy:typings": "cpy src/*.d.ts dist", | ||
"build": "run-s lint compile copy:typings", | ||
"compile:tests": "tsc --lib es6 test/typings.test.ts", | ||
"check": "jest --testPathIgnorePatterns \"browser.test.js\" --collectCoverage", | ||
"check:browser": "jest --testPathPattern browser.test.js", | ||
"benchmark": "node perf", | ||
"test": "run-s compile:tests generate:plural-rule-definitions check generate:browser-tests check:browser", | ||
"start": "python -m SimpleHTTPServer" | ||
"check": "node test/cjs.cjs && node --experimental-vm-modules node_modules/jest/bin/jest --testPathIgnorePatterns \"browser.test.js\" --collectCoverage", | ||
"check:browser": "node --experimental-vm-modules node_modules/jest/bin/jest --testPathPattern browser.test.js", | ||
"pretest": "run-s lint generate:plural-rule-definitions generate:browser-tests", | ||
"test": "run-s lint check check:browser", | ||
"start": "python3 -m http.server" | ||
}, | ||
@@ -86,39 +86,19 @@ "standard": { | ||
"devDependencies": { | ||
"@babel/core": "7.16.12", | ||
"@babel/preset-env": "7.16.11", | ||
"@rollup/plugin-babel": "5.3.0", | ||
"@semantic-release/changelog": "6.0.1", | ||
"@semantic-release/git": "10.0.1", | ||
"@typescript-eslint/eslint-plugin": "5.10.1", | ||
"@typescript-eslint/parser": "5.10.1", | ||
"babel-core": "7.0.0-bridge.0", | ||
"babel-jest": "27.4.6", | ||
"benchmark": "2.1.4", | ||
"cldr-data": "36.0.0", | ||
"cldrpluralruleparser": "1.4.0", | ||
"connect": "3.7.0", | ||
"cpy-cli": "3.1.1", | ||
"es6-promisify": "7.0.0", | ||
"eslint": "8.7.0", | ||
"eslint-config-standard": "16.0.3", | ||
"eslint-plugin-import": "2.25.4", | ||
"eslint-plugin-node": "11.1.0", | ||
"eslint-plugin-promise": "6.0.0", | ||
"eslint-plugin-standard": "4.1.0", | ||
"fast-glob": "3.2.11", | ||
"fs-extra": "10.0.0", | ||
"jasmine-core": "^4.0.0", | ||
"jest": "27.4.7", | ||
"jest-expect-message": "1.0.2", | ||
"npm-run-all": "4.1.5", | ||
"plural-rules": "1.0.1", | ||
"puppeteer": "13.1.2", | ||
"regenerator-runtime": "0.13.9", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.66.1", | ||
"rollup-plugin-cleanup": "3.2.1", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"serve-static": "1.14.2", | ||
"standard": "16.0.4", | ||
"typescript": "4.5.5" | ||
"@node-rs/deno-lint": "^1.14.0", | ||
"@semantic-release/changelog": "^6.0.1", | ||
"@semantic-release/git": "^10.0.1", | ||
"cldr-data": "^36.0.1", | ||
"connect": "^3.7.0", | ||
"fast-glob": "^3.2.11", | ||
"fast-plural-rules": "link:", | ||
"jasmine-core": "^4.3.0", | ||
"jest": "^28.1.3", | ||
"jest-expect-message": "^1.0.2", | ||
"npm-run-all": "^4.1.5", | ||
"puppeteer": "^16.1.1", | ||
"rollup": "^2.78.0", | ||
"rollup-plugin-cleanup": "^3.2.1", | ||
"rollup-plugin-swc-minify": "^1.0.4", | ||
"serve-static": "^1.15.0", | ||
"typescript": "^4.7.4" | ||
}, | ||
@@ -125,0 +105,0 @@ "keywords": [ |
@@ -28,3 +28,2 @@ # Fast Plural Rules | ||
- [Contributing](#contributing) | ||
- [Release History](#release-history) | ||
- [License](#license) | ||
@@ -35,3 +34,3 @@ | ||
```js | ||
const { getPluralFormForCardinalByLocale } = require('fast-plural-rules') | ||
import { getPluralFormForCardinalByLocale } from 'fast-plural-rules' | ||
@@ -111,3 +110,3 @@ // Returns index of the plural form for the specified locale and cardinal. | ||
```js | ||
const { getPluralFormForCardinalByLocale } = require('fast-plural-rules') | ||
import { getPluralFormForCardinalByLocale } from 'fast-plural-rules' | ||
``` | ||
@@ -125,8 +124,2 @@ | ||
## Release History | ||
* 2019-07-31 v1.0.0 Correct rules for Baltic, Celtic, Semitic, Shuar and Welsh | ||
language families to match the latest Mozilla documentation, support CLDR plural form names, complete the test suite | ||
* 2018-10-28 v0.0.1 Initial release | ||
## License | ||
@@ -133,0 +126,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
237973
80.66%17
-54.05%13
8.33%Yes
NaN993
-19.92%139
-4.79%1
Infinity%