typia 3.4.6 → 3.4.8

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 (130) hide show
  1. package/README.md +12 -2
  2. package/lib/executable/internal/CommandParser.d.ts +3 -0
  3. package/lib/executable/internal/CommandParser.js +21 -0
  4. package/lib/executable/internal/CommandParser.js.map +1 -0
  5. package/lib/executable/internal/TypiaSetupWizard.d.ts +2 -2
  6. package/lib/executable/internal/TypiaSetupWizard.js +57 -35
  7. package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
  8. package/lib/executable/typia.js +22 -21
  9. package/lib/executable/typia.js.map +1 -1
  10. package/lib/factories/internal/iterate_metadata.js +1 -1
  11. package/lib/factories/internal/iterate_metadata.js.map +1 -1
  12. package/lib/factories/internal/iterate_metadata_tuple.d.ts +1 -1
  13. package/lib/factories/internal/iterate_metadata_tuple.js +5 -13
  14. package/lib/factories/internal/iterate_metadata_tuple.js.map +1 -1
  15. package/package.json +2 -2
  16. package/src/IValidation.ts +21 -21
  17. package/src/Primitive.ts +82 -82
  18. package/src/TypeGuardError.ts +36 -36
  19. package/src/executable/internal/CommandParser.ts +15 -0
  20. package/src/executable/internal/TypiaSetupWizard.ts +108 -87
  21. package/src/executable/typia.ts +25 -14
  22. package/src/factories/CommentFactory.ts +10 -10
  23. package/src/factories/ExpressionFactory.ts +52 -52
  24. package/src/factories/IdentifierFactory.ts +72 -72
  25. package/src/factories/LiteralFactory.ts +44 -44
  26. package/src/factories/MetadataCollection.ts +122 -122
  27. package/src/factories/MetadataFactory.ts +46 -46
  28. package/src/factories/StatementFactory.ts +60 -60
  29. package/src/factories/TemplateFactory.ts +56 -56
  30. package/src/factories/TypeFactory.ts +101 -101
  31. package/src/factories/ValueFactory.ts +12 -12
  32. package/src/factories/internal/MetadataHelper.ts +12 -12
  33. package/src/factories/internal/emplace_metadata_object.ts +140 -140
  34. package/src/factories/internal/explore_metadata.ts +91 -91
  35. package/src/factories/internal/iterate_metadata.ts +1 -2
  36. package/src/factories/internal/iterate_metadata_array.ts +29 -29
  37. package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
  38. package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
  39. package/src/factories/internal/iterate_metadata_constant.ts +58 -58
  40. package/src/factories/internal/iterate_metadata_map.ts +41 -41
  41. package/src/factories/internal/iterate_metadata_object.ts +45 -45
  42. package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
  43. package/src/factories/internal/iterate_metadata_set.ts +33 -33
  44. package/src/factories/internal/iterate_metadata_template.ts +38 -38
  45. package/src/factories/internal/iterate_metadata_tuple.ts +45 -51
  46. package/src/factories/internal/iterate_metadata_union.ts +59 -59
  47. package/src/functional/$every.ts +11 -11
  48. package/src/functional/$guard.ts +35 -35
  49. package/src/functional/$is_email.ts +5 -5
  50. package/src/functional/$is_ipv4.ts +5 -5
  51. package/src/functional/$is_ipv6.ts +5 -5
  52. package/src/functional/$is_url.ts +5 -5
  53. package/src/functional/$is_uuid.ts +5 -5
  54. package/src/functional/$join.ts +50 -50
  55. package/src/functional/$report.ts +15 -15
  56. package/src/functional/$rest.ts +3 -3
  57. package/src/functional/$string.ts +37 -37
  58. package/src/functional/$tail.ts +6 -6
  59. package/src/metadata/IJsDocTagInfo.ts +10 -10
  60. package/src/metadata/IMetadata.ts +25 -25
  61. package/src/metadata/IMetadataApplication.ts +7 -7
  62. package/src/metadata/IMetadataConstant.ts +16 -16
  63. package/src/metadata/IMetadataEntry.ts +6 -6
  64. package/src/metadata/IMetadataObject.ts +29 -29
  65. package/src/metadata/IMetadataProperty.ts +11 -11
  66. package/src/metadata/IMetadataTag.ts +122 -122
  67. package/src/metadata/Metadata.ts +477 -477
  68. package/src/metadata/MetadataConstant.ts +3 -3
  69. package/src/metadata/MetadataObject.ts +131 -131
  70. package/src/metadata/MetadataProperty.ts +64 -64
  71. package/src/programmers/AssertParseProgrammer.ts +45 -45
  72. package/src/programmers/AssertProgrammer.ts +444 -444
  73. package/src/programmers/AssertStringifyProgrammer.ts +45 -45
  74. package/src/programmers/CheckerProgrammer.ts +798 -798
  75. package/src/programmers/FeatureProgrammer.ts +327 -327
  76. package/src/programmers/IsParseProgrammer.ts +51 -51
  77. package/src/programmers/IsProgrammer.ts +169 -169
  78. package/src/programmers/IsStringifyProgrammer.ts +49 -49
  79. package/src/programmers/ValidateParseProgrammer.ts +49 -49
  80. package/src/programmers/ValidateProgrammer.ts +236 -236
  81. package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
  82. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  83. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  84. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  85. package/src/programmers/helpers/OptionPredicator.ts +18 -18
  86. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  87. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  88. package/src/programmers/helpers/UnionExplorer.ts +437 -437
  89. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  90. package/src/programmers/internal/application_boolean.ts +17 -17
  91. package/src/programmers/internal/application_constant.ts +29 -29
  92. package/src/programmers/internal/application_default_string.ts +32 -32
  93. package/src/programmers/internal/application_native.ts +29 -29
  94. package/src/programmers/internal/application_schema.ts +221 -221
  95. package/src/programmers/internal/application_templates.ts +27 -27
  96. package/src/programmers/internal/application_tuple.ts +25 -25
  97. package/src/programmers/internal/check_array.ts +44 -44
  98. package/src/programmers/internal/check_dynamic_properties.ts +146 -146
  99. package/src/programmers/internal/check_everything.ts +25 -25
  100. package/src/programmers/internal/check_length.ts +46 -46
  101. package/src/programmers/internal/check_native.ts +9 -9
  102. package/src/programmers/internal/check_number.ts +181 -181
  103. package/src/programmers/internal/check_object.ts +42 -42
  104. package/src/programmers/internal/check_string.ts +24 -24
  105. package/src/programmers/internal/check_string_tags.ts +63 -63
  106. package/src/programmers/internal/check_template.ts +50 -50
  107. package/src/programmers/internal/decode_union_object.ts +73 -73
  108. package/src/programmers/internal/feature_object_entries.ts +49 -49
  109. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  110. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  111. package/src/programmers/internal/stringify_native.ts +8 -8
  112. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  113. package/src/programmers/internal/template_to_pattern.ts +15 -15
  114. package/src/schemas/IJsonApplication.ts +9 -9
  115. package/src/transform.ts +20 -20
  116. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  117. package/src/transformers/FileTransformer.ts +49 -49
  118. package/src/transformers/IProject.ts +11 -11
  119. package/src/transformers/ITransformOptions.ts +4 -4
  120. package/src/transformers/NodeTransformer.ts +19 -19
  121. package/src/typings/Atomic.ts +17 -17
  122. package/src/typings/ClassProperties.ts +5 -5
  123. package/src/typings/OmitNever.ts +3 -3
  124. package/src/typings/SpecialFields.ts +3 -3
  125. package/src/typings/Writable.ts +11 -11
  126. package/src/utils/ArrayUtil.ts +49 -49
  127. package/src/utils/Escaper.ts +50 -50
  128. package/src/utils/MapUtil.ts +14 -14
  129. package/src/utils/PatternUtil.ts +30 -30
  130. package/src/utils/Singleton.ts +17 -17
@@ -1,181 +1,181 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTag } from "../../metadata/IMetadataTag";
4
-
5
- import { IProject } from "../../transformers/IProject";
6
-
7
- import { OptionPredicator } from "../helpers/OptionPredicator";
8
-
9
- /**
10
- * @internal
11
- */
12
- export function check_number(project: IProject, numeric: boolean) {
13
- return function (input: ts.Expression, tagList: IMetadataTag[]) {
14
- // TYPEOF
15
- const conditions: ts.Expression[] = [
16
- ts.factory.createStrictEquality(
17
- ts.factory.createStringLiteral("number"),
18
- ts.factory.createTypeOfExpression(input),
19
- ),
20
- ];
21
-
22
- // TAG (RANGE)
23
- for (const tag of tagList)
24
- if (tag.kind === "type") {
25
- conditions.push(
26
- ts.factory.createStrictEquality(
27
- ts.factory.createCallExpression(
28
- ts.factory.createIdentifier("parseInt"),
29
- undefined,
30
- [input],
31
- ),
32
- input,
33
- ),
34
- );
35
- if (tag.value === "uint")
36
- conditions.push(
37
- ts.factory.createLessThanEquals(
38
- ts.factory.createNumericLiteral(0),
39
- input,
40
- ),
41
- );
42
- } else if (tag.kind === "multipleOf")
43
- conditions.push(
44
- ts.factory.createStrictEquality(
45
- ts.factory.createNumericLiteral(0),
46
- ts.factory.createModulo(
47
- input,
48
- ts.factory.createNumericLiteral(tag.value),
49
- ),
50
- ),
51
- );
52
- else if (tag.kind === "step") {
53
- const modulo = () =>
54
- ts.factory.createModulo(
55
- input,
56
- ts.factory.createNumericLiteral(tag.value),
57
- );
58
- const minimum = (() => {
59
- for (const tag of tagList)
60
- if (tag.kind === "minimum") return tag.value;
61
- else if (tag.kind === "exclusiveMinimum")
62
- return tag.value;
63
- else if (
64
- tag.kind === "range" &&
65
- tag.minimum !== undefined
66
- )
67
- return tag.minimum.value;
68
- return undefined;
69
- })();
70
- conditions.push(
71
- ts.factory.createStrictEquality(
72
- ts.factory.createNumericLiteral(0),
73
- minimum !== undefined
74
- ? ts.factory.createSubtract(
75
- modulo(),
76
- ts.factory.createNumericLiteral(minimum),
77
- )
78
- : modulo(),
79
- ),
80
- );
81
- } else if (tag.kind === "range") {
82
- if (tag.minimum !== undefined)
83
- conditions.push(
84
- (tag.minimum.include
85
- ? ts.factory.createLessThanEquals
86
- : ts.factory.createLessThan)(
87
- ts.factory.createNumericLiteral(tag.minimum.value),
88
- input,
89
- ),
90
- );
91
- if (tag.maximum !== undefined)
92
- conditions.push(
93
- (tag.maximum.include
94
- ? ts.factory.createLessThanEquals
95
- : ts.factory.createLessThan)(
96
- input,
97
- ts.factory.createNumericLiteral(tag.maximum.value),
98
- ),
99
- );
100
- } else if (tag.kind === "minimum")
101
- conditions.push(
102
- ts.factory.createLessThanEquals(
103
- ts.factory.createNumericLiteral(tag.value),
104
- input,
105
- ),
106
- );
107
- else if (tag.kind === "maximum")
108
- conditions.push(
109
- ts.factory.createGreaterThanEquals(
110
- ts.factory.createNumericLiteral(tag.value),
111
- input,
112
- ),
113
- );
114
- else if (tag.kind === "exclusiveMinimum")
115
- conditions.push(
116
- ts.factory.createLessThan(
117
- ts.factory.createNumericLiteral(tag.value),
118
- input,
119
- ),
120
- );
121
- else if (tag.kind === "exclusiveMaximum")
122
- conditions.push(
123
- ts.factory.createGreaterThan(
124
- ts.factory.createNumericLiteral(tag.value),
125
- input,
126
- ),
127
- );
128
-
129
- // NUMERIC VALIDATION
130
- const finite: boolean =
131
- !!tagList.find(
132
- (tag) =>
133
- tag.kind === "range" &&
134
- tag.minimum !== undefined &&
135
- tag.maximum !== undefined,
136
- ) ||
137
- (!!tagList.find(
138
- (tag) =>
139
- tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
140
- ) &&
141
- !!tagList.find(
142
- (tag) =>
143
- tag.kind === "maximum" ||
144
- tag.kind === "exclusiveMaximum",
145
- )) ||
146
- !!tagList.find(
147
- (tag) => tag.kind === "step" || tag.kind === "multipleOf",
148
- );
149
- const valid: boolean =
150
- finite || tagList.find((tag) => tag.kind === "type") !== undefined;
151
-
152
- if (
153
- numeric &&
154
- OptionPredicator.numeric(project.options, "checker") === false
155
- ) {
156
- if (finite === false)
157
- conditions.push(
158
- ts.factory.createCallExpression(
159
- ts.factory.createIdentifier("Number.isFinite"),
160
- undefined,
161
- [input],
162
- ),
163
- );
164
- if (valid === false)
165
- conditions.push(
166
- ts.factory.createLogicalNot(
167
- ts.factory.createCallExpression(
168
- ts.factory.createIdentifier("Number.isNaN"),
169
- undefined,
170
- [input],
171
- ),
172
- ),
173
- );
174
- }
175
-
176
- // COMBINATION
177
- return conditions.length === 1
178
- ? conditions[0]!
179
- : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
180
- };
181
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+
5
+ import { IProject } from "../../transformers/IProject";
6
+
7
+ import { OptionPredicator } from "../helpers/OptionPredicator";
8
+
9
+ /**
10
+ * @internal
11
+ */
12
+ export function check_number(project: IProject, numeric: boolean) {
13
+ return function (input: ts.Expression, tagList: IMetadataTag[]) {
14
+ // TYPEOF
15
+ const conditions: ts.Expression[] = [
16
+ ts.factory.createStrictEquality(
17
+ ts.factory.createStringLiteral("number"),
18
+ ts.factory.createTypeOfExpression(input),
19
+ ),
20
+ ];
21
+
22
+ // TAG (RANGE)
23
+ for (const tag of tagList)
24
+ if (tag.kind === "type") {
25
+ conditions.push(
26
+ ts.factory.createStrictEquality(
27
+ ts.factory.createCallExpression(
28
+ ts.factory.createIdentifier("parseInt"),
29
+ undefined,
30
+ [input],
31
+ ),
32
+ input,
33
+ ),
34
+ );
35
+ if (tag.value === "uint")
36
+ conditions.push(
37
+ ts.factory.createLessThanEquals(
38
+ ts.factory.createNumericLiteral(0),
39
+ input,
40
+ ),
41
+ );
42
+ } else if (tag.kind === "multipleOf")
43
+ conditions.push(
44
+ ts.factory.createStrictEquality(
45
+ ts.factory.createNumericLiteral(0),
46
+ ts.factory.createModulo(
47
+ input,
48
+ ts.factory.createNumericLiteral(tag.value),
49
+ ),
50
+ ),
51
+ );
52
+ else if (tag.kind === "step") {
53
+ const modulo = () =>
54
+ ts.factory.createModulo(
55
+ input,
56
+ ts.factory.createNumericLiteral(tag.value),
57
+ );
58
+ const minimum = (() => {
59
+ for (const tag of tagList)
60
+ if (tag.kind === "minimum") return tag.value;
61
+ else if (tag.kind === "exclusiveMinimum")
62
+ return tag.value;
63
+ else if (
64
+ tag.kind === "range" &&
65
+ tag.minimum !== undefined
66
+ )
67
+ return tag.minimum.value;
68
+ return undefined;
69
+ })();
70
+ conditions.push(
71
+ ts.factory.createStrictEquality(
72
+ ts.factory.createNumericLiteral(0),
73
+ minimum !== undefined
74
+ ? ts.factory.createSubtract(
75
+ modulo(),
76
+ ts.factory.createNumericLiteral(minimum),
77
+ )
78
+ : modulo(),
79
+ ),
80
+ );
81
+ } else if (tag.kind === "range") {
82
+ if (tag.minimum !== undefined)
83
+ conditions.push(
84
+ (tag.minimum.include
85
+ ? ts.factory.createLessThanEquals
86
+ : ts.factory.createLessThan)(
87
+ ts.factory.createNumericLiteral(tag.minimum.value),
88
+ input,
89
+ ),
90
+ );
91
+ if (tag.maximum !== undefined)
92
+ conditions.push(
93
+ (tag.maximum.include
94
+ ? ts.factory.createLessThanEquals
95
+ : ts.factory.createLessThan)(
96
+ input,
97
+ ts.factory.createNumericLiteral(tag.maximum.value),
98
+ ),
99
+ );
100
+ } else if (tag.kind === "minimum")
101
+ conditions.push(
102
+ ts.factory.createLessThanEquals(
103
+ ts.factory.createNumericLiteral(tag.value),
104
+ input,
105
+ ),
106
+ );
107
+ else if (tag.kind === "maximum")
108
+ conditions.push(
109
+ ts.factory.createGreaterThanEquals(
110
+ ts.factory.createNumericLiteral(tag.value),
111
+ input,
112
+ ),
113
+ );
114
+ else if (tag.kind === "exclusiveMinimum")
115
+ conditions.push(
116
+ ts.factory.createLessThan(
117
+ ts.factory.createNumericLiteral(tag.value),
118
+ input,
119
+ ),
120
+ );
121
+ else if (tag.kind === "exclusiveMaximum")
122
+ conditions.push(
123
+ ts.factory.createGreaterThan(
124
+ ts.factory.createNumericLiteral(tag.value),
125
+ input,
126
+ ),
127
+ );
128
+
129
+ // NUMERIC VALIDATION
130
+ const finite: boolean =
131
+ !!tagList.find(
132
+ (tag) =>
133
+ tag.kind === "range" &&
134
+ tag.minimum !== undefined &&
135
+ tag.maximum !== undefined,
136
+ ) ||
137
+ (!!tagList.find(
138
+ (tag) =>
139
+ tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
140
+ ) &&
141
+ !!tagList.find(
142
+ (tag) =>
143
+ tag.kind === "maximum" ||
144
+ tag.kind === "exclusiveMaximum",
145
+ )) ||
146
+ !!tagList.find(
147
+ (tag) => tag.kind === "step" || tag.kind === "multipleOf",
148
+ );
149
+ const valid: boolean =
150
+ finite || tagList.find((tag) => tag.kind === "type") !== undefined;
151
+
152
+ if (
153
+ numeric &&
154
+ OptionPredicator.numeric(project.options, "checker") === false
155
+ ) {
156
+ if (finite === false)
157
+ conditions.push(
158
+ ts.factory.createCallExpression(
159
+ ts.factory.createIdentifier("Number.isFinite"),
160
+ undefined,
161
+ [input],
162
+ ),
163
+ );
164
+ if (valid === false)
165
+ conditions.push(
166
+ ts.factory.createLogicalNot(
167
+ ts.factory.createCallExpression(
168
+ ts.factory.createIdentifier("Number.isNaN"),
169
+ undefined,
170
+ [input],
171
+ ),
172
+ ),
173
+ );
174
+ }
175
+
176
+ // COMBINATION
177
+ return conditions.length === 1
178
+ ? conditions[0]!
179
+ : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
180
+ };
181
+ }
@@ -1,42 +1,42 @@
1
- import ts from "typescript";
2
-
3
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
4
- import { check_dynamic_properties } from "./check_dynamic_properties";
5
- import { check_everything } from "./check_everything";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const check_object =
11
- (props: check_object.IProps) => (entries: IExpressionEntry[]) => {
12
- // PREPARE ASSETS
13
- const regular = entries.filter((entry) => entry.key.isSoleLiteral());
14
- const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
15
- const flags: ts.Expression[] = regular.map((entry) => entry.expression);
16
-
17
- // REGULAR WITHOUT DYNAMIC PROPERTIES
18
- if (props.equals === false && dynamic.length === 0)
19
- return regular.length === 0 ? props.positive : reduce(props)(flags);
20
-
21
- // CHECK DYNAMIC PROPERTIES
22
- flags.push(check_dynamic_properties(props)(regular, dynamic));
23
- return reduce(props)(flags);
24
- };
25
- export namespace check_object {
26
- export interface IProps {
27
- equals: boolean;
28
- assert: boolean;
29
- halt?: (exp: ts.Expression) => ts.Expression;
30
- reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
31
- positive: ts.Expression;
32
- superfluous: (value: ts.Expression) => ts.Expression;
33
- entries?: ts.Identifier;
34
- }
35
- }
36
-
37
- const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
38
- props.assert
39
- ? expressions.reduce(props.reduce)
40
- : check_everything(
41
- ts.factory.createArrayLiteralExpression(expressions),
42
- );
1
+ import ts from "typescript";
2
+
3
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
4
+ import { check_dynamic_properties } from "./check_dynamic_properties";
5
+ import { check_everything } from "./check_everything";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const check_object =
11
+ (props: check_object.IProps) => (entries: IExpressionEntry[]) => {
12
+ // PREPARE ASSETS
13
+ const regular = entries.filter((entry) => entry.key.isSoleLiteral());
14
+ const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
15
+ const flags: ts.Expression[] = regular.map((entry) => entry.expression);
16
+
17
+ // REGULAR WITHOUT DYNAMIC PROPERTIES
18
+ if (props.equals === false && dynamic.length === 0)
19
+ return regular.length === 0 ? props.positive : reduce(props)(flags);
20
+
21
+ // CHECK DYNAMIC PROPERTIES
22
+ flags.push(check_dynamic_properties(props)(regular, dynamic));
23
+ return reduce(props)(flags);
24
+ };
25
+ export namespace check_object {
26
+ export interface IProps {
27
+ equals: boolean;
28
+ assert: boolean;
29
+ halt?: (exp: ts.Expression) => ts.Expression;
30
+ reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
31
+ positive: ts.Expression;
32
+ superfluous: (value: ts.Expression) => ts.Expression;
33
+ entries?: ts.Identifier;
34
+ }
35
+ }
36
+
37
+ const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
38
+ props.assert
39
+ ? expressions.reduce(props.reduce)
40
+ : check_everything(
41
+ ts.factory.createArrayLiteralExpression(expressions),
42
+ );
@@ -1,24 +1,24 @@
1
- import ts from "typescript";
2
-
3
- import { IMetadataTag } from "../../metadata/IMetadataTag";
4
-
5
- import { FunctionImporter } from "../helpers/FunctionImporeter";
6
- import { check_string_tags } from "./check_string_tags";
7
-
8
- /**
9
- * @internal
10
- */
11
- export function check_string(importer: FunctionImporter) {
12
- return function (input: ts.Expression, tagList: IMetadataTag[]) {
13
- const conditions: ts.Expression[] = [
14
- ts.factory.createStrictEquality(
15
- ts.factory.createStringLiteral("string"),
16
- ts.factory.createTypeOfExpression(input),
17
- ),
18
- ...check_string_tags(importer)(input, tagList),
19
- ];
20
- return conditions.length === 1
21
- ? conditions[0]!
22
- : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
23
- };
24
- }
1
+ import ts from "typescript";
2
+
3
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
4
+
5
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
6
+ import { check_string_tags } from "./check_string_tags";
7
+
8
+ /**
9
+ * @internal
10
+ */
11
+ export function check_string(importer: FunctionImporter) {
12
+ return function (input: ts.Expression, tagList: IMetadataTag[]) {
13
+ const conditions: ts.Expression[] = [
14
+ ts.factory.createStrictEquality(
15
+ ts.factory.createStringLiteral("string"),
16
+ ts.factory.createTypeOfExpression(input),
17
+ ),
18
+ ...check_string_tags(importer)(input, tagList),
19
+ ];
20
+ return conditions.length === 1
21
+ ? conditions[0]!
22
+ : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
23
+ };
24
+ }
@@ -1,63 +1,63 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
-
5
- import { IMetadataTag } from "../../metadata/IMetadataTag";
6
-
7
- import { FunctionImporter } from "../helpers/FunctionImporeter";
8
- import { check_length } from "./check_length";
9
-
10
- /**
11
- * @internal
12
- */
13
- export const check_string_tags =
14
- (importer: FunctionImporter) =>
15
- (input: ts.Expression, tagList: IMetadataTag[]) => {
16
- const conditions: ts.Expression[] = [];
17
- for (const tag of tagList)
18
- if (tag.kind === "format")
19
- conditions.push(
20
- ts.factory.createStrictEquality(
21
- ts.factory.createTrue(),
22
- ts.factory.createCallExpression(
23
- importer.use(`is_${tag.value}`),
24
- undefined,
25
- [input],
26
- ),
27
- ),
28
- );
29
- else if (tag.kind === "pattern")
30
- conditions.push(
31
- ts.factory.createStrictEquality(
32
- ts.factory.createTrue(),
33
- ts.factory.createCallExpression(
34
- ts.factory.createIdentifier(
35
- `RegExp(/${tag.value}/).test`,
36
- ),
37
- undefined,
38
- [input],
39
- ),
40
- ),
41
- );
42
- else if (tag.kind === "minLength")
43
- conditions.push(
44
- ts.factory.createLessThanEquals(
45
- ts.factory.createNumericLiteral(tag.value),
46
- IdentifierFactory.join(input, "length"),
47
- ),
48
- );
49
- else if (tag.kind === "maxLength")
50
- conditions.push(
51
- ts.factory.createGreaterThanEquals(
52
- ts.factory.createNumericLiteral(tag.value),
53
- IdentifierFactory.join(input, "length"),
54
- ),
55
- );
56
- else if (tag.kind === "length")
57
- check_length(
58
- conditions,
59
- IdentifierFactory.join(input, "length"),
60
- tag,
61
- );
62
- return conditions;
63
- };
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+
5
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
6
+
7
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
8
+ import { check_length } from "./check_length";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export const check_string_tags =
14
+ (importer: FunctionImporter) =>
15
+ (input: ts.Expression, tagList: IMetadataTag[]) => {
16
+ const conditions: ts.Expression[] = [];
17
+ for (const tag of tagList)
18
+ if (tag.kind === "format")
19
+ conditions.push(
20
+ ts.factory.createStrictEquality(
21
+ ts.factory.createTrue(),
22
+ ts.factory.createCallExpression(
23
+ importer.use(`is_${tag.value}`),
24
+ undefined,
25
+ [input],
26
+ ),
27
+ ),
28
+ );
29
+ else if (tag.kind === "pattern")
30
+ conditions.push(
31
+ ts.factory.createStrictEquality(
32
+ ts.factory.createTrue(),
33
+ ts.factory.createCallExpression(
34
+ ts.factory.createIdentifier(
35
+ `RegExp(/${tag.value}/).test`,
36
+ ),
37
+ undefined,
38
+ [input],
39
+ ),
40
+ ),
41
+ );
42
+ else if (tag.kind === "minLength")
43
+ conditions.push(
44
+ ts.factory.createLessThanEquals(
45
+ ts.factory.createNumericLiteral(tag.value),
46
+ IdentifierFactory.join(input, "length"),
47
+ ),
48
+ );
49
+ else if (tag.kind === "maxLength")
50
+ conditions.push(
51
+ ts.factory.createGreaterThanEquals(
52
+ ts.factory.createNumericLiteral(tag.value),
53
+ IdentifierFactory.join(input, "length"),
54
+ ),
55
+ );
56
+ else if (tag.kind === "length")
57
+ check_length(
58
+ conditions,
59
+ IdentifierFactory.join(input, "length"),
60
+ tag,
61
+ );
62
+ return conditions;
63
+ };