inlang-plugin-rich-icu 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +86 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4842 -0
- package/package.json +46 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,4842 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/typebox.js
|
|
28
|
+
var require_typebox = __commonJS({
|
|
29
|
+
"node_modules/.pnpm/@sinclair+typebox@0.31.28/node_modules/@sinclair/typebox/typebox.js"(exports) {
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.Type = exports.JsonType = exports.JavaScriptTypeBuilder = exports.JsonTypeBuilder = exports.TypeBuilder = exports.TypeBuilderError = exports.TransformEncodeBuilder = exports.TransformDecodeBuilder = exports.TemplateLiteralDslParser = exports.TemplateLiteralGenerator = exports.TemplateLiteralGeneratorError = exports.TemplateLiteralFinite = exports.TemplateLiteralFiniteError = exports.TemplateLiteralParser = exports.TemplateLiteralParserError = exports.TemplateLiteralResolver = exports.TemplateLiteralPattern = exports.TemplateLiteralPatternError = exports.UnionResolver = exports.KeyArrayResolver = exports.KeyArrayResolverError = exports.KeyResolver = exports.ObjectMap = exports.Intrinsic = exports.IndexedAccessor = exports.TypeClone = exports.TypeExtends = exports.TypeExtendsResult = exports.TypeExtendsError = exports.ExtendsUndefined = exports.TypeGuard = exports.TypeGuardUnknownTypeError = exports.ValueGuard = exports.FormatRegistry = exports.TypeBoxError = exports.TypeRegistry = exports.PatternStringExact = exports.PatternNumberExact = exports.PatternBooleanExact = exports.PatternString = exports.PatternNumber = exports.PatternBoolean = exports.Kind = exports.Hint = exports.Optional = exports.Readonly = exports.Transform = void 0;
|
|
32
|
+
exports.Transform = /* @__PURE__ */ Symbol.for("TypeBox.Transform");
|
|
33
|
+
exports.Readonly = /* @__PURE__ */ Symbol.for("TypeBox.Readonly");
|
|
34
|
+
exports.Optional = /* @__PURE__ */ Symbol.for("TypeBox.Optional");
|
|
35
|
+
exports.Hint = /* @__PURE__ */ Symbol.for("TypeBox.Hint");
|
|
36
|
+
exports.Kind = /* @__PURE__ */ Symbol.for("TypeBox.Kind");
|
|
37
|
+
exports.PatternBoolean = "(true|false)";
|
|
38
|
+
exports.PatternNumber = "(0|[1-9][0-9]*)";
|
|
39
|
+
exports.PatternString = "(.*)";
|
|
40
|
+
exports.PatternBooleanExact = `^${exports.PatternBoolean}$`;
|
|
41
|
+
exports.PatternNumberExact = `^${exports.PatternNumber}$`;
|
|
42
|
+
exports.PatternStringExact = `^${exports.PatternString}$`;
|
|
43
|
+
var TypeRegistry;
|
|
44
|
+
(function(TypeRegistry2) {
|
|
45
|
+
const map = /* @__PURE__ */ new Map();
|
|
46
|
+
function Entries() {
|
|
47
|
+
return new Map(map);
|
|
48
|
+
}
|
|
49
|
+
TypeRegistry2.Entries = Entries;
|
|
50
|
+
function Clear() {
|
|
51
|
+
return map.clear();
|
|
52
|
+
}
|
|
53
|
+
TypeRegistry2.Clear = Clear;
|
|
54
|
+
function Delete(kind) {
|
|
55
|
+
return map.delete(kind);
|
|
56
|
+
}
|
|
57
|
+
TypeRegistry2.Delete = Delete;
|
|
58
|
+
function Has(kind) {
|
|
59
|
+
return map.has(kind);
|
|
60
|
+
}
|
|
61
|
+
TypeRegistry2.Has = Has;
|
|
62
|
+
function Set2(kind, func) {
|
|
63
|
+
map.set(kind, func);
|
|
64
|
+
}
|
|
65
|
+
TypeRegistry2.Set = Set2;
|
|
66
|
+
function Get(kind) {
|
|
67
|
+
return map.get(kind);
|
|
68
|
+
}
|
|
69
|
+
TypeRegistry2.Get = Get;
|
|
70
|
+
})(TypeRegistry || (exports.TypeRegistry = TypeRegistry = {}));
|
|
71
|
+
var TypeBoxError = class extends Error {
|
|
72
|
+
constructor(message) {
|
|
73
|
+
super(message);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.TypeBoxError = TypeBoxError;
|
|
77
|
+
var FormatRegistry;
|
|
78
|
+
(function(FormatRegistry2) {
|
|
79
|
+
const map = /* @__PURE__ */ new Map();
|
|
80
|
+
function Entries() {
|
|
81
|
+
return new Map(map);
|
|
82
|
+
}
|
|
83
|
+
FormatRegistry2.Entries = Entries;
|
|
84
|
+
function Clear() {
|
|
85
|
+
return map.clear();
|
|
86
|
+
}
|
|
87
|
+
FormatRegistry2.Clear = Clear;
|
|
88
|
+
function Delete(format) {
|
|
89
|
+
return map.delete(format);
|
|
90
|
+
}
|
|
91
|
+
FormatRegistry2.Delete = Delete;
|
|
92
|
+
function Has(format) {
|
|
93
|
+
return map.has(format);
|
|
94
|
+
}
|
|
95
|
+
FormatRegistry2.Has = Has;
|
|
96
|
+
function Set2(format, func) {
|
|
97
|
+
map.set(format, func);
|
|
98
|
+
}
|
|
99
|
+
FormatRegistry2.Set = Set2;
|
|
100
|
+
function Get(format) {
|
|
101
|
+
return map.get(format);
|
|
102
|
+
}
|
|
103
|
+
FormatRegistry2.Get = Get;
|
|
104
|
+
})(FormatRegistry || (exports.FormatRegistry = FormatRegistry = {}));
|
|
105
|
+
var ValueGuard;
|
|
106
|
+
(function(ValueGuard2) {
|
|
107
|
+
function IsArray(value) {
|
|
108
|
+
return Array.isArray(value);
|
|
109
|
+
}
|
|
110
|
+
ValueGuard2.IsArray = IsArray;
|
|
111
|
+
function IsBigInt(value) {
|
|
112
|
+
return typeof value === "bigint";
|
|
113
|
+
}
|
|
114
|
+
ValueGuard2.IsBigInt = IsBigInt;
|
|
115
|
+
function IsBoolean(value) {
|
|
116
|
+
return typeof value === "boolean";
|
|
117
|
+
}
|
|
118
|
+
ValueGuard2.IsBoolean = IsBoolean;
|
|
119
|
+
function IsDate(value) {
|
|
120
|
+
return value instanceof globalThis.Date;
|
|
121
|
+
}
|
|
122
|
+
ValueGuard2.IsDate = IsDate;
|
|
123
|
+
function IsNull(value) {
|
|
124
|
+
return value === null;
|
|
125
|
+
}
|
|
126
|
+
ValueGuard2.IsNull = IsNull;
|
|
127
|
+
function IsNumber(value) {
|
|
128
|
+
return typeof value === "number";
|
|
129
|
+
}
|
|
130
|
+
ValueGuard2.IsNumber = IsNumber;
|
|
131
|
+
function IsObject(value) {
|
|
132
|
+
return typeof value === "object" && value !== null;
|
|
133
|
+
}
|
|
134
|
+
ValueGuard2.IsObject = IsObject;
|
|
135
|
+
function IsString(value) {
|
|
136
|
+
return typeof value === "string";
|
|
137
|
+
}
|
|
138
|
+
ValueGuard2.IsString = IsString;
|
|
139
|
+
function IsUint8Array(value) {
|
|
140
|
+
return value instanceof globalThis.Uint8Array;
|
|
141
|
+
}
|
|
142
|
+
ValueGuard2.IsUint8Array = IsUint8Array;
|
|
143
|
+
function IsUndefined(value) {
|
|
144
|
+
return value === void 0;
|
|
145
|
+
}
|
|
146
|
+
ValueGuard2.IsUndefined = IsUndefined;
|
|
147
|
+
})(ValueGuard || (exports.ValueGuard = ValueGuard = {}));
|
|
148
|
+
var TypeGuardUnknownTypeError = class extends TypeBoxError {
|
|
149
|
+
};
|
|
150
|
+
exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
|
|
151
|
+
var TypeGuard;
|
|
152
|
+
(function(TypeGuard2) {
|
|
153
|
+
function IsPattern(value) {
|
|
154
|
+
try {
|
|
155
|
+
new RegExp(value);
|
|
156
|
+
return true;
|
|
157
|
+
} catch {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function IsControlCharacterFree(value) {
|
|
162
|
+
if (!ValueGuard.IsString(value))
|
|
163
|
+
return false;
|
|
164
|
+
for (let i = 0; i < value.length; i++) {
|
|
165
|
+
const code = value.charCodeAt(i);
|
|
166
|
+
if (code >= 7 && code <= 13 || code === 27 || code === 127) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
function IsAdditionalProperties(value) {
|
|
173
|
+
return IsOptionalBoolean(value) || TSchema(value);
|
|
174
|
+
}
|
|
175
|
+
function IsOptionalBigInt(value) {
|
|
176
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsBigInt(value);
|
|
177
|
+
}
|
|
178
|
+
function IsOptionalNumber(value) {
|
|
179
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsNumber(value);
|
|
180
|
+
}
|
|
181
|
+
function IsOptionalBoolean(value) {
|
|
182
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsBoolean(value);
|
|
183
|
+
}
|
|
184
|
+
function IsOptionalString(value) {
|
|
185
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value);
|
|
186
|
+
}
|
|
187
|
+
function IsOptionalPattern(value) {
|
|
188
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value) && IsControlCharacterFree(value) && IsPattern(value);
|
|
189
|
+
}
|
|
190
|
+
function IsOptionalFormat(value) {
|
|
191
|
+
return ValueGuard.IsUndefined(value) || ValueGuard.IsString(value) && IsControlCharacterFree(value);
|
|
192
|
+
}
|
|
193
|
+
function IsOptionalSchema(value) {
|
|
194
|
+
return ValueGuard.IsUndefined(value) || TSchema(value);
|
|
195
|
+
}
|
|
196
|
+
function TAny(schema) {
|
|
197
|
+
return TKindOf(schema, "Any") && IsOptionalString(schema.$id);
|
|
198
|
+
}
|
|
199
|
+
TypeGuard2.TAny = TAny;
|
|
200
|
+
function TArray(schema) {
|
|
201
|
+
return TKindOf(schema, "Array") && schema.type === "array" && IsOptionalString(schema.$id) && TSchema(schema.items) && IsOptionalNumber(schema.minItems) && IsOptionalNumber(schema.maxItems) && IsOptionalBoolean(schema.uniqueItems) && IsOptionalSchema(schema.contains) && IsOptionalNumber(schema.minContains) && IsOptionalNumber(schema.maxContains);
|
|
202
|
+
}
|
|
203
|
+
TypeGuard2.TArray = TArray;
|
|
204
|
+
function TAsyncIterator(schema) {
|
|
205
|
+
return TKindOf(schema, "AsyncIterator") && schema.type === "AsyncIterator" && IsOptionalString(schema.$id) && TSchema(schema.items);
|
|
206
|
+
}
|
|
207
|
+
TypeGuard2.TAsyncIterator = TAsyncIterator;
|
|
208
|
+
function TBigInt(schema) {
|
|
209
|
+
return TKindOf(schema, "BigInt") && schema.type === "bigint" && IsOptionalString(schema.$id) && IsOptionalBigInt(schema.exclusiveMaximum) && IsOptionalBigInt(schema.exclusiveMinimum) && IsOptionalBigInt(schema.maximum) && IsOptionalBigInt(schema.minimum) && IsOptionalBigInt(schema.multipleOf);
|
|
210
|
+
}
|
|
211
|
+
TypeGuard2.TBigInt = TBigInt;
|
|
212
|
+
function TBoolean(schema) {
|
|
213
|
+
return TKindOf(schema, "Boolean") && schema.type === "boolean" && IsOptionalString(schema.$id);
|
|
214
|
+
}
|
|
215
|
+
TypeGuard2.TBoolean = TBoolean;
|
|
216
|
+
function TConstructor(schema) {
|
|
217
|
+
return TKindOf(schema, "Constructor") && schema.type === "Constructor" && IsOptionalString(schema.$id) && ValueGuard.IsArray(schema.parameters) && schema.parameters.every((schema2) => TSchema(schema2)) && TSchema(schema.returns);
|
|
218
|
+
}
|
|
219
|
+
TypeGuard2.TConstructor = TConstructor;
|
|
220
|
+
function TDate(schema) {
|
|
221
|
+
return TKindOf(schema, "Date") && schema.type === "Date" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.exclusiveMaximumTimestamp) && IsOptionalNumber(schema.exclusiveMinimumTimestamp) && IsOptionalNumber(schema.maximumTimestamp) && IsOptionalNumber(schema.minimumTimestamp) && IsOptionalNumber(schema.multipleOfTimestamp);
|
|
222
|
+
}
|
|
223
|
+
TypeGuard2.TDate = TDate;
|
|
224
|
+
function TFunction(schema) {
|
|
225
|
+
return TKindOf(schema, "Function") && schema.type === "Function" && IsOptionalString(schema.$id) && ValueGuard.IsArray(schema.parameters) && schema.parameters.every((schema2) => TSchema(schema2)) && TSchema(schema.returns);
|
|
226
|
+
}
|
|
227
|
+
TypeGuard2.TFunction = TFunction;
|
|
228
|
+
function TInteger(schema) {
|
|
229
|
+
return TKindOf(schema, "Integer") && schema.type === "integer" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.exclusiveMaximum) && IsOptionalNumber(schema.exclusiveMinimum) && IsOptionalNumber(schema.maximum) && IsOptionalNumber(schema.minimum) && IsOptionalNumber(schema.multipleOf);
|
|
230
|
+
}
|
|
231
|
+
TypeGuard2.TInteger = TInteger;
|
|
232
|
+
function TIntersect(schema) {
|
|
233
|
+
return TKindOf(schema, "Intersect") && (ValueGuard.IsString(schema.type) && schema.type !== "object" ? false : true) && ValueGuard.IsArray(schema.allOf) && schema.allOf.every((schema2) => TSchema(schema2) && !TTransform(schema2)) && IsOptionalString(schema.type) && (IsOptionalBoolean(schema.unevaluatedProperties) || IsOptionalSchema(schema.unevaluatedProperties)) && IsOptionalString(schema.$id);
|
|
234
|
+
}
|
|
235
|
+
TypeGuard2.TIntersect = TIntersect;
|
|
236
|
+
function TIterator(schema) {
|
|
237
|
+
return TKindOf(schema, "Iterator") && schema.type === "Iterator" && IsOptionalString(schema.$id) && TSchema(schema.items);
|
|
238
|
+
}
|
|
239
|
+
TypeGuard2.TIterator = TIterator;
|
|
240
|
+
function TKindOf(schema, kind) {
|
|
241
|
+
return TKind(schema) && schema[exports.Kind] === kind;
|
|
242
|
+
}
|
|
243
|
+
TypeGuard2.TKindOf = TKindOf;
|
|
244
|
+
function TKind(schema) {
|
|
245
|
+
return ValueGuard.IsObject(schema) && exports.Kind in schema && ValueGuard.IsString(schema[exports.Kind]);
|
|
246
|
+
}
|
|
247
|
+
TypeGuard2.TKind = TKind;
|
|
248
|
+
function TLiteralString(schema) {
|
|
249
|
+
return TLiteral(schema) && ValueGuard.IsString(schema.const);
|
|
250
|
+
}
|
|
251
|
+
TypeGuard2.TLiteralString = TLiteralString;
|
|
252
|
+
function TLiteralNumber(schema) {
|
|
253
|
+
return TLiteral(schema) && ValueGuard.IsNumber(schema.const);
|
|
254
|
+
}
|
|
255
|
+
TypeGuard2.TLiteralNumber = TLiteralNumber;
|
|
256
|
+
function TLiteralBoolean(schema) {
|
|
257
|
+
return TLiteral(schema) && ValueGuard.IsBoolean(schema.const);
|
|
258
|
+
}
|
|
259
|
+
TypeGuard2.TLiteralBoolean = TLiteralBoolean;
|
|
260
|
+
function TLiteral(schema) {
|
|
261
|
+
return TKindOf(schema, "Literal") && IsOptionalString(schema.$id) && (ValueGuard.IsBoolean(schema.const) || ValueGuard.IsNumber(schema.const) || ValueGuard.IsString(schema.const));
|
|
262
|
+
}
|
|
263
|
+
TypeGuard2.TLiteral = TLiteral;
|
|
264
|
+
function TNever(schema) {
|
|
265
|
+
return TKindOf(schema, "Never") && ValueGuard.IsObject(schema.not) && Object.getOwnPropertyNames(schema.not).length === 0;
|
|
266
|
+
}
|
|
267
|
+
TypeGuard2.TNever = TNever;
|
|
268
|
+
function TNot(schema) {
|
|
269
|
+
return TKindOf(schema, "Not") && TSchema(schema.not);
|
|
270
|
+
}
|
|
271
|
+
TypeGuard2.TNot = TNot;
|
|
272
|
+
function TNull(schema) {
|
|
273
|
+
return TKindOf(schema, "Null") && schema.type === "null" && IsOptionalString(schema.$id);
|
|
274
|
+
}
|
|
275
|
+
TypeGuard2.TNull = TNull;
|
|
276
|
+
function TNumber(schema) {
|
|
277
|
+
return TKindOf(schema, "Number") && schema.type === "number" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.exclusiveMaximum) && IsOptionalNumber(schema.exclusiveMinimum) && IsOptionalNumber(schema.maximum) && IsOptionalNumber(schema.minimum) && IsOptionalNumber(schema.multipleOf);
|
|
278
|
+
}
|
|
279
|
+
TypeGuard2.TNumber = TNumber;
|
|
280
|
+
function TObject(schema) {
|
|
281
|
+
return TKindOf(schema, "Object") && schema.type === "object" && IsOptionalString(schema.$id) && ValueGuard.IsObject(schema.properties) && IsAdditionalProperties(schema.additionalProperties) && IsOptionalNumber(schema.minProperties) && IsOptionalNumber(schema.maxProperties) && Object.entries(schema.properties).every(([key, schema2]) => IsControlCharacterFree(key) && TSchema(schema2));
|
|
282
|
+
}
|
|
283
|
+
TypeGuard2.TObject = TObject;
|
|
284
|
+
function TPromise(schema) {
|
|
285
|
+
return TKindOf(schema, "Promise") && schema.type === "Promise" && IsOptionalString(schema.$id) && TSchema(schema.item);
|
|
286
|
+
}
|
|
287
|
+
TypeGuard2.TPromise = TPromise;
|
|
288
|
+
function TRecord(schema) {
|
|
289
|
+
return TKindOf(schema, "Record") && schema.type === "object" && IsOptionalString(schema.$id) && IsAdditionalProperties(schema.additionalProperties) && ValueGuard.IsObject(schema.patternProperties) && ((schema2) => {
|
|
290
|
+
const keys = Object.getOwnPropertyNames(schema2.patternProperties);
|
|
291
|
+
return keys.length === 1 && IsPattern(keys[0]) && ValueGuard.IsObject(schema2.patternProperties) && TSchema(schema2.patternProperties[keys[0]]);
|
|
292
|
+
})(schema);
|
|
293
|
+
}
|
|
294
|
+
TypeGuard2.TRecord = TRecord;
|
|
295
|
+
function TRecursive(schema) {
|
|
296
|
+
return ValueGuard.IsObject(schema) && exports.Hint in schema && schema[exports.Hint] === "Recursive";
|
|
297
|
+
}
|
|
298
|
+
TypeGuard2.TRecursive = TRecursive;
|
|
299
|
+
function TRef(schema) {
|
|
300
|
+
return TKindOf(schema, "Ref") && IsOptionalString(schema.$id) && ValueGuard.IsString(schema.$ref);
|
|
301
|
+
}
|
|
302
|
+
TypeGuard2.TRef = TRef;
|
|
303
|
+
function TString(schema) {
|
|
304
|
+
return TKindOf(schema, "String") && schema.type === "string" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.minLength) && IsOptionalNumber(schema.maxLength) && IsOptionalPattern(schema.pattern) && IsOptionalFormat(schema.format);
|
|
305
|
+
}
|
|
306
|
+
TypeGuard2.TString = TString;
|
|
307
|
+
function TSymbol(schema) {
|
|
308
|
+
return TKindOf(schema, "Symbol") && schema.type === "symbol" && IsOptionalString(schema.$id);
|
|
309
|
+
}
|
|
310
|
+
TypeGuard2.TSymbol = TSymbol;
|
|
311
|
+
function TTemplateLiteral(schema) {
|
|
312
|
+
return TKindOf(schema, "TemplateLiteral") && schema.type === "string" && ValueGuard.IsString(schema.pattern) && schema.pattern[0] === "^" && schema.pattern[schema.pattern.length - 1] === "$";
|
|
313
|
+
}
|
|
314
|
+
TypeGuard2.TTemplateLiteral = TTemplateLiteral;
|
|
315
|
+
function TThis(schema) {
|
|
316
|
+
return TKindOf(schema, "This") && IsOptionalString(schema.$id) && ValueGuard.IsString(schema.$ref);
|
|
317
|
+
}
|
|
318
|
+
TypeGuard2.TThis = TThis;
|
|
319
|
+
function TTransform(schema) {
|
|
320
|
+
return ValueGuard.IsObject(schema) && exports.Transform in schema;
|
|
321
|
+
}
|
|
322
|
+
TypeGuard2.TTransform = TTransform;
|
|
323
|
+
function TTuple(schema) {
|
|
324
|
+
return TKindOf(schema, "Tuple") && schema.type === "array" && IsOptionalString(schema.$id) && ValueGuard.IsNumber(schema.minItems) && ValueGuard.IsNumber(schema.maxItems) && schema.minItems === schema.maxItems && // empty
|
|
325
|
+
(ValueGuard.IsUndefined(schema.items) && ValueGuard.IsUndefined(schema.additionalItems) && schema.minItems === 0 || ValueGuard.IsArray(schema.items) && schema.items.every((schema2) => TSchema(schema2)));
|
|
326
|
+
}
|
|
327
|
+
TypeGuard2.TTuple = TTuple;
|
|
328
|
+
function TUndefined(schema) {
|
|
329
|
+
return TKindOf(schema, "Undefined") && schema.type === "undefined" && IsOptionalString(schema.$id);
|
|
330
|
+
}
|
|
331
|
+
TypeGuard2.TUndefined = TUndefined;
|
|
332
|
+
function TUnionLiteral(schema) {
|
|
333
|
+
return TUnion(schema) && schema.anyOf.every((schema2) => TLiteralString(schema2) || TLiteralNumber(schema2));
|
|
334
|
+
}
|
|
335
|
+
TypeGuard2.TUnionLiteral = TUnionLiteral;
|
|
336
|
+
function TUnion(schema) {
|
|
337
|
+
return TKindOf(schema, "Union") && IsOptionalString(schema.$id) && ValueGuard.IsObject(schema) && ValueGuard.IsArray(schema.anyOf) && schema.anyOf.every((schema2) => TSchema(schema2));
|
|
338
|
+
}
|
|
339
|
+
TypeGuard2.TUnion = TUnion;
|
|
340
|
+
function TUint8Array(schema) {
|
|
341
|
+
return TKindOf(schema, "Uint8Array") && schema.type === "Uint8Array" && IsOptionalString(schema.$id) && IsOptionalNumber(schema.minByteLength) && IsOptionalNumber(schema.maxByteLength);
|
|
342
|
+
}
|
|
343
|
+
TypeGuard2.TUint8Array = TUint8Array;
|
|
344
|
+
function TUnknown(schema) {
|
|
345
|
+
return TKindOf(schema, "Unknown") && IsOptionalString(schema.$id);
|
|
346
|
+
}
|
|
347
|
+
TypeGuard2.TUnknown = TUnknown;
|
|
348
|
+
function TUnsafe(schema) {
|
|
349
|
+
return TKindOf(schema, "Unsafe");
|
|
350
|
+
}
|
|
351
|
+
TypeGuard2.TUnsafe = TUnsafe;
|
|
352
|
+
function TVoid(schema) {
|
|
353
|
+
return TKindOf(schema, "Void") && schema.type === "void" && IsOptionalString(schema.$id);
|
|
354
|
+
}
|
|
355
|
+
TypeGuard2.TVoid = TVoid;
|
|
356
|
+
function TReadonly(schema) {
|
|
357
|
+
return ValueGuard.IsObject(schema) && schema[exports.Readonly] === "Readonly";
|
|
358
|
+
}
|
|
359
|
+
TypeGuard2.TReadonly = TReadonly;
|
|
360
|
+
function TOptional(schema) {
|
|
361
|
+
return ValueGuard.IsObject(schema) && schema[exports.Optional] === "Optional";
|
|
362
|
+
}
|
|
363
|
+
TypeGuard2.TOptional = TOptional;
|
|
364
|
+
function TSchema(schema) {
|
|
365
|
+
return ValueGuard.IsObject(schema) && (TAny(schema) || TArray(schema) || TBoolean(schema) || TBigInt(schema) || TAsyncIterator(schema) || TConstructor(schema) || TDate(schema) || TFunction(schema) || TInteger(schema) || TIntersect(schema) || TIterator(schema) || TLiteral(schema) || TNever(schema) || TNot(schema) || TNull(schema) || TNumber(schema) || TObject(schema) || TPromise(schema) || TRecord(schema) || TRef(schema) || TString(schema) || TSymbol(schema) || TTemplateLiteral(schema) || TThis(schema) || TTuple(schema) || TUndefined(schema) || TUnion(schema) || TUint8Array(schema) || TUnknown(schema) || TUnsafe(schema) || TVoid(schema) || TKind(schema) && TypeRegistry.Has(schema[exports.Kind]));
|
|
366
|
+
}
|
|
367
|
+
TypeGuard2.TSchema = TSchema;
|
|
368
|
+
})(TypeGuard || (exports.TypeGuard = TypeGuard = {}));
|
|
369
|
+
var ExtendsUndefined;
|
|
370
|
+
(function(ExtendsUndefined2) {
|
|
371
|
+
function Check(schema) {
|
|
372
|
+
return schema[exports.Kind] === "Intersect" ? schema.allOf.every((schema2) => Check(schema2)) : schema[exports.Kind] === "Union" ? schema.anyOf.some((schema2) => Check(schema2)) : schema[exports.Kind] === "Undefined" ? true : schema[exports.Kind] === "Not" ? !Check(schema.not) : false;
|
|
373
|
+
}
|
|
374
|
+
ExtendsUndefined2.Check = Check;
|
|
375
|
+
})(ExtendsUndefined || (exports.ExtendsUndefined = ExtendsUndefined = {}));
|
|
376
|
+
var TypeExtendsError = class extends TypeBoxError {
|
|
377
|
+
};
|
|
378
|
+
exports.TypeExtendsError = TypeExtendsError;
|
|
379
|
+
var TypeExtendsResult;
|
|
380
|
+
(function(TypeExtendsResult2) {
|
|
381
|
+
TypeExtendsResult2[TypeExtendsResult2["Union"] = 0] = "Union";
|
|
382
|
+
TypeExtendsResult2[TypeExtendsResult2["True"] = 1] = "True";
|
|
383
|
+
TypeExtendsResult2[TypeExtendsResult2["False"] = 2] = "False";
|
|
384
|
+
})(TypeExtendsResult || (exports.TypeExtendsResult = TypeExtendsResult = {}));
|
|
385
|
+
var TypeExtends;
|
|
386
|
+
(function(TypeExtends2) {
|
|
387
|
+
function IntoBooleanResult(result) {
|
|
388
|
+
return result === TypeExtendsResult.False ? result : TypeExtendsResult.True;
|
|
389
|
+
}
|
|
390
|
+
function Throw(message) {
|
|
391
|
+
throw new TypeExtendsError(message);
|
|
392
|
+
}
|
|
393
|
+
function IsStructuralRight(right) {
|
|
394
|
+
return TypeGuard.TNever(right) || TypeGuard.TIntersect(right) || TypeGuard.TUnion(right) || TypeGuard.TUnknown(right) || TypeGuard.TAny(right);
|
|
395
|
+
}
|
|
396
|
+
function StructuralRight(left, right) {
|
|
397
|
+
return TypeGuard.TNever(right) ? TNeverRight() : TypeGuard.TIntersect(right) ? TIntersectRight(left, right) : TypeGuard.TUnion(right) ? TUnionRight(left, right) : TypeGuard.TUnknown(right) ? TUnknownRight() : TypeGuard.TAny(right) ? TAnyRight() : Throw("StructuralRight");
|
|
398
|
+
}
|
|
399
|
+
function TAnyRight(left, right) {
|
|
400
|
+
return TypeExtendsResult.True;
|
|
401
|
+
}
|
|
402
|
+
function TAny(left, right) {
|
|
403
|
+
return TypeGuard.TIntersect(right) ? TIntersectRight(left, right) : TypeGuard.TUnion(right) && right.anyOf.some((schema) => TypeGuard.TAny(schema) || TypeGuard.TUnknown(schema)) ? TypeExtendsResult.True : TypeGuard.TUnion(right) ? TypeExtendsResult.Union : TypeGuard.TUnknown(right) ? TypeExtendsResult.True : TypeGuard.TAny(right) ? TypeExtendsResult.True : TypeExtendsResult.Union;
|
|
404
|
+
}
|
|
405
|
+
function TArrayRight(left, right) {
|
|
406
|
+
return TypeGuard.TUnknown(left) ? TypeExtendsResult.False : TypeGuard.TAny(left) ? TypeExtendsResult.Union : TypeGuard.TNever(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
407
|
+
}
|
|
408
|
+
function TArray(left, right) {
|
|
409
|
+
return TypeGuard.TObject(right) && IsObjectArrayLike(right) ? TypeExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TArray(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
|
|
410
|
+
}
|
|
411
|
+
function TAsyncIterator(left, right) {
|
|
412
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TAsyncIterator(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
|
|
413
|
+
}
|
|
414
|
+
function TBigInt(left, right) {
|
|
415
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TBigInt(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
416
|
+
}
|
|
417
|
+
function TBooleanRight(left, right) {
|
|
418
|
+
return TypeGuard.TLiteral(left) && ValueGuard.IsBoolean(left.const) ? TypeExtendsResult.True : TypeGuard.TBoolean(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
419
|
+
}
|
|
420
|
+
function TBoolean(left, right) {
|
|
421
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TBoolean(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
422
|
+
}
|
|
423
|
+
function TConstructor(left, right) {
|
|
424
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : !TypeGuard.TConstructor(right) ? TypeExtendsResult.False : left.parameters.length > right.parameters.length ? TypeExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.returns, right.returns));
|
|
425
|
+
}
|
|
426
|
+
function TDate(left, right) {
|
|
427
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TDate(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
428
|
+
}
|
|
429
|
+
function TFunction(left, right) {
|
|
430
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : !TypeGuard.TFunction(right) ? TypeExtendsResult.False : left.parameters.length > right.parameters.length ? TypeExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit(right.parameters[index], schema)) === TypeExtendsResult.True) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.returns, right.returns));
|
|
431
|
+
}
|
|
432
|
+
function TIntegerRight(left, right) {
|
|
433
|
+
return TypeGuard.TLiteral(left) && ValueGuard.IsNumber(left.const) ? TypeExtendsResult.True : TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
434
|
+
}
|
|
435
|
+
function TInteger(left, right) {
|
|
436
|
+
return TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeExtendsResult.False;
|
|
437
|
+
}
|
|
438
|
+
function TIntersectRight(left, right) {
|
|
439
|
+
return right.allOf.every((schema) => Visit(left, schema) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
440
|
+
}
|
|
441
|
+
function TIntersect(left, right) {
|
|
442
|
+
return left.allOf.some((schema) => Visit(schema, right) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
443
|
+
}
|
|
444
|
+
function TIterator(left, right) {
|
|
445
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : !TypeGuard.TIterator(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.items, right.items));
|
|
446
|
+
}
|
|
447
|
+
function TLiteral(left, right) {
|
|
448
|
+
return TypeGuard.TLiteral(right) && right.const === left.const ? TypeExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TString(right) ? TStringRight(left) : TypeGuard.TNumber(right) ? TNumberRight(left) : TypeGuard.TInteger(right) ? TIntegerRight(left) : TypeGuard.TBoolean(right) ? TBooleanRight(left) : TypeExtendsResult.False;
|
|
449
|
+
}
|
|
450
|
+
function TNeverRight(left, right) {
|
|
451
|
+
return TypeExtendsResult.False;
|
|
452
|
+
}
|
|
453
|
+
function TNever(left, right) {
|
|
454
|
+
return TypeExtendsResult.True;
|
|
455
|
+
}
|
|
456
|
+
function UnwrapTNot(schema) {
|
|
457
|
+
let [current, depth] = [schema, 0];
|
|
458
|
+
while (true) {
|
|
459
|
+
if (!TypeGuard.TNot(current))
|
|
460
|
+
break;
|
|
461
|
+
current = current.not;
|
|
462
|
+
depth += 1;
|
|
463
|
+
}
|
|
464
|
+
return depth % 2 === 0 ? current : exports.Type.Unknown();
|
|
465
|
+
}
|
|
466
|
+
function TNot(left, right) {
|
|
467
|
+
return TypeGuard.TNot(left) ? Visit(UnwrapTNot(left), right) : TypeGuard.TNot(right) ? Visit(left, UnwrapTNot(right)) : Throw("Invalid fallthrough for Not");
|
|
468
|
+
}
|
|
469
|
+
function TNull(left, right) {
|
|
470
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TNull(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
471
|
+
}
|
|
472
|
+
function TNumberRight(left, right) {
|
|
473
|
+
return TypeGuard.TLiteralNumber(left) ? TypeExtendsResult.True : TypeGuard.TNumber(left) || TypeGuard.TInteger(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
474
|
+
}
|
|
475
|
+
function TNumber(left, right) {
|
|
476
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TInteger(right) || TypeGuard.TNumber(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
477
|
+
}
|
|
478
|
+
function IsObjectPropertyCount(schema, count) {
|
|
479
|
+
return Object.getOwnPropertyNames(schema.properties).length === count;
|
|
480
|
+
}
|
|
481
|
+
function IsObjectStringLike(schema) {
|
|
482
|
+
return IsObjectArrayLike(schema);
|
|
483
|
+
}
|
|
484
|
+
function IsObjectSymbolLike(schema) {
|
|
485
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "description" in schema.properties && TypeGuard.TUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && (TypeGuard.TString(schema.properties.description.anyOf[0]) && TypeGuard.TUndefined(schema.properties.description.anyOf[1]) || TypeGuard.TString(schema.properties.description.anyOf[1]) && TypeGuard.TUndefined(schema.properties.description.anyOf[0]));
|
|
486
|
+
}
|
|
487
|
+
function IsObjectNumberLike(schema) {
|
|
488
|
+
return IsObjectPropertyCount(schema, 0);
|
|
489
|
+
}
|
|
490
|
+
function IsObjectBooleanLike(schema) {
|
|
491
|
+
return IsObjectPropertyCount(schema, 0);
|
|
492
|
+
}
|
|
493
|
+
function IsObjectBigIntLike(schema) {
|
|
494
|
+
return IsObjectPropertyCount(schema, 0);
|
|
495
|
+
}
|
|
496
|
+
function IsObjectDateLike(schema) {
|
|
497
|
+
return IsObjectPropertyCount(schema, 0);
|
|
498
|
+
}
|
|
499
|
+
function IsObjectUint8ArrayLike(schema) {
|
|
500
|
+
return IsObjectArrayLike(schema);
|
|
501
|
+
}
|
|
502
|
+
function IsObjectFunctionLike(schema) {
|
|
503
|
+
const length = exports.Type.Number();
|
|
504
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit(schema.properties["length"], length)) === TypeExtendsResult.True;
|
|
505
|
+
}
|
|
506
|
+
function IsObjectConstructorLike(schema) {
|
|
507
|
+
return IsObjectPropertyCount(schema, 0);
|
|
508
|
+
}
|
|
509
|
+
function IsObjectArrayLike(schema) {
|
|
510
|
+
const length = exports.Type.Number();
|
|
511
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit(schema.properties["length"], length)) === TypeExtendsResult.True;
|
|
512
|
+
}
|
|
513
|
+
function IsObjectPromiseLike(schema) {
|
|
514
|
+
const then = exports.Type.Function([exports.Type.Any()], exports.Type.Any());
|
|
515
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "then" in schema.properties && IntoBooleanResult(Visit(schema.properties["then"], then)) === TypeExtendsResult.True;
|
|
516
|
+
}
|
|
517
|
+
function Property(left, right) {
|
|
518
|
+
return Visit(left, right) === TypeExtendsResult.False ? TypeExtendsResult.False : TypeGuard.TOptional(left) && !TypeGuard.TOptional(right) ? TypeExtendsResult.False : TypeExtendsResult.True;
|
|
519
|
+
}
|
|
520
|
+
function TObjectRight(left, right) {
|
|
521
|
+
return TypeGuard.TUnknown(left) ? TypeExtendsResult.False : TypeGuard.TAny(left) ? TypeExtendsResult.Union : TypeGuard.TNever(left) || TypeGuard.TLiteralString(left) && IsObjectStringLike(right) || TypeGuard.TLiteralNumber(left) && IsObjectNumberLike(right) || TypeGuard.TLiteralBoolean(left) && IsObjectBooleanLike(right) || TypeGuard.TSymbol(left) && IsObjectSymbolLike(right) || TypeGuard.TBigInt(left) && IsObjectBigIntLike(right) || TypeGuard.TString(left) && IsObjectStringLike(right) || TypeGuard.TSymbol(left) && IsObjectSymbolLike(right) || TypeGuard.TNumber(left) && IsObjectNumberLike(right) || TypeGuard.TInteger(left) && IsObjectNumberLike(right) || TypeGuard.TBoolean(left) && IsObjectBooleanLike(right) || TypeGuard.TUint8Array(left) && IsObjectUint8ArrayLike(right) || TypeGuard.TDate(left) && IsObjectDateLike(right) || TypeGuard.TConstructor(left) && IsObjectConstructorLike(right) || TypeGuard.TFunction(left) && IsObjectFunctionLike(right) ? TypeExtendsResult.True : TypeGuard.TRecord(left) && TypeGuard.TString(RecordKey(left)) ? (() => {
|
|
522
|
+
return right[exports.Hint] === "Record" ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
523
|
+
})() : TypeGuard.TRecord(left) && TypeGuard.TNumber(RecordKey(left)) ? (() => {
|
|
524
|
+
return IsObjectPropertyCount(right, 0) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
525
|
+
})() : TypeExtendsResult.False;
|
|
526
|
+
}
|
|
527
|
+
function TObject(left, right) {
|
|
528
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : !TypeGuard.TObject(right) ? TypeExtendsResult.False : (() => {
|
|
529
|
+
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
530
|
+
if (!(key in left.properties) && !TypeGuard.TOptional(right.properties[key])) {
|
|
531
|
+
return TypeExtendsResult.False;
|
|
532
|
+
}
|
|
533
|
+
if (TypeGuard.TOptional(right.properties[key])) {
|
|
534
|
+
return TypeExtendsResult.True;
|
|
535
|
+
}
|
|
536
|
+
if (Property(left.properties[key], right.properties[key]) === TypeExtendsResult.False) {
|
|
537
|
+
return TypeExtendsResult.False;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
return TypeExtendsResult.True;
|
|
541
|
+
})();
|
|
542
|
+
}
|
|
543
|
+
function TPromise(left, right) {
|
|
544
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) && IsObjectPromiseLike(right) ? TypeExtendsResult.True : !TypeGuard.TPromise(right) ? TypeExtendsResult.False : IntoBooleanResult(Visit(left.item, right.item));
|
|
545
|
+
}
|
|
546
|
+
function RecordKey(schema) {
|
|
547
|
+
return exports.PatternNumberExact in schema.patternProperties ? exports.Type.Number() : exports.PatternStringExact in schema.patternProperties ? exports.Type.String() : Throw("Unknown record key pattern");
|
|
548
|
+
}
|
|
549
|
+
function RecordValue(schema) {
|
|
550
|
+
return exports.PatternNumberExact in schema.patternProperties ? schema.patternProperties[exports.PatternNumberExact] : exports.PatternStringExact in schema.patternProperties ? schema.patternProperties[exports.PatternStringExact] : Throw("Unable to get record value schema");
|
|
551
|
+
}
|
|
552
|
+
function TRecordRight(left, right) {
|
|
553
|
+
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
554
|
+
return TypeGuard.TLiteralString(left) && TypeGuard.TNumber(Key) && IntoBooleanResult(Visit(left, Value)) === TypeExtendsResult.True ? TypeExtendsResult.True : TypeGuard.TUint8Array(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) : TypeGuard.TString(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) : TypeGuard.TArray(left) && TypeGuard.TNumber(Key) ? Visit(left, Value) : TypeGuard.TObject(left) ? (() => {
|
|
555
|
+
for (const key of Object.getOwnPropertyNames(left.properties)) {
|
|
556
|
+
if (Property(Value, left.properties[key]) === TypeExtendsResult.False) {
|
|
557
|
+
return TypeExtendsResult.False;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return TypeExtendsResult.True;
|
|
561
|
+
})() : TypeExtendsResult.False;
|
|
562
|
+
}
|
|
563
|
+
function TRecord(left, right) {
|
|
564
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : !TypeGuard.TRecord(right) ? TypeExtendsResult.False : Visit(RecordValue(left), RecordValue(right));
|
|
565
|
+
}
|
|
566
|
+
function TStringRight(left, right) {
|
|
567
|
+
return TypeGuard.TLiteral(left) && ValueGuard.IsString(left.const) ? TypeExtendsResult.True : TypeGuard.TString(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
568
|
+
}
|
|
569
|
+
function TString(left, right) {
|
|
570
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TString(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
571
|
+
}
|
|
572
|
+
function TSymbol(left, right) {
|
|
573
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TSymbol(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
574
|
+
}
|
|
575
|
+
function TTemplateLiteral(left, right) {
|
|
576
|
+
return TypeGuard.TTemplateLiteral(left) ? Visit(TemplateLiteralResolver.Resolve(left), right) : TypeGuard.TTemplateLiteral(right) ? Visit(left, TemplateLiteralResolver.Resolve(right)) : Throw("Invalid fallthrough for TemplateLiteral");
|
|
577
|
+
}
|
|
578
|
+
function IsArrayOfTuple(left, right) {
|
|
579
|
+
return TypeGuard.TArray(right) && left.items !== void 0 && left.items.every((schema) => Visit(schema, right.items) === TypeExtendsResult.True);
|
|
580
|
+
}
|
|
581
|
+
function TTupleRight(left, right) {
|
|
582
|
+
return TypeGuard.TNever(left) ? TypeExtendsResult.True : TypeGuard.TUnknown(left) ? TypeExtendsResult.False : TypeGuard.TAny(left) ? TypeExtendsResult.Union : TypeExtendsResult.False;
|
|
583
|
+
}
|
|
584
|
+
function TTuple(left, right) {
|
|
585
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) && IsObjectArrayLike(right) ? TypeExtendsResult.True : TypeGuard.TArray(right) && IsArrayOfTuple(left, right) ? TypeExtendsResult.True : !TypeGuard.TTuple(right) ? TypeExtendsResult.False : ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items) || !ValueGuard.IsUndefined(left.items) && ValueGuard.IsUndefined(right.items) ? TypeExtendsResult.False : ValueGuard.IsUndefined(left.items) && !ValueGuard.IsUndefined(right.items) ? TypeExtendsResult.True : left.items.every((schema, index) => Visit(schema, right.items[index]) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
586
|
+
}
|
|
587
|
+
function TUint8Array(left, right) {
|
|
588
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TUint8Array(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
589
|
+
}
|
|
590
|
+
function TUndefined(left, right) {
|
|
591
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TRecord(right) ? TRecordRight(left, right) : TypeGuard.TVoid(right) ? VoidRight(left) : TypeGuard.TUndefined(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
592
|
+
}
|
|
593
|
+
function TUnionRight(left, right) {
|
|
594
|
+
return right.anyOf.some((schema) => Visit(left, schema) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
595
|
+
}
|
|
596
|
+
function TUnion(left, right) {
|
|
597
|
+
return left.anyOf.every((schema) => Visit(schema, right) === TypeExtendsResult.True) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
598
|
+
}
|
|
599
|
+
function TUnknownRight(left, right) {
|
|
600
|
+
return TypeExtendsResult.True;
|
|
601
|
+
}
|
|
602
|
+
function TUnknown(left, right) {
|
|
603
|
+
return TypeGuard.TNever(right) ? TNeverRight() : TypeGuard.TIntersect(right) ? TIntersectRight(left, right) : TypeGuard.TUnion(right) ? TUnionRight(left, right) : TypeGuard.TAny(right) ? TAnyRight() : TypeGuard.TString(right) ? TStringRight(left) : TypeGuard.TNumber(right) ? TNumberRight(left) : TypeGuard.TInteger(right) ? TIntegerRight(left) : TypeGuard.TBoolean(right) ? TBooleanRight(left) : TypeGuard.TArray(right) ? TArrayRight(left) : TypeGuard.TTuple(right) ? TTupleRight(left) : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TUnknown(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
604
|
+
}
|
|
605
|
+
function VoidRight(left, right) {
|
|
606
|
+
return TypeGuard.TUndefined(left) ? TypeExtendsResult.True : TypeGuard.TUndefined(left) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
607
|
+
}
|
|
608
|
+
function TVoid(left, right) {
|
|
609
|
+
return TypeGuard.TIntersect(right) ? TIntersectRight(left, right) : TypeGuard.TUnion(right) ? TUnionRight(left, right) : TypeGuard.TUnknown(right) ? TUnknownRight() : TypeGuard.TAny(right) ? TAnyRight() : TypeGuard.TObject(right) ? TObjectRight(left, right) : TypeGuard.TVoid(right) ? TypeExtendsResult.True : TypeExtendsResult.False;
|
|
610
|
+
}
|
|
611
|
+
function Visit(left, right) {
|
|
612
|
+
return (
|
|
613
|
+
// resolvable
|
|
614
|
+
TypeGuard.TTemplateLiteral(left) || TypeGuard.TTemplateLiteral(right) ? TTemplateLiteral(left, right) : TypeGuard.TNot(left) || TypeGuard.TNot(right) ? TNot(left, right) : (
|
|
615
|
+
// standard
|
|
616
|
+
TypeGuard.TAny(left) ? TAny(left, right) : TypeGuard.TArray(left) ? TArray(left, right) : TypeGuard.TBigInt(left) ? TBigInt(left, right) : TypeGuard.TBoolean(left) ? TBoolean(left, right) : TypeGuard.TAsyncIterator(left) ? TAsyncIterator(left, right) : TypeGuard.TConstructor(left) ? TConstructor(left, right) : TypeGuard.TDate(left) ? TDate(left, right) : TypeGuard.TFunction(left) ? TFunction(left, right) : TypeGuard.TInteger(left) ? TInteger(left, right) : TypeGuard.TIntersect(left) ? TIntersect(left, right) : TypeGuard.TIterator(left) ? TIterator(left, right) : TypeGuard.TLiteral(left) ? TLiteral(left, right) : TypeGuard.TNever(left) ? TNever() : TypeGuard.TNull(left) ? TNull(left, right) : TypeGuard.TNumber(left) ? TNumber(left, right) : TypeGuard.TObject(left) ? TObject(left, right) : TypeGuard.TRecord(left) ? TRecord(left, right) : TypeGuard.TString(left) ? TString(left, right) : TypeGuard.TSymbol(left) ? TSymbol(left, right) : TypeGuard.TTuple(left) ? TTuple(left, right) : TypeGuard.TPromise(left) ? TPromise(left, right) : TypeGuard.TUint8Array(left) ? TUint8Array(left, right) : TypeGuard.TUndefined(left) ? TUndefined(left, right) : TypeGuard.TUnion(left) ? TUnion(left, right) : TypeGuard.TUnknown(left) ? TUnknown(left, right) : TypeGuard.TVoid(left) ? TVoid(left, right) : Throw(`Unknown left type operand '${left[exports.Kind]}'`)
|
|
617
|
+
)
|
|
618
|
+
);
|
|
619
|
+
}
|
|
620
|
+
function Extends(left, right) {
|
|
621
|
+
return Visit(left, right);
|
|
622
|
+
}
|
|
623
|
+
TypeExtends2.Extends = Extends;
|
|
624
|
+
})(TypeExtends || (exports.TypeExtends = TypeExtends = {}));
|
|
625
|
+
var TypeClone;
|
|
626
|
+
(function(TypeClone2) {
|
|
627
|
+
function ArrayType(value) {
|
|
628
|
+
return value.map((value2) => Visit(value2));
|
|
629
|
+
}
|
|
630
|
+
function DateType(value) {
|
|
631
|
+
return new Date(value.getTime());
|
|
632
|
+
}
|
|
633
|
+
function Uint8ArrayType(value) {
|
|
634
|
+
return new Uint8Array(value);
|
|
635
|
+
}
|
|
636
|
+
function ObjectType(value) {
|
|
637
|
+
const clonedProperties = Object.getOwnPropertyNames(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
|
|
638
|
+
const clonedSymbols = Object.getOwnPropertySymbols(value).reduce((acc, key) => ({ ...acc, [key]: Visit(value[key]) }), {});
|
|
639
|
+
return { ...clonedProperties, ...clonedSymbols };
|
|
640
|
+
}
|
|
641
|
+
function Visit(value) {
|
|
642
|
+
return ValueGuard.IsArray(value) ? ArrayType(value) : ValueGuard.IsDate(value) ? DateType(value) : ValueGuard.IsUint8Array(value) ? Uint8ArrayType(value) : ValueGuard.IsObject(value) ? ObjectType(value) : value;
|
|
643
|
+
}
|
|
644
|
+
function Rest(schemas) {
|
|
645
|
+
return schemas.map((schema) => Type2(schema));
|
|
646
|
+
}
|
|
647
|
+
TypeClone2.Rest = Rest;
|
|
648
|
+
function Type2(schema, options = {}) {
|
|
649
|
+
return { ...Visit(schema), ...options };
|
|
650
|
+
}
|
|
651
|
+
TypeClone2.Type = Type2;
|
|
652
|
+
})(TypeClone || (exports.TypeClone = TypeClone = {}));
|
|
653
|
+
var IndexedAccessor;
|
|
654
|
+
(function(IndexedAccessor2) {
|
|
655
|
+
function OptionalUnwrap(schema) {
|
|
656
|
+
return schema.map((schema2) => {
|
|
657
|
+
const { [exports.Optional]: _, ...clone } = TypeClone.Type(schema2);
|
|
658
|
+
return clone;
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
function IsIntersectOptional(schema) {
|
|
662
|
+
return schema.every((schema2) => TypeGuard.TOptional(schema2));
|
|
663
|
+
}
|
|
664
|
+
function IsUnionOptional(schema) {
|
|
665
|
+
return schema.some((schema2) => TypeGuard.TOptional(schema2));
|
|
666
|
+
}
|
|
667
|
+
function ResolveIntersect(schema) {
|
|
668
|
+
return IsIntersectOptional(schema.allOf) ? exports.Type.Optional(exports.Type.Intersect(OptionalUnwrap(schema.allOf))) : schema;
|
|
669
|
+
}
|
|
670
|
+
function ResolveUnion(schema) {
|
|
671
|
+
return IsUnionOptional(schema.anyOf) ? exports.Type.Optional(exports.Type.Union(OptionalUnwrap(schema.anyOf))) : schema;
|
|
672
|
+
}
|
|
673
|
+
function ResolveOptional(schema) {
|
|
674
|
+
return schema[exports.Kind] === "Intersect" ? ResolveIntersect(schema) : schema[exports.Kind] === "Union" ? ResolveUnion(schema) : schema;
|
|
675
|
+
}
|
|
676
|
+
function TIntersect(schema, key) {
|
|
677
|
+
const resolved = schema.allOf.reduce((acc, schema2) => {
|
|
678
|
+
const indexed = Visit(schema2, key);
|
|
679
|
+
return indexed[exports.Kind] === "Never" ? acc : [...acc, indexed];
|
|
680
|
+
}, []);
|
|
681
|
+
return ResolveOptional(exports.Type.Intersect(resolved));
|
|
682
|
+
}
|
|
683
|
+
function TUnion(schema, key) {
|
|
684
|
+
const resolved = schema.anyOf.map((schema2) => Visit(schema2, key));
|
|
685
|
+
return ResolveOptional(exports.Type.Union(resolved));
|
|
686
|
+
}
|
|
687
|
+
function TObject(schema, key) {
|
|
688
|
+
const property = schema.properties[key];
|
|
689
|
+
return ValueGuard.IsUndefined(property) ? exports.Type.Never() : exports.Type.Union([property]);
|
|
690
|
+
}
|
|
691
|
+
function TTuple(schema, key) {
|
|
692
|
+
const items = schema.items;
|
|
693
|
+
if (ValueGuard.IsUndefined(items))
|
|
694
|
+
return exports.Type.Never();
|
|
695
|
+
const element = items[key];
|
|
696
|
+
if (ValueGuard.IsUndefined(element))
|
|
697
|
+
return exports.Type.Never();
|
|
698
|
+
return element;
|
|
699
|
+
}
|
|
700
|
+
function Visit(schema, key) {
|
|
701
|
+
return schema[exports.Kind] === "Intersect" ? TIntersect(schema, key) : schema[exports.Kind] === "Union" ? TUnion(schema, key) : schema[exports.Kind] === "Object" ? TObject(schema, key) : schema[exports.Kind] === "Tuple" ? TTuple(schema, key) : exports.Type.Never();
|
|
702
|
+
}
|
|
703
|
+
function Resolve(schema, keys, options = {}) {
|
|
704
|
+
const resolved = keys.map((key) => Visit(schema, key.toString()));
|
|
705
|
+
return ResolveOptional(exports.Type.Union(resolved, options));
|
|
706
|
+
}
|
|
707
|
+
IndexedAccessor2.Resolve = Resolve;
|
|
708
|
+
})(IndexedAccessor || (exports.IndexedAccessor = IndexedAccessor = {}));
|
|
709
|
+
var Intrinsic;
|
|
710
|
+
(function(Intrinsic2) {
|
|
711
|
+
function Uncapitalize(value) {
|
|
712
|
+
const [first, rest] = [value.slice(0, 1), value.slice(1)];
|
|
713
|
+
return `${first.toLowerCase()}${rest}`;
|
|
714
|
+
}
|
|
715
|
+
function Capitalize(value) {
|
|
716
|
+
const [first, rest] = [value.slice(0, 1), value.slice(1)];
|
|
717
|
+
return `${first.toUpperCase()}${rest}`;
|
|
718
|
+
}
|
|
719
|
+
function Uppercase(value) {
|
|
720
|
+
return value.toUpperCase();
|
|
721
|
+
}
|
|
722
|
+
function Lowercase(value) {
|
|
723
|
+
return value.toLowerCase();
|
|
724
|
+
}
|
|
725
|
+
function IntrinsicTemplateLiteral(schema, mode) {
|
|
726
|
+
const expression = TemplateLiteralParser.ParseExact(schema.pattern);
|
|
727
|
+
const finite = TemplateLiteralFinite.Check(expression);
|
|
728
|
+
if (!finite)
|
|
729
|
+
return { ...schema, pattern: IntrinsicLiteral(schema.pattern, mode) };
|
|
730
|
+
const strings = [...TemplateLiteralGenerator.Generate(expression)];
|
|
731
|
+
const literals = strings.map((value) => exports.Type.Literal(value));
|
|
732
|
+
const mapped = IntrinsicRest(literals, mode);
|
|
733
|
+
const union = exports.Type.Union(mapped);
|
|
734
|
+
return exports.Type.TemplateLiteral([union]);
|
|
735
|
+
}
|
|
736
|
+
function IntrinsicLiteral(value, mode) {
|
|
737
|
+
return typeof value === "string" ? mode === "Uncapitalize" ? Uncapitalize(value) : mode === "Capitalize" ? Capitalize(value) : mode === "Uppercase" ? Uppercase(value) : mode === "Lowercase" ? Lowercase(value) : value : value.toString();
|
|
738
|
+
}
|
|
739
|
+
function IntrinsicRest(schema, mode) {
|
|
740
|
+
if (schema.length === 0)
|
|
741
|
+
return [];
|
|
742
|
+
const [L, ...R] = schema;
|
|
743
|
+
return [Map2(L, mode), ...IntrinsicRest(R, mode)];
|
|
744
|
+
}
|
|
745
|
+
function Visit(schema, mode) {
|
|
746
|
+
return TypeGuard.TTemplateLiteral(schema) ? IntrinsicTemplateLiteral(schema, mode) : TypeGuard.TUnion(schema) ? exports.Type.Union(IntrinsicRest(schema.anyOf, mode)) : TypeGuard.TLiteral(schema) ? exports.Type.Literal(IntrinsicLiteral(schema.const, mode)) : schema;
|
|
747
|
+
}
|
|
748
|
+
function Map2(schema, mode) {
|
|
749
|
+
return Visit(schema, mode);
|
|
750
|
+
}
|
|
751
|
+
Intrinsic2.Map = Map2;
|
|
752
|
+
})(Intrinsic || (exports.Intrinsic = Intrinsic = {}));
|
|
753
|
+
var ObjectMap;
|
|
754
|
+
(function(ObjectMap2) {
|
|
755
|
+
function TIntersect(schema, callback) {
|
|
756
|
+
return exports.Type.Intersect(schema.allOf.map((inner) => Visit(inner, callback)), { ...schema });
|
|
757
|
+
}
|
|
758
|
+
function TUnion(schema, callback) {
|
|
759
|
+
return exports.Type.Union(schema.anyOf.map((inner) => Visit(inner, callback)), { ...schema });
|
|
760
|
+
}
|
|
761
|
+
function TObject(schema, callback) {
|
|
762
|
+
return callback(schema);
|
|
763
|
+
}
|
|
764
|
+
function Visit(schema, callback) {
|
|
765
|
+
return schema[exports.Kind] === "Intersect" ? TIntersect(schema, callback) : schema[exports.Kind] === "Union" ? TUnion(schema, callback) : schema[exports.Kind] === "Object" ? TObject(schema, callback) : schema;
|
|
766
|
+
}
|
|
767
|
+
function Map2(schema, callback, options) {
|
|
768
|
+
return { ...Visit(TypeClone.Type(schema), callback), ...options };
|
|
769
|
+
}
|
|
770
|
+
ObjectMap2.Map = Map2;
|
|
771
|
+
})(ObjectMap || (exports.ObjectMap = ObjectMap = {}));
|
|
772
|
+
var KeyResolver;
|
|
773
|
+
(function(KeyResolver2) {
|
|
774
|
+
function UnwrapPattern(key) {
|
|
775
|
+
return key[0] === "^" && key[key.length - 1] === "$" ? key.slice(1, key.length - 1) : key;
|
|
776
|
+
}
|
|
777
|
+
function TIntersect(schema, options) {
|
|
778
|
+
return schema.allOf.reduce((acc, schema2) => [...acc, ...Visit(schema2, options)], []);
|
|
779
|
+
}
|
|
780
|
+
function TUnion(schema, options) {
|
|
781
|
+
const sets = schema.anyOf.map((inner) => Visit(inner, options));
|
|
782
|
+
return [...sets.reduce((set, outer) => outer.map((key) => sets.every((inner) => inner.includes(key)) ? set.add(key) : set)[0], /* @__PURE__ */ new Set())];
|
|
783
|
+
}
|
|
784
|
+
function TObject(schema, options) {
|
|
785
|
+
return Object.getOwnPropertyNames(schema.properties);
|
|
786
|
+
}
|
|
787
|
+
function TRecord(schema, options) {
|
|
788
|
+
return options.includePatterns ? Object.getOwnPropertyNames(schema.patternProperties) : [];
|
|
789
|
+
}
|
|
790
|
+
function Visit(schema, options) {
|
|
791
|
+
return TypeGuard.TIntersect(schema) ? TIntersect(schema, options) : TypeGuard.TUnion(schema) ? TUnion(schema, options) : TypeGuard.TObject(schema) ? TObject(schema) : TypeGuard.TRecord(schema) ? TRecord(schema, options) : [];
|
|
792
|
+
}
|
|
793
|
+
function ResolveKeys(schema, options) {
|
|
794
|
+
return [...new Set(Visit(schema, options))];
|
|
795
|
+
}
|
|
796
|
+
KeyResolver2.ResolveKeys = ResolveKeys;
|
|
797
|
+
function ResolvePattern(schema) {
|
|
798
|
+
const keys = ResolveKeys(schema, { includePatterns: true });
|
|
799
|
+
const pattern = keys.map((key) => `(${UnwrapPattern(key)})`);
|
|
800
|
+
return `^(${pattern.join("|")})$`;
|
|
801
|
+
}
|
|
802
|
+
KeyResolver2.ResolvePattern = ResolvePattern;
|
|
803
|
+
})(KeyResolver || (exports.KeyResolver = KeyResolver = {}));
|
|
804
|
+
var KeyArrayResolverError = class extends TypeBoxError {
|
|
805
|
+
};
|
|
806
|
+
exports.KeyArrayResolverError = KeyArrayResolverError;
|
|
807
|
+
var KeyArrayResolver;
|
|
808
|
+
(function(KeyArrayResolver2) {
|
|
809
|
+
function Resolve(schema) {
|
|
810
|
+
return Array.isArray(schema) ? schema : TypeGuard.TUnionLiteral(schema) ? schema.anyOf.map((schema2) => schema2.const.toString()) : TypeGuard.TLiteral(schema) ? [schema.const] : TypeGuard.TTemplateLiteral(schema) ? (() => {
|
|
811
|
+
const expression = TemplateLiteralParser.ParseExact(schema.pattern);
|
|
812
|
+
if (!TemplateLiteralFinite.Check(expression))
|
|
813
|
+
throw new KeyArrayResolverError("Cannot resolve keys from infinite template expression");
|
|
814
|
+
return [...TemplateLiteralGenerator.Generate(expression)];
|
|
815
|
+
})() : [];
|
|
816
|
+
}
|
|
817
|
+
KeyArrayResolver2.Resolve = Resolve;
|
|
818
|
+
})(KeyArrayResolver || (exports.KeyArrayResolver = KeyArrayResolver = {}));
|
|
819
|
+
var UnionResolver;
|
|
820
|
+
(function(UnionResolver2) {
|
|
821
|
+
function* TUnion(union) {
|
|
822
|
+
for (const schema of union.anyOf) {
|
|
823
|
+
if (schema[exports.Kind] === "Union") {
|
|
824
|
+
yield* TUnion(schema);
|
|
825
|
+
} else {
|
|
826
|
+
yield schema;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
function Resolve(union) {
|
|
831
|
+
return exports.Type.Union([...TUnion(union)], { ...union });
|
|
832
|
+
}
|
|
833
|
+
UnionResolver2.Resolve = Resolve;
|
|
834
|
+
})(UnionResolver || (exports.UnionResolver = UnionResolver = {}));
|
|
835
|
+
var TemplateLiteralPatternError = class extends TypeBoxError {
|
|
836
|
+
};
|
|
837
|
+
exports.TemplateLiteralPatternError = TemplateLiteralPatternError;
|
|
838
|
+
var TemplateLiteralPattern;
|
|
839
|
+
(function(TemplateLiteralPattern2) {
|
|
840
|
+
function Throw(message) {
|
|
841
|
+
throw new TemplateLiteralPatternError(message);
|
|
842
|
+
}
|
|
843
|
+
function Escape(value) {
|
|
844
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
845
|
+
}
|
|
846
|
+
function Visit(schema, acc) {
|
|
847
|
+
return TypeGuard.TTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) : TypeGuard.TUnion(schema) ? `(${schema.anyOf.map((schema2) => Visit(schema2, acc)).join("|")})` : TypeGuard.TNumber(schema) ? `${acc}${exports.PatternNumber}` : TypeGuard.TInteger(schema) ? `${acc}${exports.PatternNumber}` : TypeGuard.TBigInt(schema) ? `${acc}${exports.PatternNumber}` : TypeGuard.TString(schema) ? `${acc}${exports.PatternString}` : TypeGuard.TLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` : TypeGuard.TBoolean(schema) ? `${acc}${exports.PatternBoolean}` : Throw(`Unexpected Kind '${schema[exports.Kind]}'`);
|
|
848
|
+
}
|
|
849
|
+
function Create(kinds) {
|
|
850
|
+
return `^${kinds.map((schema) => Visit(schema, "")).join("")}$`;
|
|
851
|
+
}
|
|
852
|
+
TemplateLiteralPattern2.Create = Create;
|
|
853
|
+
})(TemplateLiteralPattern || (exports.TemplateLiteralPattern = TemplateLiteralPattern = {}));
|
|
854
|
+
var TemplateLiteralResolver;
|
|
855
|
+
(function(TemplateLiteralResolver2) {
|
|
856
|
+
function Resolve(template) {
|
|
857
|
+
const expression = TemplateLiteralParser.ParseExact(template.pattern);
|
|
858
|
+
if (!TemplateLiteralFinite.Check(expression))
|
|
859
|
+
return exports.Type.String();
|
|
860
|
+
const literals = [...TemplateLiteralGenerator.Generate(expression)].map((value) => exports.Type.Literal(value));
|
|
861
|
+
return exports.Type.Union(literals);
|
|
862
|
+
}
|
|
863
|
+
TemplateLiteralResolver2.Resolve = Resolve;
|
|
864
|
+
})(TemplateLiteralResolver || (exports.TemplateLiteralResolver = TemplateLiteralResolver = {}));
|
|
865
|
+
var TemplateLiteralParserError = class extends TypeBoxError {
|
|
866
|
+
};
|
|
867
|
+
exports.TemplateLiteralParserError = TemplateLiteralParserError;
|
|
868
|
+
var TemplateLiteralParser;
|
|
869
|
+
(function(TemplateLiteralParser2) {
|
|
870
|
+
function IsNonEscaped(pattern, index, char) {
|
|
871
|
+
return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
|
|
872
|
+
}
|
|
873
|
+
function IsOpenParen(pattern, index) {
|
|
874
|
+
return IsNonEscaped(pattern, index, "(");
|
|
875
|
+
}
|
|
876
|
+
function IsCloseParen(pattern, index) {
|
|
877
|
+
return IsNonEscaped(pattern, index, ")");
|
|
878
|
+
}
|
|
879
|
+
function IsSeparator(pattern, index) {
|
|
880
|
+
return IsNonEscaped(pattern, index, "|");
|
|
881
|
+
}
|
|
882
|
+
function IsGroup(pattern) {
|
|
883
|
+
if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
|
|
884
|
+
return false;
|
|
885
|
+
let count = 0;
|
|
886
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
887
|
+
if (IsOpenParen(pattern, index))
|
|
888
|
+
count += 1;
|
|
889
|
+
if (IsCloseParen(pattern, index))
|
|
890
|
+
count -= 1;
|
|
891
|
+
if (count === 0 && index !== pattern.length - 1)
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
return true;
|
|
895
|
+
}
|
|
896
|
+
function InGroup(pattern) {
|
|
897
|
+
return pattern.slice(1, pattern.length - 1);
|
|
898
|
+
}
|
|
899
|
+
function IsPrecedenceOr(pattern) {
|
|
900
|
+
let count = 0;
|
|
901
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
902
|
+
if (IsOpenParen(pattern, index))
|
|
903
|
+
count += 1;
|
|
904
|
+
if (IsCloseParen(pattern, index))
|
|
905
|
+
count -= 1;
|
|
906
|
+
if (IsSeparator(pattern, index) && count === 0)
|
|
907
|
+
return true;
|
|
908
|
+
}
|
|
909
|
+
return false;
|
|
910
|
+
}
|
|
911
|
+
function IsPrecedenceAnd(pattern) {
|
|
912
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
913
|
+
if (IsOpenParen(pattern, index))
|
|
914
|
+
return true;
|
|
915
|
+
}
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
function Or(pattern) {
|
|
919
|
+
let [count, start] = [0, 0];
|
|
920
|
+
const expressions = [];
|
|
921
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
922
|
+
if (IsOpenParen(pattern, index))
|
|
923
|
+
count += 1;
|
|
924
|
+
if (IsCloseParen(pattern, index))
|
|
925
|
+
count -= 1;
|
|
926
|
+
if (IsSeparator(pattern, index) && count === 0) {
|
|
927
|
+
const range2 = pattern.slice(start, index);
|
|
928
|
+
if (range2.length > 0)
|
|
929
|
+
expressions.push(Parse(range2));
|
|
930
|
+
start = index + 1;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
const range = pattern.slice(start);
|
|
934
|
+
if (range.length > 0)
|
|
935
|
+
expressions.push(Parse(range));
|
|
936
|
+
if (expressions.length === 0)
|
|
937
|
+
return { type: "const", const: "" };
|
|
938
|
+
if (expressions.length === 1)
|
|
939
|
+
return expressions[0];
|
|
940
|
+
return { type: "or", expr: expressions };
|
|
941
|
+
}
|
|
942
|
+
function And(pattern) {
|
|
943
|
+
function Group(value, index) {
|
|
944
|
+
if (!IsOpenParen(value, index))
|
|
945
|
+
throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
|
|
946
|
+
let count = 0;
|
|
947
|
+
for (let scan = index; scan < value.length; scan++) {
|
|
948
|
+
if (IsOpenParen(value, scan))
|
|
949
|
+
count += 1;
|
|
950
|
+
if (IsCloseParen(value, scan))
|
|
951
|
+
count -= 1;
|
|
952
|
+
if (count === 0)
|
|
953
|
+
return [index, scan];
|
|
954
|
+
}
|
|
955
|
+
throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
|
|
956
|
+
}
|
|
957
|
+
function Range(pattern2, index) {
|
|
958
|
+
for (let scan = index; scan < pattern2.length; scan++) {
|
|
959
|
+
if (IsOpenParen(pattern2, scan))
|
|
960
|
+
return [index, scan];
|
|
961
|
+
}
|
|
962
|
+
return [index, pattern2.length];
|
|
963
|
+
}
|
|
964
|
+
const expressions = [];
|
|
965
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
966
|
+
if (IsOpenParen(pattern, index)) {
|
|
967
|
+
const [start, end] = Group(pattern, index);
|
|
968
|
+
const range = pattern.slice(start, end + 1);
|
|
969
|
+
expressions.push(Parse(range));
|
|
970
|
+
index = end;
|
|
971
|
+
} else {
|
|
972
|
+
const [start, end] = Range(pattern, index);
|
|
973
|
+
const range = pattern.slice(start, end);
|
|
974
|
+
if (range.length > 0)
|
|
975
|
+
expressions.push(Parse(range));
|
|
976
|
+
index = end - 1;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return expressions.length === 0 ? { type: "const", const: "" } : expressions.length === 1 ? expressions[0] : { type: "and", expr: expressions };
|
|
980
|
+
}
|
|
981
|
+
function Parse(pattern) {
|
|
982
|
+
return IsGroup(pattern) ? Parse(InGroup(pattern)) : IsPrecedenceOr(pattern) ? Or(pattern) : IsPrecedenceAnd(pattern) ? And(pattern) : { type: "const", const: pattern };
|
|
983
|
+
}
|
|
984
|
+
TemplateLiteralParser2.Parse = Parse;
|
|
985
|
+
function ParseExact(pattern) {
|
|
986
|
+
return Parse(pattern.slice(1, pattern.length - 1));
|
|
987
|
+
}
|
|
988
|
+
TemplateLiteralParser2.ParseExact = ParseExact;
|
|
989
|
+
})(TemplateLiteralParser || (exports.TemplateLiteralParser = TemplateLiteralParser = {}));
|
|
990
|
+
var TemplateLiteralFiniteError = class extends TypeBoxError {
|
|
991
|
+
};
|
|
992
|
+
exports.TemplateLiteralFiniteError = TemplateLiteralFiniteError;
|
|
993
|
+
var TemplateLiteralFinite;
|
|
994
|
+
(function(TemplateLiteralFinite2) {
|
|
995
|
+
function Throw(message) {
|
|
996
|
+
throw new TemplateLiteralFiniteError(message);
|
|
997
|
+
}
|
|
998
|
+
function IsNumber(expression) {
|
|
999
|
+
return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "0" && expression.expr[1].type === "const" && expression.expr[1].const === "[1-9][0-9]*";
|
|
1000
|
+
}
|
|
1001
|
+
function IsBoolean(expression) {
|
|
1002
|
+
return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "true" && expression.expr[1].type === "const" && expression.expr[1].const === "false";
|
|
1003
|
+
}
|
|
1004
|
+
function IsString(expression) {
|
|
1005
|
+
return expression.type === "const" && expression.const === ".*";
|
|
1006
|
+
}
|
|
1007
|
+
function Check(expression) {
|
|
1008
|
+
return IsBoolean(expression) ? true : IsNumber(expression) || IsString(expression) ? false : expression.type === "and" ? expression.expr.every((expr) => Check(expr)) : expression.type === "or" ? expression.expr.every((expr) => Check(expr)) : expression.type === "const" ? true : Throw(`Unknown expression type`);
|
|
1009
|
+
}
|
|
1010
|
+
TemplateLiteralFinite2.Check = Check;
|
|
1011
|
+
})(TemplateLiteralFinite || (exports.TemplateLiteralFinite = TemplateLiteralFinite = {}));
|
|
1012
|
+
var TemplateLiteralGeneratorError = class extends TypeBoxError {
|
|
1013
|
+
};
|
|
1014
|
+
exports.TemplateLiteralGeneratorError = TemplateLiteralGeneratorError;
|
|
1015
|
+
var TemplateLiteralGenerator;
|
|
1016
|
+
(function(TemplateLiteralGenerator2) {
|
|
1017
|
+
function* Reduce(buffer) {
|
|
1018
|
+
if (buffer.length === 1)
|
|
1019
|
+
return yield* buffer[0];
|
|
1020
|
+
for (const left of buffer[0]) {
|
|
1021
|
+
for (const right of Reduce(buffer.slice(1))) {
|
|
1022
|
+
yield `${left}${right}`;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
function* And(expression) {
|
|
1027
|
+
return yield* Reduce(expression.expr.map((expr) => [...Generate(expr)]));
|
|
1028
|
+
}
|
|
1029
|
+
function* Or(expression) {
|
|
1030
|
+
for (const expr of expression.expr)
|
|
1031
|
+
yield* Generate(expr);
|
|
1032
|
+
}
|
|
1033
|
+
function* Const(expression) {
|
|
1034
|
+
return yield expression.const;
|
|
1035
|
+
}
|
|
1036
|
+
function* Generate(expression) {
|
|
1037
|
+
return expression.type === "and" ? yield* And(expression) : expression.type === "or" ? yield* Or(expression) : expression.type === "const" ? yield* Const(expression) : (() => {
|
|
1038
|
+
throw new TemplateLiteralGeneratorError("Unknown expression");
|
|
1039
|
+
})();
|
|
1040
|
+
}
|
|
1041
|
+
TemplateLiteralGenerator2.Generate = Generate;
|
|
1042
|
+
})(TemplateLiteralGenerator || (exports.TemplateLiteralGenerator = TemplateLiteralGenerator = {}));
|
|
1043
|
+
var TemplateLiteralDslParser;
|
|
1044
|
+
(function(TemplateLiteralDslParser2) {
|
|
1045
|
+
function* ParseUnion(template) {
|
|
1046
|
+
const trim = template.trim().replace(/"|'/g, "");
|
|
1047
|
+
return trim === "boolean" ? yield exports.Type.Boolean() : trim === "number" ? yield exports.Type.Number() : trim === "bigint" ? yield exports.Type.BigInt() : trim === "string" ? yield exports.Type.String() : yield (() => {
|
|
1048
|
+
const literals = trim.split("|").map((literal) => exports.Type.Literal(literal.trim()));
|
|
1049
|
+
return literals.length === 0 ? exports.Type.Never() : literals.length === 1 ? literals[0] : exports.Type.Union(literals);
|
|
1050
|
+
})();
|
|
1051
|
+
}
|
|
1052
|
+
function* ParseTerminal(template) {
|
|
1053
|
+
if (template[1] !== "{") {
|
|
1054
|
+
const L = exports.Type.Literal("$");
|
|
1055
|
+
const R = ParseLiteral(template.slice(1));
|
|
1056
|
+
return yield* [L, ...R];
|
|
1057
|
+
}
|
|
1058
|
+
for (let i = 2; i < template.length; i++) {
|
|
1059
|
+
if (template[i] === "}") {
|
|
1060
|
+
const L = ParseUnion(template.slice(2, i));
|
|
1061
|
+
const R = ParseLiteral(template.slice(i + 1));
|
|
1062
|
+
return yield* [...L, ...R];
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
yield exports.Type.Literal(template);
|
|
1066
|
+
}
|
|
1067
|
+
function* ParseLiteral(template) {
|
|
1068
|
+
for (let i = 0; i < template.length; i++) {
|
|
1069
|
+
if (template[i] === "$") {
|
|
1070
|
+
const L = exports.Type.Literal(template.slice(0, i));
|
|
1071
|
+
const R = ParseTerminal(template.slice(i));
|
|
1072
|
+
return yield* [L, ...R];
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
yield exports.Type.Literal(template);
|
|
1076
|
+
}
|
|
1077
|
+
function Parse(template_dsl) {
|
|
1078
|
+
return [...ParseLiteral(template_dsl)];
|
|
1079
|
+
}
|
|
1080
|
+
TemplateLiteralDslParser2.Parse = Parse;
|
|
1081
|
+
})(TemplateLiteralDslParser || (exports.TemplateLiteralDslParser = TemplateLiteralDslParser = {}));
|
|
1082
|
+
var TransformDecodeBuilder = class {
|
|
1083
|
+
constructor(schema) {
|
|
1084
|
+
this.schema = schema;
|
|
1085
|
+
}
|
|
1086
|
+
Decode(decode) {
|
|
1087
|
+
return new TransformEncodeBuilder(this.schema, decode);
|
|
1088
|
+
}
|
|
1089
|
+
};
|
|
1090
|
+
exports.TransformDecodeBuilder = TransformDecodeBuilder;
|
|
1091
|
+
var TransformEncodeBuilder = class {
|
|
1092
|
+
constructor(schema, decode) {
|
|
1093
|
+
this.schema = schema;
|
|
1094
|
+
this.decode = decode;
|
|
1095
|
+
}
|
|
1096
|
+
Encode(encode) {
|
|
1097
|
+
const schema = TypeClone.Type(this.schema);
|
|
1098
|
+
return TypeGuard.TTransform(schema) ? (() => {
|
|
1099
|
+
const Encode = (value) => schema[exports.Transform].Encode(encode(value));
|
|
1100
|
+
const Decode = (value) => this.decode(schema[exports.Transform].Decode(value));
|
|
1101
|
+
const Codec = { Encode, Decode };
|
|
1102
|
+
return { ...schema, [exports.Transform]: Codec };
|
|
1103
|
+
})() : (() => {
|
|
1104
|
+
const Codec = { Decode: this.decode, Encode: encode };
|
|
1105
|
+
return { ...schema, [exports.Transform]: Codec };
|
|
1106
|
+
})();
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
exports.TransformEncodeBuilder = TransformEncodeBuilder;
|
|
1110
|
+
var TypeOrdinal = 0;
|
|
1111
|
+
var TypeBuilderError = class extends TypeBoxError {
|
|
1112
|
+
};
|
|
1113
|
+
exports.TypeBuilderError = TypeBuilderError;
|
|
1114
|
+
var TypeBuilder = class {
|
|
1115
|
+
/** `[Internal]` Creates a schema without `static` and `params` types */
|
|
1116
|
+
Create(schema) {
|
|
1117
|
+
return schema;
|
|
1118
|
+
}
|
|
1119
|
+
/** `[Internal]` Throws a TypeBuilder error with the given message */
|
|
1120
|
+
Throw(message) {
|
|
1121
|
+
throw new TypeBuilderError(message);
|
|
1122
|
+
}
|
|
1123
|
+
/** `[Internal]` Discards property keys from the given record type */
|
|
1124
|
+
Discard(record, keys) {
|
|
1125
|
+
return keys.reduce((acc, key) => {
|
|
1126
|
+
const { [key]: _, ...rest } = acc;
|
|
1127
|
+
return rest;
|
|
1128
|
+
}, record);
|
|
1129
|
+
}
|
|
1130
|
+
/** `[Json]` Omits compositing symbols from this schema */
|
|
1131
|
+
Strict(schema) {
|
|
1132
|
+
return JSON.parse(JSON.stringify(schema));
|
|
1133
|
+
}
|
|
1134
|
+
};
|
|
1135
|
+
exports.TypeBuilder = TypeBuilder;
|
|
1136
|
+
var JsonTypeBuilder = class extends TypeBuilder {
|
|
1137
|
+
// ------------------------------------------------------------------------
|
|
1138
|
+
// Modifiers
|
|
1139
|
+
// ------------------------------------------------------------------------
|
|
1140
|
+
/** `[Json]` Creates a Readonly and Optional property */
|
|
1141
|
+
ReadonlyOptional(schema) {
|
|
1142
|
+
return this.Readonly(this.Optional(schema));
|
|
1143
|
+
}
|
|
1144
|
+
/** `[Json]` Creates a Readonly property */
|
|
1145
|
+
Readonly(schema) {
|
|
1146
|
+
return { ...TypeClone.Type(schema), [exports.Readonly]: "Readonly" };
|
|
1147
|
+
}
|
|
1148
|
+
/** `[Json]` Creates an Optional property */
|
|
1149
|
+
Optional(schema) {
|
|
1150
|
+
return { ...TypeClone.Type(schema), [exports.Optional]: "Optional" };
|
|
1151
|
+
}
|
|
1152
|
+
// ------------------------------------------------------------------------
|
|
1153
|
+
// Types
|
|
1154
|
+
// ------------------------------------------------------------------------
|
|
1155
|
+
/** `[Json]` Creates an Any type */
|
|
1156
|
+
Any(options = {}) {
|
|
1157
|
+
return this.Create({ ...options, [exports.Kind]: "Any" });
|
|
1158
|
+
}
|
|
1159
|
+
/** `[Json]` Creates an Array type */
|
|
1160
|
+
Array(schema, options = {}) {
|
|
1161
|
+
return this.Create({ ...options, [exports.Kind]: "Array", type: "array", items: TypeClone.Type(schema) });
|
|
1162
|
+
}
|
|
1163
|
+
/** `[Json]` Creates a Boolean type */
|
|
1164
|
+
Boolean(options = {}) {
|
|
1165
|
+
return this.Create({ ...options, [exports.Kind]: "Boolean", type: "boolean" });
|
|
1166
|
+
}
|
|
1167
|
+
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
1168
|
+
Capitalize(schema, options = {}) {
|
|
1169
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), "Capitalize"), ...options };
|
|
1170
|
+
}
|
|
1171
|
+
/** `[Json]` Creates a Composite object type */
|
|
1172
|
+
Composite(objects, options) {
|
|
1173
|
+
const intersect = exports.Type.Intersect(objects, {});
|
|
1174
|
+
const keys = KeyResolver.ResolveKeys(intersect, { includePatterns: false });
|
|
1175
|
+
const properties = keys.reduce((acc, key) => ({ ...acc, [key]: exports.Type.Index(intersect, [key]) }), {});
|
|
1176
|
+
return exports.Type.Object(properties, options);
|
|
1177
|
+
}
|
|
1178
|
+
/** `[Json]` Creates a Enum type */
|
|
1179
|
+
Enum(item, options = {}) {
|
|
1180
|
+
if (ValueGuard.IsUndefined(item))
|
|
1181
|
+
return this.Throw("Enum undefined or empty");
|
|
1182
|
+
const values1 = Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
|
|
1183
|
+
const values2 = [...new Set(values1)];
|
|
1184
|
+
const anyOf = values2.map((value) => exports.Type.Literal(value));
|
|
1185
|
+
return this.Union(anyOf, { ...options, [exports.Hint]: "Enum" });
|
|
1186
|
+
}
|
|
1187
|
+
/** `[Json]` Creates a Conditional type */
|
|
1188
|
+
Extends(left, right, trueType, falseType, options = {}) {
|
|
1189
|
+
switch (TypeExtends.Extends(left, right)) {
|
|
1190
|
+
case TypeExtendsResult.Union:
|
|
1191
|
+
return this.Union([TypeClone.Type(trueType, options), TypeClone.Type(falseType, options)]);
|
|
1192
|
+
case TypeExtendsResult.True:
|
|
1193
|
+
return TypeClone.Type(trueType, options);
|
|
1194
|
+
case TypeExtendsResult.False:
|
|
1195
|
+
return TypeClone.Type(falseType, options);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
1199
|
+
Exclude(unionType, excludedMembers, options = {}) {
|
|
1200
|
+
return TypeGuard.TTemplateLiteral(unionType) ? this.Exclude(TemplateLiteralResolver.Resolve(unionType), excludedMembers, options) : TypeGuard.TTemplateLiteral(excludedMembers) ? this.Exclude(unionType, TemplateLiteralResolver.Resolve(excludedMembers), options) : TypeGuard.TUnion(unionType) ? (() => {
|
|
1201
|
+
const narrowed = unionType.anyOf.filter((inner) => TypeExtends.Extends(inner, excludedMembers) === TypeExtendsResult.False);
|
|
1202
|
+
return narrowed.length === 1 ? TypeClone.Type(narrowed[0], options) : this.Union(narrowed, options);
|
|
1203
|
+
})() : TypeExtends.Extends(unionType, excludedMembers) !== TypeExtendsResult.False ? this.Never(options) : TypeClone.Type(unionType, options);
|
|
1204
|
+
}
|
|
1205
|
+
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
1206
|
+
Extract(type, union, options = {}) {
|
|
1207
|
+
return TypeGuard.TTemplateLiteral(type) ? this.Extract(TemplateLiteralResolver.Resolve(type), union, options) : TypeGuard.TTemplateLiteral(union) ? this.Extract(type, TemplateLiteralResolver.Resolve(union), options) : TypeGuard.TUnion(type) ? (() => {
|
|
1208
|
+
const narrowed = type.anyOf.filter((inner) => TypeExtends.Extends(inner, union) !== TypeExtendsResult.False);
|
|
1209
|
+
return narrowed.length === 1 ? TypeClone.Type(narrowed[0], options) : this.Union(narrowed, options);
|
|
1210
|
+
})() : TypeExtends.Extends(type, union) !== TypeExtendsResult.False ? TypeClone.Type(type, options) : this.Never(options);
|
|
1211
|
+
}
|
|
1212
|
+
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
1213
|
+
Index(schema, unresolved, options = {}) {
|
|
1214
|
+
return TypeGuard.TArray(schema) && TypeGuard.TNumber(unresolved) ? (() => {
|
|
1215
|
+
return TypeClone.Type(schema.items, options);
|
|
1216
|
+
})() : TypeGuard.TTuple(schema) && TypeGuard.TNumber(unresolved) ? (() => {
|
|
1217
|
+
const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
|
|
1218
|
+
const cloned = items.map((schema2) => TypeClone.Type(schema2));
|
|
1219
|
+
return this.Union(cloned, options);
|
|
1220
|
+
})() : (() => {
|
|
1221
|
+
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
1222
|
+
const clone = TypeClone.Type(schema);
|
|
1223
|
+
return IndexedAccessor.Resolve(clone, keys, options);
|
|
1224
|
+
})();
|
|
1225
|
+
}
|
|
1226
|
+
/** `[Json]` Creates an Integer type */
|
|
1227
|
+
Integer(options = {}) {
|
|
1228
|
+
return this.Create({ ...options, [exports.Kind]: "Integer", type: "integer" });
|
|
1229
|
+
}
|
|
1230
|
+
/** `[Json]` Creates an Intersect type */
|
|
1231
|
+
Intersect(allOf, options = {}) {
|
|
1232
|
+
if (allOf.length === 0)
|
|
1233
|
+
return exports.Type.Never();
|
|
1234
|
+
if (allOf.length === 1)
|
|
1235
|
+
return TypeClone.Type(allOf[0], options);
|
|
1236
|
+
if (allOf.some((schema) => TypeGuard.TTransform(schema)))
|
|
1237
|
+
this.Throw("Cannot intersect transform types");
|
|
1238
|
+
const objects = allOf.every((schema) => TypeGuard.TObject(schema));
|
|
1239
|
+
const cloned = TypeClone.Rest(allOf);
|
|
1240
|
+
const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties) ? { unevaluatedProperties: TypeClone.Type(options.unevaluatedProperties) } : {};
|
|
1241
|
+
return options.unevaluatedProperties === false || TypeGuard.TSchema(options.unevaluatedProperties) || objects ? this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: "Intersect", type: "object", allOf: cloned }) : this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: "Intersect", allOf: cloned });
|
|
1242
|
+
}
|
|
1243
|
+
/** `[Json]` Creates a KeyOf type */
|
|
1244
|
+
KeyOf(schema, options = {}) {
|
|
1245
|
+
return TypeGuard.TRecord(schema) ? (() => {
|
|
1246
|
+
const pattern = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
1247
|
+
return pattern === exports.PatternNumberExact ? this.Number(options) : pattern === exports.PatternStringExact ? this.String(options) : this.Throw("Unable to resolve key type from Record key pattern");
|
|
1248
|
+
})() : TypeGuard.TTuple(schema) ? (() => {
|
|
1249
|
+
const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
|
|
1250
|
+
const literals = items.map((_, index) => exports.Type.Literal(index.toString()));
|
|
1251
|
+
return this.Union(literals, options);
|
|
1252
|
+
})() : TypeGuard.TArray(schema) ? (() => {
|
|
1253
|
+
return this.Number(options);
|
|
1254
|
+
})() : (() => {
|
|
1255
|
+
const keys = KeyResolver.ResolveKeys(schema, { includePatterns: false });
|
|
1256
|
+
if (keys.length === 0)
|
|
1257
|
+
return this.Never(options);
|
|
1258
|
+
const literals = keys.map((key) => this.Literal(key));
|
|
1259
|
+
return this.Union(literals, options);
|
|
1260
|
+
})();
|
|
1261
|
+
}
|
|
1262
|
+
/** `[Json]` Creates a Literal type */
|
|
1263
|
+
Literal(value, options = {}) {
|
|
1264
|
+
return this.Create({ ...options, [exports.Kind]: "Literal", const: value, type: typeof value });
|
|
1265
|
+
}
|
|
1266
|
+
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
1267
|
+
Lowercase(schema, options = {}) {
|
|
1268
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), "Lowercase"), ...options };
|
|
1269
|
+
}
|
|
1270
|
+
/** `[Json]` Creates a Never type */
|
|
1271
|
+
Never(options = {}) {
|
|
1272
|
+
return this.Create({ ...options, [exports.Kind]: "Never", not: {} });
|
|
1273
|
+
}
|
|
1274
|
+
/** `[Json]` Creates a Not type */
|
|
1275
|
+
Not(schema, options) {
|
|
1276
|
+
return this.Create({ ...options, [exports.Kind]: "Not", not: TypeClone.Type(schema) });
|
|
1277
|
+
}
|
|
1278
|
+
/** `[Json]` Creates a Null type */
|
|
1279
|
+
Null(options = {}) {
|
|
1280
|
+
return this.Create({ ...options, [exports.Kind]: "Null", type: "null" });
|
|
1281
|
+
}
|
|
1282
|
+
/** `[Json]` Creates a Number type */
|
|
1283
|
+
Number(options = {}) {
|
|
1284
|
+
return this.Create({ ...options, [exports.Kind]: "Number", type: "number" });
|
|
1285
|
+
}
|
|
1286
|
+
/** `[Json]` Creates an Object type */
|
|
1287
|
+
Object(properties, options = {}) {
|
|
1288
|
+
const propertyKeys = Object.getOwnPropertyNames(properties);
|
|
1289
|
+
const optionalKeys = propertyKeys.filter((key) => TypeGuard.TOptional(properties[key]));
|
|
1290
|
+
const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
|
|
1291
|
+
const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Type(options.additionalProperties) } : {};
|
|
1292
|
+
const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Type(properties[key]) }), {});
|
|
1293
|
+
return requiredKeys.length > 0 ? this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: "Object", type: "object", properties: clonedProperties, required: requiredKeys }) : this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: "Object", type: "object", properties: clonedProperties });
|
|
1294
|
+
}
|
|
1295
|
+
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
1296
|
+
Omit(schema, unresolved, options = {}) {
|
|
1297
|
+
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
1298
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
|
|
1299
|
+
if (ValueGuard.IsArray(object.required)) {
|
|
1300
|
+
object.required = object.required.filter((key) => !keys.includes(key));
|
|
1301
|
+
if (object.required.length === 0)
|
|
1302
|
+
delete object.required;
|
|
1303
|
+
}
|
|
1304
|
+
for (const key of Object.getOwnPropertyNames(object.properties)) {
|
|
1305
|
+
if (keys.includes(key))
|
|
1306
|
+
delete object.properties[key];
|
|
1307
|
+
}
|
|
1308
|
+
return this.Create(object);
|
|
1309
|
+
}, options);
|
|
1310
|
+
}
|
|
1311
|
+
/** `[Json]` Constructs a type where all properties are optional */
|
|
1312
|
+
Partial(schema, options = {}) {
|
|
1313
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
|
|
1314
|
+
const properties = Object.getOwnPropertyNames(object.properties).reduce((acc, key) => {
|
|
1315
|
+
return { ...acc, [key]: this.Optional(object.properties[key]) };
|
|
1316
|
+
}, {});
|
|
1317
|
+
return this.Object(
|
|
1318
|
+
properties,
|
|
1319
|
+
this.Discard(object, ["required"])
|
|
1320
|
+
/* object used as options to retain other constraints */
|
|
1321
|
+
);
|
|
1322
|
+
}, options);
|
|
1323
|
+
}
|
|
1324
|
+
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
1325
|
+
Pick(schema, unresolved, options = {}) {
|
|
1326
|
+
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
1327
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
|
|
1328
|
+
if (ValueGuard.IsArray(object.required)) {
|
|
1329
|
+
object.required = object.required.filter((key) => keys.includes(key));
|
|
1330
|
+
if (object.required.length === 0)
|
|
1331
|
+
delete object.required;
|
|
1332
|
+
}
|
|
1333
|
+
for (const key of Object.getOwnPropertyNames(object.properties)) {
|
|
1334
|
+
if (!keys.includes(key))
|
|
1335
|
+
delete object.properties[key];
|
|
1336
|
+
}
|
|
1337
|
+
return this.Create(object);
|
|
1338
|
+
}, options);
|
|
1339
|
+
}
|
|
1340
|
+
/** `[Json]` Creates a Record type */
|
|
1341
|
+
Record(key, schema, options = {}) {
|
|
1342
|
+
return TypeGuard.TTemplateLiteral(key) ? (() => {
|
|
1343
|
+
const expression = TemplateLiteralParser.ParseExact(key.pattern);
|
|
1344
|
+
return TemplateLiteralFinite.Check(expression) ? this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key2) => ({ ...acc, [key2]: TypeClone.Type(schema) }), {}), options) : this.Create({ ...options, [exports.Kind]: "Record", type: "object", patternProperties: { [key.pattern]: TypeClone.Type(schema) } });
|
|
1345
|
+
})() : TypeGuard.TUnion(key) ? (() => {
|
|
1346
|
+
const union = UnionResolver.Resolve(key);
|
|
1347
|
+
if (TypeGuard.TUnionLiteral(union)) {
|
|
1348
|
+
const properties = union.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Type(schema) }), {});
|
|
1349
|
+
return this.Object(properties, { ...options, [exports.Hint]: "Record" });
|
|
1350
|
+
} else
|
|
1351
|
+
this.Throw("Record key of type union contains non-literal types");
|
|
1352
|
+
})() : TypeGuard.TLiteral(key) ? (() => {
|
|
1353
|
+
return ValueGuard.IsString(key.const) || ValueGuard.IsNumber(key.const) ? this.Object({ [key.const]: TypeClone.Type(schema) }, options) : this.Throw("Record key of type literal is not of type string or number");
|
|
1354
|
+
})() : TypeGuard.TInteger(key) || TypeGuard.TNumber(key) ? (() => {
|
|
1355
|
+
return this.Create({ ...options, [exports.Kind]: "Record", type: "object", patternProperties: { [exports.PatternNumberExact]: TypeClone.Type(schema) } });
|
|
1356
|
+
})() : TypeGuard.TString(key) ? (() => {
|
|
1357
|
+
const pattern = ValueGuard.IsUndefined(key.pattern) ? exports.PatternStringExact : key.pattern;
|
|
1358
|
+
return this.Create({ ...options, [exports.Kind]: "Record", type: "object", patternProperties: { [pattern]: TypeClone.Type(schema) } });
|
|
1359
|
+
})() : this.Never();
|
|
1360
|
+
}
|
|
1361
|
+
/** `[Json]` Creates a Recursive type */
|
|
1362
|
+
Recursive(callback, options = {}) {
|
|
1363
|
+
if (ValueGuard.IsUndefined(options.$id))
|
|
1364
|
+
options.$id = `T${TypeOrdinal++}`;
|
|
1365
|
+
const thisType = callback({ [exports.Kind]: "This", $ref: `${options.$id}` });
|
|
1366
|
+
thisType.$id = options.$id;
|
|
1367
|
+
return this.Create({ ...options, [exports.Hint]: "Recursive", ...thisType });
|
|
1368
|
+
}
|
|
1369
|
+
/** `[Json]` Creates a Ref type. */
|
|
1370
|
+
Ref(unresolved, options = {}) {
|
|
1371
|
+
if (ValueGuard.IsString(unresolved))
|
|
1372
|
+
return this.Create({ ...options, [exports.Kind]: "Ref", $ref: unresolved });
|
|
1373
|
+
if (ValueGuard.IsUndefined(unresolved.$id))
|
|
1374
|
+
this.Throw("Reference target type must specify an $id");
|
|
1375
|
+
return this.Create({ ...options, [exports.Kind]: "Ref", $ref: unresolved.$id });
|
|
1376
|
+
}
|
|
1377
|
+
/** `[Json]` Constructs a type where all properties are required */
|
|
1378
|
+
Required(schema, options = {}) {
|
|
1379
|
+
return ObjectMap.Map(this.Discard(TypeClone.Type(schema), ["$id", exports.Transform]), (object) => {
|
|
1380
|
+
const properties = Object.getOwnPropertyNames(object.properties).reduce((acc, key) => {
|
|
1381
|
+
return { ...acc, [key]: this.Discard(object.properties[key], [exports.Optional]) };
|
|
1382
|
+
}, {});
|
|
1383
|
+
return this.Object(
|
|
1384
|
+
properties,
|
|
1385
|
+
object
|
|
1386
|
+
/* object used as options to retain other constraints */
|
|
1387
|
+
);
|
|
1388
|
+
}, options);
|
|
1389
|
+
}
|
|
1390
|
+
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
1391
|
+
Rest(schema) {
|
|
1392
|
+
return TypeGuard.TTuple(schema) && !ValueGuard.IsUndefined(schema.items) ? TypeClone.Rest(schema.items) : TypeGuard.TIntersect(schema) ? TypeClone.Rest(schema.allOf) : TypeGuard.TUnion(schema) ? TypeClone.Rest(schema.anyOf) : [];
|
|
1393
|
+
}
|
|
1394
|
+
/** `[Json]` Creates a String type */
|
|
1395
|
+
String(options = {}) {
|
|
1396
|
+
return this.Create({ ...options, [exports.Kind]: "String", type: "string" });
|
|
1397
|
+
}
|
|
1398
|
+
/** `[Json]` Creates a TemplateLiteral type */
|
|
1399
|
+
TemplateLiteral(unresolved, options = {}) {
|
|
1400
|
+
const pattern = ValueGuard.IsString(unresolved) ? TemplateLiteralPattern.Create(TemplateLiteralDslParser.Parse(unresolved)) : TemplateLiteralPattern.Create(unresolved);
|
|
1401
|
+
return this.Create({ ...options, [exports.Kind]: "TemplateLiteral", type: "string", pattern });
|
|
1402
|
+
}
|
|
1403
|
+
/** `[Json]` Creates a Transform type */
|
|
1404
|
+
Transform(schema) {
|
|
1405
|
+
return new TransformDecodeBuilder(schema);
|
|
1406
|
+
}
|
|
1407
|
+
/** `[Json]` Creates a Tuple type */
|
|
1408
|
+
Tuple(items, options = {}) {
|
|
1409
|
+
const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
|
|
1410
|
+
const clonedItems = TypeClone.Rest(items);
|
|
1411
|
+
const schema = items.length > 0 ? { ...options, [exports.Kind]: "Tuple", type: "array", items: clonedItems, additionalItems, minItems, maxItems } : { ...options, [exports.Kind]: "Tuple", type: "array", minItems, maxItems };
|
|
1412
|
+
return this.Create(schema);
|
|
1413
|
+
}
|
|
1414
|
+
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
1415
|
+
Uncapitalize(schema, options = {}) {
|
|
1416
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), "Uncapitalize"), ...options };
|
|
1417
|
+
}
|
|
1418
|
+
/** `[Json]` Creates a Union type */
|
|
1419
|
+
Union(union, options = {}) {
|
|
1420
|
+
return TypeGuard.TTemplateLiteral(union) ? TemplateLiteralResolver.Resolve(union) : (() => {
|
|
1421
|
+
const anyOf = union;
|
|
1422
|
+
if (anyOf.length === 0)
|
|
1423
|
+
return this.Never(options);
|
|
1424
|
+
if (anyOf.length === 1)
|
|
1425
|
+
return this.Create(TypeClone.Type(anyOf[0], options));
|
|
1426
|
+
const clonedAnyOf = TypeClone.Rest(anyOf);
|
|
1427
|
+
return this.Create({ ...options, [exports.Kind]: "Union", anyOf: clonedAnyOf });
|
|
1428
|
+
})();
|
|
1429
|
+
}
|
|
1430
|
+
/** `[Json]` Creates an Unknown type */
|
|
1431
|
+
Unknown(options = {}) {
|
|
1432
|
+
return this.Create({ ...options, [exports.Kind]: "Unknown" });
|
|
1433
|
+
}
|
|
1434
|
+
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
1435
|
+
Unsafe(options = {}) {
|
|
1436
|
+
return this.Create({ ...options, [exports.Kind]: options[exports.Kind] || "Unsafe" });
|
|
1437
|
+
}
|
|
1438
|
+
/** `[Json]` Intrinsic function to Uppercase LiteralString types */
|
|
1439
|
+
Uppercase(schema, options = {}) {
|
|
1440
|
+
return { ...Intrinsic.Map(TypeClone.Type(schema), "Uppercase"), ...options };
|
|
1441
|
+
}
|
|
1442
|
+
};
|
|
1443
|
+
exports.JsonTypeBuilder = JsonTypeBuilder;
|
|
1444
|
+
var JavaScriptTypeBuilder = class extends JsonTypeBuilder {
|
|
1445
|
+
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
1446
|
+
AsyncIterator(items, options = {}) {
|
|
1447
|
+
return this.Create({ ...options, [exports.Kind]: "AsyncIterator", type: "AsyncIterator", items: TypeClone.Type(items) });
|
|
1448
|
+
}
|
|
1449
|
+
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
1450
|
+
Awaited(schema, options = {}) {
|
|
1451
|
+
const Unwrap = (rest) => rest.length > 0 ? (() => {
|
|
1452
|
+
const [L, ...R] = rest;
|
|
1453
|
+
return [this.Awaited(L), ...Unwrap(R)];
|
|
1454
|
+
})() : rest;
|
|
1455
|
+
return TypeGuard.TIntersect(schema) ? exports.Type.Intersect(Unwrap(schema.allOf)) : TypeGuard.TUnion(schema) ? exports.Type.Union(Unwrap(schema.anyOf)) : TypeGuard.TPromise(schema) ? this.Awaited(schema.item) : TypeClone.Type(schema, options);
|
|
1456
|
+
}
|
|
1457
|
+
/** `[JavaScript]` Creates a BigInt type */
|
|
1458
|
+
BigInt(options = {}) {
|
|
1459
|
+
return this.Create({ ...options, [exports.Kind]: "BigInt", type: "bigint" });
|
|
1460
|
+
}
|
|
1461
|
+
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
1462
|
+
ConstructorParameters(schema, options = {}) {
|
|
1463
|
+
return this.Tuple([...schema.parameters], { ...options });
|
|
1464
|
+
}
|
|
1465
|
+
/** `[JavaScript]` Creates a Constructor type */
|
|
1466
|
+
Constructor(parameters, returns, options) {
|
|
1467
|
+
const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
|
|
1468
|
+
return this.Create({ ...options, [exports.Kind]: "Constructor", type: "Constructor", parameters: clonedParameters, returns: clonedReturns });
|
|
1469
|
+
}
|
|
1470
|
+
/** `[JavaScript]` Creates a Date type */
|
|
1471
|
+
Date(options = {}) {
|
|
1472
|
+
return this.Create({ ...options, [exports.Kind]: "Date", type: "Date" });
|
|
1473
|
+
}
|
|
1474
|
+
/** `[JavaScript]` Creates a Function type */
|
|
1475
|
+
Function(parameters, returns, options) {
|
|
1476
|
+
const [clonedParameters, clonedReturns] = [TypeClone.Rest(parameters), TypeClone.Type(returns)];
|
|
1477
|
+
return this.Create({ ...options, [exports.Kind]: "Function", type: "Function", parameters: clonedParameters, returns: clonedReturns });
|
|
1478
|
+
}
|
|
1479
|
+
/** `[JavaScript]` Extracts the InstanceType from the given Constructor type */
|
|
1480
|
+
InstanceType(schema, options = {}) {
|
|
1481
|
+
return TypeClone.Type(schema.returns, options);
|
|
1482
|
+
}
|
|
1483
|
+
/** `[JavaScript]` Creates an Iterator type */
|
|
1484
|
+
Iterator(items, options = {}) {
|
|
1485
|
+
return this.Create({ ...options, [exports.Kind]: "Iterator", type: "Iterator", items: TypeClone.Type(items) });
|
|
1486
|
+
}
|
|
1487
|
+
/** `[JavaScript]` Extracts the Parameters from the given Function type */
|
|
1488
|
+
Parameters(schema, options = {}) {
|
|
1489
|
+
return this.Tuple(schema.parameters, { ...options });
|
|
1490
|
+
}
|
|
1491
|
+
/** `[JavaScript]` Creates a Promise type */
|
|
1492
|
+
Promise(item, options = {}) {
|
|
1493
|
+
return this.Create({ ...options, [exports.Kind]: "Promise", type: "Promise", item: TypeClone.Type(item) });
|
|
1494
|
+
}
|
|
1495
|
+
/** `[Extended]` Creates a String type */
|
|
1496
|
+
RegExp(unresolved, options = {}) {
|
|
1497
|
+
const pattern = ValueGuard.IsString(unresolved) ? unresolved : unresolved.source;
|
|
1498
|
+
return this.Create({ ...options, [exports.Kind]: "String", type: "string", pattern });
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* @deprecated Use `Type.RegExp`
|
|
1502
|
+
*/
|
|
1503
|
+
RegEx(regex, options = {}) {
|
|
1504
|
+
return this.RegExp(regex, options);
|
|
1505
|
+
}
|
|
1506
|
+
/** `[JavaScript]` Extracts the ReturnType from the given Function type */
|
|
1507
|
+
ReturnType(schema, options = {}) {
|
|
1508
|
+
return TypeClone.Type(schema.returns, options);
|
|
1509
|
+
}
|
|
1510
|
+
/** `[JavaScript]` Creates a Symbol type */
|
|
1511
|
+
Symbol(options) {
|
|
1512
|
+
return this.Create({ ...options, [exports.Kind]: "Symbol", type: "symbol" });
|
|
1513
|
+
}
|
|
1514
|
+
/** `[JavaScript]` Creates a Undefined type */
|
|
1515
|
+
Undefined(options = {}) {
|
|
1516
|
+
return this.Create({ ...options, [exports.Kind]: "Undefined", type: "undefined" });
|
|
1517
|
+
}
|
|
1518
|
+
/** `[JavaScript]` Creates a Uint8Array type */
|
|
1519
|
+
Uint8Array(options = {}) {
|
|
1520
|
+
return this.Create({ ...options, [exports.Kind]: "Uint8Array", type: "Uint8Array" });
|
|
1521
|
+
}
|
|
1522
|
+
/** `[JavaScript]` Creates a Void type */
|
|
1523
|
+
Void(options = {}) {
|
|
1524
|
+
return this.Create({ ...options, [exports.Kind]: "Void", type: "void" });
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
exports.JavaScriptTypeBuilder = JavaScriptTypeBuilder;
|
|
1528
|
+
exports.JsonType = new JsonTypeBuilder();
|
|
1529
|
+
exports.Type = new JavaScriptTypeBuilder();
|
|
1530
|
+
}
|
|
1531
|
+
});
|
|
1532
|
+
|
|
1533
|
+
// node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs
|
|
1534
|
+
var __assign = function() {
|
|
1535
|
+
__assign = Object.assign || function __assign2(t) {
|
|
1536
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
1537
|
+
s = arguments[i];
|
|
1538
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
1539
|
+
}
|
|
1540
|
+
return t;
|
|
1541
|
+
};
|
|
1542
|
+
return __assign.apply(this, arguments);
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1545
|
+
// node_modules/.pnpm/@formatjs+icu-messageformat-parser@2.11.4/node_modules/@formatjs/icu-messageformat-parser/lib/error.js
|
|
1546
|
+
var ErrorKind;
|
|
1547
|
+
(function(ErrorKind2) {
|
|
1548
|
+
ErrorKind2[ErrorKind2["EXPECT_ARGUMENT_CLOSING_BRACE"] = 1] = "EXPECT_ARGUMENT_CLOSING_BRACE";
|
|
1549
|
+
ErrorKind2[ErrorKind2["EMPTY_ARGUMENT"] = 2] = "EMPTY_ARGUMENT";
|
|
1550
|
+
ErrorKind2[ErrorKind2["MALFORMED_ARGUMENT"] = 3] = "MALFORMED_ARGUMENT";
|
|
1551
|
+
ErrorKind2[ErrorKind2["EXPECT_ARGUMENT_TYPE"] = 4] = "EXPECT_ARGUMENT_TYPE";
|
|
1552
|
+
ErrorKind2[ErrorKind2["INVALID_ARGUMENT_TYPE"] = 5] = "INVALID_ARGUMENT_TYPE";
|
|
1553
|
+
ErrorKind2[ErrorKind2["EXPECT_ARGUMENT_STYLE"] = 6] = "EXPECT_ARGUMENT_STYLE";
|
|
1554
|
+
ErrorKind2[ErrorKind2["INVALID_NUMBER_SKELETON"] = 7] = "INVALID_NUMBER_SKELETON";
|
|
1555
|
+
ErrorKind2[ErrorKind2["INVALID_DATE_TIME_SKELETON"] = 8] = "INVALID_DATE_TIME_SKELETON";
|
|
1556
|
+
ErrorKind2[ErrorKind2["EXPECT_NUMBER_SKELETON"] = 9] = "EXPECT_NUMBER_SKELETON";
|
|
1557
|
+
ErrorKind2[ErrorKind2["EXPECT_DATE_TIME_SKELETON"] = 10] = "EXPECT_DATE_TIME_SKELETON";
|
|
1558
|
+
ErrorKind2[ErrorKind2["UNCLOSED_QUOTE_IN_ARGUMENT_STYLE"] = 11] = "UNCLOSED_QUOTE_IN_ARGUMENT_STYLE";
|
|
1559
|
+
ErrorKind2[ErrorKind2["EXPECT_SELECT_ARGUMENT_OPTIONS"] = 12] = "EXPECT_SELECT_ARGUMENT_OPTIONS";
|
|
1560
|
+
ErrorKind2[ErrorKind2["EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE"] = 13] = "EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE";
|
|
1561
|
+
ErrorKind2[ErrorKind2["INVALID_PLURAL_ARGUMENT_OFFSET_VALUE"] = 14] = "INVALID_PLURAL_ARGUMENT_OFFSET_VALUE";
|
|
1562
|
+
ErrorKind2[ErrorKind2["EXPECT_SELECT_ARGUMENT_SELECTOR"] = 15] = "EXPECT_SELECT_ARGUMENT_SELECTOR";
|
|
1563
|
+
ErrorKind2[ErrorKind2["EXPECT_PLURAL_ARGUMENT_SELECTOR"] = 16] = "EXPECT_PLURAL_ARGUMENT_SELECTOR";
|
|
1564
|
+
ErrorKind2[ErrorKind2["EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT"] = 17] = "EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT";
|
|
1565
|
+
ErrorKind2[ErrorKind2["EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT"] = 18] = "EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT";
|
|
1566
|
+
ErrorKind2[ErrorKind2["INVALID_PLURAL_ARGUMENT_SELECTOR"] = 19] = "INVALID_PLURAL_ARGUMENT_SELECTOR";
|
|
1567
|
+
ErrorKind2[ErrorKind2["DUPLICATE_PLURAL_ARGUMENT_SELECTOR"] = 20] = "DUPLICATE_PLURAL_ARGUMENT_SELECTOR";
|
|
1568
|
+
ErrorKind2[ErrorKind2["DUPLICATE_SELECT_ARGUMENT_SELECTOR"] = 21] = "DUPLICATE_SELECT_ARGUMENT_SELECTOR";
|
|
1569
|
+
ErrorKind2[ErrorKind2["MISSING_OTHER_CLAUSE"] = 22] = "MISSING_OTHER_CLAUSE";
|
|
1570
|
+
ErrorKind2[ErrorKind2["INVALID_TAG"] = 23] = "INVALID_TAG";
|
|
1571
|
+
ErrorKind2[ErrorKind2["INVALID_TAG_NAME"] = 25] = "INVALID_TAG_NAME";
|
|
1572
|
+
ErrorKind2[ErrorKind2["UNMATCHED_CLOSING_TAG"] = 26] = "UNMATCHED_CLOSING_TAG";
|
|
1573
|
+
ErrorKind2[ErrorKind2["UNCLOSED_TAG"] = 27] = "UNCLOSED_TAG";
|
|
1574
|
+
})(ErrorKind || (ErrorKind = {}));
|
|
1575
|
+
|
|
1576
|
+
// node_modules/.pnpm/@formatjs+icu-messageformat-parser@2.11.4/node_modules/@formatjs/icu-messageformat-parser/lib/types.js
|
|
1577
|
+
var TYPE;
|
|
1578
|
+
(function(TYPE2) {
|
|
1579
|
+
TYPE2[TYPE2["literal"] = 0] = "literal";
|
|
1580
|
+
TYPE2[TYPE2["argument"] = 1] = "argument";
|
|
1581
|
+
TYPE2[TYPE2["number"] = 2] = "number";
|
|
1582
|
+
TYPE2[TYPE2["date"] = 3] = "date";
|
|
1583
|
+
TYPE2[TYPE2["time"] = 4] = "time";
|
|
1584
|
+
TYPE2[TYPE2["select"] = 5] = "select";
|
|
1585
|
+
TYPE2[TYPE2["plural"] = 6] = "plural";
|
|
1586
|
+
TYPE2[TYPE2["pound"] = 7] = "pound";
|
|
1587
|
+
TYPE2[TYPE2["tag"] = 8] = "tag";
|
|
1588
|
+
})(TYPE || (TYPE = {}));
|
|
1589
|
+
var SKELETON_TYPE;
|
|
1590
|
+
(function(SKELETON_TYPE2) {
|
|
1591
|
+
SKELETON_TYPE2[SKELETON_TYPE2["number"] = 0] = "number";
|
|
1592
|
+
SKELETON_TYPE2[SKELETON_TYPE2["dateTime"] = 1] = "dateTime";
|
|
1593
|
+
})(SKELETON_TYPE || (SKELETON_TYPE = {}));
|
|
1594
|
+
function isNumberElement(el) {
|
|
1595
|
+
return el.type === TYPE.number;
|
|
1596
|
+
}
|
|
1597
|
+
function isDateElement(el) {
|
|
1598
|
+
return el.type === TYPE.date;
|
|
1599
|
+
}
|
|
1600
|
+
function isTimeElement(el) {
|
|
1601
|
+
return el.type === TYPE.time;
|
|
1602
|
+
}
|
|
1603
|
+
function isSelectElement(el) {
|
|
1604
|
+
return el.type === TYPE.select;
|
|
1605
|
+
}
|
|
1606
|
+
function isPluralElement(el) {
|
|
1607
|
+
return el.type === TYPE.plural;
|
|
1608
|
+
}
|
|
1609
|
+
function isTagElement(el) {
|
|
1610
|
+
return el.type === TYPE.tag;
|
|
1611
|
+
}
|
|
1612
|
+
function isNumberSkeleton(el) {
|
|
1613
|
+
return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.number);
|
|
1614
|
+
}
|
|
1615
|
+
function isDateTimeSkeleton(el) {
|
|
1616
|
+
return !!(el && typeof el === "object" && el.type === SKELETON_TYPE.dateTime);
|
|
1617
|
+
}
|
|
1618
|
+
|
|
1619
|
+
// node_modules/.pnpm/@formatjs+icu-messageformat-parser@2.11.4/node_modules/@formatjs/icu-messageformat-parser/lib/regex.generated.js
|
|
1620
|
+
var SPACE_SEPARATOR_REGEX = /[ \xA0\u1680\u2000-\u200A\u202F\u205F\u3000]/;
|
|
1621
|
+
|
|
1622
|
+
// node_modules/.pnpm/@formatjs+icu-skeleton-parser@1.8.16/node_modules/@formatjs/icu-skeleton-parser/lib/date-time.js
|
|
1623
|
+
var DATE_TIME_REGEX = /(?:[Eec]{1,6}|G{1,5}|[Qq]{1,5}|(?:[yYur]+|U{1,5})|[ML]{1,5}|d{1,2}|D{1,3}|F{1}|[abB]{1,5}|[hkHK]{1,2}|w{1,2}|W{1}|m{1,2}|s{1,2}|[zZOvVxX]{1,4})(?=([^']*'[^']*')*[^']*$)/g;
|
|
1624
|
+
function parseDateTimeSkeleton(skeleton) {
|
|
1625
|
+
var result = {};
|
|
1626
|
+
skeleton.replace(DATE_TIME_REGEX, function(match) {
|
|
1627
|
+
var len = match.length;
|
|
1628
|
+
switch (match[0]) {
|
|
1629
|
+
// Era
|
|
1630
|
+
case "G":
|
|
1631
|
+
result.era = len === 4 ? "long" : len === 5 ? "narrow" : "short";
|
|
1632
|
+
break;
|
|
1633
|
+
// Year
|
|
1634
|
+
case "y":
|
|
1635
|
+
result.year = len === 2 ? "2-digit" : "numeric";
|
|
1636
|
+
break;
|
|
1637
|
+
case "Y":
|
|
1638
|
+
case "u":
|
|
1639
|
+
case "U":
|
|
1640
|
+
case "r":
|
|
1641
|
+
throw new RangeError("`Y/u/U/r` (year) patterns are not supported, use `y` instead");
|
|
1642
|
+
// Quarter
|
|
1643
|
+
case "q":
|
|
1644
|
+
case "Q":
|
|
1645
|
+
throw new RangeError("`q/Q` (quarter) patterns are not supported");
|
|
1646
|
+
// Month
|
|
1647
|
+
case "M":
|
|
1648
|
+
case "L":
|
|
1649
|
+
result.month = ["numeric", "2-digit", "short", "long", "narrow"][len - 1];
|
|
1650
|
+
break;
|
|
1651
|
+
// Week
|
|
1652
|
+
case "w":
|
|
1653
|
+
case "W":
|
|
1654
|
+
throw new RangeError("`w/W` (week) patterns are not supported");
|
|
1655
|
+
case "d":
|
|
1656
|
+
result.day = ["numeric", "2-digit"][len - 1];
|
|
1657
|
+
break;
|
|
1658
|
+
case "D":
|
|
1659
|
+
case "F":
|
|
1660
|
+
case "g":
|
|
1661
|
+
throw new RangeError("`D/F/g` (day) patterns are not supported, use `d` instead");
|
|
1662
|
+
// Weekday
|
|
1663
|
+
case "E":
|
|
1664
|
+
result.weekday = len === 4 ? "long" : len === 5 ? "narrow" : "short";
|
|
1665
|
+
break;
|
|
1666
|
+
case "e":
|
|
1667
|
+
if (len < 4) {
|
|
1668
|
+
throw new RangeError("`e..eee` (weekday) patterns are not supported");
|
|
1669
|
+
}
|
|
1670
|
+
result.weekday = ["short", "long", "narrow", "short"][len - 4];
|
|
1671
|
+
break;
|
|
1672
|
+
case "c":
|
|
1673
|
+
if (len < 4) {
|
|
1674
|
+
throw new RangeError("`c..ccc` (weekday) patterns are not supported");
|
|
1675
|
+
}
|
|
1676
|
+
result.weekday = ["short", "long", "narrow", "short"][len - 4];
|
|
1677
|
+
break;
|
|
1678
|
+
// Period
|
|
1679
|
+
case "a":
|
|
1680
|
+
result.hour12 = true;
|
|
1681
|
+
break;
|
|
1682
|
+
case "b":
|
|
1683
|
+
// am, pm, noon, midnight
|
|
1684
|
+
case "B":
|
|
1685
|
+
throw new RangeError("`b/B` (period) patterns are not supported, use `a` instead");
|
|
1686
|
+
// Hour
|
|
1687
|
+
case "h":
|
|
1688
|
+
result.hourCycle = "h12";
|
|
1689
|
+
result.hour = ["numeric", "2-digit"][len - 1];
|
|
1690
|
+
break;
|
|
1691
|
+
case "H":
|
|
1692
|
+
result.hourCycle = "h23";
|
|
1693
|
+
result.hour = ["numeric", "2-digit"][len - 1];
|
|
1694
|
+
break;
|
|
1695
|
+
case "K":
|
|
1696
|
+
result.hourCycle = "h11";
|
|
1697
|
+
result.hour = ["numeric", "2-digit"][len - 1];
|
|
1698
|
+
break;
|
|
1699
|
+
case "k":
|
|
1700
|
+
result.hourCycle = "h24";
|
|
1701
|
+
result.hour = ["numeric", "2-digit"][len - 1];
|
|
1702
|
+
break;
|
|
1703
|
+
case "j":
|
|
1704
|
+
case "J":
|
|
1705
|
+
case "C":
|
|
1706
|
+
throw new RangeError("`j/J/C` (hour) patterns are not supported, use `h/H/K/k` instead");
|
|
1707
|
+
// Minute
|
|
1708
|
+
case "m":
|
|
1709
|
+
result.minute = ["numeric", "2-digit"][len - 1];
|
|
1710
|
+
break;
|
|
1711
|
+
// Second
|
|
1712
|
+
case "s":
|
|
1713
|
+
result.second = ["numeric", "2-digit"][len - 1];
|
|
1714
|
+
break;
|
|
1715
|
+
case "S":
|
|
1716
|
+
case "A":
|
|
1717
|
+
throw new RangeError("`S/A` (second) patterns are not supported, use `s` instead");
|
|
1718
|
+
// Zone
|
|
1719
|
+
case "z":
|
|
1720
|
+
result.timeZoneName = len < 4 ? "short" : "long";
|
|
1721
|
+
break;
|
|
1722
|
+
case "Z":
|
|
1723
|
+
// 1..3, 4, 5: The ISO8601 varios formats
|
|
1724
|
+
case "O":
|
|
1725
|
+
// 1, 4: milliseconds in day short, long
|
|
1726
|
+
case "v":
|
|
1727
|
+
// 1, 4: generic non-location format
|
|
1728
|
+
case "V":
|
|
1729
|
+
// 1, 2, 3, 4: time zone ID or city
|
|
1730
|
+
case "X":
|
|
1731
|
+
// 1, 2, 3, 4: The ISO8601 varios formats
|
|
1732
|
+
case "x":
|
|
1733
|
+
throw new RangeError("`Z/O/v/V/X/x` (timeZone) patterns are not supported, use `z` instead");
|
|
1734
|
+
}
|
|
1735
|
+
return "";
|
|
1736
|
+
});
|
|
1737
|
+
return result;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1740
|
+
// node_modules/.pnpm/@formatjs+icu-skeleton-parser@1.8.16/node_modules/@formatjs/icu-skeleton-parser/lib/regex.generated.js
|
|
1741
|
+
var WHITE_SPACE_REGEX = /[\t-\r \x85\u200E\u200F\u2028\u2029]/i;
|
|
1742
|
+
|
|
1743
|
+
// node_modules/.pnpm/@formatjs+icu-skeleton-parser@1.8.16/node_modules/@formatjs/icu-skeleton-parser/lib/number.js
|
|
1744
|
+
function parseNumberSkeletonFromString(skeleton) {
|
|
1745
|
+
if (skeleton.length === 0) {
|
|
1746
|
+
throw new Error("Number skeleton cannot be empty");
|
|
1747
|
+
}
|
|
1748
|
+
var stringTokens = skeleton.split(WHITE_SPACE_REGEX).filter(function(x) {
|
|
1749
|
+
return x.length > 0;
|
|
1750
|
+
});
|
|
1751
|
+
var tokens = [];
|
|
1752
|
+
for (var _i = 0, stringTokens_1 = stringTokens; _i < stringTokens_1.length; _i++) {
|
|
1753
|
+
var stringToken = stringTokens_1[_i];
|
|
1754
|
+
var stemAndOptions = stringToken.split("/");
|
|
1755
|
+
if (stemAndOptions.length === 0) {
|
|
1756
|
+
throw new Error("Invalid number skeleton");
|
|
1757
|
+
}
|
|
1758
|
+
var stem = stemAndOptions[0], options = stemAndOptions.slice(1);
|
|
1759
|
+
for (var _a2 = 0, options_1 = options; _a2 < options_1.length; _a2++) {
|
|
1760
|
+
var option = options_1[_a2];
|
|
1761
|
+
if (option.length === 0) {
|
|
1762
|
+
throw new Error("Invalid number skeleton");
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
tokens.push({ stem, options });
|
|
1766
|
+
}
|
|
1767
|
+
return tokens;
|
|
1768
|
+
}
|
|
1769
|
+
function icuUnitToEcma(unit) {
|
|
1770
|
+
return unit.replace(/^(.*?)-/, "");
|
|
1771
|
+
}
|
|
1772
|
+
var FRACTION_PRECISION_REGEX = /^\.(?:(0+)(\*)?|(#+)|(0+)(#+))$/g;
|
|
1773
|
+
var SIGNIFICANT_PRECISION_REGEX = /^(@+)?(\+|#+)?[rs]?$/g;
|
|
1774
|
+
var INTEGER_WIDTH_REGEX = /(\*)(0+)|(#+)(0+)|(0+)/g;
|
|
1775
|
+
var CONCISE_INTEGER_WIDTH_REGEX = /^(0+)$/;
|
|
1776
|
+
function parseSignificantPrecision(str) {
|
|
1777
|
+
var result = {};
|
|
1778
|
+
if (str[str.length - 1] === "r") {
|
|
1779
|
+
result.roundingPriority = "morePrecision";
|
|
1780
|
+
} else if (str[str.length - 1] === "s") {
|
|
1781
|
+
result.roundingPriority = "lessPrecision";
|
|
1782
|
+
}
|
|
1783
|
+
str.replace(SIGNIFICANT_PRECISION_REGEX, function(_, g1, g2) {
|
|
1784
|
+
if (typeof g2 !== "string") {
|
|
1785
|
+
result.minimumSignificantDigits = g1.length;
|
|
1786
|
+
result.maximumSignificantDigits = g1.length;
|
|
1787
|
+
} else if (g2 === "+") {
|
|
1788
|
+
result.minimumSignificantDigits = g1.length;
|
|
1789
|
+
} else if (g1[0] === "#") {
|
|
1790
|
+
result.maximumSignificantDigits = g1.length;
|
|
1791
|
+
} else {
|
|
1792
|
+
result.minimumSignificantDigits = g1.length;
|
|
1793
|
+
result.maximumSignificantDigits = g1.length + (typeof g2 === "string" ? g2.length : 0);
|
|
1794
|
+
}
|
|
1795
|
+
return "";
|
|
1796
|
+
});
|
|
1797
|
+
return result;
|
|
1798
|
+
}
|
|
1799
|
+
function parseSign(str) {
|
|
1800
|
+
switch (str) {
|
|
1801
|
+
case "sign-auto":
|
|
1802
|
+
return {
|
|
1803
|
+
signDisplay: "auto"
|
|
1804
|
+
};
|
|
1805
|
+
case "sign-accounting":
|
|
1806
|
+
case "()":
|
|
1807
|
+
return {
|
|
1808
|
+
currencySign: "accounting"
|
|
1809
|
+
};
|
|
1810
|
+
case "sign-always":
|
|
1811
|
+
case "+!":
|
|
1812
|
+
return {
|
|
1813
|
+
signDisplay: "always"
|
|
1814
|
+
};
|
|
1815
|
+
case "sign-accounting-always":
|
|
1816
|
+
case "()!":
|
|
1817
|
+
return {
|
|
1818
|
+
signDisplay: "always",
|
|
1819
|
+
currencySign: "accounting"
|
|
1820
|
+
};
|
|
1821
|
+
case "sign-except-zero":
|
|
1822
|
+
case "+?":
|
|
1823
|
+
return {
|
|
1824
|
+
signDisplay: "exceptZero"
|
|
1825
|
+
};
|
|
1826
|
+
case "sign-accounting-except-zero":
|
|
1827
|
+
case "()?":
|
|
1828
|
+
return {
|
|
1829
|
+
signDisplay: "exceptZero",
|
|
1830
|
+
currencySign: "accounting"
|
|
1831
|
+
};
|
|
1832
|
+
case "sign-never":
|
|
1833
|
+
case "+_":
|
|
1834
|
+
return {
|
|
1835
|
+
signDisplay: "never"
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
function parseConciseScientificAndEngineeringStem(stem) {
|
|
1840
|
+
var result;
|
|
1841
|
+
if (stem[0] === "E" && stem[1] === "E") {
|
|
1842
|
+
result = {
|
|
1843
|
+
notation: "engineering"
|
|
1844
|
+
};
|
|
1845
|
+
stem = stem.slice(2);
|
|
1846
|
+
} else if (stem[0] === "E") {
|
|
1847
|
+
result = {
|
|
1848
|
+
notation: "scientific"
|
|
1849
|
+
};
|
|
1850
|
+
stem = stem.slice(1);
|
|
1851
|
+
}
|
|
1852
|
+
if (result) {
|
|
1853
|
+
var signDisplay = stem.slice(0, 2);
|
|
1854
|
+
if (signDisplay === "+!") {
|
|
1855
|
+
result.signDisplay = "always";
|
|
1856
|
+
stem = stem.slice(2);
|
|
1857
|
+
} else if (signDisplay === "+?") {
|
|
1858
|
+
result.signDisplay = "exceptZero";
|
|
1859
|
+
stem = stem.slice(2);
|
|
1860
|
+
}
|
|
1861
|
+
if (!CONCISE_INTEGER_WIDTH_REGEX.test(stem)) {
|
|
1862
|
+
throw new Error("Malformed concise eng/scientific notation");
|
|
1863
|
+
}
|
|
1864
|
+
result.minimumIntegerDigits = stem.length;
|
|
1865
|
+
}
|
|
1866
|
+
return result;
|
|
1867
|
+
}
|
|
1868
|
+
function parseNotationOptions(opt) {
|
|
1869
|
+
var result = {};
|
|
1870
|
+
var signOpts = parseSign(opt);
|
|
1871
|
+
if (signOpts) {
|
|
1872
|
+
return signOpts;
|
|
1873
|
+
}
|
|
1874
|
+
return result;
|
|
1875
|
+
}
|
|
1876
|
+
function parseNumberSkeleton(tokens) {
|
|
1877
|
+
var result = {};
|
|
1878
|
+
for (var _i = 0, tokens_1 = tokens; _i < tokens_1.length; _i++) {
|
|
1879
|
+
var token = tokens_1[_i];
|
|
1880
|
+
switch (token.stem) {
|
|
1881
|
+
case "percent":
|
|
1882
|
+
case "%":
|
|
1883
|
+
result.style = "percent";
|
|
1884
|
+
continue;
|
|
1885
|
+
case "%x100":
|
|
1886
|
+
result.style = "percent";
|
|
1887
|
+
result.scale = 100;
|
|
1888
|
+
continue;
|
|
1889
|
+
case "currency":
|
|
1890
|
+
result.style = "currency";
|
|
1891
|
+
result.currency = token.options[0];
|
|
1892
|
+
continue;
|
|
1893
|
+
case "group-off":
|
|
1894
|
+
case ",_":
|
|
1895
|
+
result.useGrouping = false;
|
|
1896
|
+
continue;
|
|
1897
|
+
case "precision-integer":
|
|
1898
|
+
case ".":
|
|
1899
|
+
result.maximumFractionDigits = 0;
|
|
1900
|
+
continue;
|
|
1901
|
+
case "measure-unit":
|
|
1902
|
+
case "unit":
|
|
1903
|
+
result.style = "unit";
|
|
1904
|
+
result.unit = icuUnitToEcma(token.options[0]);
|
|
1905
|
+
continue;
|
|
1906
|
+
case "compact-short":
|
|
1907
|
+
case "K":
|
|
1908
|
+
result.notation = "compact";
|
|
1909
|
+
result.compactDisplay = "short";
|
|
1910
|
+
continue;
|
|
1911
|
+
case "compact-long":
|
|
1912
|
+
case "KK":
|
|
1913
|
+
result.notation = "compact";
|
|
1914
|
+
result.compactDisplay = "long";
|
|
1915
|
+
continue;
|
|
1916
|
+
case "scientific":
|
|
1917
|
+
result = __assign(__assign(__assign({}, result), { notation: "scientific" }), token.options.reduce(function(all, opt2) {
|
|
1918
|
+
return __assign(__assign({}, all), parseNotationOptions(opt2));
|
|
1919
|
+
}, {}));
|
|
1920
|
+
continue;
|
|
1921
|
+
case "engineering":
|
|
1922
|
+
result = __assign(__assign(__assign({}, result), { notation: "engineering" }), token.options.reduce(function(all, opt2) {
|
|
1923
|
+
return __assign(__assign({}, all), parseNotationOptions(opt2));
|
|
1924
|
+
}, {}));
|
|
1925
|
+
continue;
|
|
1926
|
+
case "notation-simple":
|
|
1927
|
+
result.notation = "standard";
|
|
1928
|
+
continue;
|
|
1929
|
+
// https://github.com/unicode-org/icu/blob/master/icu4c/source/i18n/unicode/unumberformatter.h
|
|
1930
|
+
case "unit-width-narrow":
|
|
1931
|
+
result.currencyDisplay = "narrowSymbol";
|
|
1932
|
+
result.unitDisplay = "narrow";
|
|
1933
|
+
continue;
|
|
1934
|
+
case "unit-width-short":
|
|
1935
|
+
result.currencyDisplay = "code";
|
|
1936
|
+
result.unitDisplay = "short";
|
|
1937
|
+
continue;
|
|
1938
|
+
case "unit-width-full-name":
|
|
1939
|
+
result.currencyDisplay = "name";
|
|
1940
|
+
result.unitDisplay = "long";
|
|
1941
|
+
continue;
|
|
1942
|
+
case "unit-width-iso-code":
|
|
1943
|
+
result.currencyDisplay = "symbol";
|
|
1944
|
+
continue;
|
|
1945
|
+
case "scale":
|
|
1946
|
+
result.scale = parseFloat(token.options[0]);
|
|
1947
|
+
continue;
|
|
1948
|
+
case "rounding-mode-floor":
|
|
1949
|
+
result.roundingMode = "floor";
|
|
1950
|
+
continue;
|
|
1951
|
+
case "rounding-mode-ceiling":
|
|
1952
|
+
result.roundingMode = "ceil";
|
|
1953
|
+
continue;
|
|
1954
|
+
case "rounding-mode-down":
|
|
1955
|
+
result.roundingMode = "trunc";
|
|
1956
|
+
continue;
|
|
1957
|
+
case "rounding-mode-up":
|
|
1958
|
+
result.roundingMode = "expand";
|
|
1959
|
+
continue;
|
|
1960
|
+
case "rounding-mode-half-even":
|
|
1961
|
+
result.roundingMode = "halfEven";
|
|
1962
|
+
continue;
|
|
1963
|
+
case "rounding-mode-half-down":
|
|
1964
|
+
result.roundingMode = "halfTrunc";
|
|
1965
|
+
continue;
|
|
1966
|
+
case "rounding-mode-half-up":
|
|
1967
|
+
result.roundingMode = "halfExpand";
|
|
1968
|
+
continue;
|
|
1969
|
+
// https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#integer-width
|
|
1970
|
+
case "integer-width":
|
|
1971
|
+
if (token.options.length > 1) {
|
|
1972
|
+
throw new RangeError("integer-width stems only accept a single optional option");
|
|
1973
|
+
}
|
|
1974
|
+
token.options[0].replace(INTEGER_WIDTH_REGEX, function(_, g1, g2, g3, g4, g5) {
|
|
1975
|
+
if (g1) {
|
|
1976
|
+
result.minimumIntegerDigits = g2.length;
|
|
1977
|
+
} else if (g3 && g4) {
|
|
1978
|
+
throw new Error("We currently do not support maximum integer digits");
|
|
1979
|
+
} else if (g5) {
|
|
1980
|
+
throw new Error("We currently do not support exact integer digits");
|
|
1981
|
+
}
|
|
1982
|
+
return "";
|
|
1983
|
+
});
|
|
1984
|
+
continue;
|
|
1985
|
+
}
|
|
1986
|
+
if (CONCISE_INTEGER_WIDTH_REGEX.test(token.stem)) {
|
|
1987
|
+
result.minimumIntegerDigits = token.stem.length;
|
|
1988
|
+
continue;
|
|
1989
|
+
}
|
|
1990
|
+
if (FRACTION_PRECISION_REGEX.test(token.stem)) {
|
|
1991
|
+
if (token.options.length > 1) {
|
|
1992
|
+
throw new RangeError("Fraction-precision stems only accept a single optional option");
|
|
1993
|
+
}
|
|
1994
|
+
token.stem.replace(FRACTION_PRECISION_REGEX, function(_, g1, g2, g3, g4, g5) {
|
|
1995
|
+
if (g2 === "*") {
|
|
1996
|
+
result.minimumFractionDigits = g1.length;
|
|
1997
|
+
} else if (g3 && g3[0] === "#") {
|
|
1998
|
+
result.maximumFractionDigits = g3.length;
|
|
1999
|
+
} else if (g4 && g5) {
|
|
2000
|
+
result.minimumFractionDigits = g4.length;
|
|
2001
|
+
result.maximumFractionDigits = g4.length + g5.length;
|
|
2002
|
+
} else {
|
|
2003
|
+
result.minimumFractionDigits = g1.length;
|
|
2004
|
+
result.maximumFractionDigits = g1.length;
|
|
2005
|
+
}
|
|
2006
|
+
return "";
|
|
2007
|
+
});
|
|
2008
|
+
var opt = token.options[0];
|
|
2009
|
+
if (opt === "w") {
|
|
2010
|
+
result = __assign(__assign({}, result), { trailingZeroDisplay: "stripIfInteger" });
|
|
2011
|
+
} else if (opt) {
|
|
2012
|
+
result = __assign(__assign({}, result), parseSignificantPrecision(opt));
|
|
2013
|
+
}
|
|
2014
|
+
continue;
|
|
2015
|
+
}
|
|
2016
|
+
if (SIGNIFICANT_PRECISION_REGEX.test(token.stem)) {
|
|
2017
|
+
result = __assign(__assign({}, result), parseSignificantPrecision(token.stem));
|
|
2018
|
+
continue;
|
|
2019
|
+
}
|
|
2020
|
+
var signOpts = parseSign(token.stem);
|
|
2021
|
+
if (signOpts) {
|
|
2022
|
+
result = __assign(__assign({}, result), signOpts);
|
|
2023
|
+
}
|
|
2024
|
+
var conciseScientificAndEngineeringOpts = parseConciseScientificAndEngineeringStem(token.stem);
|
|
2025
|
+
if (conciseScientificAndEngineeringOpts) {
|
|
2026
|
+
result = __assign(__assign({}, result), conciseScientificAndEngineeringOpts);
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
return result;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
// node_modules/.pnpm/@formatjs+icu-messageformat-parser@2.11.4/node_modules/@formatjs/icu-messageformat-parser/lib/time-data.generated.js
|
|
2033
|
+
var timeData = {
|
|
2034
|
+
"001": [
|
|
2035
|
+
"H",
|
|
2036
|
+
"h"
|
|
2037
|
+
],
|
|
2038
|
+
"419": [
|
|
2039
|
+
"h",
|
|
2040
|
+
"H",
|
|
2041
|
+
"hB",
|
|
2042
|
+
"hb"
|
|
2043
|
+
],
|
|
2044
|
+
"AC": [
|
|
2045
|
+
"H",
|
|
2046
|
+
"h",
|
|
2047
|
+
"hb",
|
|
2048
|
+
"hB"
|
|
2049
|
+
],
|
|
2050
|
+
"AD": [
|
|
2051
|
+
"H",
|
|
2052
|
+
"hB"
|
|
2053
|
+
],
|
|
2054
|
+
"AE": [
|
|
2055
|
+
"h",
|
|
2056
|
+
"hB",
|
|
2057
|
+
"hb",
|
|
2058
|
+
"H"
|
|
2059
|
+
],
|
|
2060
|
+
"AF": [
|
|
2061
|
+
"H",
|
|
2062
|
+
"hb",
|
|
2063
|
+
"hB",
|
|
2064
|
+
"h"
|
|
2065
|
+
],
|
|
2066
|
+
"AG": [
|
|
2067
|
+
"h",
|
|
2068
|
+
"hb",
|
|
2069
|
+
"H",
|
|
2070
|
+
"hB"
|
|
2071
|
+
],
|
|
2072
|
+
"AI": [
|
|
2073
|
+
"H",
|
|
2074
|
+
"h",
|
|
2075
|
+
"hb",
|
|
2076
|
+
"hB"
|
|
2077
|
+
],
|
|
2078
|
+
"AL": [
|
|
2079
|
+
"h",
|
|
2080
|
+
"H",
|
|
2081
|
+
"hB"
|
|
2082
|
+
],
|
|
2083
|
+
"AM": [
|
|
2084
|
+
"H",
|
|
2085
|
+
"hB"
|
|
2086
|
+
],
|
|
2087
|
+
"AO": [
|
|
2088
|
+
"H",
|
|
2089
|
+
"hB"
|
|
2090
|
+
],
|
|
2091
|
+
"AR": [
|
|
2092
|
+
"h",
|
|
2093
|
+
"H",
|
|
2094
|
+
"hB",
|
|
2095
|
+
"hb"
|
|
2096
|
+
],
|
|
2097
|
+
"AS": [
|
|
2098
|
+
"h",
|
|
2099
|
+
"H"
|
|
2100
|
+
],
|
|
2101
|
+
"AT": [
|
|
2102
|
+
"H",
|
|
2103
|
+
"hB"
|
|
2104
|
+
],
|
|
2105
|
+
"AU": [
|
|
2106
|
+
"h",
|
|
2107
|
+
"hb",
|
|
2108
|
+
"H",
|
|
2109
|
+
"hB"
|
|
2110
|
+
],
|
|
2111
|
+
"AW": [
|
|
2112
|
+
"H",
|
|
2113
|
+
"hB"
|
|
2114
|
+
],
|
|
2115
|
+
"AX": [
|
|
2116
|
+
"H"
|
|
2117
|
+
],
|
|
2118
|
+
"AZ": [
|
|
2119
|
+
"H",
|
|
2120
|
+
"hB",
|
|
2121
|
+
"h"
|
|
2122
|
+
],
|
|
2123
|
+
"BA": [
|
|
2124
|
+
"H",
|
|
2125
|
+
"hB",
|
|
2126
|
+
"h"
|
|
2127
|
+
],
|
|
2128
|
+
"BB": [
|
|
2129
|
+
"h",
|
|
2130
|
+
"hb",
|
|
2131
|
+
"H",
|
|
2132
|
+
"hB"
|
|
2133
|
+
],
|
|
2134
|
+
"BD": [
|
|
2135
|
+
"h",
|
|
2136
|
+
"hB",
|
|
2137
|
+
"H"
|
|
2138
|
+
],
|
|
2139
|
+
"BE": [
|
|
2140
|
+
"H",
|
|
2141
|
+
"hB"
|
|
2142
|
+
],
|
|
2143
|
+
"BF": [
|
|
2144
|
+
"H",
|
|
2145
|
+
"hB"
|
|
2146
|
+
],
|
|
2147
|
+
"BG": [
|
|
2148
|
+
"H",
|
|
2149
|
+
"hB",
|
|
2150
|
+
"h"
|
|
2151
|
+
],
|
|
2152
|
+
"BH": [
|
|
2153
|
+
"h",
|
|
2154
|
+
"hB",
|
|
2155
|
+
"hb",
|
|
2156
|
+
"H"
|
|
2157
|
+
],
|
|
2158
|
+
"BI": [
|
|
2159
|
+
"H",
|
|
2160
|
+
"h"
|
|
2161
|
+
],
|
|
2162
|
+
"BJ": [
|
|
2163
|
+
"H",
|
|
2164
|
+
"hB"
|
|
2165
|
+
],
|
|
2166
|
+
"BL": [
|
|
2167
|
+
"H",
|
|
2168
|
+
"hB"
|
|
2169
|
+
],
|
|
2170
|
+
"BM": [
|
|
2171
|
+
"h",
|
|
2172
|
+
"hb",
|
|
2173
|
+
"H",
|
|
2174
|
+
"hB"
|
|
2175
|
+
],
|
|
2176
|
+
"BN": [
|
|
2177
|
+
"hb",
|
|
2178
|
+
"hB",
|
|
2179
|
+
"h",
|
|
2180
|
+
"H"
|
|
2181
|
+
],
|
|
2182
|
+
"BO": [
|
|
2183
|
+
"h",
|
|
2184
|
+
"H",
|
|
2185
|
+
"hB",
|
|
2186
|
+
"hb"
|
|
2187
|
+
],
|
|
2188
|
+
"BQ": [
|
|
2189
|
+
"H"
|
|
2190
|
+
],
|
|
2191
|
+
"BR": [
|
|
2192
|
+
"H",
|
|
2193
|
+
"hB"
|
|
2194
|
+
],
|
|
2195
|
+
"BS": [
|
|
2196
|
+
"h",
|
|
2197
|
+
"hb",
|
|
2198
|
+
"H",
|
|
2199
|
+
"hB"
|
|
2200
|
+
],
|
|
2201
|
+
"BT": [
|
|
2202
|
+
"h",
|
|
2203
|
+
"H"
|
|
2204
|
+
],
|
|
2205
|
+
"BW": [
|
|
2206
|
+
"H",
|
|
2207
|
+
"h",
|
|
2208
|
+
"hb",
|
|
2209
|
+
"hB"
|
|
2210
|
+
],
|
|
2211
|
+
"BY": [
|
|
2212
|
+
"H",
|
|
2213
|
+
"h"
|
|
2214
|
+
],
|
|
2215
|
+
"BZ": [
|
|
2216
|
+
"H",
|
|
2217
|
+
"h",
|
|
2218
|
+
"hb",
|
|
2219
|
+
"hB"
|
|
2220
|
+
],
|
|
2221
|
+
"CA": [
|
|
2222
|
+
"h",
|
|
2223
|
+
"hb",
|
|
2224
|
+
"H",
|
|
2225
|
+
"hB"
|
|
2226
|
+
],
|
|
2227
|
+
"CC": [
|
|
2228
|
+
"H",
|
|
2229
|
+
"h",
|
|
2230
|
+
"hb",
|
|
2231
|
+
"hB"
|
|
2232
|
+
],
|
|
2233
|
+
"CD": [
|
|
2234
|
+
"hB",
|
|
2235
|
+
"H"
|
|
2236
|
+
],
|
|
2237
|
+
"CF": [
|
|
2238
|
+
"H",
|
|
2239
|
+
"h",
|
|
2240
|
+
"hB"
|
|
2241
|
+
],
|
|
2242
|
+
"CG": [
|
|
2243
|
+
"H",
|
|
2244
|
+
"hB"
|
|
2245
|
+
],
|
|
2246
|
+
"CH": [
|
|
2247
|
+
"H",
|
|
2248
|
+
"hB",
|
|
2249
|
+
"h"
|
|
2250
|
+
],
|
|
2251
|
+
"CI": [
|
|
2252
|
+
"H",
|
|
2253
|
+
"hB"
|
|
2254
|
+
],
|
|
2255
|
+
"CK": [
|
|
2256
|
+
"H",
|
|
2257
|
+
"h",
|
|
2258
|
+
"hb",
|
|
2259
|
+
"hB"
|
|
2260
|
+
],
|
|
2261
|
+
"CL": [
|
|
2262
|
+
"h",
|
|
2263
|
+
"H",
|
|
2264
|
+
"hB",
|
|
2265
|
+
"hb"
|
|
2266
|
+
],
|
|
2267
|
+
"CM": [
|
|
2268
|
+
"H",
|
|
2269
|
+
"h",
|
|
2270
|
+
"hB"
|
|
2271
|
+
],
|
|
2272
|
+
"CN": [
|
|
2273
|
+
"H",
|
|
2274
|
+
"hB",
|
|
2275
|
+
"hb",
|
|
2276
|
+
"h"
|
|
2277
|
+
],
|
|
2278
|
+
"CO": [
|
|
2279
|
+
"h",
|
|
2280
|
+
"H",
|
|
2281
|
+
"hB",
|
|
2282
|
+
"hb"
|
|
2283
|
+
],
|
|
2284
|
+
"CP": [
|
|
2285
|
+
"H"
|
|
2286
|
+
],
|
|
2287
|
+
"CR": [
|
|
2288
|
+
"h",
|
|
2289
|
+
"H",
|
|
2290
|
+
"hB",
|
|
2291
|
+
"hb"
|
|
2292
|
+
],
|
|
2293
|
+
"CU": [
|
|
2294
|
+
"h",
|
|
2295
|
+
"H",
|
|
2296
|
+
"hB",
|
|
2297
|
+
"hb"
|
|
2298
|
+
],
|
|
2299
|
+
"CV": [
|
|
2300
|
+
"H",
|
|
2301
|
+
"hB"
|
|
2302
|
+
],
|
|
2303
|
+
"CW": [
|
|
2304
|
+
"H",
|
|
2305
|
+
"hB"
|
|
2306
|
+
],
|
|
2307
|
+
"CX": [
|
|
2308
|
+
"H",
|
|
2309
|
+
"h",
|
|
2310
|
+
"hb",
|
|
2311
|
+
"hB"
|
|
2312
|
+
],
|
|
2313
|
+
"CY": [
|
|
2314
|
+
"h",
|
|
2315
|
+
"H",
|
|
2316
|
+
"hb",
|
|
2317
|
+
"hB"
|
|
2318
|
+
],
|
|
2319
|
+
"CZ": [
|
|
2320
|
+
"H"
|
|
2321
|
+
],
|
|
2322
|
+
"DE": [
|
|
2323
|
+
"H",
|
|
2324
|
+
"hB"
|
|
2325
|
+
],
|
|
2326
|
+
"DG": [
|
|
2327
|
+
"H",
|
|
2328
|
+
"h",
|
|
2329
|
+
"hb",
|
|
2330
|
+
"hB"
|
|
2331
|
+
],
|
|
2332
|
+
"DJ": [
|
|
2333
|
+
"h",
|
|
2334
|
+
"H"
|
|
2335
|
+
],
|
|
2336
|
+
"DK": [
|
|
2337
|
+
"H"
|
|
2338
|
+
],
|
|
2339
|
+
"DM": [
|
|
2340
|
+
"h",
|
|
2341
|
+
"hb",
|
|
2342
|
+
"H",
|
|
2343
|
+
"hB"
|
|
2344
|
+
],
|
|
2345
|
+
"DO": [
|
|
2346
|
+
"h",
|
|
2347
|
+
"H",
|
|
2348
|
+
"hB",
|
|
2349
|
+
"hb"
|
|
2350
|
+
],
|
|
2351
|
+
"DZ": [
|
|
2352
|
+
"h",
|
|
2353
|
+
"hB",
|
|
2354
|
+
"hb",
|
|
2355
|
+
"H"
|
|
2356
|
+
],
|
|
2357
|
+
"EA": [
|
|
2358
|
+
"H",
|
|
2359
|
+
"h",
|
|
2360
|
+
"hB",
|
|
2361
|
+
"hb"
|
|
2362
|
+
],
|
|
2363
|
+
"EC": [
|
|
2364
|
+
"h",
|
|
2365
|
+
"H",
|
|
2366
|
+
"hB",
|
|
2367
|
+
"hb"
|
|
2368
|
+
],
|
|
2369
|
+
"EE": [
|
|
2370
|
+
"H",
|
|
2371
|
+
"hB"
|
|
2372
|
+
],
|
|
2373
|
+
"EG": [
|
|
2374
|
+
"h",
|
|
2375
|
+
"hB",
|
|
2376
|
+
"hb",
|
|
2377
|
+
"H"
|
|
2378
|
+
],
|
|
2379
|
+
"EH": [
|
|
2380
|
+
"h",
|
|
2381
|
+
"hB",
|
|
2382
|
+
"hb",
|
|
2383
|
+
"H"
|
|
2384
|
+
],
|
|
2385
|
+
"ER": [
|
|
2386
|
+
"h",
|
|
2387
|
+
"H"
|
|
2388
|
+
],
|
|
2389
|
+
"ES": [
|
|
2390
|
+
"H",
|
|
2391
|
+
"hB",
|
|
2392
|
+
"h",
|
|
2393
|
+
"hb"
|
|
2394
|
+
],
|
|
2395
|
+
"ET": [
|
|
2396
|
+
"hB",
|
|
2397
|
+
"hb",
|
|
2398
|
+
"h",
|
|
2399
|
+
"H"
|
|
2400
|
+
],
|
|
2401
|
+
"FI": [
|
|
2402
|
+
"H"
|
|
2403
|
+
],
|
|
2404
|
+
"FJ": [
|
|
2405
|
+
"h",
|
|
2406
|
+
"hb",
|
|
2407
|
+
"H",
|
|
2408
|
+
"hB"
|
|
2409
|
+
],
|
|
2410
|
+
"FK": [
|
|
2411
|
+
"H",
|
|
2412
|
+
"h",
|
|
2413
|
+
"hb",
|
|
2414
|
+
"hB"
|
|
2415
|
+
],
|
|
2416
|
+
"FM": [
|
|
2417
|
+
"h",
|
|
2418
|
+
"hb",
|
|
2419
|
+
"H",
|
|
2420
|
+
"hB"
|
|
2421
|
+
],
|
|
2422
|
+
"FO": [
|
|
2423
|
+
"H",
|
|
2424
|
+
"h"
|
|
2425
|
+
],
|
|
2426
|
+
"FR": [
|
|
2427
|
+
"H",
|
|
2428
|
+
"hB"
|
|
2429
|
+
],
|
|
2430
|
+
"GA": [
|
|
2431
|
+
"H",
|
|
2432
|
+
"hB"
|
|
2433
|
+
],
|
|
2434
|
+
"GB": [
|
|
2435
|
+
"H",
|
|
2436
|
+
"h",
|
|
2437
|
+
"hb",
|
|
2438
|
+
"hB"
|
|
2439
|
+
],
|
|
2440
|
+
"GD": [
|
|
2441
|
+
"h",
|
|
2442
|
+
"hb",
|
|
2443
|
+
"H",
|
|
2444
|
+
"hB"
|
|
2445
|
+
],
|
|
2446
|
+
"GE": [
|
|
2447
|
+
"H",
|
|
2448
|
+
"hB",
|
|
2449
|
+
"h"
|
|
2450
|
+
],
|
|
2451
|
+
"GF": [
|
|
2452
|
+
"H",
|
|
2453
|
+
"hB"
|
|
2454
|
+
],
|
|
2455
|
+
"GG": [
|
|
2456
|
+
"H",
|
|
2457
|
+
"h",
|
|
2458
|
+
"hb",
|
|
2459
|
+
"hB"
|
|
2460
|
+
],
|
|
2461
|
+
"GH": [
|
|
2462
|
+
"h",
|
|
2463
|
+
"H"
|
|
2464
|
+
],
|
|
2465
|
+
"GI": [
|
|
2466
|
+
"H",
|
|
2467
|
+
"h",
|
|
2468
|
+
"hb",
|
|
2469
|
+
"hB"
|
|
2470
|
+
],
|
|
2471
|
+
"GL": [
|
|
2472
|
+
"H",
|
|
2473
|
+
"h"
|
|
2474
|
+
],
|
|
2475
|
+
"GM": [
|
|
2476
|
+
"h",
|
|
2477
|
+
"hb",
|
|
2478
|
+
"H",
|
|
2479
|
+
"hB"
|
|
2480
|
+
],
|
|
2481
|
+
"GN": [
|
|
2482
|
+
"H",
|
|
2483
|
+
"hB"
|
|
2484
|
+
],
|
|
2485
|
+
"GP": [
|
|
2486
|
+
"H",
|
|
2487
|
+
"hB"
|
|
2488
|
+
],
|
|
2489
|
+
"GQ": [
|
|
2490
|
+
"H",
|
|
2491
|
+
"hB",
|
|
2492
|
+
"h",
|
|
2493
|
+
"hb"
|
|
2494
|
+
],
|
|
2495
|
+
"GR": [
|
|
2496
|
+
"h",
|
|
2497
|
+
"H",
|
|
2498
|
+
"hb",
|
|
2499
|
+
"hB"
|
|
2500
|
+
],
|
|
2501
|
+
"GT": [
|
|
2502
|
+
"h",
|
|
2503
|
+
"H",
|
|
2504
|
+
"hB",
|
|
2505
|
+
"hb"
|
|
2506
|
+
],
|
|
2507
|
+
"GU": [
|
|
2508
|
+
"h",
|
|
2509
|
+
"hb",
|
|
2510
|
+
"H",
|
|
2511
|
+
"hB"
|
|
2512
|
+
],
|
|
2513
|
+
"GW": [
|
|
2514
|
+
"H",
|
|
2515
|
+
"hB"
|
|
2516
|
+
],
|
|
2517
|
+
"GY": [
|
|
2518
|
+
"h",
|
|
2519
|
+
"hb",
|
|
2520
|
+
"H",
|
|
2521
|
+
"hB"
|
|
2522
|
+
],
|
|
2523
|
+
"HK": [
|
|
2524
|
+
"h",
|
|
2525
|
+
"hB",
|
|
2526
|
+
"hb",
|
|
2527
|
+
"H"
|
|
2528
|
+
],
|
|
2529
|
+
"HN": [
|
|
2530
|
+
"h",
|
|
2531
|
+
"H",
|
|
2532
|
+
"hB",
|
|
2533
|
+
"hb"
|
|
2534
|
+
],
|
|
2535
|
+
"HR": [
|
|
2536
|
+
"H",
|
|
2537
|
+
"hB"
|
|
2538
|
+
],
|
|
2539
|
+
"HU": [
|
|
2540
|
+
"H",
|
|
2541
|
+
"h"
|
|
2542
|
+
],
|
|
2543
|
+
"IC": [
|
|
2544
|
+
"H",
|
|
2545
|
+
"h",
|
|
2546
|
+
"hB",
|
|
2547
|
+
"hb"
|
|
2548
|
+
],
|
|
2549
|
+
"ID": [
|
|
2550
|
+
"H"
|
|
2551
|
+
],
|
|
2552
|
+
"IE": [
|
|
2553
|
+
"H",
|
|
2554
|
+
"h",
|
|
2555
|
+
"hb",
|
|
2556
|
+
"hB"
|
|
2557
|
+
],
|
|
2558
|
+
"IL": [
|
|
2559
|
+
"H",
|
|
2560
|
+
"hB"
|
|
2561
|
+
],
|
|
2562
|
+
"IM": [
|
|
2563
|
+
"H",
|
|
2564
|
+
"h",
|
|
2565
|
+
"hb",
|
|
2566
|
+
"hB"
|
|
2567
|
+
],
|
|
2568
|
+
"IN": [
|
|
2569
|
+
"h",
|
|
2570
|
+
"H"
|
|
2571
|
+
],
|
|
2572
|
+
"IO": [
|
|
2573
|
+
"H",
|
|
2574
|
+
"h",
|
|
2575
|
+
"hb",
|
|
2576
|
+
"hB"
|
|
2577
|
+
],
|
|
2578
|
+
"IQ": [
|
|
2579
|
+
"h",
|
|
2580
|
+
"hB",
|
|
2581
|
+
"hb",
|
|
2582
|
+
"H"
|
|
2583
|
+
],
|
|
2584
|
+
"IR": [
|
|
2585
|
+
"hB",
|
|
2586
|
+
"H"
|
|
2587
|
+
],
|
|
2588
|
+
"IS": [
|
|
2589
|
+
"H"
|
|
2590
|
+
],
|
|
2591
|
+
"IT": [
|
|
2592
|
+
"H",
|
|
2593
|
+
"hB"
|
|
2594
|
+
],
|
|
2595
|
+
"JE": [
|
|
2596
|
+
"H",
|
|
2597
|
+
"h",
|
|
2598
|
+
"hb",
|
|
2599
|
+
"hB"
|
|
2600
|
+
],
|
|
2601
|
+
"JM": [
|
|
2602
|
+
"h",
|
|
2603
|
+
"hb",
|
|
2604
|
+
"H",
|
|
2605
|
+
"hB"
|
|
2606
|
+
],
|
|
2607
|
+
"JO": [
|
|
2608
|
+
"h",
|
|
2609
|
+
"hB",
|
|
2610
|
+
"hb",
|
|
2611
|
+
"H"
|
|
2612
|
+
],
|
|
2613
|
+
"JP": [
|
|
2614
|
+
"H",
|
|
2615
|
+
"K",
|
|
2616
|
+
"h"
|
|
2617
|
+
],
|
|
2618
|
+
"KE": [
|
|
2619
|
+
"hB",
|
|
2620
|
+
"hb",
|
|
2621
|
+
"H",
|
|
2622
|
+
"h"
|
|
2623
|
+
],
|
|
2624
|
+
"KG": [
|
|
2625
|
+
"H",
|
|
2626
|
+
"h",
|
|
2627
|
+
"hB",
|
|
2628
|
+
"hb"
|
|
2629
|
+
],
|
|
2630
|
+
"KH": [
|
|
2631
|
+
"hB",
|
|
2632
|
+
"h",
|
|
2633
|
+
"H",
|
|
2634
|
+
"hb"
|
|
2635
|
+
],
|
|
2636
|
+
"KI": [
|
|
2637
|
+
"h",
|
|
2638
|
+
"hb",
|
|
2639
|
+
"H",
|
|
2640
|
+
"hB"
|
|
2641
|
+
],
|
|
2642
|
+
"KM": [
|
|
2643
|
+
"H",
|
|
2644
|
+
"h",
|
|
2645
|
+
"hB",
|
|
2646
|
+
"hb"
|
|
2647
|
+
],
|
|
2648
|
+
"KN": [
|
|
2649
|
+
"h",
|
|
2650
|
+
"hb",
|
|
2651
|
+
"H",
|
|
2652
|
+
"hB"
|
|
2653
|
+
],
|
|
2654
|
+
"KP": [
|
|
2655
|
+
"h",
|
|
2656
|
+
"H",
|
|
2657
|
+
"hB",
|
|
2658
|
+
"hb"
|
|
2659
|
+
],
|
|
2660
|
+
"KR": [
|
|
2661
|
+
"h",
|
|
2662
|
+
"H",
|
|
2663
|
+
"hB",
|
|
2664
|
+
"hb"
|
|
2665
|
+
],
|
|
2666
|
+
"KW": [
|
|
2667
|
+
"h",
|
|
2668
|
+
"hB",
|
|
2669
|
+
"hb",
|
|
2670
|
+
"H"
|
|
2671
|
+
],
|
|
2672
|
+
"KY": [
|
|
2673
|
+
"h",
|
|
2674
|
+
"hb",
|
|
2675
|
+
"H",
|
|
2676
|
+
"hB"
|
|
2677
|
+
],
|
|
2678
|
+
"KZ": [
|
|
2679
|
+
"H",
|
|
2680
|
+
"hB"
|
|
2681
|
+
],
|
|
2682
|
+
"LA": [
|
|
2683
|
+
"H",
|
|
2684
|
+
"hb",
|
|
2685
|
+
"hB",
|
|
2686
|
+
"h"
|
|
2687
|
+
],
|
|
2688
|
+
"LB": [
|
|
2689
|
+
"h",
|
|
2690
|
+
"hB",
|
|
2691
|
+
"hb",
|
|
2692
|
+
"H"
|
|
2693
|
+
],
|
|
2694
|
+
"LC": [
|
|
2695
|
+
"h",
|
|
2696
|
+
"hb",
|
|
2697
|
+
"H",
|
|
2698
|
+
"hB"
|
|
2699
|
+
],
|
|
2700
|
+
"LI": [
|
|
2701
|
+
"H",
|
|
2702
|
+
"hB",
|
|
2703
|
+
"h"
|
|
2704
|
+
],
|
|
2705
|
+
"LK": [
|
|
2706
|
+
"H",
|
|
2707
|
+
"h",
|
|
2708
|
+
"hB",
|
|
2709
|
+
"hb"
|
|
2710
|
+
],
|
|
2711
|
+
"LR": [
|
|
2712
|
+
"h",
|
|
2713
|
+
"hb",
|
|
2714
|
+
"H",
|
|
2715
|
+
"hB"
|
|
2716
|
+
],
|
|
2717
|
+
"LS": [
|
|
2718
|
+
"h",
|
|
2719
|
+
"H"
|
|
2720
|
+
],
|
|
2721
|
+
"LT": [
|
|
2722
|
+
"H",
|
|
2723
|
+
"h",
|
|
2724
|
+
"hb",
|
|
2725
|
+
"hB"
|
|
2726
|
+
],
|
|
2727
|
+
"LU": [
|
|
2728
|
+
"H",
|
|
2729
|
+
"h",
|
|
2730
|
+
"hB"
|
|
2731
|
+
],
|
|
2732
|
+
"LV": [
|
|
2733
|
+
"H",
|
|
2734
|
+
"hB",
|
|
2735
|
+
"hb",
|
|
2736
|
+
"h"
|
|
2737
|
+
],
|
|
2738
|
+
"LY": [
|
|
2739
|
+
"h",
|
|
2740
|
+
"hB",
|
|
2741
|
+
"hb",
|
|
2742
|
+
"H"
|
|
2743
|
+
],
|
|
2744
|
+
"MA": [
|
|
2745
|
+
"H",
|
|
2746
|
+
"h",
|
|
2747
|
+
"hB",
|
|
2748
|
+
"hb"
|
|
2749
|
+
],
|
|
2750
|
+
"MC": [
|
|
2751
|
+
"H",
|
|
2752
|
+
"hB"
|
|
2753
|
+
],
|
|
2754
|
+
"MD": [
|
|
2755
|
+
"H",
|
|
2756
|
+
"hB"
|
|
2757
|
+
],
|
|
2758
|
+
"ME": [
|
|
2759
|
+
"H",
|
|
2760
|
+
"hB",
|
|
2761
|
+
"h"
|
|
2762
|
+
],
|
|
2763
|
+
"MF": [
|
|
2764
|
+
"H",
|
|
2765
|
+
"hB"
|
|
2766
|
+
],
|
|
2767
|
+
"MG": [
|
|
2768
|
+
"H",
|
|
2769
|
+
"h"
|
|
2770
|
+
],
|
|
2771
|
+
"MH": [
|
|
2772
|
+
"h",
|
|
2773
|
+
"hb",
|
|
2774
|
+
"H",
|
|
2775
|
+
"hB"
|
|
2776
|
+
],
|
|
2777
|
+
"MK": [
|
|
2778
|
+
"H",
|
|
2779
|
+
"h",
|
|
2780
|
+
"hb",
|
|
2781
|
+
"hB"
|
|
2782
|
+
],
|
|
2783
|
+
"ML": [
|
|
2784
|
+
"H"
|
|
2785
|
+
],
|
|
2786
|
+
"MM": [
|
|
2787
|
+
"hB",
|
|
2788
|
+
"hb",
|
|
2789
|
+
"H",
|
|
2790
|
+
"h"
|
|
2791
|
+
],
|
|
2792
|
+
"MN": [
|
|
2793
|
+
"H",
|
|
2794
|
+
"h",
|
|
2795
|
+
"hb",
|
|
2796
|
+
"hB"
|
|
2797
|
+
],
|
|
2798
|
+
"MO": [
|
|
2799
|
+
"h",
|
|
2800
|
+
"hB",
|
|
2801
|
+
"hb",
|
|
2802
|
+
"H"
|
|
2803
|
+
],
|
|
2804
|
+
"MP": [
|
|
2805
|
+
"h",
|
|
2806
|
+
"hb",
|
|
2807
|
+
"H",
|
|
2808
|
+
"hB"
|
|
2809
|
+
],
|
|
2810
|
+
"MQ": [
|
|
2811
|
+
"H",
|
|
2812
|
+
"hB"
|
|
2813
|
+
],
|
|
2814
|
+
"MR": [
|
|
2815
|
+
"h",
|
|
2816
|
+
"hB",
|
|
2817
|
+
"hb",
|
|
2818
|
+
"H"
|
|
2819
|
+
],
|
|
2820
|
+
"MS": [
|
|
2821
|
+
"H",
|
|
2822
|
+
"h",
|
|
2823
|
+
"hb",
|
|
2824
|
+
"hB"
|
|
2825
|
+
],
|
|
2826
|
+
"MT": [
|
|
2827
|
+
"H",
|
|
2828
|
+
"h"
|
|
2829
|
+
],
|
|
2830
|
+
"MU": [
|
|
2831
|
+
"H",
|
|
2832
|
+
"h"
|
|
2833
|
+
],
|
|
2834
|
+
"MV": [
|
|
2835
|
+
"H",
|
|
2836
|
+
"h"
|
|
2837
|
+
],
|
|
2838
|
+
"MW": [
|
|
2839
|
+
"h",
|
|
2840
|
+
"hb",
|
|
2841
|
+
"H",
|
|
2842
|
+
"hB"
|
|
2843
|
+
],
|
|
2844
|
+
"MX": [
|
|
2845
|
+
"h",
|
|
2846
|
+
"H",
|
|
2847
|
+
"hB",
|
|
2848
|
+
"hb"
|
|
2849
|
+
],
|
|
2850
|
+
"MY": [
|
|
2851
|
+
"hb",
|
|
2852
|
+
"hB",
|
|
2853
|
+
"h",
|
|
2854
|
+
"H"
|
|
2855
|
+
],
|
|
2856
|
+
"MZ": [
|
|
2857
|
+
"H",
|
|
2858
|
+
"hB"
|
|
2859
|
+
],
|
|
2860
|
+
"NA": [
|
|
2861
|
+
"h",
|
|
2862
|
+
"H",
|
|
2863
|
+
"hB",
|
|
2864
|
+
"hb"
|
|
2865
|
+
],
|
|
2866
|
+
"NC": [
|
|
2867
|
+
"H",
|
|
2868
|
+
"hB"
|
|
2869
|
+
],
|
|
2870
|
+
"NE": [
|
|
2871
|
+
"H"
|
|
2872
|
+
],
|
|
2873
|
+
"NF": [
|
|
2874
|
+
"H",
|
|
2875
|
+
"h",
|
|
2876
|
+
"hb",
|
|
2877
|
+
"hB"
|
|
2878
|
+
],
|
|
2879
|
+
"NG": [
|
|
2880
|
+
"H",
|
|
2881
|
+
"h",
|
|
2882
|
+
"hb",
|
|
2883
|
+
"hB"
|
|
2884
|
+
],
|
|
2885
|
+
"NI": [
|
|
2886
|
+
"h",
|
|
2887
|
+
"H",
|
|
2888
|
+
"hB",
|
|
2889
|
+
"hb"
|
|
2890
|
+
],
|
|
2891
|
+
"NL": [
|
|
2892
|
+
"H",
|
|
2893
|
+
"hB"
|
|
2894
|
+
],
|
|
2895
|
+
"NO": [
|
|
2896
|
+
"H",
|
|
2897
|
+
"h"
|
|
2898
|
+
],
|
|
2899
|
+
"NP": [
|
|
2900
|
+
"H",
|
|
2901
|
+
"h",
|
|
2902
|
+
"hB"
|
|
2903
|
+
],
|
|
2904
|
+
"NR": [
|
|
2905
|
+
"H",
|
|
2906
|
+
"h",
|
|
2907
|
+
"hb",
|
|
2908
|
+
"hB"
|
|
2909
|
+
],
|
|
2910
|
+
"NU": [
|
|
2911
|
+
"H",
|
|
2912
|
+
"h",
|
|
2913
|
+
"hb",
|
|
2914
|
+
"hB"
|
|
2915
|
+
],
|
|
2916
|
+
"NZ": [
|
|
2917
|
+
"h",
|
|
2918
|
+
"hb",
|
|
2919
|
+
"H",
|
|
2920
|
+
"hB"
|
|
2921
|
+
],
|
|
2922
|
+
"OM": [
|
|
2923
|
+
"h",
|
|
2924
|
+
"hB",
|
|
2925
|
+
"hb",
|
|
2926
|
+
"H"
|
|
2927
|
+
],
|
|
2928
|
+
"PA": [
|
|
2929
|
+
"h",
|
|
2930
|
+
"H",
|
|
2931
|
+
"hB",
|
|
2932
|
+
"hb"
|
|
2933
|
+
],
|
|
2934
|
+
"PE": [
|
|
2935
|
+
"h",
|
|
2936
|
+
"H",
|
|
2937
|
+
"hB",
|
|
2938
|
+
"hb"
|
|
2939
|
+
],
|
|
2940
|
+
"PF": [
|
|
2941
|
+
"H",
|
|
2942
|
+
"h",
|
|
2943
|
+
"hB"
|
|
2944
|
+
],
|
|
2945
|
+
"PG": [
|
|
2946
|
+
"h",
|
|
2947
|
+
"H"
|
|
2948
|
+
],
|
|
2949
|
+
"PH": [
|
|
2950
|
+
"h",
|
|
2951
|
+
"hB",
|
|
2952
|
+
"hb",
|
|
2953
|
+
"H"
|
|
2954
|
+
],
|
|
2955
|
+
"PK": [
|
|
2956
|
+
"h",
|
|
2957
|
+
"hB",
|
|
2958
|
+
"H"
|
|
2959
|
+
],
|
|
2960
|
+
"PL": [
|
|
2961
|
+
"H",
|
|
2962
|
+
"h"
|
|
2963
|
+
],
|
|
2964
|
+
"PM": [
|
|
2965
|
+
"H",
|
|
2966
|
+
"hB"
|
|
2967
|
+
],
|
|
2968
|
+
"PN": [
|
|
2969
|
+
"H",
|
|
2970
|
+
"h",
|
|
2971
|
+
"hb",
|
|
2972
|
+
"hB"
|
|
2973
|
+
],
|
|
2974
|
+
"PR": [
|
|
2975
|
+
"h",
|
|
2976
|
+
"H",
|
|
2977
|
+
"hB",
|
|
2978
|
+
"hb"
|
|
2979
|
+
],
|
|
2980
|
+
"PS": [
|
|
2981
|
+
"h",
|
|
2982
|
+
"hB",
|
|
2983
|
+
"hb",
|
|
2984
|
+
"H"
|
|
2985
|
+
],
|
|
2986
|
+
"PT": [
|
|
2987
|
+
"H",
|
|
2988
|
+
"hB"
|
|
2989
|
+
],
|
|
2990
|
+
"PW": [
|
|
2991
|
+
"h",
|
|
2992
|
+
"H"
|
|
2993
|
+
],
|
|
2994
|
+
"PY": [
|
|
2995
|
+
"h",
|
|
2996
|
+
"H",
|
|
2997
|
+
"hB",
|
|
2998
|
+
"hb"
|
|
2999
|
+
],
|
|
3000
|
+
"QA": [
|
|
3001
|
+
"h",
|
|
3002
|
+
"hB",
|
|
3003
|
+
"hb",
|
|
3004
|
+
"H"
|
|
3005
|
+
],
|
|
3006
|
+
"RE": [
|
|
3007
|
+
"H",
|
|
3008
|
+
"hB"
|
|
3009
|
+
],
|
|
3010
|
+
"RO": [
|
|
3011
|
+
"H",
|
|
3012
|
+
"hB"
|
|
3013
|
+
],
|
|
3014
|
+
"RS": [
|
|
3015
|
+
"H",
|
|
3016
|
+
"hB",
|
|
3017
|
+
"h"
|
|
3018
|
+
],
|
|
3019
|
+
"RU": [
|
|
3020
|
+
"H"
|
|
3021
|
+
],
|
|
3022
|
+
"RW": [
|
|
3023
|
+
"H",
|
|
3024
|
+
"h"
|
|
3025
|
+
],
|
|
3026
|
+
"SA": [
|
|
3027
|
+
"h",
|
|
3028
|
+
"hB",
|
|
3029
|
+
"hb",
|
|
3030
|
+
"H"
|
|
3031
|
+
],
|
|
3032
|
+
"SB": [
|
|
3033
|
+
"h",
|
|
3034
|
+
"hb",
|
|
3035
|
+
"H",
|
|
3036
|
+
"hB"
|
|
3037
|
+
],
|
|
3038
|
+
"SC": [
|
|
3039
|
+
"H",
|
|
3040
|
+
"h",
|
|
3041
|
+
"hB"
|
|
3042
|
+
],
|
|
3043
|
+
"SD": [
|
|
3044
|
+
"h",
|
|
3045
|
+
"hB",
|
|
3046
|
+
"hb",
|
|
3047
|
+
"H"
|
|
3048
|
+
],
|
|
3049
|
+
"SE": [
|
|
3050
|
+
"H"
|
|
3051
|
+
],
|
|
3052
|
+
"SG": [
|
|
3053
|
+
"h",
|
|
3054
|
+
"hb",
|
|
3055
|
+
"H",
|
|
3056
|
+
"hB"
|
|
3057
|
+
],
|
|
3058
|
+
"SH": [
|
|
3059
|
+
"H",
|
|
3060
|
+
"h",
|
|
3061
|
+
"hb",
|
|
3062
|
+
"hB"
|
|
3063
|
+
],
|
|
3064
|
+
"SI": [
|
|
3065
|
+
"H",
|
|
3066
|
+
"hB"
|
|
3067
|
+
],
|
|
3068
|
+
"SJ": [
|
|
3069
|
+
"H"
|
|
3070
|
+
],
|
|
3071
|
+
"SK": [
|
|
3072
|
+
"H"
|
|
3073
|
+
],
|
|
3074
|
+
"SL": [
|
|
3075
|
+
"h",
|
|
3076
|
+
"hb",
|
|
3077
|
+
"H",
|
|
3078
|
+
"hB"
|
|
3079
|
+
],
|
|
3080
|
+
"SM": [
|
|
3081
|
+
"H",
|
|
3082
|
+
"h",
|
|
3083
|
+
"hB"
|
|
3084
|
+
],
|
|
3085
|
+
"SN": [
|
|
3086
|
+
"H",
|
|
3087
|
+
"h",
|
|
3088
|
+
"hB"
|
|
3089
|
+
],
|
|
3090
|
+
"SO": [
|
|
3091
|
+
"h",
|
|
3092
|
+
"H"
|
|
3093
|
+
],
|
|
3094
|
+
"SR": [
|
|
3095
|
+
"H",
|
|
3096
|
+
"hB"
|
|
3097
|
+
],
|
|
3098
|
+
"SS": [
|
|
3099
|
+
"h",
|
|
3100
|
+
"hb",
|
|
3101
|
+
"H",
|
|
3102
|
+
"hB"
|
|
3103
|
+
],
|
|
3104
|
+
"ST": [
|
|
3105
|
+
"H",
|
|
3106
|
+
"hB"
|
|
3107
|
+
],
|
|
3108
|
+
"SV": [
|
|
3109
|
+
"h",
|
|
3110
|
+
"H",
|
|
3111
|
+
"hB",
|
|
3112
|
+
"hb"
|
|
3113
|
+
],
|
|
3114
|
+
"SX": [
|
|
3115
|
+
"H",
|
|
3116
|
+
"h",
|
|
3117
|
+
"hb",
|
|
3118
|
+
"hB"
|
|
3119
|
+
],
|
|
3120
|
+
"SY": [
|
|
3121
|
+
"h",
|
|
3122
|
+
"hB",
|
|
3123
|
+
"hb",
|
|
3124
|
+
"H"
|
|
3125
|
+
],
|
|
3126
|
+
"SZ": [
|
|
3127
|
+
"h",
|
|
3128
|
+
"hb",
|
|
3129
|
+
"H",
|
|
3130
|
+
"hB"
|
|
3131
|
+
],
|
|
3132
|
+
"TA": [
|
|
3133
|
+
"H",
|
|
3134
|
+
"h",
|
|
3135
|
+
"hb",
|
|
3136
|
+
"hB"
|
|
3137
|
+
],
|
|
3138
|
+
"TC": [
|
|
3139
|
+
"h",
|
|
3140
|
+
"hb",
|
|
3141
|
+
"H",
|
|
3142
|
+
"hB"
|
|
3143
|
+
],
|
|
3144
|
+
"TD": [
|
|
3145
|
+
"h",
|
|
3146
|
+
"H",
|
|
3147
|
+
"hB"
|
|
3148
|
+
],
|
|
3149
|
+
"TF": [
|
|
3150
|
+
"H",
|
|
3151
|
+
"h",
|
|
3152
|
+
"hB"
|
|
3153
|
+
],
|
|
3154
|
+
"TG": [
|
|
3155
|
+
"H",
|
|
3156
|
+
"hB"
|
|
3157
|
+
],
|
|
3158
|
+
"TH": [
|
|
3159
|
+
"H",
|
|
3160
|
+
"h"
|
|
3161
|
+
],
|
|
3162
|
+
"TJ": [
|
|
3163
|
+
"H",
|
|
3164
|
+
"h"
|
|
3165
|
+
],
|
|
3166
|
+
"TL": [
|
|
3167
|
+
"H",
|
|
3168
|
+
"hB",
|
|
3169
|
+
"hb",
|
|
3170
|
+
"h"
|
|
3171
|
+
],
|
|
3172
|
+
"TM": [
|
|
3173
|
+
"H",
|
|
3174
|
+
"h"
|
|
3175
|
+
],
|
|
3176
|
+
"TN": [
|
|
3177
|
+
"h",
|
|
3178
|
+
"hB",
|
|
3179
|
+
"hb",
|
|
3180
|
+
"H"
|
|
3181
|
+
],
|
|
3182
|
+
"TO": [
|
|
3183
|
+
"h",
|
|
3184
|
+
"H"
|
|
3185
|
+
],
|
|
3186
|
+
"TR": [
|
|
3187
|
+
"H",
|
|
3188
|
+
"hB"
|
|
3189
|
+
],
|
|
3190
|
+
"TT": [
|
|
3191
|
+
"h",
|
|
3192
|
+
"hb",
|
|
3193
|
+
"H",
|
|
3194
|
+
"hB"
|
|
3195
|
+
],
|
|
3196
|
+
"TW": [
|
|
3197
|
+
"hB",
|
|
3198
|
+
"hb",
|
|
3199
|
+
"h",
|
|
3200
|
+
"H"
|
|
3201
|
+
],
|
|
3202
|
+
"TZ": [
|
|
3203
|
+
"hB",
|
|
3204
|
+
"hb",
|
|
3205
|
+
"H",
|
|
3206
|
+
"h"
|
|
3207
|
+
],
|
|
3208
|
+
"UA": [
|
|
3209
|
+
"H",
|
|
3210
|
+
"hB",
|
|
3211
|
+
"h"
|
|
3212
|
+
],
|
|
3213
|
+
"UG": [
|
|
3214
|
+
"hB",
|
|
3215
|
+
"hb",
|
|
3216
|
+
"H",
|
|
3217
|
+
"h"
|
|
3218
|
+
],
|
|
3219
|
+
"UM": [
|
|
3220
|
+
"h",
|
|
3221
|
+
"hb",
|
|
3222
|
+
"H",
|
|
3223
|
+
"hB"
|
|
3224
|
+
],
|
|
3225
|
+
"US": [
|
|
3226
|
+
"h",
|
|
3227
|
+
"hb",
|
|
3228
|
+
"H",
|
|
3229
|
+
"hB"
|
|
3230
|
+
],
|
|
3231
|
+
"UY": [
|
|
3232
|
+
"h",
|
|
3233
|
+
"H",
|
|
3234
|
+
"hB",
|
|
3235
|
+
"hb"
|
|
3236
|
+
],
|
|
3237
|
+
"UZ": [
|
|
3238
|
+
"H",
|
|
3239
|
+
"hB",
|
|
3240
|
+
"h"
|
|
3241
|
+
],
|
|
3242
|
+
"VA": [
|
|
3243
|
+
"H",
|
|
3244
|
+
"h",
|
|
3245
|
+
"hB"
|
|
3246
|
+
],
|
|
3247
|
+
"VC": [
|
|
3248
|
+
"h",
|
|
3249
|
+
"hb",
|
|
3250
|
+
"H",
|
|
3251
|
+
"hB"
|
|
3252
|
+
],
|
|
3253
|
+
"VE": [
|
|
3254
|
+
"h",
|
|
3255
|
+
"H",
|
|
3256
|
+
"hB",
|
|
3257
|
+
"hb"
|
|
3258
|
+
],
|
|
3259
|
+
"VG": [
|
|
3260
|
+
"h",
|
|
3261
|
+
"hb",
|
|
3262
|
+
"H",
|
|
3263
|
+
"hB"
|
|
3264
|
+
],
|
|
3265
|
+
"VI": [
|
|
3266
|
+
"h",
|
|
3267
|
+
"hb",
|
|
3268
|
+
"H",
|
|
3269
|
+
"hB"
|
|
3270
|
+
],
|
|
3271
|
+
"VN": [
|
|
3272
|
+
"H",
|
|
3273
|
+
"h"
|
|
3274
|
+
],
|
|
3275
|
+
"VU": [
|
|
3276
|
+
"h",
|
|
3277
|
+
"H"
|
|
3278
|
+
],
|
|
3279
|
+
"WF": [
|
|
3280
|
+
"H",
|
|
3281
|
+
"hB"
|
|
3282
|
+
],
|
|
3283
|
+
"WS": [
|
|
3284
|
+
"h",
|
|
3285
|
+
"H"
|
|
3286
|
+
],
|
|
3287
|
+
"XK": [
|
|
3288
|
+
"H",
|
|
3289
|
+
"hB",
|
|
3290
|
+
"h"
|
|
3291
|
+
],
|
|
3292
|
+
"YE": [
|
|
3293
|
+
"h",
|
|
3294
|
+
"hB",
|
|
3295
|
+
"hb",
|
|
3296
|
+
"H"
|
|
3297
|
+
],
|
|
3298
|
+
"YT": [
|
|
3299
|
+
"H",
|
|
3300
|
+
"hB"
|
|
3301
|
+
],
|
|
3302
|
+
"ZA": [
|
|
3303
|
+
"H",
|
|
3304
|
+
"h",
|
|
3305
|
+
"hb",
|
|
3306
|
+
"hB"
|
|
3307
|
+
],
|
|
3308
|
+
"ZM": [
|
|
3309
|
+
"h",
|
|
3310
|
+
"hb",
|
|
3311
|
+
"H",
|
|
3312
|
+
"hB"
|
|
3313
|
+
],
|
|
3314
|
+
"ZW": [
|
|
3315
|
+
"H",
|
|
3316
|
+
"h"
|
|
3317
|
+
],
|
|
3318
|
+
"af-ZA": [
|
|
3319
|
+
"H",
|
|
3320
|
+
"h",
|
|
3321
|
+
"hB",
|
|
3322
|
+
"hb"
|
|
3323
|
+
],
|
|
3324
|
+
"ar-001": [
|
|
3325
|
+
"h",
|
|
3326
|
+
"hB",
|
|
3327
|
+
"hb",
|
|
3328
|
+
"H"
|
|
3329
|
+
],
|
|
3330
|
+
"ca-ES": [
|
|
3331
|
+
"H",
|
|
3332
|
+
"h",
|
|
3333
|
+
"hB"
|
|
3334
|
+
],
|
|
3335
|
+
"en-001": [
|
|
3336
|
+
"h",
|
|
3337
|
+
"hb",
|
|
3338
|
+
"H",
|
|
3339
|
+
"hB"
|
|
3340
|
+
],
|
|
3341
|
+
"en-HK": [
|
|
3342
|
+
"h",
|
|
3343
|
+
"hb",
|
|
3344
|
+
"H",
|
|
3345
|
+
"hB"
|
|
3346
|
+
],
|
|
3347
|
+
"en-IL": [
|
|
3348
|
+
"H",
|
|
3349
|
+
"h",
|
|
3350
|
+
"hb",
|
|
3351
|
+
"hB"
|
|
3352
|
+
],
|
|
3353
|
+
"en-MY": [
|
|
3354
|
+
"h",
|
|
3355
|
+
"hb",
|
|
3356
|
+
"H",
|
|
3357
|
+
"hB"
|
|
3358
|
+
],
|
|
3359
|
+
"es-BR": [
|
|
3360
|
+
"H",
|
|
3361
|
+
"h",
|
|
3362
|
+
"hB",
|
|
3363
|
+
"hb"
|
|
3364
|
+
],
|
|
3365
|
+
"es-ES": [
|
|
3366
|
+
"H",
|
|
3367
|
+
"h",
|
|
3368
|
+
"hB",
|
|
3369
|
+
"hb"
|
|
3370
|
+
],
|
|
3371
|
+
"es-GQ": [
|
|
3372
|
+
"H",
|
|
3373
|
+
"h",
|
|
3374
|
+
"hB",
|
|
3375
|
+
"hb"
|
|
3376
|
+
],
|
|
3377
|
+
"fr-CA": [
|
|
3378
|
+
"H",
|
|
3379
|
+
"h",
|
|
3380
|
+
"hB"
|
|
3381
|
+
],
|
|
3382
|
+
"gl-ES": [
|
|
3383
|
+
"H",
|
|
3384
|
+
"h",
|
|
3385
|
+
"hB"
|
|
3386
|
+
],
|
|
3387
|
+
"gu-IN": [
|
|
3388
|
+
"hB",
|
|
3389
|
+
"hb",
|
|
3390
|
+
"h",
|
|
3391
|
+
"H"
|
|
3392
|
+
],
|
|
3393
|
+
"hi-IN": [
|
|
3394
|
+
"hB",
|
|
3395
|
+
"h",
|
|
3396
|
+
"H"
|
|
3397
|
+
],
|
|
3398
|
+
"it-CH": [
|
|
3399
|
+
"H",
|
|
3400
|
+
"h",
|
|
3401
|
+
"hB"
|
|
3402
|
+
],
|
|
3403
|
+
"it-IT": [
|
|
3404
|
+
"H",
|
|
3405
|
+
"h",
|
|
3406
|
+
"hB"
|
|
3407
|
+
],
|
|
3408
|
+
"kn-IN": [
|
|
3409
|
+
"hB",
|
|
3410
|
+
"h",
|
|
3411
|
+
"H"
|
|
3412
|
+
],
|
|
3413
|
+
"ml-IN": [
|
|
3414
|
+
"hB",
|
|
3415
|
+
"h",
|
|
3416
|
+
"H"
|
|
3417
|
+
],
|
|
3418
|
+
"mr-IN": [
|
|
3419
|
+
"hB",
|
|
3420
|
+
"hb",
|
|
3421
|
+
"h",
|
|
3422
|
+
"H"
|
|
3423
|
+
],
|
|
3424
|
+
"pa-IN": [
|
|
3425
|
+
"hB",
|
|
3426
|
+
"hb",
|
|
3427
|
+
"h",
|
|
3428
|
+
"H"
|
|
3429
|
+
],
|
|
3430
|
+
"ta-IN": [
|
|
3431
|
+
"hB",
|
|
3432
|
+
"h",
|
|
3433
|
+
"hb",
|
|
3434
|
+
"H"
|
|
3435
|
+
],
|
|
3436
|
+
"te-IN": [
|
|
3437
|
+
"hB",
|
|
3438
|
+
"h",
|
|
3439
|
+
"H"
|
|
3440
|
+
],
|
|
3441
|
+
"zu-ZA": [
|
|
3442
|
+
"H",
|
|
3443
|
+
"hB",
|
|
3444
|
+
"hb",
|
|
3445
|
+
"h"
|
|
3446
|
+
]
|
|
3447
|
+
};
|
|
3448
|
+
|
|
3449
|
+
// node_modules/.pnpm/@formatjs+icu-messageformat-parser@2.11.4/node_modules/@formatjs/icu-messageformat-parser/lib/date-time-pattern-generator.js
|
|
3450
|
+
function getBestPattern(skeleton, locale) {
|
|
3451
|
+
var skeletonCopy = "";
|
|
3452
|
+
for (var patternPos = 0; patternPos < skeleton.length; patternPos++) {
|
|
3453
|
+
var patternChar = skeleton.charAt(patternPos);
|
|
3454
|
+
if (patternChar === "j") {
|
|
3455
|
+
var extraLength = 0;
|
|
3456
|
+
while (patternPos + 1 < skeleton.length && skeleton.charAt(patternPos + 1) === patternChar) {
|
|
3457
|
+
extraLength++;
|
|
3458
|
+
patternPos++;
|
|
3459
|
+
}
|
|
3460
|
+
var hourLen = 1 + (extraLength & 1);
|
|
3461
|
+
var dayPeriodLen = extraLength < 2 ? 1 : 3 + (extraLength >> 1);
|
|
3462
|
+
var dayPeriodChar = "a";
|
|
3463
|
+
var hourChar = getDefaultHourSymbolFromLocale(locale);
|
|
3464
|
+
if (hourChar == "H" || hourChar == "k") {
|
|
3465
|
+
dayPeriodLen = 0;
|
|
3466
|
+
}
|
|
3467
|
+
while (dayPeriodLen-- > 0) {
|
|
3468
|
+
skeletonCopy += dayPeriodChar;
|
|
3469
|
+
}
|
|
3470
|
+
while (hourLen-- > 0) {
|
|
3471
|
+
skeletonCopy = hourChar + skeletonCopy;
|
|
3472
|
+
}
|
|
3473
|
+
} else if (patternChar === "J") {
|
|
3474
|
+
skeletonCopy += "H";
|
|
3475
|
+
} else {
|
|
3476
|
+
skeletonCopy += patternChar;
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3479
|
+
return skeletonCopy;
|
|
3480
|
+
}
|
|
3481
|
+
function getDefaultHourSymbolFromLocale(locale) {
|
|
3482
|
+
var hourCycle = locale.hourCycle;
|
|
3483
|
+
if (hourCycle === void 0 && // @ts-ignore hourCycle(s) is not identified yet
|
|
3484
|
+
locale.hourCycles && // @ts-ignore
|
|
3485
|
+
locale.hourCycles.length) {
|
|
3486
|
+
hourCycle = locale.hourCycles[0];
|
|
3487
|
+
}
|
|
3488
|
+
if (hourCycle) {
|
|
3489
|
+
switch (hourCycle) {
|
|
3490
|
+
case "h24":
|
|
3491
|
+
return "k";
|
|
3492
|
+
case "h23":
|
|
3493
|
+
return "H";
|
|
3494
|
+
case "h12":
|
|
3495
|
+
return "h";
|
|
3496
|
+
case "h11":
|
|
3497
|
+
return "K";
|
|
3498
|
+
default:
|
|
3499
|
+
throw new Error("Invalid hourCycle");
|
|
3500
|
+
}
|
|
3501
|
+
}
|
|
3502
|
+
var languageTag = locale.language;
|
|
3503
|
+
var regionTag;
|
|
3504
|
+
if (languageTag !== "root") {
|
|
3505
|
+
regionTag = locale.maximize().region;
|
|
3506
|
+
}
|
|
3507
|
+
var hourCycles = timeData[regionTag || ""] || timeData[languageTag || ""] || timeData["".concat(languageTag, "-001")] || timeData["001"];
|
|
3508
|
+
return hourCycles[0];
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
// node_modules/.pnpm/@formatjs+icu-messageformat-parser@2.11.4/node_modules/@formatjs/icu-messageformat-parser/lib/parser.js
|
|
3512
|
+
var _a;
|
|
3513
|
+
var SPACE_SEPARATOR_START_REGEX = new RegExp("^".concat(SPACE_SEPARATOR_REGEX.source, "*"));
|
|
3514
|
+
var SPACE_SEPARATOR_END_REGEX = new RegExp("".concat(SPACE_SEPARATOR_REGEX.source, "*$"));
|
|
3515
|
+
function createLocation(start, end) {
|
|
3516
|
+
return { start, end };
|
|
3517
|
+
}
|
|
3518
|
+
var hasNativeStartsWith = !!String.prototype.startsWith && "_a".startsWith("a", 1);
|
|
3519
|
+
var hasNativeFromCodePoint = !!String.fromCodePoint;
|
|
3520
|
+
var hasNativeFromEntries = !!Object.fromEntries;
|
|
3521
|
+
var hasNativeCodePointAt = !!String.prototype.codePointAt;
|
|
3522
|
+
var hasTrimStart = !!String.prototype.trimStart;
|
|
3523
|
+
var hasTrimEnd = !!String.prototype.trimEnd;
|
|
3524
|
+
var hasNativeIsSafeInteger = !!Number.isSafeInteger;
|
|
3525
|
+
var isSafeInteger = hasNativeIsSafeInteger ? Number.isSafeInteger : function(n) {
|
|
3526
|
+
return typeof n === "number" && isFinite(n) && Math.floor(n) === n && Math.abs(n) <= 9007199254740991;
|
|
3527
|
+
};
|
|
3528
|
+
var REGEX_SUPPORTS_U_AND_Y = true;
|
|
3529
|
+
try {
|
|
3530
|
+
re = RE("([^\\p{White_Space}\\p{Pattern_Syntax}]*)", "yu");
|
|
3531
|
+
REGEX_SUPPORTS_U_AND_Y = ((_a = re.exec("a")) === null || _a === void 0 ? void 0 : _a[0]) === "a";
|
|
3532
|
+
} catch (_) {
|
|
3533
|
+
REGEX_SUPPORTS_U_AND_Y = false;
|
|
3534
|
+
}
|
|
3535
|
+
var re;
|
|
3536
|
+
var startsWith = hasNativeStartsWith ? (
|
|
3537
|
+
// Native
|
|
3538
|
+
function startsWith2(s, search, position) {
|
|
3539
|
+
return s.startsWith(search, position);
|
|
3540
|
+
}
|
|
3541
|
+
) : (
|
|
3542
|
+
// For IE11
|
|
3543
|
+
function startsWith3(s, search, position) {
|
|
3544
|
+
return s.slice(position, position + search.length) === search;
|
|
3545
|
+
}
|
|
3546
|
+
);
|
|
3547
|
+
var fromCodePoint = hasNativeFromCodePoint ? String.fromCodePoint : (
|
|
3548
|
+
// IE11
|
|
3549
|
+
function fromCodePoint2() {
|
|
3550
|
+
var codePoints = [];
|
|
3551
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
3552
|
+
codePoints[_i] = arguments[_i];
|
|
3553
|
+
}
|
|
3554
|
+
var elements = "";
|
|
3555
|
+
var length = codePoints.length;
|
|
3556
|
+
var i = 0;
|
|
3557
|
+
var code;
|
|
3558
|
+
while (length > i) {
|
|
3559
|
+
code = codePoints[i++];
|
|
3560
|
+
if (code > 1114111)
|
|
3561
|
+
throw RangeError(code + " is not a valid code point");
|
|
3562
|
+
elements += code < 65536 ? String.fromCharCode(code) : String.fromCharCode(((code -= 65536) >> 10) + 55296, code % 1024 + 56320);
|
|
3563
|
+
}
|
|
3564
|
+
return elements;
|
|
3565
|
+
}
|
|
3566
|
+
);
|
|
3567
|
+
var fromEntries = (
|
|
3568
|
+
// native
|
|
3569
|
+
hasNativeFromEntries ? Object.fromEntries : (
|
|
3570
|
+
// Ponyfill
|
|
3571
|
+
function fromEntries2(entries) {
|
|
3572
|
+
var obj = {};
|
|
3573
|
+
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
3574
|
+
var _a2 = entries_1[_i], k = _a2[0], v = _a2[1];
|
|
3575
|
+
obj[k] = v;
|
|
3576
|
+
}
|
|
3577
|
+
return obj;
|
|
3578
|
+
}
|
|
3579
|
+
)
|
|
3580
|
+
);
|
|
3581
|
+
var codePointAt = hasNativeCodePointAt ? (
|
|
3582
|
+
// Native
|
|
3583
|
+
function codePointAt2(s, index) {
|
|
3584
|
+
return s.codePointAt(index);
|
|
3585
|
+
}
|
|
3586
|
+
) : (
|
|
3587
|
+
// IE 11
|
|
3588
|
+
function codePointAt3(s, index) {
|
|
3589
|
+
var size = s.length;
|
|
3590
|
+
if (index < 0 || index >= size) {
|
|
3591
|
+
return void 0;
|
|
3592
|
+
}
|
|
3593
|
+
var first = s.charCodeAt(index);
|
|
3594
|
+
var second;
|
|
3595
|
+
return first < 55296 || first > 56319 || index + 1 === size || (second = s.charCodeAt(index + 1)) < 56320 || second > 57343 ? first : (first - 55296 << 10) + (second - 56320) + 65536;
|
|
3596
|
+
}
|
|
3597
|
+
);
|
|
3598
|
+
var trimStart = hasTrimStart ? (
|
|
3599
|
+
// Native
|
|
3600
|
+
function trimStart2(s) {
|
|
3601
|
+
return s.trimStart();
|
|
3602
|
+
}
|
|
3603
|
+
) : (
|
|
3604
|
+
// Ponyfill
|
|
3605
|
+
function trimStart3(s) {
|
|
3606
|
+
return s.replace(SPACE_SEPARATOR_START_REGEX, "");
|
|
3607
|
+
}
|
|
3608
|
+
);
|
|
3609
|
+
var trimEnd = hasTrimEnd ? (
|
|
3610
|
+
// Native
|
|
3611
|
+
function trimEnd2(s) {
|
|
3612
|
+
return s.trimEnd();
|
|
3613
|
+
}
|
|
3614
|
+
) : (
|
|
3615
|
+
// Ponyfill
|
|
3616
|
+
function trimEnd3(s) {
|
|
3617
|
+
return s.replace(SPACE_SEPARATOR_END_REGEX, "");
|
|
3618
|
+
}
|
|
3619
|
+
);
|
|
3620
|
+
function RE(s, flag) {
|
|
3621
|
+
return new RegExp(s, flag);
|
|
3622
|
+
}
|
|
3623
|
+
var matchIdentifierAtIndex;
|
|
3624
|
+
if (REGEX_SUPPORTS_U_AND_Y) {
|
|
3625
|
+
IDENTIFIER_PREFIX_RE_1 = RE("([^\\p{White_Space}\\p{Pattern_Syntax}]*)", "yu");
|
|
3626
|
+
matchIdentifierAtIndex = function matchIdentifierAtIndex2(s, index) {
|
|
3627
|
+
var _a2;
|
|
3628
|
+
IDENTIFIER_PREFIX_RE_1.lastIndex = index;
|
|
3629
|
+
var match = IDENTIFIER_PREFIX_RE_1.exec(s);
|
|
3630
|
+
return (_a2 = match[1]) !== null && _a2 !== void 0 ? _a2 : "";
|
|
3631
|
+
};
|
|
3632
|
+
} else {
|
|
3633
|
+
matchIdentifierAtIndex = function matchIdentifierAtIndex2(s, index) {
|
|
3634
|
+
var match = [];
|
|
3635
|
+
while (true) {
|
|
3636
|
+
var c = codePointAt(s, index);
|
|
3637
|
+
if (c === void 0 || _isWhiteSpace(c) || _isPatternSyntax(c)) {
|
|
3638
|
+
break;
|
|
3639
|
+
}
|
|
3640
|
+
match.push(c);
|
|
3641
|
+
index += c >= 65536 ? 2 : 1;
|
|
3642
|
+
}
|
|
3643
|
+
return fromCodePoint.apply(void 0, match);
|
|
3644
|
+
};
|
|
3645
|
+
}
|
|
3646
|
+
var IDENTIFIER_PREFIX_RE_1;
|
|
3647
|
+
var Parser = (
|
|
3648
|
+
/** @class */
|
|
3649
|
+
(function() {
|
|
3650
|
+
function Parser2(message, options) {
|
|
3651
|
+
if (options === void 0) {
|
|
3652
|
+
options = {};
|
|
3653
|
+
}
|
|
3654
|
+
this.message = message;
|
|
3655
|
+
this.position = { offset: 0, line: 1, column: 1 };
|
|
3656
|
+
this.ignoreTag = !!options.ignoreTag;
|
|
3657
|
+
this.locale = options.locale;
|
|
3658
|
+
this.requiresOtherClause = !!options.requiresOtherClause;
|
|
3659
|
+
this.shouldParseSkeletons = !!options.shouldParseSkeletons;
|
|
3660
|
+
}
|
|
3661
|
+
Parser2.prototype.parse = function() {
|
|
3662
|
+
if (this.offset() !== 0) {
|
|
3663
|
+
throw Error("parser can only be used once");
|
|
3664
|
+
}
|
|
3665
|
+
return this.parseMessage(0, "", false);
|
|
3666
|
+
};
|
|
3667
|
+
Parser2.prototype.parseMessage = function(nestingLevel, parentArgType, expectingCloseTag) {
|
|
3668
|
+
var elements = [];
|
|
3669
|
+
while (!this.isEOF()) {
|
|
3670
|
+
var char = this.char();
|
|
3671
|
+
if (char === 123) {
|
|
3672
|
+
var result = this.parseArgument(nestingLevel, expectingCloseTag);
|
|
3673
|
+
if (result.err) {
|
|
3674
|
+
return result;
|
|
3675
|
+
}
|
|
3676
|
+
elements.push(result.val);
|
|
3677
|
+
} else if (char === 125 && nestingLevel > 0) {
|
|
3678
|
+
break;
|
|
3679
|
+
} else if (char === 35 && (parentArgType === "plural" || parentArgType === "selectordinal")) {
|
|
3680
|
+
var position = this.clonePosition();
|
|
3681
|
+
this.bump();
|
|
3682
|
+
elements.push({
|
|
3683
|
+
type: TYPE.pound,
|
|
3684
|
+
location: createLocation(position, this.clonePosition())
|
|
3685
|
+
});
|
|
3686
|
+
} else if (char === 60 && !this.ignoreTag && this.peek() === 47) {
|
|
3687
|
+
if (expectingCloseTag) {
|
|
3688
|
+
break;
|
|
3689
|
+
} else {
|
|
3690
|
+
return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(this.clonePosition(), this.clonePosition()));
|
|
3691
|
+
}
|
|
3692
|
+
} else if (char === 60 && !this.ignoreTag && _isAlpha(this.peek() || 0)) {
|
|
3693
|
+
var result = this.parseTag(nestingLevel, parentArgType);
|
|
3694
|
+
if (result.err) {
|
|
3695
|
+
return result;
|
|
3696
|
+
}
|
|
3697
|
+
elements.push(result.val);
|
|
3698
|
+
} else {
|
|
3699
|
+
var result = this.parseLiteral(nestingLevel, parentArgType);
|
|
3700
|
+
if (result.err) {
|
|
3701
|
+
return result;
|
|
3702
|
+
}
|
|
3703
|
+
elements.push(result.val);
|
|
3704
|
+
}
|
|
3705
|
+
}
|
|
3706
|
+
return { val: elements, err: null };
|
|
3707
|
+
};
|
|
3708
|
+
Parser2.prototype.parseTag = function(nestingLevel, parentArgType) {
|
|
3709
|
+
var startPosition = this.clonePosition();
|
|
3710
|
+
this.bump();
|
|
3711
|
+
var tagName = this.parseTagName();
|
|
3712
|
+
this.bumpSpace();
|
|
3713
|
+
if (this.bumpIf("/>")) {
|
|
3714
|
+
return {
|
|
3715
|
+
val: {
|
|
3716
|
+
type: TYPE.literal,
|
|
3717
|
+
value: "<".concat(tagName, "/>"),
|
|
3718
|
+
location: createLocation(startPosition, this.clonePosition())
|
|
3719
|
+
},
|
|
3720
|
+
err: null
|
|
3721
|
+
};
|
|
3722
|
+
} else if (this.bumpIf(">")) {
|
|
3723
|
+
var childrenResult = this.parseMessage(nestingLevel + 1, parentArgType, true);
|
|
3724
|
+
if (childrenResult.err) {
|
|
3725
|
+
return childrenResult;
|
|
3726
|
+
}
|
|
3727
|
+
var children = childrenResult.val;
|
|
3728
|
+
var endTagStartPosition = this.clonePosition();
|
|
3729
|
+
if (this.bumpIf("</")) {
|
|
3730
|
+
if (this.isEOF() || !_isAlpha(this.char())) {
|
|
3731
|
+
return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
|
|
3732
|
+
}
|
|
3733
|
+
var closingTagNameStartPosition = this.clonePosition();
|
|
3734
|
+
var closingTagName = this.parseTagName();
|
|
3735
|
+
if (tagName !== closingTagName) {
|
|
3736
|
+
return this.error(ErrorKind.UNMATCHED_CLOSING_TAG, createLocation(closingTagNameStartPosition, this.clonePosition()));
|
|
3737
|
+
}
|
|
3738
|
+
this.bumpSpace();
|
|
3739
|
+
if (!this.bumpIf(">")) {
|
|
3740
|
+
return this.error(ErrorKind.INVALID_TAG, createLocation(endTagStartPosition, this.clonePosition()));
|
|
3741
|
+
}
|
|
3742
|
+
return {
|
|
3743
|
+
val: {
|
|
3744
|
+
type: TYPE.tag,
|
|
3745
|
+
value: tagName,
|
|
3746
|
+
children,
|
|
3747
|
+
location: createLocation(startPosition, this.clonePosition())
|
|
3748
|
+
},
|
|
3749
|
+
err: null
|
|
3750
|
+
};
|
|
3751
|
+
} else {
|
|
3752
|
+
return this.error(ErrorKind.UNCLOSED_TAG, createLocation(startPosition, this.clonePosition()));
|
|
3753
|
+
}
|
|
3754
|
+
} else {
|
|
3755
|
+
return this.error(ErrorKind.INVALID_TAG, createLocation(startPosition, this.clonePosition()));
|
|
3756
|
+
}
|
|
3757
|
+
};
|
|
3758
|
+
Parser2.prototype.parseTagName = function() {
|
|
3759
|
+
var startOffset = this.offset();
|
|
3760
|
+
this.bump();
|
|
3761
|
+
while (!this.isEOF() && _isPotentialElementNameChar(this.char())) {
|
|
3762
|
+
this.bump();
|
|
3763
|
+
}
|
|
3764
|
+
return this.message.slice(startOffset, this.offset());
|
|
3765
|
+
};
|
|
3766
|
+
Parser2.prototype.parseLiteral = function(nestingLevel, parentArgType) {
|
|
3767
|
+
var start = this.clonePosition();
|
|
3768
|
+
var value = "";
|
|
3769
|
+
while (true) {
|
|
3770
|
+
var parseQuoteResult = this.tryParseQuote(parentArgType);
|
|
3771
|
+
if (parseQuoteResult) {
|
|
3772
|
+
value += parseQuoteResult;
|
|
3773
|
+
continue;
|
|
3774
|
+
}
|
|
3775
|
+
var parseUnquotedResult = this.tryParseUnquoted(nestingLevel, parentArgType);
|
|
3776
|
+
if (parseUnquotedResult) {
|
|
3777
|
+
value += parseUnquotedResult;
|
|
3778
|
+
continue;
|
|
3779
|
+
}
|
|
3780
|
+
var parseLeftAngleResult = this.tryParseLeftAngleBracket();
|
|
3781
|
+
if (parseLeftAngleResult) {
|
|
3782
|
+
value += parseLeftAngleResult;
|
|
3783
|
+
continue;
|
|
3784
|
+
}
|
|
3785
|
+
break;
|
|
3786
|
+
}
|
|
3787
|
+
var location = createLocation(start, this.clonePosition());
|
|
3788
|
+
return {
|
|
3789
|
+
val: { type: TYPE.literal, value, location },
|
|
3790
|
+
err: null
|
|
3791
|
+
};
|
|
3792
|
+
};
|
|
3793
|
+
Parser2.prototype.tryParseLeftAngleBracket = function() {
|
|
3794
|
+
if (!this.isEOF() && this.char() === 60 && (this.ignoreTag || // If at the opening tag or closing tag position, bail.
|
|
3795
|
+
!_isAlphaOrSlash(this.peek() || 0))) {
|
|
3796
|
+
this.bump();
|
|
3797
|
+
return "<";
|
|
3798
|
+
}
|
|
3799
|
+
return null;
|
|
3800
|
+
};
|
|
3801
|
+
Parser2.prototype.tryParseQuote = function(parentArgType) {
|
|
3802
|
+
if (this.isEOF() || this.char() !== 39) {
|
|
3803
|
+
return null;
|
|
3804
|
+
}
|
|
3805
|
+
switch (this.peek()) {
|
|
3806
|
+
case 39:
|
|
3807
|
+
this.bump();
|
|
3808
|
+
this.bump();
|
|
3809
|
+
return "'";
|
|
3810
|
+
// '{', '<', '>', '}'
|
|
3811
|
+
case 123:
|
|
3812
|
+
case 60:
|
|
3813
|
+
case 62:
|
|
3814
|
+
case 125:
|
|
3815
|
+
break;
|
|
3816
|
+
case 35:
|
|
3817
|
+
if (parentArgType === "plural" || parentArgType === "selectordinal") {
|
|
3818
|
+
break;
|
|
3819
|
+
}
|
|
3820
|
+
return null;
|
|
3821
|
+
default:
|
|
3822
|
+
return null;
|
|
3823
|
+
}
|
|
3824
|
+
this.bump();
|
|
3825
|
+
var codePoints = [this.char()];
|
|
3826
|
+
this.bump();
|
|
3827
|
+
while (!this.isEOF()) {
|
|
3828
|
+
var ch = this.char();
|
|
3829
|
+
if (ch === 39) {
|
|
3830
|
+
if (this.peek() === 39) {
|
|
3831
|
+
codePoints.push(39);
|
|
3832
|
+
this.bump();
|
|
3833
|
+
} else {
|
|
3834
|
+
this.bump();
|
|
3835
|
+
break;
|
|
3836
|
+
}
|
|
3837
|
+
} else {
|
|
3838
|
+
codePoints.push(ch);
|
|
3839
|
+
}
|
|
3840
|
+
this.bump();
|
|
3841
|
+
}
|
|
3842
|
+
return fromCodePoint.apply(void 0, codePoints);
|
|
3843
|
+
};
|
|
3844
|
+
Parser2.prototype.tryParseUnquoted = function(nestingLevel, parentArgType) {
|
|
3845
|
+
if (this.isEOF()) {
|
|
3846
|
+
return null;
|
|
3847
|
+
}
|
|
3848
|
+
var ch = this.char();
|
|
3849
|
+
if (ch === 60 || ch === 123 || ch === 35 && (parentArgType === "plural" || parentArgType === "selectordinal") || ch === 125 && nestingLevel > 0) {
|
|
3850
|
+
return null;
|
|
3851
|
+
} else {
|
|
3852
|
+
this.bump();
|
|
3853
|
+
return fromCodePoint(ch);
|
|
3854
|
+
}
|
|
3855
|
+
};
|
|
3856
|
+
Parser2.prototype.parseArgument = function(nestingLevel, expectingCloseTag) {
|
|
3857
|
+
var openingBracePosition = this.clonePosition();
|
|
3858
|
+
this.bump();
|
|
3859
|
+
this.bumpSpace();
|
|
3860
|
+
if (this.isEOF()) {
|
|
3861
|
+
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
3862
|
+
}
|
|
3863
|
+
if (this.char() === 125) {
|
|
3864
|
+
this.bump();
|
|
3865
|
+
return this.error(ErrorKind.EMPTY_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
3866
|
+
}
|
|
3867
|
+
var value = this.parseIdentifierIfPossible().value;
|
|
3868
|
+
if (!value) {
|
|
3869
|
+
return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
3870
|
+
}
|
|
3871
|
+
this.bumpSpace();
|
|
3872
|
+
if (this.isEOF()) {
|
|
3873
|
+
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
3874
|
+
}
|
|
3875
|
+
switch (this.char()) {
|
|
3876
|
+
// Simple argument: `{name}`
|
|
3877
|
+
case 125: {
|
|
3878
|
+
this.bump();
|
|
3879
|
+
return {
|
|
3880
|
+
val: {
|
|
3881
|
+
type: TYPE.argument,
|
|
3882
|
+
// value does not include the opening and closing braces.
|
|
3883
|
+
value,
|
|
3884
|
+
location: createLocation(openingBracePosition, this.clonePosition())
|
|
3885
|
+
},
|
|
3886
|
+
err: null
|
|
3887
|
+
};
|
|
3888
|
+
}
|
|
3889
|
+
// Argument with options: `{name, format, ...}`
|
|
3890
|
+
case 44: {
|
|
3891
|
+
this.bump();
|
|
3892
|
+
this.bumpSpace();
|
|
3893
|
+
if (this.isEOF()) {
|
|
3894
|
+
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
3895
|
+
}
|
|
3896
|
+
return this.parseArgumentOptions(nestingLevel, expectingCloseTag, value, openingBracePosition);
|
|
3897
|
+
}
|
|
3898
|
+
default:
|
|
3899
|
+
return this.error(ErrorKind.MALFORMED_ARGUMENT, createLocation(openingBracePosition, this.clonePosition()));
|
|
3900
|
+
}
|
|
3901
|
+
};
|
|
3902
|
+
Parser2.prototype.parseIdentifierIfPossible = function() {
|
|
3903
|
+
var startingPosition = this.clonePosition();
|
|
3904
|
+
var startOffset = this.offset();
|
|
3905
|
+
var value = matchIdentifierAtIndex(this.message, startOffset);
|
|
3906
|
+
var endOffset = startOffset + value.length;
|
|
3907
|
+
this.bumpTo(endOffset);
|
|
3908
|
+
var endPosition = this.clonePosition();
|
|
3909
|
+
var location = createLocation(startingPosition, endPosition);
|
|
3910
|
+
return { value, location };
|
|
3911
|
+
};
|
|
3912
|
+
Parser2.prototype.parseArgumentOptions = function(nestingLevel, expectingCloseTag, value, openingBracePosition) {
|
|
3913
|
+
var _a2;
|
|
3914
|
+
var typeStartPosition = this.clonePosition();
|
|
3915
|
+
var argType = this.parseIdentifierIfPossible().value;
|
|
3916
|
+
var typeEndPosition = this.clonePosition();
|
|
3917
|
+
switch (argType) {
|
|
3918
|
+
case "":
|
|
3919
|
+
return this.error(ErrorKind.EXPECT_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
|
|
3920
|
+
case "number":
|
|
3921
|
+
case "date":
|
|
3922
|
+
case "time": {
|
|
3923
|
+
this.bumpSpace();
|
|
3924
|
+
var styleAndLocation = null;
|
|
3925
|
+
if (this.bumpIf(",")) {
|
|
3926
|
+
this.bumpSpace();
|
|
3927
|
+
var styleStartPosition = this.clonePosition();
|
|
3928
|
+
var result = this.parseSimpleArgStyleIfPossible();
|
|
3929
|
+
if (result.err) {
|
|
3930
|
+
return result;
|
|
3931
|
+
}
|
|
3932
|
+
var style = trimEnd(result.val);
|
|
3933
|
+
if (style.length === 0) {
|
|
3934
|
+
return this.error(ErrorKind.EXPECT_ARGUMENT_STYLE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
3935
|
+
}
|
|
3936
|
+
var styleLocation = createLocation(styleStartPosition, this.clonePosition());
|
|
3937
|
+
styleAndLocation = { style, styleLocation };
|
|
3938
|
+
}
|
|
3939
|
+
var argCloseResult = this.tryParseArgumentClose(openingBracePosition);
|
|
3940
|
+
if (argCloseResult.err) {
|
|
3941
|
+
return argCloseResult;
|
|
3942
|
+
}
|
|
3943
|
+
var location_1 = createLocation(openingBracePosition, this.clonePosition());
|
|
3944
|
+
if (styleAndLocation && startsWith(styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style, "::", 0)) {
|
|
3945
|
+
var skeleton = trimStart(styleAndLocation.style.slice(2));
|
|
3946
|
+
if (argType === "number") {
|
|
3947
|
+
var result = this.parseNumberSkeletonFromString(skeleton, styleAndLocation.styleLocation);
|
|
3948
|
+
if (result.err) {
|
|
3949
|
+
return result;
|
|
3950
|
+
}
|
|
3951
|
+
return {
|
|
3952
|
+
val: { type: TYPE.number, value, location: location_1, style: result.val },
|
|
3953
|
+
err: null
|
|
3954
|
+
};
|
|
3955
|
+
} else {
|
|
3956
|
+
if (skeleton.length === 0) {
|
|
3957
|
+
return this.error(ErrorKind.EXPECT_DATE_TIME_SKELETON, location_1);
|
|
3958
|
+
}
|
|
3959
|
+
var dateTimePattern = skeleton;
|
|
3960
|
+
if (this.locale) {
|
|
3961
|
+
dateTimePattern = getBestPattern(skeleton, this.locale);
|
|
3962
|
+
}
|
|
3963
|
+
var style = {
|
|
3964
|
+
type: SKELETON_TYPE.dateTime,
|
|
3965
|
+
pattern: dateTimePattern,
|
|
3966
|
+
location: styleAndLocation.styleLocation,
|
|
3967
|
+
parsedOptions: this.shouldParseSkeletons ? parseDateTimeSkeleton(dateTimePattern) : {}
|
|
3968
|
+
};
|
|
3969
|
+
var type = argType === "date" ? TYPE.date : TYPE.time;
|
|
3970
|
+
return {
|
|
3971
|
+
val: { type, value, location: location_1, style },
|
|
3972
|
+
err: null
|
|
3973
|
+
};
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
return {
|
|
3977
|
+
val: {
|
|
3978
|
+
type: argType === "number" ? TYPE.number : argType === "date" ? TYPE.date : TYPE.time,
|
|
3979
|
+
value,
|
|
3980
|
+
location: location_1,
|
|
3981
|
+
style: (_a2 = styleAndLocation === null || styleAndLocation === void 0 ? void 0 : styleAndLocation.style) !== null && _a2 !== void 0 ? _a2 : null
|
|
3982
|
+
},
|
|
3983
|
+
err: null
|
|
3984
|
+
};
|
|
3985
|
+
}
|
|
3986
|
+
case "plural":
|
|
3987
|
+
case "selectordinal":
|
|
3988
|
+
case "select": {
|
|
3989
|
+
var typeEndPosition_1 = this.clonePosition();
|
|
3990
|
+
this.bumpSpace();
|
|
3991
|
+
if (!this.bumpIf(",")) {
|
|
3992
|
+
return this.error(ErrorKind.EXPECT_SELECT_ARGUMENT_OPTIONS, createLocation(typeEndPosition_1, __assign({}, typeEndPosition_1)));
|
|
3993
|
+
}
|
|
3994
|
+
this.bumpSpace();
|
|
3995
|
+
var identifierAndLocation = this.parseIdentifierIfPossible();
|
|
3996
|
+
var pluralOffset = 0;
|
|
3997
|
+
if (argType !== "select" && identifierAndLocation.value === "offset") {
|
|
3998
|
+
if (!this.bumpIf(":")) {
|
|
3999
|
+
return this.error(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
4000
|
+
}
|
|
4001
|
+
this.bumpSpace();
|
|
4002
|
+
var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE, ErrorKind.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE);
|
|
4003
|
+
if (result.err) {
|
|
4004
|
+
return result;
|
|
4005
|
+
}
|
|
4006
|
+
this.bumpSpace();
|
|
4007
|
+
identifierAndLocation = this.parseIdentifierIfPossible();
|
|
4008
|
+
pluralOffset = result.val;
|
|
4009
|
+
}
|
|
4010
|
+
var optionsResult = this.tryParsePluralOrSelectOptions(nestingLevel, argType, expectingCloseTag, identifierAndLocation);
|
|
4011
|
+
if (optionsResult.err) {
|
|
4012
|
+
return optionsResult;
|
|
4013
|
+
}
|
|
4014
|
+
var argCloseResult = this.tryParseArgumentClose(openingBracePosition);
|
|
4015
|
+
if (argCloseResult.err) {
|
|
4016
|
+
return argCloseResult;
|
|
4017
|
+
}
|
|
4018
|
+
var location_2 = createLocation(openingBracePosition, this.clonePosition());
|
|
4019
|
+
if (argType === "select") {
|
|
4020
|
+
return {
|
|
4021
|
+
val: {
|
|
4022
|
+
type: TYPE.select,
|
|
4023
|
+
value,
|
|
4024
|
+
options: fromEntries(optionsResult.val),
|
|
4025
|
+
location: location_2
|
|
4026
|
+
},
|
|
4027
|
+
err: null
|
|
4028
|
+
};
|
|
4029
|
+
} else {
|
|
4030
|
+
return {
|
|
4031
|
+
val: {
|
|
4032
|
+
type: TYPE.plural,
|
|
4033
|
+
value,
|
|
4034
|
+
options: fromEntries(optionsResult.val),
|
|
4035
|
+
offset: pluralOffset,
|
|
4036
|
+
pluralType: argType === "plural" ? "cardinal" : "ordinal",
|
|
4037
|
+
location: location_2
|
|
4038
|
+
},
|
|
4039
|
+
err: null
|
|
4040
|
+
};
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
default:
|
|
4044
|
+
return this.error(ErrorKind.INVALID_ARGUMENT_TYPE, createLocation(typeStartPosition, typeEndPosition));
|
|
4045
|
+
}
|
|
4046
|
+
};
|
|
4047
|
+
Parser2.prototype.tryParseArgumentClose = function(openingBracePosition) {
|
|
4048
|
+
if (this.isEOF() || this.char() !== 125) {
|
|
4049
|
+
return this.error(ErrorKind.EXPECT_ARGUMENT_CLOSING_BRACE, createLocation(openingBracePosition, this.clonePosition()));
|
|
4050
|
+
}
|
|
4051
|
+
this.bump();
|
|
4052
|
+
return { val: true, err: null };
|
|
4053
|
+
};
|
|
4054
|
+
Parser2.prototype.parseSimpleArgStyleIfPossible = function() {
|
|
4055
|
+
var nestedBraces = 0;
|
|
4056
|
+
var startPosition = this.clonePosition();
|
|
4057
|
+
while (!this.isEOF()) {
|
|
4058
|
+
var ch = this.char();
|
|
4059
|
+
switch (ch) {
|
|
4060
|
+
case 39: {
|
|
4061
|
+
this.bump();
|
|
4062
|
+
var apostrophePosition = this.clonePosition();
|
|
4063
|
+
if (!this.bumpUntil("'")) {
|
|
4064
|
+
return this.error(ErrorKind.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE, createLocation(apostrophePosition, this.clonePosition()));
|
|
4065
|
+
}
|
|
4066
|
+
this.bump();
|
|
4067
|
+
break;
|
|
4068
|
+
}
|
|
4069
|
+
case 123: {
|
|
4070
|
+
nestedBraces += 1;
|
|
4071
|
+
this.bump();
|
|
4072
|
+
break;
|
|
4073
|
+
}
|
|
4074
|
+
case 125: {
|
|
4075
|
+
if (nestedBraces > 0) {
|
|
4076
|
+
nestedBraces -= 1;
|
|
4077
|
+
} else {
|
|
4078
|
+
return {
|
|
4079
|
+
val: this.message.slice(startPosition.offset, this.offset()),
|
|
4080
|
+
err: null
|
|
4081
|
+
};
|
|
4082
|
+
}
|
|
4083
|
+
break;
|
|
4084
|
+
}
|
|
4085
|
+
default:
|
|
4086
|
+
this.bump();
|
|
4087
|
+
break;
|
|
4088
|
+
}
|
|
4089
|
+
}
|
|
4090
|
+
return {
|
|
4091
|
+
val: this.message.slice(startPosition.offset, this.offset()),
|
|
4092
|
+
err: null
|
|
4093
|
+
};
|
|
4094
|
+
};
|
|
4095
|
+
Parser2.prototype.parseNumberSkeletonFromString = function(skeleton, location) {
|
|
4096
|
+
var tokens = [];
|
|
4097
|
+
try {
|
|
4098
|
+
tokens = parseNumberSkeletonFromString(skeleton);
|
|
4099
|
+
} catch (e) {
|
|
4100
|
+
return this.error(ErrorKind.INVALID_NUMBER_SKELETON, location);
|
|
4101
|
+
}
|
|
4102
|
+
return {
|
|
4103
|
+
val: {
|
|
4104
|
+
type: SKELETON_TYPE.number,
|
|
4105
|
+
tokens,
|
|
4106
|
+
location,
|
|
4107
|
+
parsedOptions: this.shouldParseSkeletons ? parseNumberSkeleton(tokens) : {}
|
|
4108
|
+
},
|
|
4109
|
+
err: null
|
|
4110
|
+
};
|
|
4111
|
+
};
|
|
4112
|
+
Parser2.prototype.tryParsePluralOrSelectOptions = function(nestingLevel, parentArgType, expectCloseTag, parsedFirstIdentifier) {
|
|
4113
|
+
var _a2;
|
|
4114
|
+
var hasOtherClause = false;
|
|
4115
|
+
var options = [];
|
|
4116
|
+
var parsedSelectors = /* @__PURE__ */ new Set();
|
|
4117
|
+
var selector = parsedFirstIdentifier.value, selectorLocation = parsedFirstIdentifier.location;
|
|
4118
|
+
while (true) {
|
|
4119
|
+
if (selector.length === 0) {
|
|
4120
|
+
var startPosition = this.clonePosition();
|
|
4121
|
+
if (parentArgType !== "select" && this.bumpIf("=")) {
|
|
4122
|
+
var result = this.tryParseDecimalInteger(ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, ErrorKind.INVALID_PLURAL_ARGUMENT_SELECTOR);
|
|
4123
|
+
if (result.err) {
|
|
4124
|
+
return result;
|
|
4125
|
+
}
|
|
4126
|
+
selectorLocation = createLocation(startPosition, this.clonePosition());
|
|
4127
|
+
selector = this.message.slice(startPosition.offset, this.offset());
|
|
4128
|
+
} else {
|
|
4129
|
+
break;
|
|
4130
|
+
}
|
|
4131
|
+
}
|
|
4132
|
+
if (parsedSelectors.has(selector)) {
|
|
4133
|
+
return this.error(parentArgType === "select" ? ErrorKind.DUPLICATE_SELECT_ARGUMENT_SELECTOR : ErrorKind.DUPLICATE_PLURAL_ARGUMENT_SELECTOR, selectorLocation);
|
|
4134
|
+
}
|
|
4135
|
+
if (selector === "other") {
|
|
4136
|
+
hasOtherClause = true;
|
|
4137
|
+
}
|
|
4138
|
+
this.bumpSpace();
|
|
4139
|
+
var openingBracePosition = this.clonePosition();
|
|
4140
|
+
if (!this.bumpIf("{")) {
|
|
4141
|
+
return this.error(parentArgType === "select" ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT, createLocation(this.clonePosition(), this.clonePosition()));
|
|
4142
|
+
}
|
|
4143
|
+
var fragmentResult = this.parseMessage(nestingLevel + 1, parentArgType, expectCloseTag);
|
|
4144
|
+
if (fragmentResult.err) {
|
|
4145
|
+
return fragmentResult;
|
|
4146
|
+
}
|
|
4147
|
+
var argCloseResult = this.tryParseArgumentClose(openingBracePosition);
|
|
4148
|
+
if (argCloseResult.err) {
|
|
4149
|
+
return argCloseResult;
|
|
4150
|
+
}
|
|
4151
|
+
options.push([
|
|
4152
|
+
selector,
|
|
4153
|
+
{
|
|
4154
|
+
value: fragmentResult.val,
|
|
4155
|
+
location: createLocation(openingBracePosition, this.clonePosition())
|
|
4156
|
+
}
|
|
4157
|
+
]);
|
|
4158
|
+
parsedSelectors.add(selector);
|
|
4159
|
+
this.bumpSpace();
|
|
4160
|
+
_a2 = this.parseIdentifierIfPossible(), selector = _a2.value, selectorLocation = _a2.location;
|
|
4161
|
+
}
|
|
4162
|
+
if (options.length === 0) {
|
|
4163
|
+
return this.error(parentArgType === "select" ? ErrorKind.EXPECT_SELECT_ARGUMENT_SELECTOR : ErrorKind.EXPECT_PLURAL_ARGUMENT_SELECTOR, createLocation(this.clonePosition(), this.clonePosition()));
|
|
4164
|
+
}
|
|
4165
|
+
if (this.requiresOtherClause && !hasOtherClause) {
|
|
4166
|
+
return this.error(ErrorKind.MISSING_OTHER_CLAUSE, createLocation(this.clonePosition(), this.clonePosition()));
|
|
4167
|
+
}
|
|
4168
|
+
return { val: options, err: null };
|
|
4169
|
+
};
|
|
4170
|
+
Parser2.prototype.tryParseDecimalInteger = function(expectNumberError, invalidNumberError) {
|
|
4171
|
+
var sign = 1;
|
|
4172
|
+
var startingPosition = this.clonePosition();
|
|
4173
|
+
if (this.bumpIf("+")) ; else if (this.bumpIf("-")) {
|
|
4174
|
+
sign = -1;
|
|
4175
|
+
}
|
|
4176
|
+
var hasDigits = false;
|
|
4177
|
+
var decimal = 0;
|
|
4178
|
+
while (!this.isEOF()) {
|
|
4179
|
+
var ch = this.char();
|
|
4180
|
+
if (ch >= 48 && ch <= 57) {
|
|
4181
|
+
hasDigits = true;
|
|
4182
|
+
decimal = decimal * 10 + (ch - 48);
|
|
4183
|
+
this.bump();
|
|
4184
|
+
} else {
|
|
4185
|
+
break;
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
var location = createLocation(startingPosition, this.clonePosition());
|
|
4189
|
+
if (!hasDigits) {
|
|
4190
|
+
return this.error(expectNumberError, location);
|
|
4191
|
+
}
|
|
4192
|
+
decimal *= sign;
|
|
4193
|
+
if (!isSafeInteger(decimal)) {
|
|
4194
|
+
return this.error(invalidNumberError, location);
|
|
4195
|
+
}
|
|
4196
|
+
return { val: decimal, err: null };
|
|
4197
|
+
};
|
|
4198
|
+
Parser2.prototype.offset = function() {
|
|
4199
|
+
return this.position.offset;
|
|
4200
|
+
};
|
|
4201
|
+
Parser2.prototype.isEOF = function() {
|
|
4202
|
+
return this.offset() === this.message.length;
|
|
4203
|
+
};
|
|
4204
|
+
Parser2.prototype.clonePosition = function() {
|
|
4205
|
+
return {
|
|
4206
|
+
offset: this.position.offset,
|
|
4207
|
+
line: this.position.line,
|
|
4208
|
+
column: this.position.column
|
|
4209
|
+
};
|
|
4210
|
+
};
|
|
4211
|
+
Parser2.prototype.char = function() {
|
|
4212
|
+
var offset = this.position.offset;
|
|
4213
|
+
if (offset >= this.message.length) {
|
|
4214
|
+
throw Error("out of bound");
|
|
4215
|
+
}
|
|
4216
|
+
var code = codePointAt(this.message, offset);
|
|
4217
|
+
if (code === void 0) {
|
|
4218
|
+
throw Error("Offset ".concat(offset, " is at invalid UTF-16 code unit boundary"));
|
|
4219
|
+
}
|
|
4220
|
+
return code;
|
|
4221
|
+
};
|
|
4222
|
+
Parser2.prototype.error = function(kind, location) {
|
|
4223
|
+
return {
|
|
4224
|
+
val: null,
|
|
4225
|
+
err: {
|
|
4226
|
+
kind,
|
|
4227
|
+
message: this.message,
|
|
4228
|
+
location
|
|
4229
|
+
}
|
|
4230
|
+
};
|
|
4231
|
+
};
|
|
4232
|
+
Parser2.prototype.bump = function() {
|
|
4233
|
+
if (this.isEOF()) {
|
|
4234
|
+
return;
|
|
4235
|
+
}
|
|
4236
|
+
var code = this.char();
|
|
4237
|
+
if (code === 10) {
|
|
4238
|
+
this.position.line += 1;
|
|
4239
|
+
this.position.column = 1;
|
|
4240
|
+
this.position.offset += 1;
|
|
4241
|
+
} else {
|
|
4242
|
+
this.position.column += 1;
|
|
4243
|
+
this.position.offset += code < 65536 ? 1 : 2;
|
|
4244
|
+
}
|
|
4245
|
+
};
|
|
4246
|
+
Parser2.prototype.bumpIf = function(prefix) {
|
|
4247
|
+
if (startsWith(this.message, prefix, this.offset())) {
|
|
4248
|
+
for (var i = 0; i < prefix.length; i++) {
|
|
4249
|
+
this.bump();
|
|
4250
|
+
}
|
|
4251
|
+
return true;
|
|
4252
|
+
}
|
|
4253
|
+
return false;
|
|
4254
|
+
};
|
|
4255
|
+
Parser2.prototype.bumpUntil = function(pattern) {
|
|
4256
|
+
var currentOffset = this.offset();
|
|
4257
|
+
var index = this.message.indexOf(pattern, currentOffset);
|
|
4258
|
+
if (index >= 0) {
|
|
4259
|
+
this.bumpTo(index);
|
|
4260
|
+
return true;
|
|
4261
|
+
} else {
|
|
4262
|
+
this.bumpTo(this.message.length);
|
|
4263
|
+
return false;
|
|
4264
|
+
}
|
|
4265
|
+
};
|
|
4266
|
+
Parser2.prototype.bumpTo = function(targetOffset) {
|
|
4267
|
+
if (this.offset() > targetOffset) {
|
|
4268
|
+
throw Error("targetOffset ".concat(targetOffset, " must be greater than or equal to the current offset ").concat(this.offset()));
|
|
4269
|
+
}
|
|
4270
|
+
targetOffset = Math.min(targetOffset, this.message.length);
|
|
4271
|
+
while (true) {
|
|
4272
|
+
var offset = this.offset();
|
|
4273
|
+
if (offset === targetOffset) {
|
|
4274
|
+
break;
|
|
4275
|
+
}
|
|
4276
|
+
if (offset > targetOffset) {
|
|
4277
|
+
throw Error("targetOffset ".concat(targetOffset, " is at invalid UTF-16 code unit boundary"));
|
|
4278
|
+
}
|
|
4279
|
+
this.bump();
|
|
4280
|
+
if (this.isEOF()) {
|
|
4281
|
+
break;
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
};
|
|
4285
|
+
Parser2.prototype.bumpSpace = function() {
|
|
4286
|
+
while (!this.isEOF() && _isWhiteSpace(this.char())) {
|
|
4287
|
+
this.bump();
|
|
4288
|
+
}
|
|
4289
|
+
};
|
|
4290
|
+
Parser2.prototype.peek = function() {
|
|
4291
|
+
if (this.isEOF()) {
|
|
4292
|
+
return null;
|
|
4293
|
+
}
|
|
4294
|
+
var code = this.char();
|
|
4295
|
+
var offset = this.offset();
|
|
4296
|
+
var nextCode = this.message.charCodeAt(offset + (code >= 65536 ? 2 : 1));
|
|
4297
|
+
return nextCode !== null && nextCode !== void 0 ? nextCode : null;
|
|
4298
|
+
};
|
|
4299
|
+
return Parser2;
|
|
4300
|
+
})()
|
|
4301
|
+
);
|
|
4302
|
+
function _isAlpha(codepoint) {
|
|
4303
|
+
return codepoint >= 97 && codepoint <= 122 || codepoint >= 65 && codepoint <= 90;
|
|
4304
|
+
}
|
|
4305
|
+
function _isAlphaOrSlash(codepoint) {
|
|
4306
|
+
return _isAlpha(codepoint) || codepoint === 47;
|
|
4307
|
+
}
|
|
4308
|
+
function _isPotentialElementNameChar(c) {
|
|
4309
|
+
return c === 45 || c === 46 || c >= 48 && c <= 57 || c === 95 || c >= 97 && c <= 122 || c >= 65 && c <= 90 || c == 183 || c >= 192 && c <= 214 || c >= 216 && c <= 246 || c >= 248 && c <= 893 || c >= 895 && c <= 8191 || c >= 8204 && c <= 8205 || c >= 8255 && c <= 8256 || c >= 8304 && c <= 8591 || c >= 11264 && c <= 12271 || c >= 12289 && c <= 55295 || c >= 63744 && c <= 64975 || c >= 65008 && c <= 65533 || c >= 65536 && c <= 983039;
|
|
4310
|
+
}
|
|
4311
|
+
function _isWhiteSpace(c) {
|
|
4312
|
+
return c >= 9 && c <= 13 || c === 32 || c === 133 || c >= 8206 && c <= 8207 || c === 8232 || c === 8233;
|
|
4313
|
+
}
|
|
4314
|
+
function _isPatternSyntax(c) {
|
|
4315
|
+
return c >= 33 && c <= 35 || c === 36 || c >= 37 && c <= 39 || c === 40 || c === 41 || c === 42 || c === 43 || c === 44 || c === 45 || c >= 46 && c <= 47 || c >= 58 && c <= 59 || c >= 60 && c <= 62 || c >= 63 && c <= 64 || c === 91 || c === 92 || c === 93 || c === 94 || c === 96 || c === 123 || c === 124 || c === 125 || c === 126 || c === 161 || c >= 162 && c <= 165 || c === 166 || c === 167 || c === 169 || c === 171 || c === 172 || c === 174 || c === 176 || c === 177 || c === 182 || c === 187 || c === 191 || c === 215 || c === 247 || c >= 8208 && c <= 8213 || c >= 8214 && c <= 8215 || c === 8216 || c === 8217 || c === 8218 || c >= 8219 && c <= 8220 || c === 8221 || c === 8222 || c === 8223 || c >= 8224 && c <= 8231 || c >= 8240 && c <= 8248 || c === 8249 || c === 8250 || c >= 8251 && c <= 8254 || c >= 8257 && c <= 8259 || c === 8260 || c === 8261 || c === 8262 || c >= 8263 && c <= 8273 || c === 8274 || c === 8275 || c >= 8277 && c <= 8286 || c >= 8592 && c <= 8596 || c >= 8597 && c <= 8601 || c >= 8602 && c <= 8603 || c >= 8604 && c <= 8607 || c === 8608 || c >= 8609 && c <= 8610 || c === 8611 || c >= 8612 && c <= 8613 || c === 8614 || c >= 8615 && c <= 8621 || c === 8622 || c >= 8623 && c <= 8653 || c >= 8654 && c <= 8655 || c >= 8656 && c <= 8657 || c === 8658 || c === 8659 || c === 8660 || c >= 8661 && c <= 8691 || c >= 8692 && c <= 8959 || c >= 8960 && c <= 8967 || c === 8968 || c === 8969 || c === 8970 || c === 8971 || c >= 8972 && c <= 8991 || c >= 8992 && c <= 8993 || c >= 8994 && c <= 9e3 || c === 9001 || c === 9002 || c >= 9003 && c <= 9083 || c === 9084 || c >= 9085 && c <= 9114 || c >= 9115 && c <= 9139 || c >= 9140 && c <= 9179 || c >= 9180 && c <= 9185 || c >= 9186 && c <= 9254 || c >= 9255 && c <= 9279 || c >= 9280 && c <= 9290 || c >= 9291 && c <= 9311 || c >= 9472 && c <= 9654 || c === 9655 || c >= 9656 && c <= 9664 || c === 9665 || c >= 9666 && c <= 9719 || c >= 9720 && c <= 9727 || c >= 9728 && c <= 9838 || c === 9839 || c >= 9840 && c <= 10087 || c === 10088 || c === 10089 || c === 10090 || c === 10091 || c === 10092 || c === 10093 || c === 10094 || c === 10095 || c === 10096 || c === 10097 || c === 10098 || c === 10099 || c === 10100 || c === 10101 || c >= 10132 && c <= 10175 || c >= 10176 && c <= 10180 || c === 10181 || c === 10182 || c >= 10183 && c <= 10213 || c === 10214 || c === 10215 || c === 10216 || c === 10217 || c === 10218 || c === 10219 || c === 10220 || c === 10221 || c === 10222 || c === 10223 || c >= 10224 && c <= 10239 || c >= 10240 && c <= 10495 || c >= 10496 && c <= 10626 || c === 10627 || c === 10628 || c === 10629 || c === 10630 || c === 10631 || c === 10632 || c === 10633 || c === 10634 || c === 10635 || c === 10636 || c === 10637 || c === 10638 || c === 10639 || c === 10640 || c === 10641 || c === 10642 || c === 10643 || c === 10644 || c === 10645 || c === 10646 || c === 10647 || c === 10648 || c >= 10649 && c <= 10711 || c === 10712 || c === 10713 || c === 10714 || c === 10715 || c >= 10716 && c <= 10747 || c === 10748 || c === 10749 || c >= 10750 && c <= 11007 || c >= 11008 && c <= 11055 || c >= 11056 && c <= 11076 || c >= 11077 && c <= 11078 || c >= 11079 && c <= 11084 || c >= 11085 && c <= 11123 || c >= 11124 && c <= 11125 || c >= 11126 && c <= 11157 || c === 11158 || c >= 11159 && c <= 11263 || c >= 11776 && c <= 11777 || c === 11778 || c === 11779 || c === 11780 || c === 11781 || c >= 11782 && c <= 11784 || c === 11785 || c === 11786 || c === 11787 || c === 11788 || c === 11789 || c >= 11790 && c <= 11798 || c === 11799 || c >= 11800 && c <= 11801 || c === 11802 || c === 11803 || c === 11804 || c === 11805 || c >= 11806 && c <= 11807 || c === 11808 || c === 11809 || c === 11810 || c === 11811 || c === 11812 || c === 11813 || c === 11814 || c === 11815 || c === 11816 || c === 11817 || c >= 11818 && c <= 11822 || c === 11823 || c >= 11824 && c <= 11833 || c >= 11834 && c <= 11835 || c >= 11836 && c <= 11839 || c === 11840 || c === 11841 || c === 11842 || c >= 11843 && c <= 11855 || c >= 11856 && c <= 11857 || c === 11858 || c >= 11859 && c <= 11903 || c >= 12289 && c <= 12291 || c === 12296 || c === 12297 || c === 12298 || c === 12299 || c === 12300 || c === 12301 || c === 12302 || c === 12303 || c === 12304 || c === 12305 || c >= 12306 && c <= 12307 || c === 12308 || c === 12309 || c === 12310 || c === 12311 || c === 12312 || c === 12313 || c === 12314 || c === 12315 || c === 12316 || c === 12317 || c >= 12318 && c <= 12319 || c === 12320 || c === 12336 || c === 64830 || c === 64831 || c >= 65093 && c <= 65094;
|
|
4316
|
+
}
|
|
4317
|
+
|
|
4318
|
+
// node_modules/.pnpm/@formatjs+icu-messageformat-parser@2.11.4/node_modules/@formatjs/icu-messageformat-parser/lib/index.js
|
|
4319
|
+
function pruneLocation(els) {
|
|
4320
|
+
els.forEach(function(el) {
|
|
4321
|
+
delete el.location;
|
|
4322
|
+
if (isSelectElement(el) || isPluralElement(el)) {
|
|
4323
|
+
for (var k in el.options) {
|
|
4324
|
+
delete el.options[k].location;
|
|
4325
|
+
pruneLocation(el.options[k].value);
|
|
4326
|
+
}
|
|
4327
|
+
} else if (isNumberElement(el) && isNumberSkeleton(el.style)) {
|
|
4328
|
+
delete el.style.location;
|
|
4329
|
+
} else if ((isDateElement(el) || isTimeElement(el)) && isDateTimeSkeleton(el.style)) {
|
|
4330
|
+
delete el.style.location;
|
|
4331
|
+
} else if (isTagElement(el)) {
|
|
4332
|
+
pruneLocation(el.children);
|
|
4333
|
+
}
|
|
4334
|
+
});
|
|
4335
|
+
}
|
|
4336
|
+
function parse(message, opts) {
|
|
4337
|
+
if (opts === void 0) {
|
|
4338
|
+
opts = {};
|
|
4339
|
+
}
|
|
4340
|
+
opts = __assign({ shouldParseSkeletons: true, requiresOtherClause: true }, opts);
|
|
4341
|
+
var result = new Parser(message, opts).parse();
|
|
4342
|
+
if (result.err) {
|
|
4343
|
+
var error = SyntaxError(ErrorKind[result.err.kind]);
|
|
4344
|
+
error.location = result.err.location;
|
|
4345
|
+
error.originalMessage = result.err.message;
|
|
4346
|
+
throw error;
|
|
4347
|
+
}
|
|
4348
|
+
if (!(opts === null || opts === void 0 ? void 0 : opts.captureLocation)) {
|
|
4349
|
+
pruneLocation(result.val);
|
|
4350
|
+
}
|
|
4351
|
+
return result.val;
|
|
4352
|
+
}
|
|
4353
|
+
|
|
4354
|
+
// src/markup.ts
|
|
4355
|
+
var markupStart = (name) => ({ type: "markup-start", name });
|
|
4356
|
+
var markupEnd = (name) => ({ type: "markup-end", name });
|
|
4357
|
+
var markupStandalone = (name) => ({ type: "markup-standalone", name });
|
|
4358
|
+
function markupPartToTag(part) {
|
|
4359
|
+
switch (part.type) {
|
|
4360
|
+
case "markup-start":
|
|
4361
|
+
return `<${part.name}>`;
|
|
4362
|
+
case "markup-end":
|
|
4363
|
+
return `</${part.name}>`;
|
|
4364
|
+
case "markup-standalone":
|
|
4365
|
+
return `<${part.name}/>`;
|
|
4366
|
+
}
|
|
4367
|
+
}
|
|
4368
|
+
|
|
4369
|
+
// src/parse.ts
|
|
4370
|
+
var SELF_CLOSE_MARK = "\uE000";
|
|
4371
|
+
var SELF_CLOSE_RE = /<([\w][\w-]*)\s*\/>/y;
|
|
4372
|
+
function normalizeSelfClosingTags(source) {
|
|
4373
|
+
let out = "";
|
|
4374
|
+
let i = 0;
|
|
4375
|
+
while (i < source.length) {
|
|
4376
|
+
const ch = source[i];
|
|
4377
|
+
if (ch === "'") {
|
|
4378
|
+
if (source[i + 1] === "'") {
|
|
4379
|
+
out += "''";
|
|
4380
|
+
i += 2;
|
|
4381
|
+
continue;
|
|
4382
|
+
}
|
|
4383
|
+
const next = source[i + 1];
|
|
4384
|
+
if (next === "{" || next === "}" || next === "<" || next === "#") {
|
|
4385
|
+
const end = source.indexOf("'", i + 1);
|
|
4386
|
+
if (end === -1) {
|
|
4387
|
+
out += source.slice(i);
|
|
4388
|
+
break;
|
|
4389
|
+
}
|
|
4390
|
+
out += source.slice(i, end + 1);
|
|
4391
|
+
i = end + 1;
|
|
4392
|
+
continue;
|
|
4393
|
+
}
|
|
4394
|
+
out += ch;
|
|
4395
|
+
i += 1;
|
|
4396
|
+
continue;
|
|
4397
|
+
}
|
|
4398
|
+
if (ch === "<") {
|
|
4399
|
+
SELF_CLOSE_RE.lastIndex = i;
|
|
4400
|
+
const m = SELF_CLOSE_RE.exec(source);
|
|
4401
|
+
if (m) {
|
|
4402
|
+
out += `<${m[1]}>${SELF_CLOSE_MARK}</${m[1]}>`;
|
|
4403
|
+
i += m[0].length;
|
|
4404
|
+
continue;
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
out += ch;
|
|
4408
|
+
i += 1;
|
|
4409
|
+
}
|
|
4410
|
+
return out;
|
|
4411
|
+
}
|
|
4412
|
+
function normalizeSkeletons(elements, src) {
|
|
4413
|
+
for (const el of elements) {
|
|
4414
|
+
if ((el.type === TYPE.number || el.type === TYPE.date || el.type === TYPE.time) && el.style && typeof el.style === "object") {
|
|
4415
|
+
const loc = el.style.location;
|
|
4416
|
+
el.style = loc ? src.slice(loc.start.offset, loc.end.offset) : String(el.style);
|
|
4417
|
+
}
|
|
4418
|
+
if (el.options) {
|
|
4419
|
+
for (const key of Object.keys(el.options)) normalizeSkeletons(el.options[key].value, src);
|
|
4420
|
+
}
|
|
4421
|
+
if (el.children) normalizeSkeletons(el.children, src);
|
|
4422
|
+
}
|
|
4423
|
+
}
|
|
4424
|
+
function parseIcu(source) {
|
|
4425
|
+
const normalized = normalizeSelfClosingTags(source);
|
|
4426
|
+
const ast = parse(normalized, {
|
|
4427
|
+
ignoreTag: false,
|
|
4428
|
+
requiresOtherClause: true,
|
|
4429
|
+
captureLocation: true
|
|
4430
|
+
});
|
|
4431
|
+
normalizeSkeletons(ast, normalized);
|
|
4432
|
+
return ast;
|
|
4433
|
+
}
|
|
4434
|
+
|
|
4435
|
+
// src/icu-to-inlang.ts
|
|
4436
|
+
var EXACT_RE = /^=-?(?:0|[1-9]\d*)(?:\.\d+)?$/;
|
|
4437
|
+
var isExact = (k) => EXACT_RE.test(k);
|
|
4438
|
+
function messageToImport(args) {
|
|
4439
|
+
const ast = parseIcu(args.source);
|
|
4440
|
+
const ctx = { declarations: /* @__PURE__ */ new Map(), selectorNames: [] };
|
|
4441
|
+
const variants = expand(ast, ctx, null);
|
|
4442
|
+
return {
|
|
4443
|
+
declarations: [...ctx.declarations.values()],
|
|
4444
|
+
selectors: ctx.selectorNames.map((name) => ({ type: "variable-reference", name })),
|
|
4445
|
+
variants
|
|
4446
|
+
};
|
|
4447
|
+
}
|
|
4448
|
+
function addDecl(ctx, decl) {
|
|
4449
|
+
if (!ctx.declarations.has(decl.name)) ctx.declarations.set(decl.name, decl);
|
|
4450
|
+
}
|
|
4451
|
+
function addSelectorName(ctx, name) {
|
|
4452
|
+
if (!ctx.selectorNames.includes(name)) ctx.selectorNames.push(name);
|
|
4453
|
+
}
|
|
4454
|
+
function expand(elements, ctx, poundArg) {
|
|
4455
|
+
let variants = [{ matches: [], pattern: [] }];
|
|
4456
|
+
for (const el of elements) {
|
|
4457
|
+
const next = [];
|
|
4458
|
+
for (const v of variants) {
|
|
4459
|
+
for (const ext of extendVariant(v, el, ctx, poundArg)) next.push(ext);
|
|
4460
|
+
}
|
|
4461
|
+
variants = next;
|
|
4462
|
+
}
|
|
4463
|
+
return variants;
|
|
4464
|
+
}
|
|
4465
|
+
function extendVariant(v, el, ctx, poundArg) {
|
|
4466
|
+
if (el.type === TYPE.plural || el.type === TYPE.select) {
|
|
4467
|
+
const sel = registerSelector(el, ctx);
|
|
4468
|
+
const out = [];
|
|
4469
|
+
for (const caseKey of orderCases(el)) {
|
|
4470
|
+
const childPound = el.type === TYPE.plural ? el.value : poundArg;
|
|
4471
|
+
const caseMatches = sel.matchesFor(caseKey);
|
|
4472
|
+
for (const cv of expand(el.options[caseKey].value, ctx, childPound)) {
|
|
4473
|
+
out.push({
|
|
4474
|
+
matches: [...v.matches, ...caseMatches, ...cv.matches],
|
|
4475
|
+
pattern: [...v.pattern, ...cv.pattern]
|
|
4476
|
+
});
|
|
4477
|
+
}
|
|
4478
|
+
}
|
|
4479
|
+
return out;
|
|
4480
|
+
}
|
|
4481
|
+
if (el.type === TYPE.tag) {
|
|
4482
|
+
const name = el.value;
|
|
4483
|
+
const children = el.children ?? [];
|
|
4484
|
+
if (isSelfClosing(children)) {
|
|
4485
|
+
return [{ matches: v.matches, pattern: [...v.pattern, markupStandalone(name)] }];
|
|
4486
|
+
}
|
|
4487
|
+
const out = [];
|
|
4488
|
+
for (const cv of expand(children, ctx, poundArg)) {
|
|
4489
|
+
out.push({
|
|
4490
|
+
matches: [...v.matches, ...cv.matches],
|
|
4491
|
+
pattern: [...v.pattern, markupStart(name), ...cv.pattern, markupEnd(name)]
|
|
4492
|
+
});
|
|
4493
|
+
}
|
|
4494
|
+
return out;
|
|
4495
|
+
}
|
|
4496
|
+
return [{ matches: v.matches, pattern: [...v.pattern, ...mapSimple(el, ctx, poundArg)] }];
|
|
4497
|
+
}
|
|
4498
|
+
function isSelfClosing(children) {
|
|
4499
|
+
return children.length === 1 && children[0].type === TYPE.literal && // biome-ignore lint/suspicious/noExplicitAny: FormatJS literal carries .value
|
|
4500
|
+
children[0].value === SELF_CLOSE_MARK;
|
|
4501
|
+
}
|
|
4502
|
+
function orderCases(el) {
|
|
4503
|
+
const keys = Object.keys(el.options);
|
|
4504
|
+
const exacts = keys.filter(isExact);
|
|
4505
|
+
const cldr = keys.filter((k) => !isExact(k) && k !== "other");
|
|
4506
|
+
const other = keys.includes("other") ? ["other"] : [];
|
|
4507
|
+
return [...exacts, ...cldr, ...other];
|
|
4508
|
+
}
|
|
4509
|
+
function registerSelector(el, ctx) {
|
|
4510
|
+
const arg = el.value;
|
|
4511
|
+
if (el.type === TYPE.select) {
|
|
4512
|
+
addDecl(ctx, { type: "input-variable", name: arg });
|
|
4513
|
+
addSelectorName(ctx, arg);
|
|
4514
|
+
return {
|
|
4515
|
+
matchesFor: (c) => c === "other" ? [{ type: "catchall-match", key: arg }] : [{ type: "literal-match", key: arg, value: c }]
|
|
4516
|
+
};
|
|
4517
|
+
}
|
|
4518
|
+
const ordinal = el.pluralType === "ordinal";
|
|
4519
|
+
const offset = el.offset ?? 0;
|
|
4520
|
+
const word = ordinal ? "Ordinal" : "Plural";
|
|
4521
|
+
const pluralName = `${arg}${word}${offset ? `Offset${offset}` : ""}`;
|
|
4522
|
+
const options = [];
|
|
4523
|
+
if (ordinal) options.push({ name: "type", value: { type: "literal", value: "ordinal" } });
|
|
4524
|
+
if (offset) options.push({ name: "offset", value: { type: "literal", value: String(offset) } });
|
|
4525
|
+
addDecl(ctx, { type: "input-variable", name: arg });
|
|
4526
|
+
addDecl(ctx, {
|
|
4527
|
+
type: "local-variable",
|
|
4528
|
+
name: pluralName,
|
|
4529
|
+
value: {
|
|
4530
|
+
type: "expression",
|
|
4531
|
+
arg: { type: "variable-reference", name: arg },
|
|
4532
|
+
annotation: { type: "function-reference", name: "plural", options }
|
|
4533
|
+
}
|
|
4534
|
+
});
|
|
4535
|
+
const hasExact = Object.keys(el.options).some(isExact);
|
|
4536
|
+
const exactName = hasExact ? `${pluralName}Exact` : void 0;
|
|
4537
|
+
if (exactName) {
|
|
4538
|
+
addDecl(ctx, {
|
|
4539
|
+
type: "local-variable",
|
|
4540
|
+
name: exactName,
|
|
4541
|
+
value: { type: "expression", arg: { type: "variable-reference", name: arg } }
|
|
4542
|
+
});
|
|
4543
|
+
addSelectorName(ctx, exactName);
|
|
4544
|
+
}
|
|
4545
|
+
addSelectorName(ctx, pluralName);
|
|
4546
|
+
return {
|
|
4547
|
+
matchesFor: (c) => {
|
|
4548
|
+
const exactCase = isExact(c);
|
|
4549
|
+
const isOther = c === "other";
|
|
4550
|
+
const pluralMatch = isOther || exactCase ? { type: "catchall-match", key: pluralName } : { type: "literal-match", key: pluralName, value: c };
|
|
4551
|
+
if (!exactName) return [pluralMatch];
|
|
4552
|
+
const exactMatch = exactCase ? { type: "literal-match", key: exactName, value: c.slice(1) } : { type: "catchall-match", key: exactName };
|
|
4553
|
+
return [exactMatch, pluralMatch];
|
|
4554
|
+
}
|
|
4555
|
+
};
|
|
4556
|
+
}
|
|
4557
|
+
function mapSimple(el, ctx, poundArg) {
|
|
4558
|
+
switch (el.type) {
|
|
4559
|
+
case TYPE.literal:
|
|
4560
|
+
return [{ type: "text", value: el.value }];
|
|
4561
|
+
case TYPE.argument:
|
|
4562
|
+
addDecl(ctx, { type: "input-variable", name: el.value });
|
|
4563
|
+
return [{ type: "expression", arg: { type: "variable-reference", name: el.value } }];
|
|
4564
|
+
case TYPE.pound:
|
|
4565
|
+
return poundArg ? [
|
|
4566
|
+
{
|
|
4567
|
+
type: "expression",
|
|
4568
|
+
arg: { type: "variable-reference", name: poundArg },
|
|
4569
|
+
annotation: { type: "function-reference", name: "icu:pound", options: [] }
|
|
4570
|
+
}
|
|
4571
|
+
] : [{ type: "text", value: "#" }];
|
|
4572
|
+
case TYPE.number:
|
|
4573
|
+
case TYPE.date:
|
|
4574
|
+
case TYPE.time: {
|
|
4575
|
+
const numEl = el;
|
|
4576
|
+
addDecl(ctx, { type: "input-variable", name: numEl.value });
|
|
4577
|
+
const fn = el.type === TYPE.number ? "number" : el.type === TYPE.date ? "date" : "time";
|
|
4578
|
+
const style = numEl.style;
|
|
4579
|
+
const options = style ? [{ name: "style", value: { type: "literal", value: style } }] : [];
|
|
4580
|
+
return [
|
|
4581
|
+
{
|
|
4582
|
+
type: "expression",
|
|
4583
|
+
arg: { type: "variable-reference", name: numEl.value },
|
|
4584
|
+
annotation: { type: "function-reference", name: fn, options }
|
|
4585
|
+
}
|
|
4586
|
+
];
|
|
4587
|
+
}
|
|
4588
|
+
default:
|
|
4589
|
+
throw new Error(`Type ICU non support\xE9 : ${el.type}`);
|
|
4590
|
+
}
|
|
4591
|
+
}
|
|
4592
|
+
|
|
4593
|
+
// src/inlang-to-icu.ts
|
|
4594
|
+
function bundleToMessageString(args) {
|
|
4595
|
+
const { bundle, message, variants } = args;
|
|
4596
|
+
if (variants.length === 0) return "";
|
|
4597
|
+
if (message.selectors.length === 0) return patternToString(variants[0].pattern, false);
|
|
4598
|
+
const icuSelectors = resolveIcuSelectors(message, bundle);
|
|
4599
|
+
return reconstruct(icuSelectors, variants);
|
|
4600
|
+
}
|
|
4601
|
+
function declMap(bundle) {
|
|
4602
|
+
return new Map(bundle.declarations.map((d) => [d.name, d]));
|
|
4603
|
+
}
|
|
4604
|
+
function resolveIcuSelectors(message, bundle) {
|
|
4605
|
+
const decls = declMap(bundle);
|
|
4606
|
+
const names = message.selectors.map((s) => s.name);
|
|
4607
|
+
const consumed = /* @__PURE__ */ new Set();
|
|
4608
|
+
const out = [];
|
|
4609
|
+
function resolvePlural(pluralDecl, pluralKey, exactKey) {
|
|
4610
|
+
const arg = pluralDecl.value.arg.name;
|
|
4611
|
+
const ordinal = pluralDecl.value.annotation.options?.some(
|
|
4612
|
+
// biome-ignore lint/suspicious/noExplicitAny: AST inlang dynamique
|
|
4613
|
+
(o) => o.name === "type" && o.value.value === "ordinal"
|
|
4614
|
+
);
|
|
4615
|
+
const offset = Number(
|
|
4616
|
+
// biome-ignore lint/suspicious/noExplicitAny: AST inlang dynamique
|
|
4617
|
+
pluralDecl.value.annotation.options?.find((o) => o.name === "offset")?.value.value ?? 0
|
|
4618
|
+
);
|
|
4619
|
+
out.push({ arg, kind: ordinal ? "selectordinal" : "plural", offset, pluralKey, exactKey });
|
|
4620
|
+
}
|
|
4621
|
+
for (const name of names) {
|
|
4622
|
+
if (consumed.has(name)) continue;
|
|
4623
|
+
const decl = decls.get(name);
|
|
4624
|
+
const isPlural = decl?.type === "local-variable" && decl.value?.annotation?.name === "plural";
|
|
4625
|
+
const isExactCompanion = decl?.type === "local-variable" && decl.value && !decl.value.annotation;
|
|
4626
|
+
if (isPlural) {
|
|
4627
|
+
const arg = decl.value.arg.name;
|
|
4628
|
+
const exactKey = names.find((n) => {
|
|
4629
|
+
if (consumed.has(n) || n === name) return false;
|
|
4630
|
+
const d = decls.get(n);
|
|
4631
|
+
return d?.type === "local-variable" && d.value?.arg?.name === arg && !d.value?.annotation;
|
|
4632
|
+
});
|
|
4633
|
+
if (exactKey) consumed.add(exactKey);
|
|
4634
|
+
resolvePlural(decl, name, exactKey);
|
|
4635
|
+
} else if (isExactCompanion) {
|
|
4636
|
+
const arg = decl.value.arg.name;
|
|
4637
|
+
const pluralKey = names.find((n) => {
|
|
4638
|
+
if (consumed.has(n) || n === name) return false;
|
|
4639
|
+
const d = decls.get(n);
|
|
4640
|
+
return d?.type === "local-variable" && d.value?.annotation?.name === "plural" && d.value?.arg?.name === arg;
|
|
4641
|
+
});
|
|
4642
|
+
if (pluralKey) {
|
|
4643
|
+
consumed.add(pluralKey);
|
|
4644
|
+
resolvePlural(decls.get(pluralKey), pluralKey, name);
|
|
4645
|
+
} else {
|
|
4646
|
+
out.push({ arg: name, kind: "select", offset: 0, selectKey: name });
|
|
4647
|
+
}
|
|
4648
|
+
} else {
|
|
4649
|
+
out.push({ arg: name, kind: "select", offset: 0, selectKey: name });
|
|
4650
|
+
}
|
|
4651
|
+
}
|
|
4652
|
+
return out;
|
|
4653
|
+
}
|
|
4654
|
+
function caseFor(sel, matches) {
|
|
4655
|
+
if (sel.kind === "select") {
|
|
4656
|
+
const m = matches.find((x) => x.key === sel.selectKey);
|
|
4657
|
+
return m?.type === "literal-match" ? m.value : "other";
|
|
4658
|
+
}
|
|
4659
|
+
const exact = sel.exactKey ? matches.find((x) => x.key === sel.exactKey) : void 0;
|
|
4660
|
+
if (exact?.type === "literal-match") return `=${exact.value}`;
|
|
4661
|
+
const plural = matches.find((x) => x.key === sel.pluralKey);
|
|
4662
|
+
return plural?.type === "literal-match" ? plural.value : "other";
|
|
4663
|
+
}
|
|
4664
|
+
function orderIcuCases(keys) {
|
|
4665
|
+
const isEx = (k) => k.startsWith("=");
|
|
4666
|
+
const exacts = keys.filter(isEx);
|
|
4667
|
+
const cldr = keys.filter((k) => !isEx(k) && k !== "other");
|
|
4668
|
+
const other = keys.includes("other") ? ["other"] : [];
|
|
4669
|
+
return [...exacts, ...cldr, ...other];
|
|
4670
|
+
}
|
|
4671
|
+
function reconstruct(selectors, variants) {
|
|
4672
|
+
const [sel, ...rest] = selectors;
|
|
4673
|
+
const inPlural = sel.kind !== "select";
|
|
4674
|
+
const groups = /* @__PURE__ */ new Map();
|
|
4675
|
+
for (const v of variants) {
|
|
4676
|
+
const c = caseFor(sel, v.matches);
|
|
4677
|
+
let group = groups.get(c);
|
|
4678
|
+
if (!group) {
|
|
4679
|
+
group = [];
|
|
4680
|
+
groups.set(c, group);
|
|
4681
|
+
}
|
|
4682
|
+
group.push(v);
|
|
4683
|
+
}
|
|
4684
|
+
const offsetStr = sel.offset ? `offset:${sel.offset} ` : "";
|
|
4685
|
+
const head = `${sel.arg}, ${sel.kind}, ${offsetStr}`;
|
|
4686
|
+
const body = orderIcuCases([...groups.keys()]).map((c) => {
|
|
4687
|
+
const grp = groups.get(c) ?? [];
|
|
4688
|
+
const inner = rest.length === 0 ? patternToString(grp[0].pattern, inPlural) : reconstruct(rest, grp);
|
|
4689
|
+
return `${c} {${inner}}`;
|
|
4690
|
+
}).join(" ");
|
|
4691
|
+
return `{${head}${body}}`;
|
|
4692
|
+
}
|
|
4693
|
+
function patternToString(pattern, inPlural) {
|
|
4694
|
+
return pattern.map((part) => {
|
|
4695
|
+
const p = part;
|
|
4696
|
+
switch (p.type) {
|
|
4697
|
+
case "text":
|
|
4698
|
+
return escapeText(p.value ?? "", inPlural);
|
|
4699
|
+
case "expression":
|
|
4700
|
+
return expressionToString(p);
|
|
4701
|
+
case "markup-start":
|
|
4702
|
+
case "markup-end":
|
|
4703
|
+
case "markup-standalone":
|
|
4704
|
+
return markupPartToTag(p);
|
|
4705
|
+
default:
|
|
4706
|
+
throw new Error(`part inconnue: ${p.type}`);
|
|
4707
|
+
}
|
|
4708
|
+
}).join("");
|
|
4709
|
+
}
|
|
4710
|
+
function expressionToString(expr) {
|
|
4711
|
+
const ann = expr.annotation;
|
|
4712
|
+
if (ann?.name === "icu:pound") return "#";
|
|
4713
|
+
const name = expr.arg?.name ?? expr.arg?.value;
|
|
4714
|
+
if (!ann) return `{${name}}`;
|
|
4715
|
+
const style = ann.options?.find((o) => o.name === "style")?.value?.value;
|
|
4716
|
+
return style ? `{${name}, ${ann.name}, ${style}}` : `{${name}, ${ann.name}}`;
|
|
4717
|
+
}
|
|
4718
|
+
function escapeText(s, inPlural) {
|
|
4719
|
+
let out = s.replace(/'/g, "''");
|
|
4720
|
+
out = out.replace(inPlural ? /[{}#<]/g : /[{}<]/g, (m) => `'${m}'`);
|
|
4721
|
+
return out;
|
|
4722
|
+
}
|
|
4723
|
+
|
|
4724
|
+
// src/settings.ts
|
|
4725
|
+
var import_typebox = __toESM(require_typebox());
|
|
4726
|
+
var settingsSchema = import_typebox.Type.Object({
|
|
4727
|
+
pathPattern: import_typebox.Type.String({
|
|
4728
|
+
pattern: ".*\\{locale\\}.*\\.json$",
|
|
4729
|
+
examples: ["./messages/{locale}.json"],
|
|
4730
|
+
title: "Path to language files",
|
|
4731
|
+
description: "Must include `{locale}` and end with `.json`."
|
|
4732
|
+
})
|
|
4733
|
+
});
|
|
4734
|
+
|
|
4735
|
+
// src/plugin.ts
|
|
4736
|
+
var KEY = "plugin.donal2.richIcu";
|
|
4737
|
+
function pathPattern(settings) {
|
|
4738
|
+
return settings[KEY]?.pathPattern ?? "./messages/{locale}.json";
|
|
4739
|
+
}
|
|
4740
|
+
var LOG_PREFIX = "[inlang-plugin-rich-icu]";
|
|
4741
|
+
var richIcuPlugin = {
|
|
4742
|
+
key: KEY,
|
|
4743
|
+
settingsSchema,
|
|
4744
|
+
toBeImportedFiles: async ({ settings }) => {
|
|
4745
|
+
const s = settings;
|
|
4746
|
+
const pattern = pathPattern(s);
|
|
4747
|
+
return s.locales.map((locale) => ({ path: pattern.replace("{locale}", locale), locale }));
|
|
4748
|
+
},
|
|
4749
|
+
importFiles: ({ files }) => {
|
|
4750
|
+
const bundleMap = /* @__PURE__ */ new Map();
|
|
4751
|
+
const bundles = [];
|
|
4752
|
+
const messages = [];
|
|
4753
|
+
const variants = [];
|
|
4754
|
+
const decoder = new TextDecoder("utf-8");
|
|
4755
|
+
for (const file of files) {
|
|
4756
|
+
let json;
|
|
4757
|
+
try {
|
|
4758
|
+
json = JSON.parse(decoder.decode(file.content));
|
|
4759
|
+
} catch (err) {
|
|
4760
|
+
console.warn(
|
|
4761
|
+
`${LOG_PREFIX} JSON invalide pour la locale "${file.locale}", fichier ignor\xE9 : ${err.message}`
|
|
4762
|
+
);
|
|
4763
|
+
continue;
|
|
4764
|
+
}
|
|
4765
|
+
for (const [key, value] of Object.entries(json)) {
|
|
4766
|
+
if (key === "$schema") continue;
|
|
4767
|
+
if (typeof value !== "string") {
|
|
4768
|
+
console.warn(
|
|
4769
|
+
`${LOG_PREFIX} valeur non-string ignor\xE9e pour "${key}" (locale "${file.locale}")`
|
|
4770
|
+
);
|
|
4771
|
+
continue;
|
|
4772
|
+
}
|
|
4773
|
+
let imported;
|
|
4774
|
+
try {
|
|
4775
|
+
imported = messageToImport({ source: value, bundleId: key, locale: file.locale });
|
|
4776
|
+
} catch (err) {
|
|
4777
|
+
console.warn(
|
|
4778
|
+
`${LOG_PREFIX} ICU invalide pour "${key}" (locale "${file.locale}"), message ignor\xE9 : ${err.message}`
|
|
4779
|
+
);
|
|
4780
|
+
continue;
|
|
4781
|
+
}
|
|
4782
|
+
const { declarations, selectors, variants: vs } = imported;
|
|
4783
|
+
let bundle = bundleMap.get(key);
|
|
4784
|
+
if (!bundle) {
|
|
4785
|
+
bundle = { id: key, declarations: [] };
|
|
4786
|
+
bundleMap.set(key, bundle);
|
|
4787
|
+
bundles.push(bundle);
|
|
4788
|
+
}
|
|
4789
|
+
for (const d of declarations) {
|
|
4790
|
+
if (!bundle.declarations.some((x) => x.name === d.name)) bundle.declarations.push(d);
|
|
4791
|
+
}
|
|
4792
|
+
messages.push({ bundleId: key, locale: file.locale, selectors });
|
|
4793
|
+
for (const v of vs) {
|
|
4794
|
+
variants.push({
|
|
4795
|
+
messageBundleId: key,
|
|
4796
|
+
messageLocale: file.locale,
|
|
4797
|
+
matches: v.matches,
|
|
4798
|
+
pattern: v.pattern
|
|
4799
|
+
});
|
|
4800
|
+
}
|
|
4801
|
+
}
|
|
4802
|
+
}
|
|
4803
|
+
return { bundles, messages, variants };
|
|
4804
|
+
},
|
|
4805
|
+
exportFiles: ({ bundles, messages, variants, settings }) => {
|
|
4806
|
+
const s = settings;
|
|
4807
|
+
const bundleById = new Map(bundles.map((b) => [b.id, b]));
|
|
4808
|
+
const variantsByMsg = /* @__PURE__ */ new Map();
|
|
4809
|
+
const keyOf = (v) => v.messageId != null ? `id:${v.messageId}` : `bl:${v.messageBundleId}\0${v.messageLocale}`;
|
|
4810
|
+
for (const v of variants) {
|
|
4811
|
+
const k = keyOf(v);
|
|
4812
|
+
const arr = variantsByMsg.get(k);
|
|
4813
|
+
if (arr) arr.push(v);
|
|
4814
|
+
else variantsByMsg.set(k, [v]);
|
|
4815
|
+
}
|
|
4816
|
+
const byLocale = {};
|
|
4817
|
+
for (const message of messages) {
|
|
4818
|
+
const bundle = bundleById.get(message.bundleId);
|
|
4819
|
+
if (!bundle) continue;
|
|
4820
|
+
const vs = (message.id != null ? variantsByMsg.get(`id:${message.id}`) : void 0) ?? variantsByMsg.get(`bl:${message.bundleId}\0${message.locale}`) ?? [];
|
|
4821
|
+
if (vs.length === 0) continue;
|
|
4822
|
+
if (!byLocale[message.locale]) byLocale[message.locale] = {};
|
|
4823
|
+
byLocale[message.locale][message.bundleId] = bundleToMessageString({
|
|
4824
|
+
bundle,
|
|
4825
|
+
message,
|
|
4826
|
+
variants: vs
|
|
4827
|
+
});
|
|
4828
|
+
}
|
|
4829
|
+
const pattern = pathPattern(s);
|
|
4830
|
+
return Object.entries(byLocale).map(([locale, map]) => ({
|
|
4831
|
+
locale,
|
|
4832
|
+
name: pattern.replace("{locale}", locale).split("/").at(-1) ?? locale,
|
|
4833
|
+
content: new TextEncoder().encode(`${JSON.stringify(map, null, " ")}
|
|
4834
|
+
`)
|
|
4835
|
+
}));
|
|
4836
|
+
}
|
|
4837
|
+
};
|
|
4838
|
+
|
|
4839
|
+
// src/index.ts
|
|
4840
|
+
var index_default = richIcuPlugin;
|
|
4841
|
+
|
|
4842
|
+
export { index_default as default, richIcuPlugin as plugin, richIcuPlugin };
|