UNPKG

@formatjs/intl-relativetimeformat

Version:

Formats JavaScript dates to relative time strings.

948 lines (947 loc) • 31.3 kB
import { FilterLocales, ResolveLocale } from "@formatjs/intl-localematcher"; // packages/ecma262-abstract/intrinsics.js const objectFrom = Object; const objectCreate = Object.create; function createFromConstructor(newTarget, defaultPrototype) { const prototype = newTarget.prototype; return objectCreate(objectFrom(prototype) === prototype ? prototype : defaultPrototype); } Number.isInteger; const numberIsFinite = Number.isFinite; Number.isSafeInteger; const ErrorConstructor = Error; const TypeErrorConstructor$1 = TypeError; const RangeErrorConstructor = RangeError; const arrayApply = Reflect.apply; Array.prototype.every; const some = Array.prototype.some; function arraySome(values, predicate) { return arrayApply(some, values, [predicate]); } Array.prototype.includes; Array.prototype.indexOf; const defineProperty$1 = Object.defineProperty; function setDataProperty(target, key, value) { defineProperty$1(target, key, { __proto__: null, value, writable: true, enumerable: true, configurable: true }); } // packages/ecma262-abstract/HasOwnProperty.js const hasOwn$1 = Function.prototype.call.bind(Object.prototype.hasOwnProperty); function HasOwnProperty(o, prop) { return hasOwn$1(o, prop); } // packages/ecma402-abstract/CanonicalizeLocaleList.js let canonicalIntl = globalThis.Intl; const canonicalDescriptor = Object.getOwnPropertyDescriptor; const canonicalApply = Reflect.apply; const providerKey = Symbol.for("@formatjs/intlCanonicalizeLocaleList"); function ownCanonicalProvider() { const descriptor = canonicalIntl && canonicalDescriptor(canonicalIntl, "getCanonicalLocales"); return (descriptor && canonicalDescriptor(descriptor, "value"))?.value; } let canonicalProvider = ownCanonicalProvider(); function registeredCanonicalProvider() { try { const descriptor = canonicalIntl && canonicalDescriptor(canonicalIntl, providerKey); return descriptor && canonicalDescriptor(descriptor, "value")?.value; } catch {} } function CanonicalizeLocaleList(locales) { if (canonicalIntl === void 0) canonicalIntl = globalThis.Intl; const registered = registeredCanonicalProvider(); if (typeof registered === "function") return canonicalApply(registered, canonicalIntl, [locales]); if (typeof canonicalProvider !== "function") canonicalProvider = ownCanonicalProvider(); return canonicalApply(canonicalProvider, canonicalIntl, [locales]); } // packages/ecma402-abstract/Locale/splitUnicodeExtension.js const apply$4 = Reflect.apply; const split$1 = String.prototype.split; const hyphen = { __proto__: null, toString: () => "-" }; function splitLocaleSubtags(value) { return apply$4(split$1, value, [hyphen]); } function splitUnicodeExtension(locale) { const subtags = splitLocaleSubtags(locale); for (let i = 1; i < subtags.length; i++) { if (subtags[i] === "x") break; if (subtags[i] !== "u") continue; let end = i + 1; while (end < subtags.length && subtags[end].length > 1) end++; let base = subtags[0]; for (let j = 1; j < i; j++) base += "-" + subtags[j]; for (let j = end; j < subtags.length; j++) base += "-" + subtags[j]; let extension = ""; for (let j = i; j < end; j++) extension += "-" + subtags[j]; return { locale: base, extension }; } return { locale, extension: void 0 }; } // node_modules/.aspect_rules_js/@formatjs_generated+cldr.supported-locales@0.0.0/node_modules/@formatjs_generated/cldr.supported-locales/default-content.js const defaultContent = { "ady": ["ady-RU"], "af": ["af-ZA"], "agq": ["agq-CM"], "ak": ["ak-GH"], "am": ["am-ET"], "ar": ["ar-001"], "as": ["as-IN"], "asa": ["asa-TZ"], "ast": ["ast-ES"], "az-Cyrl": ["az-Cyrl-AZ"], "az-Latn": ["az-Latn-AZ"], "ba": ["ba-RU"], "bal-Latn": ["bal-Latn-PK"], "bas": ["bas-CM"], "be": ["be-BY"], "bem": ["bem-ZM"], "bez": ["bez-TZ"], "bg": ["bg-BG"], "bgc": ["bgc-IN"], "bho": ["bho-IN"], "blo": ["blo-BJ"], "bm": ["bm-ML"], "bn": ["bn-BD"], "bo": ["bo-CN"], "br": ["br-FR"], "brx": ["brx-IN"], "bs-Cyrl": ["bs-Cyrl-BA"], "bs-Latn": ["bs-Latn-BA"], "bua": ["bua-RU"], "ca": ["ca-ES"], "ccp": ["ccp-BD"], "ce": ["ce-RU"], "ceb": ["ceb-PH"], "cgg": ["cgg-UG"], "chr": ["chr-US"], "ckb": ["ckb-IQ"], "cop": ["cop-EG"], "cs": ["cs-CZ"], "csw": ["csw-CA"], "cv": ["cv-RU"], "cy": ["cy-GB"], "da": ["da-DK"], "dav": ["dav-KE"], "de": ["de-DE"], "dje": ["dje-NE"], "doi": ["doi-IN"], "dsb": ["dsb-DE"], "dua": ["dua-CM"], "dyo": ["dyo-SN"], "dz": ["dz-BT"], "ebu": ["ebu-KE"], "ee": ["ee-GH"], "el": ["el-GR"], "en": ["en-US"], "eo": ["eo-001"], "es": ["es-ES"], "et": ["et-EE"], "eu": ["eu-ES"], "ewo": ["ewo-CM"], "fa": ["fa-IR"], "ff-Adlm": ["ff-Adlm-GN"], "ff-Latn": ["ff-Latn-SN"], "fi": ["fi-FI"], "fil": ["fil-PH"], "fo": ["fo-FO"], "fr": ["fr-FR"], "fur": ["fur-IT"], "fy": ["fy-NL"], "ga": ["ga-IE"], "gaa": ["gaa-GH"], "gd": ["gd-GB"], "gl": ["gl-ES"], "gsw": ["gsw-CH"], "gu": ["gu-IN"], "guz": ["guz-KE"], "gv": ["gv-IM"], "ha": ["ha-NG"], "haw": ["haw-US"], "he": ["he-IL"], "hi": ["hi-IN"], "hi-Latn": ["hi-Latn-IN"], "hr": ["hr-HR"], "hsb": ["hsb-DE"], "hu": ["hu-HU"], "hy": ["hy-AM"], "ia": ["ia-001"], "id": ["id-ID"], "ie": ["ie-EE"], "ig": ["ig-NG"], "ii": ["ii-CN"], "is": ["is-IS"], "it": ["it-IT"], "ja": ["ja-JP"], "jgo": ["jgo-CM"], "jmc": ["jmc-TZ"], "jv": ["jv-ID"], "ka": ["ka-GE"], "kab": ["kab-DZ"], "kam": ["kam-KE"], "kbd": ["kbd-RU"], "kde": ["kde-TZ"], "kea": ["kea-CV"], "kek": ["kek-GT"], "kgp": ["kgp-BR"], "khq": ["khq-ML"], "ki": ["ki-KE"], "kk-Arab": ["kk-Arab-CN"], "kk-Cyrl": ["kk-Cyrl-KZ"], "kkj": ["kkj-CM"], "kl": ["kl-GL"], "kln": ["kln-KE"], "km": ["km-KH"], "kn": ["kn-IN"], "ko": ["ko-KR"], "kok-Deva": ["kok-Deva-IN"], "kok-Latn": ["kok-Latn-IN"], "ks-Arab": ["ks-Arab-IN"], "ks-Deva": ["ks-Deva-IN"], "ksb": ["ksb-TZ"], "ksf": ["ksf-CM"], "ksh": ["ksh-DE"], "ku-Latn": ["ku-Latn-TR"], "kw": ["kw-GB"], "kxv-Deva": ["kxv-Deva-IN"], "kxv-Latn": ["kxv-Latn-IN"], "kxv-Orya": ["kxv-Orya-IN"], "kxv-Telu": ["kxv-Telu-IN"], "ky": ["ky-KG"], "lag": ["lag-TZ"], "lb": ["lb-LU"], "lg": ["lg-UG"], "lij": ["lij-IT"], "lkt": ["lkt-US"], "lld": ["lld-IT"], "lmo": ["lmo-IT"], "ln": ["ln-CD"], "lo": ["lo-LA"], "lrc": ["lrc-IR"], "lt": ["lt-LT"], "lu": ["lu-CD"], "luo": ["luo-KE"], "luy": ["luy-KE"], "lv": ["lv-LV"], "mai": ["mai-IN"], "mas": ["mas-KE"], "mer": ["mer-KE"], "mfe": ["mfe-MU"], "mg": ["mg-MG"], "mgh": ["mgh-MZ"], "mgo": ["mgo-CM"], "mi": ["mi-NZ"], "mk": ["mk-MK"], "ml": ["ml-IN"], "mn": ["mn-MN"], "mni-Beng": ["mni-Beng-IN"], "mr": ["mr-IN"], "ms": ["ms-MY"], "mt": ["mt-MT"], "mua": ["mua-CM"], "my": ["my-MM"], "mzn": ["mzn-IR"], "naq": ["naq-NA"], "nb": ["nb-NO"], "nd": ["nd-ZW"], "nds": ["nds-DE"], "ne": ["ne-NP"], "nl": ["nl-NL"], "nmg": ["nmg-CM"], "nn": ["nn-NO"], "nnh": ["nnh-CM"], "nqo": ["nqo-GN"], "nso": ["nso-ZA"], "nus": ["nus-SS"], "nyn": ["nyn-UG"], "oc": ["oc-FR"], "om": ["om-ET"], "or": ["or-IN"], "os": ["os-GE"], "pa-Arab": ["pa-Arab-PK"], "pa-Guru": ["pa-Guru-IN"], "pcm": ["pcm-NG"], "pl": ["pl-PL"], "pms": ["pms-IT"], "prg": ["prg-PL"], "ps": ["ps-AF"], "pt": ["pt-BR"], "qu": ["qu-PE"], "quc": ["quc-GT"], "raj": ["raj-IN"], "rm": ["rm-CH"], "rn": ["rn-BI"], "ro": ["ro-RO"], "rof": ["rof-TZ"], "ru": ["ru-RU"], "rw": ["rw-RW"], "rwk": ["rwk-TZ"], "sa": ["sa-IN"], "sah": ["sah-RU"], "saq": ["saq-KE"], "sat-Olck": ["sat-Olck-IN"], "sbp": ["sbp-TZ"], "sc": ["sc-IT"], "scn": ["scn-IT"], "sd-Arab": ["sd-Arab-PK"], "sd-Deva": ["sd-Deva-IN"], "se": ["se-NO"], "seh": ["seh-MZ"], "ses": ["ses-ML"], "sg": ["sg-CF"], "shi-Latn": ["shi-Latn-MA"], "shi-Tfng": ["shi-Tfng-MA"], "shn": ["shn-MM"], "si": ["si-LK"], "sk": ["sk-SK"], "sl": ["sl-SI"], "smn": ["smn-FI"], "sn": ["sn-ZW"], "so": ["so-SO"], "sq": ["sq-AL"], "sr-Cyrl": ["sr-Cyrl-RS"], "sr-Latn": ["sr-Latn-RS"], "st": ["st-ZA"], "su-Latn": ["su-Latn-ID"], "suz-Sunu": ["suz-Sunu-NP"], "sv": ["sv-SE"], "sw": ["sw-TZ"], "syr": ["syr-IQ"], "szl": ["szl-PL"], "ta": ["ta-IN"], "te": ["te-IN"], "teo": ["teo-UG"], "tg": ["tg-TJ"], "th": ["th-TH"], "ti": ["ti-ET"], "tk": ["tk-TM"], "tn": ["tn-ZA"], "to": ["to-TO"], "tok": ["tok-001"], "tr": ["tr-TR"], "tt": ["tt-RU"], "twq": ["twq-NE"], "tyv": ["tyv-RU"], "tzm": ["tzm-MA"], "ug": ["ug-CN"], "uk": ["uk-UA"], "ur": ["ur-PK"], "uz-Arab": ["uz-Arab-AF"], "uz-Cyrl": ["uz-Cyrl-UZ"], "uz-Latn": ["uz-Latn-UZ"], "vai-Latn": ["vai-Latn-LR"], "vai-Vaii": ["vai-Vaii-LR"], "vec": ["vec-IT"], "vi": ["vi-VN"], "vmw": ["vmw-MZ"], "vun": ["vun-TZ"], "wae": ["wae-CH"], "wo": ["wo-SN"], "xh": ["xh-ZA"], "xnr": ["xnr-IN"], "xog": ["xog-UG"], "yav": ["yav-CM"], "yi": ["yi-UA"], "yo": ["yo-NG"], "yrl": ["yrl-BR"], "yue-Hans": ["yue-Hans-CN"], "yue-Hant": ["yue-Hant-HK"], "za": ["za-CN"], "zgh": ["zgh-MA"], "zh-Hans": ["zh-Hans-CN"], "zh-Hant": ["zh-Hant-TW"], "zu": ["zu-ZA"] }; // packages/ecma402-abstract/registerLocaleData.js const registrations = /* @__PURE__ */ new WeakMap(); const getRegistrations = registrations.get.bind(registrations); const setRegistrations = registrations.set.bind(registrations); const LocaleMap = Map; const apply$3 = Reflect.apply; const add = Set.prototype.add; const getOwner = Map.prototype.get; const setOwner = Map.prototype.set; const forEachOwner = Map.prototype.forEach; const split = String.prototype.split; const slice$1 = String.prototype.slice; function canonicalizeLocaleDataTag(tag) { const [locale] = CanonicalizeLocaleList(tag); return splitUnicodeExtension(locale).locale; } function registerLocaleData(locale, data, localeData, availableLocales) { let owners = getRegistrations(localeData); if (!owners) { owners = new LocaleMap(); setRegistrations(localeData, owners); } if (apply$3(getOwner, owners, [locale]) === locale) apply$3(forEachOwner, owners, [(owner, tag) => { if (owner === locale) setDataProperty(localeData, tag, data); }]); apply$3(setOwner, owners, [locale, locale]); setDataProperty(localeData, locale, data); apply$3(add, availableLocales, [locale]); const aliases = HasOwnProperty(defaultContent, locale) ? defaultContent[locale] : void 0; for (let index = 0; index < (aliases?.length ?? 0); index++) { const tag = aliases[index]; if (apply$3(getOwner, owners, [tag]) !== tag) { setDataProperty(localeData, tag, data); apply$3(setOwner, owners, [tag, locale]); } apply$3(add, availableLocales, [tag]); } for (let index = -1; index < (aliases?.length ?? 0); index++) { const tag = index === -1 ? locale : aliases[index]; const owner = apply$3(getOwner, owners, [tag]) ?? tag; const selected = localeData[tag]; const addFallback = (fallback) => { if (!HasOwnProperty(localeData, fallback)) { setDataProperty(localeData, fallback, selected); apply$3(setOwner, owners, [fallback, owner]); } apply$3(add, availableLocales, [fallback]); }; const parts = apply$3(split, tag, ["-"]); const scriptEnd = parts[0].length + 5; let parent = tag; let length = 1; let end = parts[0].length; for (; length < parts.length && parts[length].length > 1; length++) end += parts[length].length + 1; if (length < parts.length) { parent = apply$3(slice$1, parent, [0, end]); addFallback(parent); } for (; length > 1; length--) { if (length > 2 && parts[1].length === 4) addFallback(parts[0] + apply$3(slice$1, parent, [scriptEnd])); parent = apply$3(slice$1, parent, [0, parent.length - parts[length - 1].length - 1]); addFallback(parent); } } } // packages/ecma262-abstract/ToString.js const StringConstructor = String; const TypeErrorConstructor = TypeError; /** * https://tc39.es/ecma262/#sec-tostring */ function ToString(o) { if (typeof o === "symbol") throw TypeErrorConstructor("Cannot convert a Symbol value to a string"); return StringConstructor(o); } // packages/ecma262-abstract/ToObject.js /** * https://tc39.es/ecma262/#sec-toobject */ function ToObject(arg) { if (arg === void 0 || arg === null) throw new TypeErrorConstructor$1("undefined/null cannot be converted to object"); return objectFrom(arg); } // packages/ecma402-abstract/CoerceOptionsToObject.js const createObject = Object.create; /** * https://tc39.es/ecma402/#sec-coerceoptionstoobject * @param options * @returns */ function CoerceOptionsToObject(options) { if (options === void 0) return createObject(null); return ToObject(options); } // packages/ecma262-abstract/IsObject.js function IsObject(value) { return value !== null && (typeof value === "object" || typeof value === "function" || typeof value === "undefined" && value !== void 0); } // packages/ecma402-abstract/GetOption.js const optionApply = Reflect.apply; const optionJoin = Array.prototype.join; /** * https://tc39.es/ecma402/#sec-getoption * @param opts * @param prop * @param type * @param values * @param fallback */ function GetOption(opts, prop, type, values, fallback) { if (!IsObject(opts)) throw new TypeErrorConstructor$1("Options must be an object"); let value = opts[prop]; if (value !== void 0) { if (type !== "boolean" && type !== "string") throw new TypeErrorConstructor$1("invalid type"); if (type === "boolean") value = !!value; if (type === "string") value = ToString(value); if (values?.length && !arraySome(values, (val) => val === value)) throw new RangeErrorConstructor(`${value} is not within ${optionApply(optionJoin, values, [", "])}`); return value; } return fallback; } // packages/ecma402-abstract/SupportedLocales.js function SupportedLocales(availableLocales, requestedLocales, options) { const matcher = GetOption(CoerceOptionsToObject(options), "localeMatcher", "string", ["lookup", "best fit"], "best fit"); return FilterLocales(availableLocales, requestedLocales, matcher, true); } // packages/ecma402-abstract/IsUnicodeLocaleIdentifierType.js const typeApply = Reflect.apply; const charCodeAt = String.prototype.charCodeAt; /** Tests the Unicode locale identifier `type` grammar, not locale support. */ function IsUnicodeLocaleIdentifierType(value) { let length = 0; for (let index = 0; index < value.length; index++) { const code = typeApply(charCodeAt, value, [index]); if (code === 45) { if (length < 3) return false; length = 0; continue; } const letter = code | 32; if (!(letter >= 97 && letter <= 122) && !(code >= 48 && code <= 57)) return false; if (++length > 8) return false; } return length >= 3; } // node_modules/.aspect_rules_js/@formatjs+fast-memoize@0.0.0/node_modules/@formatjs/fast-memoize/index.js const apply$2 = Reflect.apply; const bind = Function.prototype.bind; const slice = Array.prototype.slice; const stringify = JSON.stringify; const create = Object.create; const defineProperty = Object.defineProperty; const setPrototypeOf = Object.setPrototypeOf; function memoize(fn, options) { const cache = options && options.cache ? options.cache : cacheDefault; const serializer = options && options.serializer ? options.serializer : serializerDefault; return (options && options.strategy ? options.strategy : strategyDefault)(fn, { cache, serializer }); } function isPrimitive(value) { return value == null || typeof value === "number" || typeof value === "boolean"; } function monadic(fn, cache, serializer, arg) { const cacheKey = isPrimitive(arg) ? arg : serializer(arg); let computedValue = cache.get(cacheKey); if (typeof computedValue === "undefined") { computedValue = apply$2(fn, this, [arg]); cache.set(cacheKey, computedValue); } return computedValue; } function variadic(fn, cache, serializer) { const args = apply$2(slice, arguments, [3]); if (serializer === serializerDefault) setPrototypeOf(args, null); const cacheKey = serializer(args); let computedValue = cache.get(cacheKey); if (typeof computedValue === "undefined") { computedValue = apply$2(fn, this, args); cache.set(cacheKey, computedValue); } return computedValue; } function assemble(fn, context, strategy, cache, serialize) { return apply$2(bind, strategy, [ context, fn, cache, serialize ]); } function strategyDefault(fn, options) { const strategy = fn.length === 1 ? monadic : variadic; return assemble(fn, this, strategy, options.cache.create(), options.serializer); } function strategyVariadic(fn, options) { return assemble(fn, this, variadic, options.cache.create(), options.serializer); } function strategyMonadic(fn, options) { return assemble(fn, this, monadic, options.cache.create(), options.serializer); } const serializerDefault = function() { setPrototypeOf(arguments, null); return stringify(arguments); }; var ObjectWithoutPrototypeCache = class { constructor() { defineProperty(this, "cache", { __proto__: null, value: create(null), writable: true, enumerable: true, configurable: true }); } get(key) { return this.cache[key]; } set(key, value) { this.cache[key] = value; } }; const cacheDefault = { create: function create() { return new ObjectWithoutPrototypeCache(); } }; const strategies = { variadic: strategyVariadic, monadic: strategyMonadic }; String.prototype.repeat; Array.from; Array.prototype.join; function invariant(condition, message, Err = ErrorConstructor) { if (!condition) throw new Err(message); } memoize((...args) => new Intl.NumberFormat(...args), { strategy: strategies.variadic }); memoize((...args) => new Intl.ListFormat(...args), { strategy: strategies.variadic }); const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; const formatterMemoizeOptions = { __proto__: null, strategy: strategies.variadic }; let providerIntl = globalThis.Intl; function ownIntlProvider(name) { const descriptor = providerIntl && getOwnPropertyDescriptor(providerIntl, name); return (descriptor && getOwnPropertyDescriptor(descriptor, "value"))?.value; } let numberFormatIntrinsic = ownIntlProvider("NumberFormat"); let listFormatIntrinsic = ownIntlProvider("ListFormat"); let pluralRulesProvider = ownIntlProvider("PluralRules"); const formatterIntrinsicKeys = { NumberFormat: Symbol.for("@formatjs/intlNumberFormat"), ListFormat: Symbol.for("@formatjs/intlListFormat"), PluralRules: Symbol.for("@formatjs/intlPluralRules") }; function getNumberFormatIntrinsic() { if (providerIntl === void 0) providerIntl = globalThis.Intl; const registered = ownIntlProvider(formatterIntrinsicKeys.NumberFormat); if (typeof registered === "function") return registered; if (typeof numberFormatIntrinsic !== "function") numberFormatIntrinsic = ownIntlProvider("NumberFormat"); return numberFormatIntrinsic; } function getPluralRulesIntrinsic() { if (providerIntl === void 0) providerIntl = globalThis.Intl; const registered = ownIntlProvider(formatterIntrinsicKeys.PluralRules); if (typeof registered === "function") return registered; if (typeof pluralRulesProvider !== "function") pluralRulesProvider = ownIntlProvider("PluralRules"); return pluralRulesProvider; } const getFormatterPrototype = Object.getPrototypeOf; function formatterMethodLookup(name) { const methods = /* @__PURE__ */ new WeakMap(); const owners = /* @__PURE__ */ new WeakMap(); const getMethod = methods.get.bind(methods); const setMethod = methods.set.bind(methods); const getOwner = owners.get.bind(owners); const setOwner = owners.set.bind(owners); return (Constructor) => { const cached = getMethod(Constructor); if (cached) return cached; let prototype = getOwnPropertyDescriptor(Constructor, "prototype")?.value; while (prototype != null) { const inherited = getOwner(prototype); if (inherited) { setMethod(Constructor, inherited); return inherited; } const descriptor = getOwnPropertyDescriptor(prototype, name); const value = descriptor && getOwnPropertyDescriptor(descriptor, "value"); if (value && typeof value.value === "function") { const method = value.value; setMethod(Constructor, method); setOwner(prototype, method); return method; } prototype = getFormatterPrototype(prototype); } }; } const findFormatterPartsMethod = formatterMethodLookup("formatToParts"); const findPluralRulesSelectMethod = formatterMethodLookup("select"); if (typeof numberFormatIntrinsic === "function") findFormatterPartsMethod(numberFormatIntrinsic); if (typeof listFormatIntrinsic === "function") findFormatterPartsMethod(listFormatIntrinsic); if (typeof pluralRulesProvider === "function") findPluralRulesSelectMethod(pluralRulesProvider); const numberFormatMemoizers = /* @__PURE__ */ new WeakMap(); const getNumberFormatMemoizer = numberFormatMemoizers.get.bind(numberFormatMemoizers); const setNumberFormatMemoizer = numberFormatMemoizers.set.bind(numberFormatMemoizers); const listFormatMemoizers = /* @__PURE__ */ new WeakMap(); listFormatMemoizers.get.bind(listFormatMemoizers); listFormatMemoizers.set.bind(listFormatMemoizers); const pluralRulesMemoizers = /* @__PURE__ */ new WeakMap(); const getPluralRulesMemoizer = pluralRulesMemoizers.get.bind(pluralRulesMemoizers); const setPluralRulesMemoizer = pluralRulesMemoizers.set.bind(pluralRulesMemoizers); function createMemoizedPluralRulesForConstructor(Constructor) { let factory = getPluralRulesMemoizer(Constructor); if (!factory) { factory = memoize((locale) => new Constructor(locale), formatterMemoizeOptions); setPluralRulesMemoizer(Constructor, factory); } return factory; } function createMemoizedNumberFormatForConstructor(Constructor) { let factory = getNumberFormatMemoizer(Constructor); if (!factory) { factory = memoize((...args) => new Constructor(args[0], args[1]), formatterMemoizeOptions); setNumberFormatMemoizer(Constructor, factory); } return factory; } // packages/ecma402-abstract/RelativeTimeFormat/InitializeRelativeTimeFormat.js const apply$1 = Reflect.apply; function InitializeRelativeTimeFormat(rtf, locales, options, { getInternalSlots, availableLocales, relevantExtensionKeys, localeData, getDefaultLocale }) { const internalSlots = getInternalSlots(rtf); internalSlots.initializedRelativeTimeFormat = true; const requestedLocales = CanonicalizeLocaleList(locales); const opt = { __proto__: null }; const opts = CoerceOptionsToObject(options); opt.localeMatcher = GetOption(opts, "localeMatcher", "string", ["best fit", "lookup"], "best fit"); const numberingSystem = GetOption(opts, "numberingSystem", "string", void 0, void 0); if (numberingSystem !== void 0) { if (!IsUnicodeLocaleIdentifierType(numberingSystem)) throw new RangeErrorConstructor(`Invalid numbering system ${numberingSystem}`); } opt.nu = numberingSystem; const r = ResolveLocale(availableLocales, requestedLocales, opt, relevantExtensionKeys, localeData, getDefaultLocale, "hostDefaultWithLocaleData"); const { locale, nu } = r; internalSlots.locale = locale; const fields = r.localeData; invariant(!!fields, `Missing locale data for ${r.dataLocale}`); internalSlots.fields = fields; internalSlots.numberingSystem = nu; internalSlots.style = GetOption(opts, "style", "string", [ "long", "narrow", "short" ], "long"); internalSlots.numeric = GetOption(opts, "numeric", "string", ["always", "auto"], "always"); const nfOptions = { __proto__: null, numberingSystem: nu }; const NumberFormat = getNumberFormatIntrinsic(); const numberFormat = createMemoizedNumberFormatForConstructor(NumberFormat)(locale, nfOptions); const PluralRules = getPluralRulesIntrinsic(); const pluralRules = createMemoizedPluralRulesForConstructor(PluralRules)(locale); const formatToParts = findFormatterPartsMethod(NumberFormat); if (formatToParts) internalSlots.formatNumber = (value) => apply$1(formatToParts, numberFormat, [value]); else { const format = numberFormat.format; internalSlots.formatNumber = (value) => [{ type: "literal", value: format(value) }]; } const select = findPluralRulesSelectMethod(PluralRules); invariant(select !== void 0, "Missing supplied PluralRules select method"); internalSlots.selectPlural = (value) => apply$1(select, pluralRules, [value]); return rtf; } // packages/ecma262-abstract/SameValue.js function SameValue(x, y) { if (x === y) return x !== 0 || 1 / x === 1 / y; return x !== x && y !== y; } // packages/ecma262-abstract/Type.js function Type(x) { if (x === null) return "Null"; if (x === void 0) return "Undefined"; if (IsObject(x)) return "Object"; if (typeof x === "number") return "Number"; if (typeof x === "boolean") return "Boolean"; if (typeof x === "string") return "String"; if (typeof x === "symbol") return "Symbol"; if (typeof x === "bigint") return "BigInt"; } // packages/ecma402-abstract/RelativeTimeFormat/SingularRelativeTimeUnit.js function SingularRelativeTimeUnit(unit) { invariant(Type(unit) === "String", "unit must be a string"); if (unit === "seconds") return "second"; if (unit === "minutes") return "minute"; if (unit === "hours") return "hour"; if (unit === "days") return "day"; if (unit === "weeks") return "week"; if (unit === "months") return "month"; if (unit === "quarters") return "quarter"; if (unit === "years") return "year"; if (unit !== "second" && unit !== "minute" && unit !== "hour" && unit !== "day" && unit !== "week" && unit !== "month" && unit !== "quarter" && unit !== "year") throw new RangeErrorConstructor("invalid unit"); return unit; } // packages/ecma402-abstract/PartitionPattern.js const apply = Reflect.apply; const stringIndexOf = String.prototype.indexOf; const substring = String.prototype.substring; function PartitionPattern(pattern) { const result = []; let placeholderEnd = -1; let placeholderStart = apply(stringIndexOf, pattern, ["{", 0]); while (placeholderStart !== -1) { const literal = apply(substring, pattern, [placeholderEnd + 1, placeholderStart]); if (literal !== "") setDataProperty(result, `${result.length}`, { type: "literal", value: literal }); placeholderEnd = apply(stringIndexOf, pattern, ["}", placeholderStart]); invariant(placeholderEnd > placeholderStart, `Invalid pattern ${pattern}`); const placeholderName = apply(substring, pattern, [placeholderStart + 1, placeholderEnd]); setDataProperty(result, `${result.length}`, { type: placeholderName, value: void 0 }); placeholderStart = apply(stringIndexOf, pattern, ["{", placeholderEnd]); } const tail = apply(substring, pattern, [placeholderEnd + 1]); if (tail !== "") setDataProperty(result, `${result.length}`, { type: "literal", value: tail }); return result; } // packages/ecma402-abstract/RelativeTimeFormat/MakePartsList.js function MakePartsList(pattern, unit, parts) { const patternParts = PartitionPattern(pattern); const result = []; for (let i = 0; i < patternParts.length; i++) { const patternPart = patternParts[i]; if (patternPart.type === "literal") setDataProperty(result, result.length, { type: "literal", value: patternPart.value }); else { invariant(patternPart.type === "0", `Malformed pattern ${pattern}`); for (let j = 0; j < parts.length; j++) { const part = parts[j]; setDataProperty(result, result.length, { type: part.type, value: part.value, unit }); } } } return result; } // packages/ecma402-abstract/RelativeTimeFormat/PartitionRelativeTimePattern.js const hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty); const abs = Math.abs; function PartitionRelativeTimePattern({ fields, style, numeric, selectPlural, formatNumber }, value, unit) { if (!numberIsFinite(value)) throw new RangeErrorConstructor(`Invalid value ${value}`); const resolvedUnit = SingularRelativeTimeUnit(unit); let entry = resolvedUnit; if (style === "short") entry = `${resolvedUnit}-short`; else if (style === "narrow") entry = `${resolvedUnit}-narrow`; if (!hasOwn(fields, entry)) entry = resolvedUnit; const patterns = fields[entry]; if (numeric === "auto") { const valueString = ToString(value); if (hasOwn(patterns, valueString)) return [{ type: "literal", value: patterns[valueString] }]; } let tl = "future"; if (SameValue(value, -0) || value < 0) tl = "past"; const po = patterns[tl]; const fv = formatNumber(abs(value)); const pr = selectPlural(value); return MakePartsList((hasOwn(po, pr) ? po[pr] : void 0) ?? po.other, resolvedUnit, fv); } // packages/intl-relativetimeformat/get_internal_slots.ts const internalSlotMap = /* @__PURE__ */ new WeakMap(); const readSlots = WeakMap.prototype.get.bind(internalSlotMap); const writeSlots = WeakMap.prototype.set.bind(internalSlotMap); function requireInternalSlots(receiver) { const slots = readSlots(receiver); if (!slots?.initializedRelativeTimeFormat) throw new TypeErrorConstructor$1("Incompatible Intl.RelativeTimeFormat receiver"); return slots; } function getInternalSlots(x) { let internalSlots = readSlots(x); if (!internalSlots) { internalSlots = objectCreate(null); writeSlots(x, internalSlots); } return internalSlots; } // packages/intl-relativetimeformat/index.ts let defaultLocale = ""; function getDefaultLocale() { return defaultLocale; } var RelativeTimeFormat = class RelativeTimeFormat extends null { constructor(locales, options) { return InitializeRelativeTimeFormat(createFromConstructor(new.target, RelativeTimeFormat.prototype), locales, options, { getInternalSlots, availableLocales: RelativeTimeFormat.availableLocales, relevantExtensionKeys: ["nu"], localeData: RelativeTimeFormat.localeData, getDefaultLocale }); } format(value, unit) { const parts = PartitionRelativeTimePattern(requireInternalSlots(this), +value, ToString(unit)); let result = ""; for (let index = 0; index < parts.length; index++) result += parts[index].value; return result; } formatToParts(value, unit) { return PartitionRelativeTimePattern(requireInternalSlots(this), +value, ToString(unit)); } resolvedOptions() { const internalSlots = requireInternalSlots(this); return { locale: internalSlots.locale, style: internalSlots.style, numeric: internalSlots.numeric, numberingSystem: internalSlots.numberingSystem }; } static supportedLocalesOf(locales, options) { return SupportedLocales(RelativeTimeFormat.availableLocales, CanonicalizeLocaleList(locales), options); } static __addLocaleData(...data) { for (const { data: d, locale: tag } of data) { const locale = canonicalizeLocaleDataTag(tag); registerLocaleData(locale, d, RelativeTimeFormat.localeData, RelativeTimeFormat.availableLocales); if (!defaultLocale) defaultLocale = locale; } } static { this.localeData = {}; } static { this.availableLocales = /* @__PURE__ */ new Set(); } static { this.polyfilled = true; } }; Object.setPrototypeOf(RelativeTimeFormat.prototype, Object.prototype); try { if (typeof Symbol !== "undefined") Object.defineProperty(RelativeTimeFormat.prototype, Symbol.toStringTag, { value: "Intl.RelativeTimeFormat", writable: false, enumerable: false, configurable: true }); Object.defineProperty(RelativeTimeFormat.prototype.constructor, "length", { value: 0, writable: false, enumerable: false, configurable: true }); Object.defineProperty(RelativeTimeFormat.supportedLocalesOf, "length", { value: 1, writable: false, enumerable: false, configurable: true }); } catch {} export { RelativeTimeFormat as default }; //# sourceMappingURL=index.js.map