@formatjs/intl-pluralrules
Version:
Polyfill for Intl.PluralRules
40 lines (39 loc) • 1.89 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":["one","other"],"ordinal":["other"]},"fn":function(num, isOrdinal, exponent = 0) {
function modDigits(start, end, divisor) {
let value = 0;
for (let index = start; index < end; index++) {
value = (value * 10 + +numStr[index]) % divisor;
}
return value;
}
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 i = readDigits(integerStart, integerEnd);
const w = (() => { let end = numStr.length; while (end > fractionStart && numStr[end - 1] === "0") end--; return end - fractionStart; })();
const t = readDigits(fractionStart, fractionStart + w);
if (isOrdinal) {
}
else {
if (t === 0 && modDigits(integerStart, integerEnd, 10) === 1 && modDigits(integerStart, integerEnd, 100) !== 11 || modDigits(fractionStart, fractionStart + w, 10) === 1 && modDigits(fractionStart, fractionStart + w, 100) !== 11)
return "one";
}
return "other";
},"pluralRanges":{"cardinal":{"one_one":"one","one_other":"other","other_one":"one","other_other":"other"},"ordinal":{}}},"locale":"is"});