UNPKG

@formatjs/intl-pluralrules

Version:

Polyfill for Intl.PluralRules

46 lines (45 loc) • 2.16 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":["many","one","other"],"ordinal":["many","other"]},"compactExponents":{"short":{"3":3,"4":3,"5":3,"6":6,"7":6,"8":6,"9":9,"10":9,"11":9,"12":12,"13":12,"14":12},"long":{"3":3,"4":3,"5":3,"6":6,"7":6,"8":6,"9":9,"10":9,"11":9,"12":12,"13":12,"14":12}},"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 n = readDigits(integerStart, integerEnd); const i = n; const v = numStr.length - fractionStart; const w = (() => { let end = numStr.length; while (end > fractionStart && numStr[end - 1] === "0") end--; return end - fractionStart; })(); const e = exponent; if (isOrdinal) { if ((!(w !== 0) && (((n === 11 || n === 8) || n === 80) || n === 800))) return "many"; } else { if (i === 1 && v === 0) return "one"; if (e === 0 && i !== 0 && modDigits(integerStart, integerEnd, 1000000) === 0 && v === 0 || (e < 0 || e > 5)) return "many"; } return "other"; },"pluralRanges":{"cardinal":{"one_other":"other","other_one":"one","other_other":"other"},"ordinal":{}}},"locale":"it"});