UNPKG

@formatjs/intl-pluralrules

Version:

Polyfill for Intl.PluralRules

43 lines (42 loc) • 2.04 kB
/* @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","one","other","two"],"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 v = numStr.length - fractionStart; if (isOrdinal) { } else { if (v === 0 && modDigits(integerStart, integerEnd, 100) === 1) return "one"; if (v === 0 && modDigits(integerStart, integerEnd, 100) === 2) return "two"; if (v === 0 && (modDigits(integerStart, integerEnd, 100) >= 3 && modDigits(integerStart, integerEnd, 100) <= 4) || v !== 0) return "few"; } return "other"; },"pluralRanges":{"cardinal":{"few_few":"few","few_one":"few","few_other":"other","few_two":"two","one_few":"few","one_one":"few","one_other":"other","one_two":"two","other_few":"few","other_one":"few","other_other":"other","other_two":"two","two_few":"few","two_one":"few","two_other":"other","two_two":"two"},"ordinal":{}}},"locale":"sl"});