UNPKG

fast-plural-rules

Version:

Evaluates locale-specific plural rules to identify the right plural form for a cardinal number, which represents an item count.

3 lines (2 loc) 4.13 kB
!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