typia 4.3.1-dev.20230821 → 4.3.2-dev.20230821
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.
|
@@ -53,8 +53,7 @@ var check_bigint = function (importer) {
|
|
|
53
53
|
try {
|
|
54
54
|
for (var metaTags_1 = __values(metaTags), metaTags_1_1 = metaTags_1.next(); !metaTags_1_1.done; metaTags_1_1 = metaTags_1.next()) {
|
|
55
55
|
var tag = metaTags_1_1.value;
|
|
56
|
-
if (tag.kind === "type" &&
|
|
57
|
-
(tag.value === "uint" || tag.value === "uint64"))
|
|
56
|
+
if (tag.kind === "type" && tag.value === "uint64")
|
|
58
57
|
entries.push([
|
|
59
58
|
tag,
|
|
60
59
|
typescript_1.default.factory.createLessThanEquals(ExpressionFactory_1.ExpressionFactory.bigint(0), input),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check_bigint.js","sourceRoot":"","sources":["../../../src/programmers/internal/check_bigint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,uEAAsE;AAOtE,+CAA8C;AAKvC,IAAM,YAAY,GACrB,UAAC,QAA0B;IAC3B,OAAA,UAAC,QAAwB;QACzB,OAAA,UAAC,QAAyB;YAC1B,OAAA,UAAC,KAAoB;;;gBACjB,IAAM,OAAO,GAAoC,EAAE,CAAC;;oBACpD,KAAkB,IAAA,aAAA,SAAA,QAAQ,CAAA,kCAAA,wDAAE;wBAAvB,IAAM,GAAG,qBAAA;wBACV,
|
|
1
|
+
{"version":3,"file":"check_bigint.js","sourceRoot":"","sources":["../../../src/programmers/internal/check_bigint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAA4B;AAE5B,uEAAsE;AAOtE,+CAA8C;AAKvC,IAAM,YAAY,GACrB,UAAC,QAA0B;IAC3B,OAAA,UAAC,QAAwB;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AAC,EACxC,oBAAE,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAC3C;oBACD,IAAI,yCACG,OAAO,CAAC,GAAG,CAAC,UAAC,EAAiB;4BAAjB,KAAA,aAAiB,EAAhB,GAAG,QAAA,EAAE,UAAU,QAAA;wBAAM,OAAA,CAAC;4BACnC,QAAQ,EAAE,mBAAY,GAAG,CAAC,IAAI,cAAI,GAAG,CAAC,KAAK,MAAG;4BAC9C,UAAU,YAAA;yBACb,CAAC;oBAHoC,CAGpC,CAAC,kBACA,IAAA,2BAAY,EAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,SACvD;iBACJ,CAAC;YACN,CAAC;QA3FD,CA2FC;IA5FD,CA4FC;AA7FD,CA6FC,CAAC;AA/FO,QAAA,YAAY,gBA+FnB"}
|
package/package.json
CHANGED
|
@@ -19,10 +19,7 @@ export const check_bigint =
|
|
|
19
19
|
(input: ts.Expression): ICheckEntry => {
|
|
20
20
|
const entries: [IMetadataTag, ts.Expression][] = [];
|
|
21
21
|
for (const tag of metaTags) {
|
|
22
|
-
if (
|
|
23
|
-
tag.kind === "type" &&
|
|
24
|
-
(tag.value === "uint" || tag.value === "uint64")
|
|
25
|
-
)
|
|
22
|
+
if (tag.kind === "type" && tag.value === "uint64")
|
|
26
23
|
entries.push([
|
|
27
24
|
tag,
|
|
28
25
|
ts.factory.createLessThanEquals(
|
|
@@ -1,258 +1,258 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
5
|
-
|
|
6
|
-
import { IProject } from "../../transformers/IProject";
|
|
7
|
-
|
|
8
|
-
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
9
|
-
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
10
|
-
import { OptionPredicator } from "../helpers/OptionPredicator";
|
|
11
|
-
import { check_custom } from "./check_custom";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
export const check_number =
|
|
17
|
-
(project: IProject, numeric: boolean) =>
|
|
18
|
-
(importer: FunctionImporter) =>
|
|
19
|
-
(metaTags: IMetadataTag[]) =>
|
|
20
|
-
(jsDocTag: IJsDocTagInfo[]) =>
|
|
21
|
-
(input: ts.Expression): ICheckEntry => {
|
|
22
|
-
const entries: [IMetadataTag, ts.Expression][] = [];
|
|
23
|
-
for (const tag of metaTags)
|
|
24
|
-
if (tag.kind === "type") {
|
|
25
|
-
// MUST BE INTEGER
|
|
26
|
-
if (
|
|
27
|
-
tag.value === "int" ||
|
|
28
|
-
tag.value === "uint" ||
|
|
29
|
-
tag.value === "int32" ||
|
|
30
|
-
tag.value === "uint32" ||
|
|
31
|
-
tag.value === "int64" ||
|
|
32
|
-
tag.value === "uint64"
|
|
33
|
-
)
|
|
34
|
-
entries.push([
|
|
35
|
-
tag,
|
|
36
|
-
ts.factory.createStrictEquality(
|
|
37
|
-
ts.factory.createCallExpression(
|
|
38
|
-
ts.factory.createIdentifier("Math.floor"),
|
|
39
|
-
undefined,
|
|
40
|
-
[input],
|
|
41
|
-
),
|
|
42
|
-
input,
|
|
43
|
-
),
|
|
44
|
-
]);
|
|
45
|
-
// GREATER THAN OR EQUAL TO ZERO
|
|
46
|
-
if (
|
|
47
|
-
tag.value === "uint" ||
|
|
48
|
-
tag.value === "uint32" ||
|
|
49
|
-
tag.value === "uint64"
|
|
50
|
-
)
|
|
51
|
-
entries.push([
|
|
52
|
-
tag,
|
|
53
|
-
ts.factory.createLessThanEquals(
|
|
54
|
-
ts.factory.createNumericLiteral(0),
|
|
55
|
-
input,
|
|
56
|
-
),
|
|
57
|
-
]);
|
|
58
|
-
// RANGE LIMIT
|
|
59
|
-
if (tag.value === "uint" || tag.value === "uint32")
|
|
60
|
-
entries.push([
|
|
61
|
-
tag,
|
|
62
|
-
ts.factory.createLessThanEquals(
|
|
63
|
-
input,
|
|
64
|
-
ts.factory.createNumericLiteral(4294967295),
|
|
65
|
-
),
|
|
66
|
-
]);
|
|
67
|
-
else if (tag.value === "uint64")
|
|
68
|
-
entries.push([
|
|
69
|
-
tag,
|
|
70
|
-
ts.factory.createLessThanEquals(
|
|
71
|
-
input,
|
|
72
|
-
ts.factory.createNumericLiteral(
|
|
73
|
-
18446744073709551615,
|
|
74
|
-
),
|
|
75
|
-
),
|
|
76
|
-
]);
|
|
77
|
-
else if (tag.value === "int64")
|
|
78
|
-
entries.push([
|
|
79
|
-
tag,
|
|
80
|
-
ts.factory.createLogicalAnd(
|
|
81
|
-
ts.factory.createLessThanEquals(
|
|
82
|
-
ts.factory.createNumericLiteral(
|
|
83
|
-
-9223372036854775808,
|
|
84
|
-
),
|
|
85
|
-
input,
|
|
86
|
-
),
|
|
87
|
-
ts.factory.createLessThanEquals(
|
|
88
|
-
input,
|
|
89
|
-
ts.factory.createNumericLiteral(
|
|
90
|
-
9223372036854775807,
|
|
91
|
-
),
|
|
92
|
-
),
|
|
93
|
-
),
|
|
94
|
-
]);
|
|
95
|
-
else if (tag.value === "int" || tag.value === "int32")
|
|
96
|
-
entries.push([
|
|
97
|
-
tag,
|
|
98
|
-
ts.factory.createLogicalAnd(
|
|
99
|
-
ts.factory.createLessThanEquals(
|
|
100
|
-
ts.factory.createNumericLiteral(-2147483648),
|
|
101
|
-
input,
|
|
102
|
-
),
|
|
103
|
-
ts.factory.createLessThanEquals(
|
|
104
|
-
input,
|
|
105
|
-
ts.factory.createNumericLiteral(2147483647),
|
|
106
|
-
),
|
|
107
|
-
),
|
|
108
|
-
]);
|
|
109
|
-
else if (tag.value === "float")
|
|
110
|
-
entries.push([
|
|
111
|
-
tag,
|
|
112
|
-
ts.factory.createLogicalAnd(
|
|
113
|
-
ts.factory.createLessThanEquals(
|
|
114
|
-
ts.factory.createNumericLiteral(
|
|
115
|
-
-1.175494351e38,
|
|
116
|
-
),
|
|
117
|
-
input,
|
|
118
|
-
),
|
|
119
|
-
ts.factory.createLessThanEquals(
|
|
120
|
-
input,
|
|
121
|
-
ts.factory.createNumericLiteral(3.4028235e38),
|
|
122
|
-
),
|
|
123
|
-
),
|
|
124
|
-
]);
|
|
125
|
-
} else if (tag.kind === "multipleOf")
|
|
126
|
-
entries.push([
|
|
127
|
-
tag,
|
|
128
|
-
ts.factory.createStrictEquality(
|
|
129
|
-
ts.factory.createNumericLiteral(0),
|
|
130
|
-
ts.factory.createModulo(
|
|
131
|
-
input,
|
|
132
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
133
|
-
),
|
|
134
|
-
),
|
|
135
|
-
]);
|
|
136
|
-
else if (tag.kind === "step") {
|
|
137
|
-
const modulo = ts.factory.createModulo(
|
|
138
|
-
input,
|
|
139
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
140
|
-
);
|
|
141
|
-
const minimum =
|
|
142
|
-
(metaTags.find(
|
|
143
|
-
(tag) =>
|
|
144
|
-
tag.kind === "minimum" ||
|
|
145
|
-
tag.kind === "exclusiveMinimum",
|
|
146
|
-
)?.value as number | undefined) ?? undefined;
|
|
147
|
-
entries.push([
|
|
148
|
-
tag,
|
|
149
|
-
ts.factory.createStrictEquality(
|
|
150
|
-
ts.factory.createNumericLiteral(0),
|
|
151
|
-
minimum !== undefined
|
|
152
|
-
? ts.factory.createSubtract(
|
|
153
|
-
modulo,
|
|
154
|
-
ts.factory.createNumericLiteral(minimum),
|
|
155
|
-
)
|
|
156
|
-
: modulo,
|
|
157
|
-
),
|
|
158
|
-
]);
|
|
159
|
-
} else if (tag.kind === "minimum")
|
|
160
|
-
entries.push([
|
|
161
|
-
tag,
|
|
162
|
-
ts.factory.createLessThanEquals(
|
|
163
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
164
|
-
input,
|
|
165
|
-
),
|
|
166
|
-
]);
|
|
167
|
-
else if (tag.kind === "maximum")
|
|
168
|
-
entries.push([
|
|
169
|
-
tag,
|
|
170
|
-
ts.factory.createGreaterThanEquals(
|
|
171
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
172
|
-
input,
|
|
173
|
-
),
|
|
174
|
-
]);
|
|
175
|
-
else if (tag.kind === "exclusiveMinimum")
|
|
176
|
-
entries.push([
|
|
177
|
-
tag,
|
|
178
|
-
ts.factory.createLessThan(
|
|
179
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
180
|
-
input,
|
|
181
|
-
),
|
|
182
|
-
]);
|
|
183
|
-
else if (tag.kind === "exclusiveMaximum")
|
|
184
|
-
entries.push([
|
|
185
|
-
tag,
|
|
186
|
-
ts.factory.createGreaterThan(
|
|
187
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
188
|
-
input,
|
|
189
|
-
),
|
|
190
|
-
]);
|
|
191
|
-
|
|
192
|
-
return {
|
|
193
|
-
expression: is_number(project, numeric)(metaTags)(input),
|
|
194
|
-
tags: [
|
|
195
|
-
...entries.map(([tag, expression]) => ({
|
|
196
|
-
expected: `number (@${tag.kind} ${tag.value})`,
|
|
197
|
-
expression,
|
|
198
|
-
})),
|
|
199
|
-
...check_custom("number")(importer)(jsDocTag)(input),
|
|
200
|
-
],
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* @internal
|
|
206
|
-
*/
|
|
207
|
-
const is_number =
|
|
208
|
-
({ options }: IProject, numeric: boolean) =>
|
|
209
|
-
(metaTags: IMetadataTag[]) =>
|
|
210
|
-
(input: ts.Expression) => {
|
|
211
|
-
// TYPEOF STATEMENT
|
|
212
|
-
const conditions: ts.Expression[] = [
|
|
213
|
-
ts.factory.createStrictEquality(
|
|
214
|
-
ts.factory.createStringLiteral("number"),
|
|
215
|
-
ts.factory.createTypeOfExpression(input),
|
|
216
|
-
),
|
|
217
|
-
];
|
|
218
|
-
|
|
219
|
-
// CHECK FINITE AND NAN
|
|
220
|
-
const finite: boolean =
|
|
221
|
-
(!!metaTags.find(
|
|
222
|
-
(tag) =>
|
|
223
|
-
tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
|
|
224
|
-
) &&
|
|
225
|
-
!!metaTags.find(
|
|
226
|
-
(tag) =>
|
|
227
|
-
tag.kind === "maximum" ||
|
|
228
|
-
tag.kind === "exclusiveMaximum",
|
|
229
|
-
)) ||
|
|
230
|
-
!!metaTags.find(
|
|
231
|
-
(tag) => tag.kind === "step" || tag.kind === "multipleOf",
|
|
232
|
-
);
|
|
233
|
-
|
|
234
|
-
if (numeric === true && finite === false)
|
|
235
|
-
if (OptionPredicator.finite(options))
|
|
236
|
-
conditions.push(
|
|
237
|
-
ts.factory.createCallExpression(
|
|
238
|
-
ts.factory.createIdentifier("Number.isFinite"),
|
|
239
|
-
undefined,
|
|
240
|
-
[input],
|
|
241
|
-
),
|
|
242
|
-
);
|
|
243
|
-
else if (OptionPredicator.numeric(options))
|
|
244
|
-
conditions.push(
|
|
245
|
-
ts.factory.createLogicalNot(
|
|
246
|
-
ts.factory.createCallExpression(
|
|
247
|
-
ts.factory.createIdentifier("Number.isNaN"),
|
|
248
|
-
undefined,
|
|
249
|
-
[input],
|
|
250
|
-
),
|
|
251
|
-
),
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
// COMBINATE
|
|
255
|
-
return conditions.length === 1
|
|
256
|
-
? conditions[0]!
|
|
257
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
258
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
5
|
+
|
|
6
|
+
import { IProject } from "../../transformers/IProject";
|
|
7
|
+
|
|
8
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
9
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
10
|
+
import { OptionPredicator } from "../helpers/OptionPredicator";
|
|
11
|
+
import { check_custom } from "./check_custom";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export const check_number =
|
|
17
|
+
(project: IProject, numeric: boolean) =>
|
|
18
|
+
(importer: FunctionImporter) =>
|
|
19
|
+
(metaTags: IMetadataTag[]) =>
|
|
20
|
+
(jsDocTag: IJsDocTagInfo[]) =>
|
|
21
|
+
(input: ts.Expression): ICheckEntry => {
|
|
22
|
+
const entries: [IMetadataTag, ts.Expression][] = [];
|
|
23
|
+
for (const tag of metaTags)
|
|
24
|
+
if (tag.kind === "type") {
|
|
25
|
+
// MUST BE INTEGER
|
|
26
|
+
if (
|
|
27
|
+
tag.value === "int" ||
|
|
28
|
+
tag.value === "uint" ||
|
|
29
|
+
tag.value === "int32" ||
|
|
30
|
+
tag.value === "uint32" ||
|
|
31
|
+
tag.value === "int64" ||
|
|
32
|
+
tag.value === "uint64"
|
|
33
|
+
)
|
|
34
|
+
entries.push([
|
|
35
|
+
tag,
|
|
36
|
+
ts.factory.createStrictEquality(
|
|
37
|
+
ts.factory.createCallExpression(
|
|
38
|
+
ts.factory.createIdentifier("Math.floor"),
|
|
39
|
+
undefined,
|
|
40
|
+
[input],
|
|
41
|
+
),
|
|
42
|
+
input,
|
|
43
|
+
),
|
|
44
|
+
]);
|
|
45
|
+
// GREATER THAN OR EQUAL TO ZERO
|
|
46
|
+
if (
|
|
47
|
+
tag.value === "uint" ||
|
|
48
|
+
tag.value === "uint32" ||
|
|
49
|
+
tag.value === "uint64"
|
|
50
|
+
)
|
|
51
|
+
entries.push([
|
|
52
|
+
tag,
|
|
53
|
+
ts.factory.createLessThanEquals(
|
|
54
|
+
ts.factory.createNumericLiteral(0),
|
|
55
|
+
input,
|
|
56
|
+
),
|
|
57
|
+
]);
|
|
58
|
+
// RANGE LIMIT
|
|
59
|
+
if (tag.value === "uint" || tag.value === "uint32")
|
|
60
|
+
entries.push([
|
|
61
|
+
tag,
|
|
62
|
+
ts.factory.createLessThanEquals(
|
|
63
|
+
input,
|
|
64
|
+
ts.factory.createNumericLiteral(4294967295),
|
|
65
|
+
),
|
|
66
|
+
]);
|
|
67
|
+
else if (tag.value === "uint64")
|
|
68
|
+
entries.push([
|
|
69
|
+
tag,
|
|
70
|
+
ts.factory.createLessThanEquals(
|
|
71
|
+
input,
|
|
72
|
+
ts.factory.createNumericLiteral(
|
|
73
|
+
18446744073709551615,
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
]);
|
|
77
|
+
else if (tag.value === "int64")
|
|
78
|
+
entries.push([
|
|
79
|
+
tag,
|
|
80
|
+
ts.factory.createLogicalAnd(
|
|
81
|
+
ts.factory.createLessThanEquals(
|
|
82
|
+
ts.factory.createNumericLiteral(
|
|
83
|
+
-9223372036854775808,
|
|
84
|
+
),
|
|
85
|
+
input,
|
|
86
|
+
),
|
|
87
|
+
ts.factory.createLessThanEquals(
|
|
88
|
+
input,
|
|
89
|
+
ts.factory.createNumericLiteral(
|
|
90
|
+
9223372036854775807,
|
|
91
|
+
),
|
|
92
|
+
),
|
|
93
|
+
),
|
|
94
|
+
]);
|
|
95
|
+
else if (tag.value === "int" || tag.value === "int32")
|
|
96
|
+
entries.push([
|
|
97
|
+
tag,
|
|
98
|
+
ts.factory.createLogicalAnd(
|
|
99
|
+
ts.factory.createLessThanEquals(
|
|
100
|
+
ts.factory.createNumericLiteral(-2147483648),
|
|
101
|
+
input,
|
|
102
|
+
),
|
|
103
|
+
ts.factory.createLessThanEquals(
|
|
104
|
+
input,
|
|
105
|
+
ts.factory.createNumericLiteral(2147483647),
|
|
106
|
+
),
|
|
107
|
+
),
|
|
108
|
+
]);
|
|
109
|
+
else if (tag.value === "float")
|
|
110
|
+
entries.push([
|
|
111
|
+
tag,
|
|
112
|
+
ts.factory.createLogicalAnd(
|
|
113
|
+
ts.factory.createLessThanEquals(
|
|
114
|
+
ts.factory.createNumericLiteral(
|
|
115
|
+
-1.175494351e38,
|
|
116
|
+
),
|
|
117
|
+
input,
|
|
118
|
+
),
|
|
119
|
+
ts.factory.createLessThanEquals(
|
|
120
|
+
input,
|
|
121
|
+
ts.factory.createNumericLiteral(3.4028235e38),
|
|
122
|
+
),
|
|
123
|
+
),
|
|
124
|
+
]);
|
|
125
|
+
} else if (tag.kind === "multipleOf")
|
|
126
|
+
entries.push([
|
|
127
|
+
tag,
|
|
128
|
+
ts.factory.createStrictEquality(
|
|
129
|
+
ts.factory.createNumericLiteral(0),
|
|
130
|
+
ts.factory.createModulo(
|
|
131
|
+
input,
|
|
132
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
133
|
+
),
|
|
134
|
+
),
|
|
135
|
+
]);
|
|
136
|
+
else if (tag.kind === "step") {
|
|
137
|
+
const modulo = ts.factory.createModulo(
|
|
138
|
+
input,
|
|
139
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
140
|
+
);
|
|
141
|
+
const minimum =
|
|
142
|
+
(metaTags.find(
|
|
143
|
+
(tag) =>
|
|
144
|
+
tag.kind === "minimum" ||
|
|
145
|
+
tag.kind === "exclusiveMinimum",
|
|
146
|
+
)?.value as number | undefined) ?? undefined;
|
|
147
|
+
entries.push([
|
|
148
|
+
tag,
|
|
149
|
+
ts.factory.createStrictEquality(
|
|
150
|
+
ts.factory.createNumericLiteral(0),
|
|
151
|
+
minimum !== undefined
|
|
152
|
+
? ts.factory.createSubtract(
|
|
153
|
+
modulo,
|
|
154
|
+
ts.factory.createNumericLiteral(minimum),
|
|
155
|
+
)
|
|
156
|
+
: modulo,
|
|
157
|
+
),
|
|
158
|
+
]);
|
|
159
|
+
} else if (tag.kind === "minimum")
|
|
160
|
+
entries.push([
|
|
161
|
+
tag,
|
|
162
|
+
ts.factory.createLessThanEquals(
|
|
163
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
164
|
+
input,
|
|
165
|
+
),
|
|
166
|
+
]);
|
|
167
|
+
else if (tag.kind === "maximum")
|
|
168
|
+
entries.push([
|
|
169
|
+
tag,
|
|
170
|
+
ts.factory.createGreaterThanEquals(
|
|
171
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
172
|
+
input,
|
|
173
|
+
),
|
|
174
|
+
]);
|
|
175
|
+
else if (tag.kind === "exclusiveMinimum")
|
|
176
|
+
entries.push([
|
|
177
|
+
tag,
|
|
178
|
+
ts.factory.createLessThan(
|
|
179
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
180
|
+
input,
|
|
181
|
+
),
|
|
182
|
+
]);
|
|
183
|
+
else if (tag.kind === "exclusiveMaximum")
|
|
184
|
+
entries.push([
|
|
185
|
+
tag,
|
|
186
|
+
ts.factory.createGreaterThan(
|
|
187
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
188
|
+
input,
|
|
189
|
+
),
|
|
190
|
+
]);
|
|
191
|
+
|
|
192
|
+
return {
|
|
193
|
+
expression: is_number(project, numeric)(metaTags)(input),
|
|
194
|
+
tags: [
|
|
195
|
+
...entries.map(([tag, expression]) => ({
|
|
196
|
+
expected: `number (@${tag.kind} ${tag.value})`,
|
|
197
|
+
expression,
|
|
198
|
+
})),
|
|
199
|
+
...check_custom("number")(importer)(jsDocTag)(input),
|
|
200
|
+
],
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @internal
|
|
206
|
+
*/
|
|
207
|
+
const is_number =
|
|
208
|
+
({ options }: IProject, numeric: boolean) =>
|
|
209
|
+
(metaTags: IMetadataTag[]) =>
|
|
210
|
+
(input: ts.Expression) => {
|
|
211
|
+
// TYPEOF STATEMENT
|
|
212
|
+
const conditions: ts.Expression[] = [
|
|
213
|
+
ts.factory.createStrictEquality(
|
|
214
|
+
ts.factory.createStringLiteral("number"),
|
|
215
|
+
ts.factory.createTypeOfExpression(input),
|
|
216
|
+
),
|
|
217
|
+
];
|
|
218
|
+
|
|
219
|
+
// CHECK FINITE AND NAN
|
|
220
|
+
const finite: boolean =
|
|
221
|
+
(!!metaTags.find(
|
|
222
|
+
(tag) =>
|
|
223
|
+
tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
|
|
224
|
+
) &&
|
|
225
|
+
!!metaTags.find(
|
|
226
|
+
(tag) =>
|
|
227
|
+
tag.kind === "maximum" ||
|
|
228
|
+
tag.kind === "exclusiveMaximum",
|
|
229
|
+
)) ||
|
|
230
|
+
!!metaTags.find(
|
|
231
|
+
(tag) => tag.kind === "step" || tag.kind === "multipleOf",
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
if (numeric === true && finite === false)
|
|
235
|
+
if (OptionPredicator.finite(options))
|
|
236
|
+
conditions.push(
|
|
237
|
+
ts.factory.createCallExpression(
|
|
238
|
+
ts.factory.createIdentifier("Number.isFinite"),
|
|
239
|
+
undefined,
|
|
240
|
+
[input],
|
|
241
|
+
),
|
|
242
|
+
);
|
|
243
|
+
else if (OptionPredicator.numeric(options))
|
|
244
|
+
conditions.push(
|
|
245
|
+
ts.factory.createLogicalNot(
|
|
246
|
+
ts.factory.createCallExpression(
|
|
247
|
+
ts.factory.createIdentifier("Number.isNaN"),
|
|
248
|
+
undefined,
|
|
249
|
+
[input],
|
|
250
|
+
),
|
|
251
|
+
),
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
// COMBINATE
|
|
255
|
+
return conditions.length === 1
|
|
256
|
+
? conditions[0]!
|
|
257
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
258
|
+
};
|