decord/source/16382_StringFormat.js

251 lines
7.1 KiB
JavaScript
Raw Normal View History

2026-08-12 06:57:52 +00:00
// Module ID: 16382
// Function ID: 16383
2026-07-20 16:05:17 +00:00
// Name: StringFormat
// Dependencies: []
2026-08-12 06:57:52 +00:00
// Module 16382 (StringFormat)
2026-07-20 16:05:17 +00:00
class Compiler {
constructor(arg0, arg1, arg2) {
return;
}
compile(arg0) {
2026-07-29 08:29:29 +00:00
obj = { pluralStack: [], currentPlural: null, pluralNumberFormat: null };
return obj.compileMessage(arg0);
2026-07-20 16:05:17 +00:00
}
compileMessage(arg0) {
self = this;
if (arg0) {
str = "messageFormatPattern";
if ("messageFormatPattern" === arg0.type) {
elements = arg0.elements;
items = [];
length = elements.length;
num = 0;
num2 = 1;
str3 = "argumentElement";
str4 = "messageTextElement";
if (0 < length) {
while (true) {
tmp = elements[num];
type = tmp.type;
2026-07-29 08:29:29 +00:00
tmp2 = num;
2026-07-20 16:05:17 +00:00
if ("messageTextElement" === type) {
arr = items.push(self.compileMessageText(tmp));
} else if ("argumentElement" !== type) {
break;
} else {
arr1 = items.push(self.compileArgument(tmp));
}
num = num + 1;
}
2026-07-29 08:29:29 +00:00
tmp3 = globalThis;
2026-07-20 16:05:17 +00:00
_Error = Error;
tmp4 = new.target;
2026-07-29 08:29:29 +00:00
str2 = "Message element does not have a valid type";
tmp5 = new.target;
2026-07-20 16:05:17 +00:00
error = new Error("Message element does not have a valid type");
2026-07-29 08:29:29 +00:00
tmp7 = error;
2026-07-20 16:05:17 +00:00
throw error;
}
return items;
}
}
error1 = new Error("Message AST is not of type: \"messageFormatPattern\"");
throw error1;
}
compileMessageText(arg0) {
self = this;
if (this.currentPlural) {
obj = /(^|[^\\])#/g;
if (obj.test(arg0.value)) {
if (!self.pluralNumberFormat) {
tmp2 = globalThis;
_Intl = Intl;
tmp3 = new.target;
tmp4 = new.target;
2026-07-29 08:29:29 +00:00
numberFormat = new Intl.NumberFormat(self.locales);
2026-07-20 16:05:17 +00:00
tmp6 = numberFormat;
self.pluralNumberFormat = numberFormat;
}
tmp7 = PluralOffsetString;
2026-07-29 08:29:29 +00:00
obj = Object.create(PluralOffsetString.prototype);
obj1 = {};
obj1.id = self.currentPlural.id;
obj1.offset = self.currentPlural.format.offset;
obj1.numberFormat = self.pluralNumberFormat;
obj1.string = arg0.value;
replaced = obj1;
2026-07-20 16:05:17 +00:00
}
return replaced;
}
str = arg0.value;
replaced = str.replace(/\\#/g, "#");
return;
}
compileArgument(arg0) {
format = arg0.format;
if (format) {
2026-07-29 08:29:29 +00:00
self = this;
({ formats, locales } = this);
2026-07-20 16:05:17 +00:00
type = format.type;
str = "numberFormat";
if ("numberFormat" === type) {
2026-07-29 08:29:29 +00:00
obj = { id: null, format: null };
obj[0] = arg0.id;
tmp27 = globalThis;
2026-07-20 16:05:17 +00:00
_Intl3 = Intl;
2026-07-29 08:29:29 +00:00
tmp28 = new.target;
tmp29 = new.target;
tmp30 = locales;
numberFormat = new Intl.NumberFormat(locales, formats.number[format.style]);
tmp32 = numberFormat;
obj[1] = numberFormat.format;
2026-07-20 16:05:17 +00:00
return obj;
} else {
str4 = "dateFormat";
if ("dateFormat" === type) {
2026-07-29 08:29:29 +00:00
obj1 = { id: null, format: null };
obj1[0] = arg0.id;
tmp21 = globalThis;
2026-07-20 16:05:17 +00:00
_Intl2 = Intl;
2026-07-29 08:29:29 +00:00
tmp22 = new.target;
tmp23 = new.target;
tmp24 = locales;
dateTimeFormat = new Intl.DateTimeFormat(locales, formats.date[format.style]);
tmp26 = dateTimeFormat;
obj1[1] = dateTimeFormat.format;
2026-07-20 16:05:17 +00:00
return obj1;
} else {
str5 = "timeFormat";
if ("timeFormat" === type) {
2026-07-29 08:29:29 +00:00
obj2 = { id: null, format: null };
obj2[0] = arg0.id;
tmp15 = globalThis;
2026-07-20 16:05:17 +00:00
_Intl = Intl;
2026-07-29 08:29:29 +00:00
tmp16 = new.target;
tmp17 = new.target;
tmp18 = locales;
dateTimeFormat1 = new Intl.DateTimeFormat(locales, formats.time[format.style]);
tmp20 = dateTimeFormat1;
obj2[1] = dateTimeFormat1.format;
return obj2;
2026-07-20 16:05:17 +00:00
} else {
str6 = "pluralFormat";
if ("pluralFormat" === type) {
2026-07-29 08:29:29 +00:00
tmp13 = PluralFormat;
compileOptionsResult = self.compileOptions(arg0);
({ ordinal, offset } = format);
obj3 = Object.create(PluralFormat.prototype);
obj4 = {};
obj4.id = arg0.id;
obj4.useOrdinal = ordinal;
obj4.offset = offset;
obj4.options = compileOptionsResult;
obj4.pluralFn = tmp3;
return obj4;
2026-07-20 16:05:17 +00:00
} else {
str2 = "selectFormat";
if ("selectFormat" === type) {
2026-07-29 08:29:29 +00:00
tmp10 = SelectFormat;
compileOptionsResult1 = self.compileOptions(arg0);
obj5 = Object.create(SelectFormat.prototype);
obj = {};
obj.id = arg0.id;
obj.options = compileOptionsResult1;
return obj;
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
tmp4 = globalThis;
2026-07-20 16:05:17 +00:00
_Error = Error;
2026-07-29 08:29:29 +00:00
tmp5 = new.target;
2026-07-20 16:05:17 +00:00
str3 = "Message element does not have a valid format type";
2026-07-29 08:29:29 +00:00
tmp6 = new.target;
2026-07-20 16:05:17 +00:00
error = new Error("Message element does not have a valid format type");
2026-07-29 08:29:29 +00:00
tmp8 = error;
2026-07-20 16:05:17 +00:00
throw error;
}
}
}
}
}
} else {
tmp = StringFormat;
2026-07-29 08:29:29 +00:00
obj6 = Object.create(StringFormat.prototype);
obj6.id = arg0.id;
return obj6;
2026-07-20 16:05:17 +00:00
}
}
compileOptions(arg0) {
self = this;
format = arg0.format;
options = format.options;
pluralStack = this.pluralStack;
arr = pluralStack.push(this.currentPlural);
tmp2 = null;
if ("pluralFormat" === format.type) {
tmp2 = arg0;
}
2026-07-29 08:29:29 +00:00
obj = {};
2026-07-20 16:05:17 +00:00
self.currentPlural = tmp2;
length = options.length;
for (let num = 0; num < length; num = num + 1) {
iter = options[num];
obj[iter.selector] = self.compileMessage(iter.value);
}
pluralStack1 = self.pluralStack;
self.currentPlural = pluralStack1.pop();
return obj;
}
}
class StringFormat {
constructor(arg0) {
this.id = arg0;
return;
}
format(arg0) {
str = "";
if (arg0) {
StringResult = arg0;
2026-08-04 21:03:28 +00:00
if (typeof arg0 !== "string") {
2026-07-20 16:05:17 +00:00
tmp2 = globalThis;
_String = String;
StringResult = String(arg0);
}
str = StringResult;
}
return str;
}
}
class PluralFormat {
constructor(arg0, arg1, arg2, arg3, arg4) {
return;
}
getOption(arg0) {
self = this;
options = this.options;
tmp = options["=" + arg0] || options[self.pluralFn(self, arg0 - self.offset, self.useOrdinal)] || options.other;
return tmp;
}
}
class PluralOffsetString {
constructor(arg0, arg1, arg2, arg3) {
return;
}
format(arg0) {
numberFormat = this.numberFormat;
str = this.string;
str2 = str.replace(/(^|[^\\])#/g, `$1${numberFormat.format(arg0 - this.offset)}`);
return str2.replace(/\\#/g, "#");
}
}
class SelectFormat {
constructor(arg0, arg1) {
return;
}
getOption(arg0) {
options = this.options;
tmp = options[arg0] || options.other;
return tmp;
}
}
arg5.default = Compiler;