@formatjs/intl-pluralrules
Version:
Polyfill for Intl.PluralRules
50 lines (49 loc) • 2.39 kB
JavaScript
/* @generated */
// prettier-ignore
;(function (data) {
if (Intl.PluralRules && typeof Intl.PluralRules.__addLocaleData === 'function') {
Intl.PluralRules.__addLocaleData(data)
} else {
(globalThis.__FORMATJS_PLURALRULES_DATA__ = globalThis.__FORMATJS_PLURALRULES_DATA__ || []).push(data)
}
})({"data":{"categories":{"cardinal":["few","many","one","other","two","zero"],"ordinal":["few","many","one","other","two","zero"]},"fn":function(num, isOrdinal, exponent = 0) {
const numStr = '' + num;
const integerStart = numStr[0] === '-' || numStr[0] === '+' ? 1 : 0;
let integerEnd = integerStart;
while (integerEnd < numStr.length && numStr[integerEnd] !== '.') integerEnd++;
const fractionStart = integerEnd < numStr.length ? integerEnd + 1 : integerEnd;
function readDigits(start, end) {
let value = 0;
for (let index = start; index < end; index++) {
value = value * 10 + +numStr[index];
}
return value;
}
const n = readDigits(integerStart, integerEnd);
const w = (() => { let end = numStr.length; while (end > fractionStart && numStr[end - 1] === "0") end--; return end - fractionStart; })();
if (isOrdinal) {
if ((!(w !== 0) && (((n === 0 || n === 7) || n === 8) || n === 9)))
return "zero";
if ((!(w !== 0) && n === 1))
return "one";
if ((!(w !== 0) && n === 2))
return "two";
if ((!(w !== 0) && (n === 3 || n === 4)))
return "few";
if ((!(w !== 0) && (n === 5 || n === 6)))
return "many";
}
else {
if ((!(w !== 0) && n === 0))
return "zero";
if ((!(w !== 0) && n === 1))
return "one";
if ((!(w !== 0) && n === 2))
return "two";
if ((!(w !== 0) && n === 3))
return "few";
if ((!(w !== 0) && n === 6))
return "many";
}
return "other";
},"pluralRanges":{"cardinal":{"few_many":"many","few_other":"other","many_other":"other","one_few":"few","one_many":"many","one_other":"other","one_two":"two","other_few":"few","other_many":"many","other_one":"one","other_other":"other","other_two":"two","two_few":"few","two_many":"many","two_other":"other","zero_few":"few","zero_many":"many","zero_one":"one","zero_other":"other","zero_two":"two"},"ordinal":{}}},"locale":"cy"});