Files
discord-decomp/_bundle/GetOption.js
T
2026-11-01 12:12:55 +02:00

463 lines
14 KiB
JavaScript

// Metro module 13450 (f13451).
import { ResolveLocale, LookupSupportedLocales } from "./invariant_13451";
function $mk91286() {
return function getMultiInternalSlots(a0, a1, ...args) {
const r13 = a0.get(a1);
let c27443_0 = r13;
if (r13) {
return args.reduce((acc, arg) => {
acc[arg] = c27443_0[arg];
return acc;
}, Object.create(null));
}
throw new TypeError(`${a1} InternalSlot has not been initialized`);
};
}
let monadic, variadic, strategyDefault, serializerDefault, c9328_10, isLiteralPart, invariant, validateInstance, stringListFromIterable, createPartsFromList, deconstructPattern;
const GetOption = function GetOption(a0, a1, a2, a3, a4) {
if (typeof a0 !== "object") {
throw new TypeError("Options must be an object");
}
const r5 = a0[a1];
let c20465_0 = r5;
if (r5 !== void 0) {
if ("boolean" !== "string" && "string" !== "string") {
throw new TypeError("invalid type");
}
let r4 = r5;
if ("boolean" === "string") {
const r16 = Boolean(r5);
c20465_0 = r16;
r4 = r16;
}
let r17 = r4;
if ("string" === "string") {
if (typeof r4 === "symbol") {
throw TypeError("Cannot convert a Symbol value to a string");
}
const r20 = String(r4);
c20465_0 = r20;
r17 = r20;
}
if (a3.filter((item) => item == c20465_0).length) {
return r17;
}
throw new RangeError(`${r17} is not within ${a3.join(", ")}`);
}
return a4;
};
const memoize = function memoize(a0, a1) {
return (a1.strategy ? a1.strategy : strategyDefault)(a0, {
cache: a1.cache ? a1.cache : c9328_10,
serializer: a1.serializer ? a1.serializer : serializerDefault
});
};
monadic = function monadic(a0, a1, a2, a3) {
const r3 = a3 == null || typeof a3 === "number" || typeof a3 === "boolean" ? a3 : a2(a3);
let r12 = a1.get(r3);
if (r12 === void 0) {
const r15 = a0.call(this, a3);
a1.set(r3, r15);
r12 = r15;
}
return r12;
};
variadic = function variadic(a0, a1, a2, ...args) {
const r17 = a2(args);
let r19 = a1.get(r17);
if (r19 === void 0) {
const r22 = a0.apply(this, args);
a1.set(r17, r22);
r19 = r22;
}
return r19;
};
strategyDefault = function strategyDefault(a0, a1) {
return (a0.length === 1 ? monadic : variadic).bind(this, a0, a1.cache.create(), a1.serializer);
};
isLiteralPart = function isLiteralPart(item) {
return item.type === "literal";
};
invariant = function invariant(a0, a1) {
const r4 = void 0 === void 0 ? Error : void 0;
if (a0) {
return void 0;
}
throw new r4(a1);
};
validateInstance = function validateInstance(a0, a1) {
if (a0 instanceof ListFormat) {
return void 0;
}
throw new TypeError(`Method Intl.ListFormat.prototype.format called on incompatible receiver ${String(a0)}`);
};
stringListFromIterable = function stringListFromIterable(a0) {
let done2;
if (typeof a0 !== "object") {
return [];
}
const r0 = [];
const r5 = a0[Symbol.iterator]();
const r13 = r5.next();
const done = r13.done;
let r4 = r13;
if (!done) {
do {
const value = r4.value;
const r16 = r4;
if (typeof value !== "string") {
throw new TypeError(`Iterable yielded ${r16.value} which is not a string`);
}
r0.push(r16.value);
const r20 = r5.next();
done2 = r20.done;
r4 = r20;
} while (!done2);
}
return r0;
};
createPartsFromList = function createPartsFromList(a0, a1, a2) {
const length = a2.length;
if (length === 0) {
return [];
}
if (length === 2) {
return deconstructPattern($mk91286()(a0, a1, "templatePair").templatePair, {
0: {
type: "element",
value: a2[0]
},
1: {
type: "element",
value: a2[1]
}
});
}
const r8 = {
type: "element",
value: a2[length - 1]
};
let r23 = length - 2;
let r24 = r8;
let r25 = r24;
while (0 <= r23) {
const r1 = r23;
const r20 = r24;
const r18 = r1 !== 0 ? r1 < length - 2 ? "templateMiddle" : "templateEnd" : "templateStart";
r24 = deconstructPattern($mk91286()(a0, a1, r18)[r18], {
0: {
type: "element",
value: a2[r1]
},
1: r20
});
r23 = r1 - 1;
r25 = r24;
}
return r25;
};
deconstructPattern = function deconstructPattern(templatePair, a1) {
const r30 = (function PartitionPattern(a0) {
const r4 = [];
let r23 = a0.indexOf("{");
const length = a0.length;
const r3 = r23 < a0.length;
let r8 = 0;
if (r3) {
const r24 = r23 > -1;
let r25 = 0;
r8 = 0;
if (r24) {
do {
const r26 = a0.indexOf("}", r23);
const r27 = r26 > r23;
const r18 = `Invalid pattern ${a0}`;
const r29 = Error;
const r19 = r25;
const r17 = r23;
if (!r27) {
throw new r29(r18);
}
if (r17 > r19) {
r4.push({
type: "literal",
value: a0.substring(r19, r17)
});
}
r4.push({
type: a0.substring(r17 + 1, r26),
value: void 0
});
const r43 = r26 + 1;
const r45 = a0.indexOf("{", r43);
const length2 = a0.length;
r8 = r43;
if (!(r45 < length2)) {
break;
}
r25 = r43;
r8 = r25;
r23 = r45;
} while (r23 > -1);
}
}
if (r8 < length) {
r4.push({
type: "literal",
value: a0.substring(r8, length)
});
}
return r4;
})(templatePair);
const r31 = [];
for (const item of r30) {
const type = item.type;
if (isLiteralPart(item)) {
r31.push({
type: "literal",
value: item.value
});
} else {
invariant(type in a1, `${type} is missing from placables`);
const r44 = a1[type];
const isArray = Array.isArray(r44);
const push = r31.push;
if (isArray) {
push.apply(r31, [...r44]);
} else {
push.call(r31, r44);
}
}
}
return r31;
};
serializerDefault = function serializerDefault() {
return JSON.stringify(arguments);
};
class ObjectWithoutPrototypeCache {
cache = Object.create(null);
get(a0) {
return this.cache[a0];
}
set(a0, a1) {
this.cache[a0] = a1;
}
}
c9328_10 = {
create: function create() {
return new ObjectWithoutPrototypeCache();
}
};
const strategyVariadic = function strategyVariadic(a0, a1) {
return variadic.bind(this, a0, a1.cache.create(), a1.serializer);
};
memoize(function() {
return new Intl.NumberFormat(...[...Array.prototype.slice.call(arguments, 0)]);
}, {
strategy: strategyVariadic
});
memoize(function() {
return new Intl.PluralRules(...[...Array.prototype.slice.call(arguments, 0)]);
}, {
strategy: strategyVariadic
});
memoize(function() {
return new Intl.Locale(...[...Array.prototype.slice.call(arguments, 0)]);
}, {
strategy: strategyVariadic
});
memoize(function() {
return new Intl.ListFormat(...[...Array.prototype.slice.call(arguments, 0)]);
}, {
strategy: strategyVariadic
});
class ListFormat {
static localeData = {};
static availableLocales = new Set();
static __defaultLocale = "";
static relevantExtensionKeys = [];
static polyfilled = true;
static __INTERNAL_SLOT_MAP__ = new WeakMap();
static __ = void 0;
constructor(a0, a1) {
if (this ? this instanceof ListFormat ? this.constructor : void 0 : void 0) {
const __INTERNAL_SLOT_MAP__ = ListFormat.__INTERNAL_SLOT_MAP__;
if (!__INTERNAL_SLOT_MAP__.get(this)) {
__INTERNAL_SLOT_MAP__.set(this, Object.create(null));
}
let r12 = a1;
__INTERNAL_SLOT_MAP__.get(this).initializedListFormat = true;
const canonicalLocales = Intl.getCanonicalLocales(a0);
const r16 = Object.create(null);
if (a1 === void 0) {
r12 = Object.create(null);
} else if (typeof a1 !== "object") {
throw new TypeError("Options must be an object");
}
r16.localeMatcher = GetOption(r12, "localeMatcher", "string", ["best fit", "lookup"], "best fit");
const localeData = ListFormat.localeData;
const r71 = ResolveLocale(ListFormat.availableLocales, canonicalLocales, r16, ListFormat.relevantExtensionKeys, localeData, ListFormat.getDefaultLocale);
const __INTERNAL_SLOT_MAP__2 = ListFormat.__INTERNAL_SLOT_MAP__;
const locale = r71.locale;
const r75 = __INTERNAL_SLOT_MAP__2.get(this);
const r76 = r12;
if (!r75) {
__INTERNAL_SLOT_MAP__2.set(this, Object.create(null));
}
__INTERNAL_SLOT_MAP__2.get(this).locale = locale;
const type = GetOption(r76, "type", "string", ["conjunction", "disjunction", "unit"], "conjunction");
const __INTERNAL_SLOT_MAP__3 = ListFormat.__INTERNAL_SLOT_MAP__;
if (!__INTERNAL_SLOT_MAP__3.get(this)) {
__INTERNAL_SLOT_MAP__3.set(this, Object.create(null));
}
__INTERNAL_SLOT_MAP__3.get(this).type = type;
const style = GetOption(r76, "style", "string", ["long", "short", "narrow"], "long");
const __INTERNAL_SLOT_MAP__4 = ListFormat.__INTERNAL_SLOT_MAP__;
if (!__INTERNAL_SLOT_MAP__4.get(this)) {
__INTERNAL_SLOT_MAP__4.set(this, Object.create(null));
}
__INTERNAL_SLOT_MAP__4.get(this).style = style;
const dataLocale = r71.dataLocale;
const r119 = localeData[dataLocale];
const r3 = !r119;
const r123 = `Missing locale data for ${dataLocale}`;
const r124 = Error;
if (!r3) {
const r132 = r119[type][style];
const __INTERNAL_SLOT_MAP__5 = ListFormat.__INTERNAL_SLOT_MAP__;
const pair = r132.pair;
if (!__INTERNAL_SLOT_MAP__5.get(this)) {
__INTERNAL_SLOT_MAP__5.set(this, Object.create(null));
}
__INTERNAL_SLOT_MAP__5.get(this).templatePair = pair;
const __INTERNAL_SLOT_MAP__6 = ListFormat.__INTERNAL_SLOT_MAP__;
const start = r132.start;
if (!__INTERNAL_SLOT_MAP__6.get(this)) {
__INTERNAL_SLOT_MAP__6.set(this, Object.create(null));
}
__INTERNAL_SLOT_MAP__6.get(this).templateStart = start;
const __INTERNAL_SLOT_MAP__7 = ListFormat.__INTERNAL_SLOT_MAP__;
const middle = r132.middle;
if (!__INTERNAL_SLOT_MAP__7.get(this)) {
__INTERNAL_SLOT_MAP__7.set(this, Object.create(null));
}
__INTERNAL_SLOT_MAP__7.get(this).templateMiddle = middle;
const __INTERNAL_SLOT_MAP__8 = ListFormat.__INTERNAL_SLOT_MAP__;
const end = r132.end;
if (!__INTERNAL_SLOT_MAP__8.get(this)) {
__INTERNAL_SLOT_MAP__8.set(this, Object.create(null));
}
__INTERNAL_SLOT_MAP__8.get(this).templateEnd = end;
return void 0;
}
throw new r124(r123);
}
throw new TypeError("Intl.ListFormat must be called with 'new'");
}
format(a0) {
validateInstance(this, "format");
let r22 = "";
const partsFromList = createPartsFromList(ListFormat.__INTERNAL_SLOT_MAP__, this, stringListFromIterable(a0));
if (!Array.isArray(partsFromList)) {
return partsFromList.value;
}
for (const item of partsFromList) {
r22 = r22 + item.value;
}
return r22;
}
formatToParts(a0) {
validateInstance(this, "format");
const partsFromList = createPartsFromList(ListFormat.__INTERNAL_SLOT_MAP__, this, stringListFromIterable(a0));
if (!Array.isArray(partsFromList)) {
return [partsFromList];
}
const r33 = [];
for (const item of partsFromList) {
r33.push({
...item
});
}
return r33;
}
resolvedOptions() {
if (this instanceof ListFormat) {
const __INTERNAL_SLOT_MAP__ = ListFormat.__INTERNAL_SLOT_MAP__;
const r29 = {
locale: $mk91286()(__INTERNAL_SLOT_MAP__, this, "locale").locale,
type: null,
style: null
};
const __INTERNAL_SLOT_MAP__2 = ListFormat.__INTERNAL_SLOT_MAP__;
r29.type = $mk91286()(__INTERNAL_SLOT_MAP__2, this, "type").type;
const __INTERNAL_SLOT_MAP__3 = ListFormat.__INTERNAL_SLOT_MAP__;
r29.style = $mk91286()(__INTERNAL_SLOT_MAP__3, this, "style").style;
return r29;
}
throw new TypeError(`Method Intl.ListFormat.prototype.resolvedOptions called on incompatible receiver ${String(this)}`);
}
static supportedLocalesOf(a0, a1) {
const availableLocales = ListFormat.availableLocales;
const canonicalLocales = Intl.getCanonicalLocales(a0);
if (a1 !== void 0) {
if (a1 == null) {
throw new TypeError("undefined/null cannot be converted to object");
}
GetOption(Object(a1), "localeMatcher", "string", ["lookup", "best fit"], "best fit");
}
return LookupSupportedLocales(Array.from(availableLocales), canonicalLocales);
}
static __addLocaleData() {
for (const item of Array.prototype.slice.call(arguments, 0)) {
const { data, locale } = item;
const r10 = new Intl.Locale(locale).minimize().toString();
const localeData = ListFormat.localeData;
ListFormat.localeData[r10] = data;
localeData[locale] = data;
ListFormat.availableLocales.add(r10);
ListFormat.availableLocales.add(locale);
if (!ListFormat.__defaultLocale) {
ListFormat.__defaultLocale = r10;
}
}
}
static getDefaultLocale() {
return ListFormat.__defaultLocale;
}
}
try {
if (typeof globalThis.Symbol !== "undefined") {
Object.defineProperty(ListFormat.prototype, Symbol.toStringTag, {
value: "Intl.ListFormat",
writable: false,
enumerable: false,
configurable: true
});
}
Object.defineProperty(ListFormat.prototype.constructor, "length", {
value: 0,
writable: false,
enumerable: false,
configurable: true
});
Object.defineProperty(ListFormat.supportedLocalesOf, "length", {
value: 1,
writable: false,
enumerable: false,
configurable: true
});
} catch ($e) {}
Object.defineProperty(Intl, "ListFormat", {
value: ListFormat,
writable: true,
enumerable: false,
configurable: true
});
const __FORMATJS_LISTFORMAT_DATA__ = globalThis.globalThis.__FORMATJS_LISTFORMAT_DATA__;
if (__FORMATJS_LISTFORMAT_DATA__) {
for (const item of __FORMATJS_LISTFORMAT_DATA__) {
ListFormat.__addLocaleData(item);
}
delete globalThis.globalThis["__FORMATJS_LISTFORMAT_DATA__"];
}