typia 7.0.0-dev.20241009-2 → 7.0.0-dev.20241010

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.
Files changed (151) hide show
  1. package/lib/factories/JsonMetadataFactory.d.ts +5 -1
  2. package/lib/factories/JsonMetadataFactory.js +4 -1
  3. package/lib/factories/JsonMetadataFactory.js.map +1 -1
  4. package/lib/internal/{$httpFormDataReadArray.js → $httpFormdataReadArray.js} +1 -1
  5. package/lib/internal/$httpFormdataReadArray.js.map +1 -0
  6. package/lib/programmers/CheckerProgrammer.js +4 -1
  7. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  8. package/lib/programmers/FeatureProgrammer.d.ts +4 -1
  9. package/lib/programmers/FeatureProgrammer.js +2 -2
  10. package/lib/programmers/FeatureProgrammer.js.map +1 -1
  11. package/lib/programmers/RandomProgrammer.js +12 -9
  12. package/lib/programmers/RandomProgrammer.js.map +1 -1
  13. package/lib/programmers/TypiaProgrammer.js +4 -1
  14. package/lib/programmers/TypiaProgrammer.js.map +1 -1
  15. package/lib/programmers/internal/prune_object_properties.js +3 -2
  16. package/lib/programmers/internal/prune_object_properties.js.map +1 -1
  17. package/lib/programmers/json/JsonAssertParseProgrammer.js +2 -2
  18. package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
  19. package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
  20. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  21. package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
  22. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  23. package/lib/programmers/notations/NotationGeneralProgrammer.js +4 -1
  24. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  25. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
  26. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  27. package/lib/transformers/FileTransformer.js +0 -6
  28. package/lib/transformers/FileTransformer.js.map +1 -1
  29. package/lib/transformers/ImportTransformer.d.ts +4 -1
  30. package/lib/transformers/ImportTransformer.js +34 -30
  31. package/lib/transformers/ImportTransformer.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/IRandomGenerator.ts +49 -49
  34. package/src/factories/ExpressionFactory.ts +164 -164
  35. package/src/factories/JsonMetadataFactory.ts +25 -15
  36. package/src/factories/LiteralFactory.ts +50 -50
  37. package/src/factories/MetadataCommentTagFactory.ts +650 -650
  38. package/src/functional.ts +750 -750
  39. package/src/http.ts +1042 -1042
  40. package/src/internal/$IProtobufWriter.ts +18 -18
  41. package/src/internal/$ProtobufReader.ts +194 -194
  42. package/src/internal/$ProtobufSizer.ts +151 -151
  43. package/src/internal/$ProtobufWriter.ts +145 -145
  44. package/src/internal/$accessExpressionAsString.ts +46 -46
  45. package/src/internal/$assertGuard.ts +13 -13
  46. package/src/internal/$functionalTypeGuardErrorFactory.ts +4 -4
  47. package/src/internal/$httpFormDataReadBigint.ts +18 -18
  48. package/src/internal/$httpFormDataReadBlob.ts +10 -10
  49. package/src/internal/$httpFormDataReadBoolean.ts +16 -16
  50. package/src/internal/$httpFormDataReadFile.ts +10 -10
  51. package/src/internal/$httpFormDataReadNumber.ts +15 -15
  52. package/src/internal/$httpFormDataReadString.ts +10 -10
  53. package/src/internal/{$httpFormDataReadArray.ts → $httpFormdataReadArray.ts} +4 -4
  54. package/src/internal/$httpHeaderReadBigint.ts +10 -10
  55. package/src/internal/$httpHeaderReadBoolean.ts +8 -8
  56. package/src/internal/$httpHeaderReadNumber.ts +7 -7
  57. package/src/internal/$httpParameterBigint.ts +10 -10
  58. package/src/internal/$httpParameterBoolean.ts +8 -8
  59. package/src/internal/$httpParameterNumber.ts +7 -7
  60. package/src/internal/$httpParameterString.ts +2 -2
  61. package/src/internal/$httpQueryParseURLSearchParams.ts +10 -10
  62. package/src/internal/$httpQueryReadArray.ts +4 -4
  63. package/src/internal/$httpQueryReadBigint.ts +12 -12
  64. package/src/internal/$httpQueryReadBoolean.ts +14 -14
  65. package/src/internal/$httpQueryReadNumber.ts +9 -9
  66. package/src/internal/$httpQueryReadString.ts +4 -4
  67. package/src/internal/$isBetween.ts +2 -2
  68. package/src/internal/$isBigintString.ts +8 -8
  69. package/src/internal/$jsonStringifyNumber.ts +12 -12
  70. package/src/internal/$jsonStringifyRest.ts +3 -3
  71. package/src/internal/$jsonStringifyString.ts +42 -42
  72. package/src/internal/$jsonStringifyTail.ts +2 -2
  73. package/src/internal/$llmApplicationFinalize.ts +18 -18
  74. package/src/internal/$miscCloneAny.ts +48 -48
  75. package/src/internal/$notationAny.ts +37 -37
  76. package/src/internal/$notationCamel.ts +13 -13
  77. package/src/internal/$notationPascal.ts +8 -8
  78. package/src/internal/$notationSnake.ts +43 -43
  79. package/src/internal/$randomArray.ts +21 -21
  80. package/src/internal/$randomBigint.ts +6 -6
  81. package/src/internal/$randomBoolean.ts +1 -1
  82. package/src/internal/$randomFormatByte.ts +3 -3
  83. package/src/internal/$randomFormatDate.ts +18 -18
  84. package/src/internal/$randomFormatDatetime.ts +16 -16
  85. package/src/internal/$randomFormatDuration.ts +27 -27
  86. package/src/internal/$randomFormatEmail.ts +11 -11
  87. package/src/internal/$randomFormatHostname.ts +6 -6
  88. package/src/internal/$randomFormatIdnEmail.ts +3 -3
  89. package/src/internal/$randomFormatIdnHostname.ts +3 -3
  90. package/src/internal/$randomFormatIpv4.ts +11 -11
  91. package/src/internal/$randomFormatIpv6.ts +11 -11
  92. package/src/internal/$randomFormatIri.ts +3 -3
  93. package/src/internal/$randomFormatIriReference.ts +3 -3
  94. package/src/internal/$randomFormatJsonPointer.ts +7 -7
  95. package/src/internal/$randomFormatPassword.ts +8 -8
  96. package/src/internal/$randomFormatRegex.ts +4 -4
  97. package/src/internal/$randomFormatRelativeJsonPointer.ts +8 -8
  98. package/src/internal/$randomFormatTime.ts +14 -14
  99. package/src/internal/$randomFormatUri.ts +3 -3
  100. package/src/internal/$randomFormatUriReference.ts +3 -3
  101. package/src/internal/$randomFormatUriTemplate.ts +3 -3
  102. package/src/internal/$randomFormatUrl.ts +11 -11
  103. package/src/internal/$randomFormatUuid.ts +6 -6
  104. package/src/internal/$randomInteger.ts +47 -47
  105. package/src/internal/$randomNumber.ts +74 -74
  106. package/src/internal/$randomPattern.ts +10 -10
  107. package/src/internal/$randomPick.ts +9 -9
  108. package/src/internal/$randomString.ts +24 -24
  109. package/src/internal/$throwTypeGuardError.ts +5 -5
  110. package/src/internal/$validateReport.ts +13 -13
  111. package/src/internal/private/$__notationCapitalize.ts +2 -2
  112. package/src/internal/private/$__notationUnsnake.ts +24 -24
  113. package/src/json.ts +651 -651
  114. package/src/llm.ts +178 -178
  115. package/src/misc.ts +658 -658
  116. package/src/module.ts +933 -933
  117. package/src/notations.ts +827 -827
  118. package/src/programmers/CheckerProgrammer.ts +4 -1
  119. package/src/programmers/FeatureProgrammer.ts +619 -616
  120. package/src/programmers/RandomProgrammer.ts +24 -16
  121. package/src/programmers/TypiaProgrammer.ts +4 -1
  122. package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +153 -153
  123. package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +125 -125
  124. package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +115 -115
  125. package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +119 -119
  126. package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +274 -274
  127. package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +135 -135
  128. package/src/programmers/helpers/FunctionProgrammer.ts +67 -67
  129. package/src/programmers/helpers/RandomJoiner.ts +168 -168
  130. package/src/programmers/helpers/StringifyJoinder.ts +115 -115
  131. package/src/programmers/helpers/disable_function_programmer_declare.ts +32 -32
  132. package/src/programmers/internal/check_dynamic_key.ts +201 -201
  133. package/src/programmers/internal/check_dynamic_properties.ts +208 -208
  134. package/src/programmers/internal/check_object.ts +75 -75
  135. package/src/programmers/internal/feature_object_entries.ts +61 -61
  136. package/src/programmers/internal/prune_object_properties.ts +71 -63
  137. package/src/programmers/json/JsonAssertParseProgrammer.ts +14 -11
  138. package/src/programmers/llm/LlmApplicationProgrammer.ts +235 -235
  139. package/src/programmers/llm/LlmSchemaProgrammer.ts +51 -51
  140. package/src/programmers/misc/MiscCloneProgrammer.ts +4 -1
  141. package/src/programmers/misc/MiscPruneProgrammer.ts +4 -1
  142. package/src/programmers/notations/NotationGeneralProgrammer.ts +4 -1
  143. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -1
  144. package/src/protobuf.ts +868 -868
  145. package/src/reflect.ts +57 -57
  146. package/src/transformers/FileTransformer.ts +0 -6
  147. package/src/transformers/ImportTransformer.ts +59 -44
  148. package/src/utils/NamingConvention.ts +94 -94
  149. package/src/utils/StringUtil.ts +16 -16
  150. package/lib/internal/$httpFormDataReadArray.js.map +0 -1
  151. /package/lib/internal/{$httpFormDataReadArray.d.ts → $httpFormdataReadArray.d.ts} +0 -0
@@ -1,650 +1,650 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTypeTag } from "../schemas/metadata/IMetadataTypeTag";
4
- import { Metadata } from "../schemas/metadata/Metadata";
5
-
6
- import { Writable } from "../typings/Writable";
7
-
8
- import { FormatCheatSheet } from "../tags/internal/FormatCheatSheet";
9
- import { MetadataFactory } from "./MetadataFactory";
10
- import { MetadataTypeTagFactory } from "./MetadataTypeTagFactory";
11
-
12
- /**
13
- * @internal
14
- */
15
- export namespace MetadataCommentTagFactory {
16
- export const analyze = (props: {
17
- errors: MetadataFactory.IError[];
18
- metadata: Metadata;
19
- tags: ts.JSDocTagInfo[];
20
- explore: MetadataFactory.IExplore;
21
- }): void => {
22
- // PREPARE MESSAGE CONTAINER
23
- const messages: string[] = [];
24
- const report = (msg: string) => {
25
- messages.push(msg);
26
- return null;
27
- };
28
- const validateReport = (next: {
29
- property: string | null;
30
- message: string;
31
- }): false => {
32
- messages.push(
33
- `the property ${
34
- next.property === null
35
- ? `["typia.tag"]`
36
- : `["typia.tag.${next.property}"]`
37
- } ${next.message}.`,
38
- );
39
- return false;
40
- };
41
-
42
- // VALIDATE AND CONSTRUCT COMMENT TAGS
43
- for (const tag of props.tags) {
44
- const tagger: TagRecord | null = parse({
45
- report,
46
- tag,
47
- });
48
- if (tagger === null) continue;
49
- for (const [key, value] of Object.entries(tagger)) {
50
- const filtered: IMetadataTypeTag[] = value.filter(
51
- (v) => v.validate !== null,
52
- ) as IMetadataTypeTag[];
53
- if (key === "array") {
54
- if (props.metadata.arrays.length === 0) {
55
- report(`requires array type`);
56
- continue;
57
- }
58
- for (const a of props.metadata.arrays) {
59
- Writable(a).tags = a.tags.filter((x) =>
60
- MetadataTypeTagFactory.validate({
61
- report: validateReport,
62
- type: "array",
63
- tags: [...x, ...filtered],
64
- }),
65
- );
66
- if (a.tags.length === 0) a.tags.push(filtered);
67
- else for (const tags of a.tags) tags.push(...filtered);
68
- }
69
- } else {
70
- const atomic = props.metadata.atomics.find((a) => a.type == key);
71
- if (atomic === undefined)
72
- if (key === "bigint" || key === "number") {
73
- const opposite = key === "bigint" ? "number" : "bigint";
74
- if (
75
- tagger[opposite] !== undefined &&
76
- props.metadata.atomics.some((a) => a.type === opposite)
77
- )
78
- continue;
79
- } else if (
80
- key === "string" &&
81
- value[0]?.kind === "format" &&
82
- value[0]?.value === "date-time"
83
- )
84
- continue;
85
- else report(`requires ${key} type`);
86
- else {
87
- Writable(atomic).tags = atomic.tags.filter((x) =>
88
- MetadataTypeTagFactory.validate({
89
- report: validateReport,
90
- type: key as "string",
91
- tags: [...x, ...filtered],
92
- }),
93
- );
94
- if (atomic.tags.length === 0) atomic.tags.push(filtered);
95
- else for (const tags of atomic.tags) tags.push(...filtered);
96
- }
97
- }
98
- }
99
- }
100
-
101
- // DO REPORT
102
- if (messages.length !== 0)
103
- props.errors.push({
104
- name: "comment tag(s)",
105
- explore: props.explore,
106
- messages,
107
- });
108
- };
109
-
110
- const parse = (props: {
111
- report: (msg: string) => null;
112
- tag: ts.JSDocTagInfo;
113
- }): TagRecord | null => {
114
- const next = PARSER[props.tag.name];
115
- if (next === undefined) return {};
116
-
117
- const value = (props.tag.text || [])[0]?.text;
118
- if (value === undefined && props.tag.name !== "uniqueItems")
119
- return props.report(`no comment tag value`);
120
- return next({
121
- report: props.report,
122
- value: value!,
123
- });
124
- };
125
-
126
- export const get = (props: {
127
- kind: string;
128
- type: "array" | "bigint" | "number" | "string";
129
- value: string;
130
- }): IMetadataTypeTag[] => {
131
- const output: IMetadataTypeTag[] | undefined = PARSER[props.kind]?.({
132
- report: () => null,
133
- value: props.value,
134
- })?.[props.type];
135
- if (output === undefined)
136
- throw new Error(
137
- `no tag found for (kind: ${props.kind}, type: ${props.type}).`,
138
- );
139
- return output;
140
- };
141
- }
142
-
143
- /**
144
- * @internal
145
- */
146
- type TagRecord = {
147
- [P in Target]?: NotDeterminedTypeTag[];
148
- };
149
-
150
- /**
151
- * @internal
152
- */
153
- type Target = "bigint" | "number" | "string" | "array";
154
-
155
- /**
156
- * @internal
157
- */
158
- type NotDeterminedTypeTag = Omit<IMetadataTypeTag, "validate" | "schema"> & {
159
- validate: string | undefined;
160
- schema: object | undefined;
161
- };
162
-
163
- /**
164
- * @internal
165
- */
166
- const PARSER: Record<
167
- string,
168
- (props: { report: (msg: string) => null; value: string }) => {
169
- [P in Target]?: NotDeterminedTypeTag[];
170
- }
171
- > = {
172
- /* -----------------------------------------------------------
173
- ARRAY
174
- ----------------------------------------------------------- */
175
- items: ({ report, value }) => ({
176
- array: [
177
- {
178
- name: `MinItems<${value}>`,
179
- target: "array",
180
- kind: "minItems",
181
- value: parse_integer({
182
- report,
183
- value,
184
- unsigned: true,
185
- }),
186
- validate: `${value} <= $input.length`,
187
- exclusive: true,
188
- schema: {
189
- minItems: parse_integer({
190
- report,
191
- value,
192
- unsigned: true,
193
- }),
194
- },
195
- },
196
- {
197
- name: `MaxItems<${value}>`,
198
- target: "array",
199
- kind: "maxItems",
200
- value: parse_integer({
201
- report,
202
- value,
203
- unsigned: true,
204
- }),
205
- validate: `$input.length <= ${value}`,
206
- exclusive: true,
207
- schema: {
208
- maxItems: parse_integer({
209
- report,
210
- unsigned: true,
211
- value,
212
- }),
213
- },
214
- },
215
- ],
216
- }),
217
- minItems: ({ report, value }) => ({
218
- array: [
219
- {
220
- name: `MinItems<${value}>`,
221
- target: "array",
222
- kind: "minItems",
223
- value: parse_integer({
224
- report,
225
- value,
226
- unsigned: true,
227
- }),
228
- validate: `${value} <= $input.length`,
229
- exclusive: true,
230
- schema: {
231
- minItems: parse_integer({
232
- report,
233
- value,
234
- unsigned: true,
235
- }),
236
- },
237
- },
238
- ],
239
- }),
240
- maxItems: ({ report, value }) => ({
241
- array: [
242
- {
243
- name: `MaxItems<${value}>`,
244
- target: "array",
245
- kind: "maxItems",
246
- value: parse_integer({
247
- report,
248
- value,
249
- unsigned: true,
250
- }),
251
- validate: `$input.length <= ${value}`,
252
- exclusive: true,
253
- schema: {
254
- maxItems: parse_integer({
255
- report,
256
- value,
257
- unsigned: true,
258
- }),
259
- },
260
- },
261
- ],
262
- }),
263
- uniqueItems: () => ({
264
- array: [
265
- {
266
- name: `UniqueItems`,
267
- target: "array",
268
- kind: "uniqueItems",
269
- value: true,
270
- validate: `$input.length <= 1 || (new Set($input).size === $input.length)`,
271
- exclusive: true,
272
- schema: {
273
- uniqueItems: true,
274
- },
275
- },
276
- ],
277
- }),
278
-
279
- /* -----------------------------------------------------------
280
- NUMBER
281
- ----------------------------------------------------------- */
282
- type: ({ value }) => {
283
- // EMENDATIONS
284
- if (value.startsWith("{") && value.endsWith("}"))
285
- value = value.substring(1, value.length - 1);
286
- if (value === "int") value = "int32";
287
- else if (value === "uint") value = "uint32";
288
-
289
- // MUST BE ONE OF THEM
290
- if (
291
- ["int32", "uint32", "int64", "uint64", "float", "double"].includes(
292
- value,
293
- ) === false
294
- )
295
- return {};
296
- return {
297
- number: [
298
- {
299
- name: `Type<${JSON.stringify(value)}>`,
300
- target: "number",
301
- kind: "type",
302
- value: value,
303
- validate:
304
- value === "int32"
305
- ? `Math.floor($input) === $input && -2147483648 <= $input && $input <= 2147483647`
306
- : value === "uint32"
307
- ? `Math.floor($input) === $input && 0 <= $input && $input <= 4294967295`
308
- : value === "int64"
309
- ? `Math.floor($input) === $input && -9223372036854775808 <= $input && $input <= 9223372036854775807`
310
- : value === "uint64"
311
- ? `Math.floor($input) === $input && 0 <= $input && $input <= 18446744073709551615`
312
- : value === "float"
313
- ? `-1.175494351e38 <= $input && $input <= 3.4028235e38`
314
- : `true`,
315
- exclusive: true,
316
- schema: ["int32", "uint32", "int64", "uint64"].includes(value)
317
- ? { type: "integer" }
318
- : undefined,
319
- },
320
- ],
321
- bigint:
322
- value === "int64" || "uint64"
323
- ? [
324
- {
325
- name: `Type<${JSON.stringify(value)}>`,
326
- target: "bigint",
327
- kind: "type",
328
- value: value,
329
- validate: value === "int64" ? "true" : "BigInt(0) <= $input",
330
- exclusive: true,
331
- schema: value === "uint64" ? { minimum: 0 } : undefined,
332
- },
333
- ]
334
- : [],
335
- };
336
- },
337
- minimum: (props) => ({
338
- number: [
339
- {
340
- name: `Minimum<${props.value}>`,
341
- target: "number",
342
- kind: "minimum",
343
- value: parse_number(props),
344
- validate: `${props.value} <= $input`,
345
- exclusive: ["minimum", "exclusiveMinimum"],
346
- schema: {
347
- minimum: parse_number(props),
348
- },
349
- },
350
- ],
351
- bigint: [
352
- {
353
- name: `Minimum<${props.value}n>`,
354
- target: "bigint",
355
- kind: "minimum",
356
- value: (() => {
357
- const parsed = parse_integer({
358
- report: props.report,
359
- value: props.value,
360
- unsigned: false,
361
- });
362
- return parsed === null ? null : BigInt(parsed);
363
- })(),
364
- validate: `${props.value} <= $input`,
365
- exclusive: ["minimum", "exclusiveMinimum"],
366
- schema: {
367
- minimum: parse_number(props),
368
- },
369
- },
370
- ],
371
- }),
372
- maximum: (props) => ({
373
- number: [
374
- {
375
- name: `Maximum<${props.value}>`,
376
- target: "number",
377
- kind: "maximum",
378
- value: parse_number(props),
379
- validate: `$input <= ${props.value}`,
380
- exclusive: ["maximum", "exclusiveMaximum"],
381
- schema: {
382
- maximum: parse_number(props),
383
- },
384
- },
385
- ],
386
- bigint: [
387
- {
388
- name: `Maximum<${props.value}n>`,
389
- target: "bigint",
390
- kind: "maximum",
391
- value: (() => {
392
- const parsed = parse_integer({
393
- report: props.report,
394
- value: props.value,
395
- unsigned: false,
396
- });
397
- return parsed === null ? null : BigInt(parsed);
398
- })(),
399
- validate: `$input <= ${props.value}`,
400
- exclusive: ["maximum", "exclusiveMaximum"],
401
- schema: {
402
- maximum: parse_number(props),
403
- },
404
- },
405
- ],
406
- }),
407
- exclusiveMinimum: (props) => ({
408
- number: [
409
- {
410
- name: `ExclusiveMinimum<${props.value}>`,
411
- target: "number",
412
- kind: "exclusiveMinimum",
413
- value: parse_number(props),
414
- validate: `${props.value} < $input`,
415
- exclusive: ["minimum", "exclusiveMinimum"],
416
- schema: {
417
- exclusiveMinimum: true,
418
- minimum: parse_number(props),
419
- },
420
- },
421
- ],
422
- bigint: [
423
- {
424
- name: `ExclusiveMinimum<${props.value}n>`,
425
- target: "bigint",
426
- kind: "exclusiveMinimum",
427
- value: (() => {
428
- const parsed = parse_integer({
429
- report: props.report,
430
- value: props.value,
431
- unsigned: false,
432
- });
433
- return parsed === null ? null : BigInt(parsed);
434
- })(),
435
- validate: `${props.value} < $input`,
436
- exclusive: ["minimum", "exclusiveMinimum"],
437
- schema: {
438
- exclusiveMinimum: true,
439
- minimum: parse_number(props),
440
- },
441
- },
442
- ],
443
- }),
444
- exclusiveMaximum: (props) => ({
445
- number: [
446
- {
447
- name: `ExclusiveMaximum<${props.value}>`,
448
- target: "number",
449
- kind: "exclusiveMaximum",
450
- value: parse_number(props),
451
- validate: `$input < ${props.value}`,
452
- exclusive: ["maximum", "exclusiveMaximum"],
453
- schema: {
454
- exclusiveMaximum: true,
455
- maximum: parse_number(props),
456
- },
457
- },
458
- ],
459
- bigint: [
460
- {
461
- name: `ExclusiveMaximum<${props.value}n>`,
462
- target: "bigint",
463
- kind: "exclusiveMaximum",
464
- value: (() => {
465
- const parsed = parse_integer({
466
- report: props.report,
467
- value: props.value,
468
- unsigned: false,
469
- });
470
- return parsed === null ? null : BigInt(parsed);
471
- })(),
472
- validate: `$input < ${props.value}`,
473
- exclusive: ["maximum", "exclusiveMaximum"],
474
- schema: {
475
- exclusiveMaximum: true,
476
- maximum: parse_number(props),
477
- },
478
- },
479
- ],
480
- }),
481
- multipleOf: (props) => ({
482
- number: [
483
- {
484
- name: `MultipleOf<${props.value}>`,
485
- target: "number",
486
- kind: "multipleOf",
487
- value: parse_number(props),
488
- validate: `$input % ${props.value} === 0`,
489
- exclusive: true,
490
- schema: {
491
- multipleOf: parse_number(props),
492
- },
493
- },
494
- ],
495
- bigint: [
496
- {
497
- name: `MultipleOf<${props.value}n>`,
498
- target: "bigint",
499
- kind: "multipleOf",
500
- value: (() => {
501
- const parsed = parse_integer({
502
- report: props.report,
503
- value: props.value,
504
- unsigned: false,
505
- });
506
- return parsed === null ? null : BigInt(parsed);
507
- })(),
508
- validate: `$input % ${props.value}n === 0n`,
509
- exclusive: true,
510
- schema: {
511
- multipleOf: parse_number(props),
512
- },
513
- },
514
- ],
515
- }),
516
-
517
- /* -----------------------------------------------------------
518
- STRING
519
- ----------------------------------------------------------- */
520
- format: ({ value }) => {
521
- const matched = FORMATS.get(value);
522
- if (matched === undefined) return {};
523
- return {
524
- string: [
525
- {
526
- name: `Format<${JSON.stringify(matched[0])}>`,
527
- target: "string",
528
- kind: "format",
529
- value: matched[0],
530
- validate: matched[1],
531
- exclusive: true,
532
- schema: {
533
- format: matched[0],
534
- },
535
- },
536
- ],
537
- };
538
- },
539
- pattern: ({ value }) => ({
540
- string: [
541
- {
542
- name: `Pattern<${JSON.stringify(value)}>`,
543
- target: "string",
544
- kind: "pattern",
545
- value: value,
546
- validate: `RegExp(${JSON.stringify(value)}).test($input)`,
547
- exclusive: ["format"],
548
- schema: {
549
- pattern: value,
550
- },
551
- },
552
- ],
553
- }),
554
- length: (props) => ({
555
- string: [
556
- {
557
- name: `MinLength<${props.value}>`,
558
- target: "string",
559
- kind: "minLength",
560
- value: parse_number(props),
561
- validate: `${props.value} <= $input.length`,
562
- exclusive: true,
563
- schema: {
564
- minLength: parse_number(props),
565
- },
566
- },
567
- {
568
- name: `MaxLength<${props.value}>`,
569
- target: "string",
570
- kind: "maxLength",
571
- value: parse_number(props),
572
- validate: `$input.length <= ${props.value}`,
573
- exclusive: true,
574
- schema: {
575
- maxLength: parse_number(props),
576
- },
577
- },
578
- ],
579
- }),
580
- minLength: ({ report, value }) => ({
581
- string: [
582
- {
583
- name: `MinLength<${value}>`,
584
- target: "string",
585
- kind: "minLength",
586
- value: parse_number({ report, value }),
587
- validate: `${value} <= $input.length`,
588
- exclusive: true,
589
- schema: {
590
- minLength: parse_number({ report, value }),
591
- },
592
- },
593
- ],
594
- }),
595
- maxLength: ({ report, value }) => ({
596
- string: [
597
- {
598
- name: `MaxLength<${value}>`,
599
- target: "string",
600
- kind: "maxLength",
601
- value: parse_number({ report, value }),
602
- validate: `$input.length <= ${value}`,
603
- exclusive: true,
604
- schema: {
605
- maxLength: parse_number({ report, value }),
606
- },
607
- },
608
- ],
609
- }),
610
- };
611
-
612
- /**
613
- * @internal
614
- */
615
- const parse_number = (props: {
616
- report: (msg: string) => null;
617
- value: string;
618
- }): number | null => {
619
- const parsed: number = Number(props.value);
620
- if (isNaN(parsed) === true) return props.report(`invalid number`);
621
- return parsed;
622
- };
623
-
624
- /**
625
- * @internal
626
- */
627
- const parse_integer = (props: {
628
- report: (msg: string) => null;
629
- unsigned: boolean;
630
- value: string;
631
- }): number | null => {
632
- const parsed: number | null = parse_number(props);
633
- if (parsed === null) return null;
634
- else if (Math.floor(parsed) !== parsed)
635
- return props.report(`invalid integer`);
636
- else if (props.unsigned === true && parsed < 0)
637
- return props.report(`invalid unsigned integer`);
638
- return parsed;
639
- };
640
-
641
- /**
642
- * @internal
643
- */
644
- const FORMATS: Map<string, [string, string]> = new Map([
645
- ...Object.entries(FormatCheatSheet).map(
646
- ([key, value]) => [key, [key, value]] as any,
647
- ),
648
- ["datetime", ["date-time", `!isNaN(new Date($input).getTime())`]],
649
- ["dateTime", ["date-time", `!isNaN(new Date($input).getTime())`]],
650
- ]);
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTypeTag } from "../schemas/metadata/IMetadataTypeTag";
4
+ import { Metadata } from "../schemas/metadata/Metadata";
5
+
6
+ import { Writable } from "../typings/Writable";
7
+
8
+ import { FormatCheatSheet } from "../tags/internal/FormatCheatSheet";
9
+ import { MetadataFactory } from "./MetadataFactory";
10
+ import { MetadataTypeTagFactory } from "./MetadataTypeTagFactory";
11
+
12
+ /**
13
+ * @internal
14
+ */
15
+ export namespace MetadataCommentTagFactory {
16
+ export const analyze = (props: {
17
+ errors: MetadataFactory.IError[];
18
+ metadata: Metadata;
19
+ tags: ts.JSDocTagInfo[];
20
+ explore: MetadataFactory.IExplore;
21
+ }): void => {
22
+ // PREPARE MESSAGE CONTAINER
23
+ const messages: string[] = [];
24
+ const report = (msg: string) => {
25
+ messages.push(msg);
26
+ return null;
27
+ };
28
+ const validateReport = (next: {
29
+ property: string | null;
30
+ message: string;
31
+ }): false => {
32
+ messages.push(
33
+ `the property ${
34
+ next.property === null
35
+ ? `["typia.tag"]`
36
+ : `["typia.tag.${next.property}"]`
37
+ } ${next.message}.`,
38
+ );
39
+ return false;
40
+ };
41
+
42
+ // VALIDATE AND CONSTRUCT COMMENT TAGS
43
+ for (const tag of props.tags) {
44
+ const tagger: TagRecord | null = parse({
45
+ report,
46
+ tag,
47
+ });
48
+ if (tagger === null) continue;
49
+ for (const [key, value] of Object.entries(tagger)) {
50
+ const filtered: IMetadataTypeTag[] = value.filter(
51
+ (v) => v.validate !== null,
52
+ ) as IMetadataTypeTag[];
53
+ if (key === "array") {
54
+ if (props.metadata.arrays.length === 0) {
55
+ report(`requires array type`);
56
+ continue;
57
+ }
58
+ for (const a of props.metadata.arrays) {
59
+ Writable(a).tags = a.tags.filter((x) =>
60
+ MetadataTypeTagFactory.validate({
61
+ report: validateReport,
62
+ type: "array",
63
+ tags: [...x, ...filtered],
64
+ }),
65
+ );
66
+ if (a.tags.length === 0) a.tags.push(filtered);
67
+ else for (const tags of a.tags) tags.push(...filtered);
68
+ }
69
+ } else {
70
+ const atomic = props.metadata.atomics.find((a) => a.type == key);
71
+ if (atomic === undefined)
72
+ if (key === "bigint" || key === "number") {
73
+ const opposite = key === "bigint" ? "number" : "bigint";
74
+ if (
75
+ tagger[opposite] !== undefined &&
76
+ props.metadata.atomics.some((a) => a.type === opposite)
77
+ )
78
+ continue;
79
+ } else if (
80
+ key === "string" &&
81
+ value[0]?.kind === "format" &&
82
+ value[0]?.value === "date-time"
83
+ )
84
+ continue;
85
+ else report(`requires ${key} type`);
86
+ else {
87
+ Writable(atomic).tags = atomic.tags.filter((x) =>
88
+ MetadataTypeTagFactory.validate({
89
+ report: validateReport,
90
+ type: key as "string",
91
+ tags: [...x, ...filtered],
92
+ }),
93
+ );
94
+ if (atomic.tags.length === 0) atomic.tags.push(filtered);
95
+ else for (const tags of atomic.tags) tags.push(...filtered);
96
+ }
97
+ }
98
+ }
99
+ }
100
+
101
+ // DO REPORT
102
+ if (messages.length !== 0)
103
+ props.errors.push({
104
+ name: "comment tag(s)",
105
+ explore: props.explore,
106
+ messages,
107
+ });
108
+ };
109
+
110
+ const parse = (props: {
111
+ report: (msg: string) => null;
112
+ tag: ts.JSDocTagInfo;
113
+ }): TagRecord | null => {
114
+ const next = PARSER[props.tag.name];
115
+ if (next === undefined) return {};
116
+
117
+ const value = (props.tag.text || [])[0]?.text;
118
+ if (value === undefined && props.tag.name !== "uniqueItems")
119
+ return props.report(`no comment tag value`);
120
+ return next({
121
+ report: props.report,
122
+ value: value!,
123
+ });
124
+ };
125
+
126
+ export const get = (props: {
127
+ kind: string;
128
+ type: "array" | "bigint" | "number" | "string";
129
+ value: string;
130
+ }): IMetadataTypeTag[] => {
131
+ const output: IMetadataTypeTag[] | undefined = PARSER[props.kind]?.({
132
+ report: () => null,
133
+ value: props.value,
134
+ })?.[props.type];
135
+ if (output === undefined)
136
+ throw new Error(
137
+ `no tag found for (kind: ${props.kind}, type: ${props.type}).`,
138
+ );
139
+ return output;
140
+ };
141
+ }
142
+
143
+ /**
144
+ * @internal
145
+ */
146
+ type TagRecord = {
147
+ [P in Target]?: NotDeterminedTypeTag[];
148
+ };
149
+
150
+ /**
151
+ * @internal
152
+ */
153
+ type Target = "bigint" | "number" | "string" | "array";
154
+
155
+ /**
156
+ * @internal
157
+ */
158
+ type NotDeterminedTypeTag = Omit<IMetadataTypeTag, "validate" | "schema"> & {
159
+ validate: string | undefined;
160
+ schema: object | undefined;
161
+ };
162
+
163
+ /**
164
+ * @internal
165
+ */
166
+ const PARSER: Record<
167
+ string,
168
+ (props: { report: (msg: string) => null; value: string }) => {
169
+ [P in Target]?: NotDeterminedTypeTag[];
170
+ }
171
+ > = {
172
+ /* -----------------------------------------------------------
173
+ ARRAY
174
+ ----------------------------------------------------------- */
175
+ items: ({ report, value }) => ({
176
+ array: [
177
+ {
178
+ name: `MinItems<${value}>`,
179
+ target: "array",
180
+ kind: "minItems",
181
+ value: parse_integer({
182
+ report,
183
+ value,
184
+ unsigned: true,
185
+ }),
186
+ validate: `${value} <= $input.length`,
187
+ exclusive: true,
188
+ schema: {
189
+ minItems: parse_integer({
190
+ report,
191
+ value,
192
+ unsigned: true,
193
+ }),
194
+ },
195
+ },
196
+ {
197
+ name: `MaxItems<${value}>`,
198
+ target: "array",
199
+ kind: "maxItems",
200
+ value: parse_integer({
201
+ report,
202
+ value,
203
+ unsigned: true,
204
+ }),
205
+ validate: `$input.length <= ${value}`,
206
+ exclusive: true,
207
+ schema: {
208
+ maxItems: parse_integer({
209
+ report,
210
+ unsigned: true,
211
+ value,
212
+ }),
213
+ },
214
+ },
215
+ ],
216
+ }),
217
+ minItems: ({ report, value }) => ({
218
+ array: [
219
+ {
220
+ name: `MinItems<${value}>`,
221
+ target: "array",
222
+ kind: "minItems",
223
+ value: parse_integer({
224
+ report,
225
+ value,
226
+ unsigned: true,
227
+ }),
228
+ validate: `${value} <= $input.length`,
229
+ exclusive: true,
230
+ schema: {
231
+ minItems: parse_integer({
232
+ report,
233
+ value,
234
+ unsigned: true,
235
+ }),
236
+ },
237
+ },
238
+ ],
239
+ }),
240
+ maxItems: ({ report, value }) => ({
241
+ array: [
242
+ {
243
+ name: `MaxItems<${value}>`,
244
+ target: "array",
245
+ kind: "maxItems",
246
+ value: parse_integer({
247
+ report,
248
+ value,
249
+ unsigned: true,
250
+ }),
251
+ validate: `$input.length <= ${value}`,
252
+ exclusive: true,
253
+ schema: {
254
+ maxItems: parse_integer({
255
+ report,
256
+ value,
257
+ unsigned: true,
258
+ }),
259
+ },
260
+ },
261
+ ],
262
+ }),
263
+ uniqueItems: () => ({
264
+ array: [
265
+ {
266
+ name: `UniqueItems`,
267
+ target: "array",
268
+ kind: "uniqueItems",
269
+ value: true,
270
+ validate: `$input.length <= 1 || (new Set($input).size === $input.length)`,
271
+ exclusive: true,
272
+ schema: {
273
+ uniqueItems: true,
274
+ },
275
+ },
276
+ ],
277
+ }),
278
+
279
+ /* -----------------------------------------------------------
280
+ NUMBER
281
+ ----------------------------------------------------------- */
282
+ type: ({ value }) => {
283
+ // EMENDATIONS
284
+ if (value.startsWith("{") && value.endsWith("}"))
285
+ value = value.substring(1, value.length - 1);
286
+ if (value === "int") value = "int32";
287
+ else if (value === "uint") value = "uint32";
288
+
289
+ // MUST BE ONE OF THEM
290
+ if (
291
+ ["int32", "uint32", "int64", "uint64", "float", "double"].includes(
292
+ value,
293
+ ) === false
294
+ )
295
+ return {};
296
+ return {
297
+ number: [
298
+ {
299
+ name: `Type<${JSON.stringify(value)}>`,
300
+ target: "number",
301
+ kind: "type",
302
+ value: value,
303
+ validate:
304
+ value === "int32"
305
+ ? `Math.floor($input) === $input && -2147483648 <= $input && $input <= 2147483647`
306
+ : value === "uint32"
307
+ ? `Math.floor($input) === $input && 0 <= $input && $input <= 4294967295`
308
+ : value === "int64"
309
+ ? `Math.floor($input) === $input && -9223372036854775808 <= $input && $input <= 9223372036854775807`
310
+ : value === "uint64"
311
+ ? `Math.floor($input) === $input && 0 <= $input && $input <= 18446744073709551615`
312
+ : value === "float"
313
+ ? `-1.175494351e38 <= $input && $input <= 3.4028235e38`
314
+ : `true`,
315
+ exclusive: true,
316
+ schema: ["int32", "uint32", "int64", "uint64"].includes(value)
317
+ ? { type: "integer" }
318
+ : undefined,
319
+ },
320
+ ],
321
+ bigint:
322
+ value === "int64" || "uint64"
323
+ ? [
324
+ {
325
+ name: `Type<${JSON.stringify(value)}>`,
326
+ target: "bigint",
327
+ kind: "type",
328
+ value: value,
329
+ validate: value === "int64" ? "true" : "BigInt(0) <= $input",
330
+ exclusive: true,
331
+ schema: value === "uint64" ? { minimum: 0 } : undefined,
332
+ },
333
+ ]
334
+ : [],
335
+ };
336
+ },
337
+ minimum: (props) => ({
338
+ number: [
339
+ {
340
+ name: `Minimum<${props.value}>`,
341
+ target: "number",
342
+ kind: "minimum",
343
+ value: parse_number(props),
344
+ validate: `${props.value} <= $input`,
345
+ exclusive: ["minimum", "exclusiveMinimum"],
346
+ schema: {
347
+ minimum: parse_number(props),
348
+ },
349
+ },
350
+ ],
351
+ bigint: [
352
+ {
353
+ name: `Minimum<${props.value}n>`,
354
+ target: "bigint",
355
+ kind: "minimum",
356
+ value: (() => {
357
+ const parsed = parse_integer({
358
+ report: props.report,
359
+ value: props.value,
360
+ unsigned: false,
361
+ });
362
+ return parsed === null ? null : BigInt(parsed);
363
+ })(),
364
+ validate: `${props.value} <= $input`,
365
+ exclusive: ["minimum", "exclusiveMinimum"],
366
+ schema: {
367
+ minimum: parse_number(props),
368
+ },
369
+ },
370
+ ],
371
+ }),
372
+ maximum: (props) => ({
373
+ number: [
374
+ {
375
+ name: `Maximum<${props.value}>`,
376
+ target: "number",
377
+ kind: "maximum",
378
+ value: parse_number(props),
379
+ validate: `$input <= ${props.value}`,
380
+ exclusive: ["maximum", "exclusiveMaximum"],
381
+ schema: {
382
+ maximum: parse_number(props),
383
+ },
384
+ },
385
+ ],
386
+ bigint: [
387
+ {
388
+ name: `Maximum<${props.value}n>`,
389
+ target: "bigint",
390
+ kind: "maximum",
391
+ value: (() => {
392
+ const parsed = parse_integer({
393
+ report: props.report,
394
+ value: props.value,
395
+ unsigned: false,
396
+ });
397
+ return parsed === null ? null : BigInt(parsed);
398
+ })(),
399
+ validate: `$input <= ${props.value}`,
400
+ exclusive: ["maximum", "exclusiveMaximum"],
401
+ schema: {
402
+ maximum: parse_number(props),
403
+ },
404
+ },
405
+ ],
406
+ }),
407
+ exclusiveMinimum: (props) => ({
408
+ number: [
409
+ {
410
+ name: `ExclusiveMinimum<${props.value}>`,
411
+ target: "number",
412
+ kind: "exclusiveMinimum",
413
+ value: parse_number(props),
414
+ validate: `${props.value} < $input`,
415
+ exclusive: ["minimum", "exclusiveMinimum"],
416
+ schema: {
417
+ exclusiveMinimum: true,
418
+ minimum: parse_number(props),
419
+ },
420
+ },
421
+ ],
422
+ bigint: [
423
+ {
424
+ name: `ExclusiveMinimum<${props.value}n>`,
425
+ target: "bigint",
426
+ kind: "exclusiveMinimum",
427
+ value: (() => {
428
+ const parsed = parse_integer({
429
+ report: props.report,
430
+ value: props.value,
431
+ unsigned: false,
432
+ });
433
+ return parsed === null ? null : BigInt(parsed);
434
+ })(),
435
+ validate: `${props.value} < $input`,
436
+ exclusive: ["minimum", "exclusiveMinimum"],
437
+ schema: {
438
+ exclusiveMinimum: true,
439
+ minimum: parse_number(props),
440
+ },
441
+ },
442
+ ],
443
+ }),
444
+ exclusiveMaximum: (props) => ({
445
+ number: [
446
+ {
447
+ name: `ExclusiveMaximum<${props.value}>`,
448
+ target: "number",
449
+ kind: "exclusiveMaximum",
450
+ value: parse_number(props),
451
+ validate: `$input < ${props.value}`,
452
+ exclusive: ["maximum", "exclusiveMaximum"],
453
+ schema: {
454
+ exclusiveMaximum: true,
455
+ maximum: parse_number(props),
456
+ },
457
+ },
458
+ ],
459
+ bigint: [
460
+ {
461
+ name: `ExclusiveMaximum<${props.value}n>`,
462
+ target: "bigint",
463
+ kind: "exclusiveMaximum",
464
+ value: (() => {
465
+ const parsed = parse_integer({
466
+ report: props.report,
467
+ value: props.value,
468
+ unsigned: false,
469
+ });
470
+ return parsed === null ? null : BigInt(parsed);
471
+ })(),
472
+ validate: `$input < ${props.value}`,
473
+ exclusive: ["maximum", "exclusiveMaximum"],
474
+ schema: {
475
+ exclusiveMaximum: true,
476
+ maximum: parse_number(props),
477
+ },
478
+ },
479
+ ],
480
+ }),
481
+ multipleOf: (props) => ({
482
+ number: [
483
+ {
484
+ name: `MultipleOf<${props.value}>`,
485
+ target: "number",
486
+ kind: "multipleOf",
487
+ value: parse_number(props),
488
+ validate: `$input % ${props.value} === 0`,
489
+ exclusive: true,
490
+ schema: {
491
+ multipleOf: parse_number(props),
492
+ },
493
+ },
494
+ ],
495
+ bigint: [
496
+ {
497
+ name: `MultipleOf<${props.value}n>`,
498
+ target: "bigint",
499
+ kind: "multipleOf",
500
+ value: (() => {
501
+ const parsed = parse_integer({
502
+ report: props.report,
503
+ value: props.value,
504
+ unsigned: false,
505
+ });
506
+ return parsed === null ? null : BigInt(parsed);
507
+ })(),
508
+ validate: `$input % ${props.value}n === 0n`,
509
+ exclusive: true,
510
+ schema: {
511
+ multipleOf: parse_number(props),
512
+ },
513
+ },
514
+ ],
515
+ }),
516
+
517
+ /* -----------------------------------------------------------
518
+ STRING
519
+ ----------------------------------------------------------- */
520
+ format: ({ value }) => {
521
+ const matched = FORMATS.get(value);
522
+ if (matched === undefined) return {};
523
+ return {
524
+ string: [
525
+ {
526
+ name: `Format<${JSON.stringify(matched[0])}>`,
527
+ target: "string",
528
+ kind: "format",
529
+ value: matched[0],
530
+ validate: matched[1],
531
+ exclusive: true,
532
+ schema: {
533
+ format: matched[0],
534
+ },
535
+ },
536
+ ],
537
+ };
538
+ },
539
+ pattern: ({ value }) => ({
540
+ string: [
541
+ {
542
+ name: `Pattern<${JSON.stringify(value)}>`,
543
+ target: "string",
544
+ kind: "pattern",
545
+ value: value,
546
+ validate: `RegExp(${JSON.stringify(value)}).test($input)`,
547
+ exclusive: ["format"],
548
+ schema: {
549
+ pattern: value,
550
+ },
551
+ },
552
+ ],
553
+ }),
554
+ length: (props) => ({
555
+ string: [
556
+ {
557
+ name: `MinLength<${props.value}>`,
558
+ target: "string",
559
+ kind: "minLength",
560
+ value: parse_number(props),
561
+ validate: `${props.value} <= $input.length`,
562
+ exclusive: true,
563
+ schema: {
564
+ minLength: parse_number(props),
565
+ },
566
+ },
567
+ {
568
+ name: `MaxLength<${props.value}>`,
569
+ target: "string",
570
+ kind: "maxLength",
571
+ value: parse_number(props),
572
+ validate: `$input.length <= ${props.value}`,
573
+ exclusive: true,
574
+ schema: {
575
+ maxLength: parse_number(props),
576
+ },
577
+ },
578
+ ],
579
+ }),
580
+ minLength: ({ report, value }) => ({
581
+ string: [
582
+ {
583
+ name: `MinLength<${value}>`,
584
+ target: "string",
585
+ kind: "minLength",
586
+ value: parse_number({ report, value }),
587
+ validate: `${value} <= $input.length`,
588
+ exclusive: true,
589
+ schema: {
590
+ minLength: parse_number({ report, value }),
591
+ },
592
+ },
593
+ ],
594
+ }),
595
+ maxLength: ({ report, value }) => ({
596
+ string: [
597
+ {
598
+ name: `MaxLength<${value}>`,
599
+ target: "string",
600
+ kind: "maxLength",
601
+ value: parse_number({ report, value }),
602
+ validate: `$input.length <= ${value}`,
603
+ exclusive: true,
604
+ schema: {
605
+ maxLength: parse_number({ report, value }),
606
+ },
607
+ },
608
+ ],
609
+ }),
610
+ };
611
+
612
+ /**
613
+ * @internal
614
+ */
615
+ const parse_number = (props: {
616
+ report: (msg: string) => null;
617
+ value: string;
618
+ }): number | null => {
619
+ const parsed: number = Number(props.value);
620
+ if (isNaN(parsed) === true) return props.report(`invalid number`);
621
+ return parsed;
622
+ };
623
+
624
+ /**
625
+ * @internal
626
+ */
627
+ const parse_integer = (props: {
628
+ report: (msg: string) => null;
629
+ unsigned: boolean;
630
+ value: string;
631
+ }): number | null => {
632
+ const parsed: number | null = parse_number(props);
633
+ if (parsed === null) return null;
634
+ else if (Math.floor(parsed) !== parsed)
635
+ return props.report(`invalid integer`);
636
+ else if (props.unsigned === true && parsed < 0)
637
+ return props.report(`invalid unsigned integer`);
638
+ return parsed;
639
+ };
640
+
641
+ /**
642
+ * @internal
643
+ */
644
+ const FORMATS: Map<string, [string, string]> = new Map([
645
+ ...Object.entries(FormatCheatSheet).map(
646
+ ([key, value]) => [key, [key, value]] as any,
647
+ ),
648
+ ["datetime", ["date-time", `!isNaN(new Date($input).getTime())`]],
649
+ ["dateTime", ["date-time", `!isNaN(new Date($input).getTime())`]],
650
+ ]);