UNPKG

@formatjs/intl-pluralrules

Version:

Polyfill for Intl.PluralRules

42 lines (41 loc) • 1.74 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":["few","one","other","two"]},"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 === 1 || n === 11))) return "one"; if ((!(w !== 0) && (n === 2 || n === 12))) return "two"; if ((!(w !== 0) && (n === 3 || n === 13))) return "few"; } else { if ((!(w !== 0) && (n === 1 || n === 11))) return "one"; if ((!(w !== 0) && (n === 2 || n === 12))) return "two"; if ((!(w !== 0) && ((n >= 3 && n <= 10) || (n >= 13 && n <= 19)))) return "few"; } return "other"; }},"locale":"gd"});