typia 3.4.4 → 3.4.6
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/README.md +5 -47
- package/lib/executable/internal/TypiaSetupWizard.js +8 -6
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/package.json +1 -1
- package/src/executable/internal/TypiaSetupWizard.ts +148 -149
- package/src/executable/typia.ts +35 -35
- package/src/factories/MetadataTagFactory.ts +347 -347
- package/src/factories/internal/iterate_metadata.ts +81 -81
- package/src/factories/internal/iterate_metadata_native.ts +227 -227
- package/src/functional/$number.ts +19 -19
- package/src/index.ts +4 -4
- package/src/module.ts +1535 -1535
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/StringifyProgrammer.ts +746 -746
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +103 -103
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/schemas/IJsonComponents.ts +24 -24
- package/src/schemas/IJsonSchema.ts +92 -92
- package/src/transformers/CallExpressionTransformer.ts +124 -124
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
package/src/module.ts
CHANGED
|
@@ -1,1535 +1,1535 @@
|
|
|
1
|
-
import { $every } from "./functional/$every";
|
|
2
|
-
import { $guard } from "./functional/$guard";
|
|
3
|
-
import { $is_email } from "./functional/$is_email";
|
|
4
|
-
import { $is_ipv4 } from "./functional/$is_ipv4";
|
|
5
|
-
import { $is_ipv6 } from "./functional/$is_ipv6";
|
|
6
|
-
import { $is_url } from "./functional/$is_url";
|
|
7
|
-
import { $is_uuid } from "./functional/$is_uuid";
|
|
8
|
-
import { $join } from "./functional/$join";
|
|
9
|
-
import { $number } from "./functional/$number";
|
|
10
|
-
import { $report } from "./functional/$report";
|
|
11
|
-
import { $rest } from "./functional/$rest";
|
|
12
|
-
import { $string } from "./functional/$string";
|
|
13
|
-
import { $tail } from "./functional/$tail";
|
|
14
|
-
|
|
15
|
-
import { IMetadataApplication } from "./metadata/IMetadataApplication";
|
|
16
|
-
import { IJsonApplication } from "./schemas/IJsonApplication";
|
|
17
|
-
|
|
18
|
-
import { IValidation } from "./IValidation";
|
|
19
|
-
import { TypeGuardError } from "./TypeGuardError";
|
|
20
|
-
|
|
21
|
-
export * from "./schemas/IJsonApplication";
|
|
22
|
-
export * from "./schemas/IJsonComponents";
|
|
23
|
-
export * from "./schemas/IJsonSchema";
|
|
24
|
-
export * from "./Primitive";
|
|
25
|
-
export * from "./TypeGuardError";
|
|
26
|
-
export * from "./IValidation";
|
|
27
|
-
|
|
28
|
-
/* ===========================================================
|
|
29
|
-
SINGLE FUNCTIONS
|
|
30
|
-
- BASIC VALIDATORS
|
|
31
|
-
- STRICT VALIDATORS
|
|
32
|
-
- JSON FUNCTIONS
|
|
33
|
-
==============================================================
|
|
34
|
-
BASIC VALIDATORS
|
|
35
|
-
----------------------------------------------------------- */
|
|
36
|
-
/**
|
|
37
|
-
* Asserts a value type.
|
|
38
|
-
*
|
|
39
|
-
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
40
|
-
* reason, if the parametric value is not following the type `T`. Otherwise, the
|
|
41
|
-
* value is following the type `T`, just input parameter would be returned.
|
|
42
|
-
*
|
|
43
|
-
* If what you want is not asserting but just knowing whether the parametric value is
|
|
44
|
-
* following the type `T` or not, you can choose the {@link is} function instead.
|
|
45
|
-
* Otherwise you want to know all the errors, {@link validate} is the way to go.
|
|
46
|
-
*
|
|
47
|
-
* On the other and, if you don't want to allow any superfluous property that is not
|
|
48
|
-
* enrolled to the type `T`, you can use {@link assertEquals} function instead.
|
|
49
|
-
*
|
|
50
|
-
* @template T Type of the input value
|
|
51
|
-
* @param input A value to be asserted
|
|
52
|
-
* @returns Parametric input value
|
|
53
|
-
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
54
|
-
*
|
|
55
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
56
|
-
*/
|
|
57
|
-
export function assert<T>(input: T): T;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Asserts a value type.
|
|
61
|
-
*
|
|
62
|
-
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
63
|
-
* reason, if the parametric value is not following the type `T`. Otherwise, the
|
|
64
|
-
* value is following the type `T`, just input parameter would be returned.
|
|
65
|
-
*
|
|
66
|
-
* If what you want is not asserting but just knowing whether the parametric value is
|
|
67
|
-
* following the type `T` or not, you can choose the {@link is} function instead.
|
|
68
|
-
* Otherwise, you want to know all the errors, {@link validate} is the way to go.
|
|
69
|
-
*
|
|
70
|
-
* On the other and, if you don't want to allow any superfluous property that is not
|
|
71
|
-
* enrolled to the type `T`, you can use {@link assertEquals} function instead.
|
|
72
|
-
*
|
|
73
|
-
* @template T Type of the input value
|
|
74
|
-
* @param input A value to be asserted
|
|
75
|
-
* @returns Parametric input value casted as `T`
|
|
76
|
-
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
77
|
-
*
|
|
78
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
79
|
-
*/
|
|
80
|
-
export function assert<T>(input: unknown): T;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* @internal
|
|
84
|
-
*/
|
|
85
|
-
export function assert(): never {
|
|
86
|
-
halt("assert");
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @internal
|
|
91
|
-
*/
|
|
92
|
-
export namespace assert {
|
|
93
|
-
export const is_uuid = $is_uuid;
|
|
94
|
-
export const is_email = $is_email;
|
|
95
|
-
export const is_url = $is_url;
|
|
96
|
-
export const is_ipv4 = $is_ipv4;
|
|
97
|
-
export const is_ipv6 = $is_ipv6;
|
|
98
|
-
|
|
99
|
-
export const join = $join;
|
|
100
|
-
export const every = $every;
|
|
101
|
-
export const guard = $guard("typia.assert");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Asserts a value type.
|
|
106
|
-
*
|
|
107
|
-
* Duplicated function of {@link assert} for `typescript-is` users.
|
|
108
|
-
*
|
|
109
|
-
* @template T Type of the input value
|
|
110
|
-
* @param input A value to be asserted
|
|
111
|
-
* @returns Parametric input value
|
|
112
|
-
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
113
|
-
*
|
|
114
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
115
|
-
* @deprecated
|
|
116
|
-
*/
|
|
117
|
-
export function assertType<T>(input: T): T;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Asserts a value type.
|
|
121
|
-
*
|
|
122
|
-
* Duplicated function of {@link assert} for `typescript-is` users.
|
|
123
|
-
*
|
|
124
|
-
* @template T Type of the input value
|
|
125
|
-
* @param input A value to be asserted
|
|
126
|
-
* @returns Parametric input value
|
|
127
|
-
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
128
|
-
*
|
|
129
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
130
|
-
* @deprecated
|
|
131
|
-
*/
|
|
132
|
-
export function assertType<T>(input: unknown): T;
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* @internal
|
|
136
|
-
*/
|
|
137
|
-
export function assertType(): never {
|
|
138
|
-
halt("assertType");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* @internal
|
|
143
|
-
*/
|
|
144
|
-
export namespace assertType {
|
|
145
|
-
// FOR LEGACY FUNCTIONS
|
|
146
|
-
export function predicate(
|
|
147
|
-
matched: boolean,
|
|
148
|
-
exceptionable: boolean,
|
|
149
|
-
closure: () => Omit<TypeGuardError.IProps, "method">,
|
|
150
|
-
): boolean {
|
|
151
|
-
if (matched === false && exceptionable === true)
|
|
152
|
-
throw new TypeGuardError({
|
|
153
|
-
method: "typia.assertType",
|
|
154
|
-
...closure(),
|
|
155
|
-
});
|
|
156
|
-
return matched;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
Object.assign(assertType, assert);
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Tests a value type.
|
|
163
|
-
*
|
|
164
|
-
* Tests a parametric value type and returns whether it's following the type `T` or not.
|
|
165
|
-
* If the parametric value is matched with the type `T`, `true` value would be returned.
|
|
166
|
-
* Otherwise, the parametric value is not following the type `T`, `false` value would be
|
|
167
|
-
* returned.
|
|
168
|
-
*
|
|
169
|
-
* If what you want is not just knowing whether the parametric value is following the
|
|
170
|
-
* type `T` or not, but throwing an exception with detailed reason, you can choose
|
|
171
|
-
* {@link assert} function instead. Also, if you want to know all the errors with
|
|
172
|
-
* detailed reasons, {@link validate} function would be useful.
|
|
173
|
-
*
|
|
174
|
-
* On the other and, if you don't want to allow any superfluous property that is not
|
|
175
|
-
* enrolled to the type `T`, you can use {@link equals} function instead.
|
|
176
|
-
*
|
|
177
|
-
* @template T Type of the input value
|
|
178
|
-
* @param input A value to be tested
|
|
179
|
-
* @returns Whether the parametric value is following the type `T` or not
|
|
180
|
-
*
|
|
181
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
182
|
-
*/
|
|
183
|
-
export function is<T>(input: T): input is T;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Tests a value type.
|
|
187
|
-
*
|
|
188
|
-
* Tests a parametric value type and returns whether it's following the type `T` or not.
|
|
189
|
-
* If the parametric value is matched with the type `T`, `true` value would be returned.
|
|
190
|
-
* Otherwise, the parametric value is not following the type `T`, `false` value would be
|
|
191
|
-
* returned.
|
|
192
|
-
*
|
|
193
|
-
* If what you want is not just knowing whether the parametric value is following the
|
|
194
|
-
* type `T` or not, but throwing an exception with detailed reason, you can choose
|
|
195
|
-
* {@link assert} function instead. Also, if you want to know all the errors with
|
|
196
|
-
* detailed reasons, {@link validate} function would be useful.
|
|
197
|
-
*
|
|
198
|
-
* On the other and, if you don't want to allow any superfluous property that is not
|
|
199
|
-
* enrolled to the type `T`, you can use {@link equals} function instead.
|
|
200
|
-
*
|
|
201
|
-
* @template T Type of the input value
|
|
202
|
-
* @param input A value to be tested
|
|
203
|
-
* @returns Whether the parametric value is following the type `T` or not
|
|
204
|
-
*
|
|
205
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
206
|
-
*/
|
|
207
|
-
export function is<T>(input: unknown): input is T;
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @internal
|
|
211
|
-
*/
|
|
212
|
-
export function is(): never {
|
|
213
|
-
halt("is");
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* @internal
|
|
218
|
-
*/
|
|
219
|
-
export namespace is {
|
|
220
|
-
export const is_uuid = $is_uuid;
|
|
221
|
-
export const is_email = $is_email;
|
|
222
|
-
export const is_url = $is_url;
|
|
223
|
-
export const is_ipv4 = $is_ipv4;
|
|
224
|
-
export const is_ipv6 = $is_ipv6;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Validates a value type.
|
|
229
|
-
*
|
|
230
|
-
* Validates a parametric value type and archives all the type errors into an
|
|
231
|
-
* {@link IValidation.errors} array, if the parametric value is not following the
|
|
232
|
-
* type `T`. Of course, if the parametric value is following the type `T`, the
|
|
233
|
-
* {@link IValidation.errors} array would be empty and {@link IValidation.success}
|
|
234
|
-
* would have the `true` value.
|
|
235
|
-
*
|
|
236
|
-
* If what you want is not finding all the error, but asserting the parametric value
|
|
237
|
-
* type with exception throwing, you can choose {@link assert} function instead.
|
|
238
|
-
* Otherwise, you just want to know whether the parametric value is matched with the
|
|
239
|
-
* type `T`, {@link is} function is the way to go.
|
|
240
|
-
*
|
|
241
|
-
* On the other and, if you don't want to allow any superfluous property that is not
|
|
242
|
-
* enrolled to the type `T`, you can use {@link validateEquals} function instead.
|
|
243
|
-
*
|
|
244
|
-
* @template Type of the input value
|
|
245
|
-
* @param input A value to be validated
|
|
246
|
-
* @returns Validation result
|
|
247
|
-
*
|
|
248
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
249
|
-
*/
|
|
250
|
-
export function validate<T>(input: T): IValidation<T>;
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Validates a value type.
|
|
254
|
-
*
|
|
255
|
-
* Validates a parametric value type and archives all the type errors into an
|
|
256
|
-
* {@link IValidation.errors} array, if the parametric value is not following the
|
|
257
|
-
* type `T`. Of course, if the parametric value is following the type `T`, the
|
|
258
|
-
* {@link IValidation.errors} array would be empty and {@link IValidation.success}
|
|
259
|
-
* would have the `true` value.
|
|
260
|
-
*
|
|
261
|
-
* If what you want is not finding all the error, but asserting the parametric value
|
|
262
|
-
* type with exception throwing, you can choose {@link assert} function instead.
|
|
263
|
-
* Otherwise, you just want to know whether the parametric value is matched with the
|
|
264
|
-
* type `T`, {@link is} function is the way to go.
|
|
265
|
-
*
|
|
266
|
-
* On the other and, if you don't want to allow any superfluous property that is not
|
|
267
|
-
* enrolled to the type `T`, you can use {@link validateEquals} function instead.
|
|
268
|
-
*
|
|
269
|
-
* @template Type of the input value
|
|
270
|
-
* @param input A value to be validated
|
|
271
|
-
* @returns Validation result
|
|
272
|
-
*
|
|
273
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
274
|
-
*/
|
|
275
|
-
export function validate<T>(input: unknown): IValidation<T>;
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* @internal
|
|
279
|
-
*/
|
|
280
|
-
export function validate(): never {
|
|
281
|
-
halt("validate");
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* @internal
|
|
286
|
-
*/
|
|
287
|
-
export namespace validate {
|
|
288
|
-
export const is_uuid = $is_uuid;
|
|
289
|
-
export const is_email = $is_email;
|
|
290
|
-
export const is_url = $is_url;
|
|
291
|
-
export const is_ipv4 = $is_ipv4;
|
|
292
|
-
export const is_ipv6 = $is_ipv6;
|
|
293
|
-
|
|
294
|
-
export const join = $join;
|
|
295
|
-
export const report = $report;
|
|
296
|
-
|
|
297
|
-
// FOR LEGACY FUNCTIONS
|
|
298
|
-
export const predicate =
|
|
299
|
-
(res: IValidation) =>
|
|
300
|
-
(
|
|
301
|
-
matched: boolean,
|
|
302
|
-
exceptionable: boolean,
|
|
303
|
-
closure: () => IValidation.IError,
|
|
304
|
-
) => {
|
|
305
|
-
// CHECK FAILURE
|
|
306
|
-
if (matched === false && exceptionable === true)
|
|
307
|
-
(() => {
|
|
308
|
-
res.success &&= false;
|
|
309
|
-
const errorList = (res as IValidation.IFailure).errors;
|
|
310
|
-
|
|
311
|
-
// TRACE ERROR
|
|
312
|
-
const error = closure();
|
|
313
|
-
if (errorList.length) {
|
|
314
|
-
const last = errorList[errorList.length - 1]!.path;
|
|
315
|
-
if (
|
|
316
|
-
last.length >= error.path.length &&
|
|
317
|
-
last.substring(0, error.path.length) === error.path
|
|
318
|
-
)
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
errorList.push(error);
|
|
322
|
-
return;
|
|
323
|
-
})();
|
|
324
|
-
return matched;
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
/* -----------------------------------------------------------
|
|
329
|
-
STRICT VALIDATORS
|
|
330
|
-
----------------------------------------------------------- */
|
|
331
|
-
/**
|
|
332
|
-
* Asserts equality between a value and its type.
|
|
333
|
-
*
|
|
334
|
-
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
335
|
-
* reason, if the parametric value is not following the type `T` or some superfluous
|
|
336
|
-
* property that is not listed on the type `T` has been found. Otherwise, the value is
|
|
337
|
-
* following the type `T` without any superfluous property, just input parameter would
|
|
338
|
-
* be returned.
|
|
339
|
-
*
|
|
340
|
-
* If what you want is not asserting but just knowing whether the parametric value is
|
|
341
|
-
* following the type `T` or not, you can choose the {@link equals} function instead.
|
|
342
|
-
* Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
|
|
343
|
-
*
|
|
344
|
-
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
345
|
-
* to the type `T`, you can use {@link assert} function instead.
|
|
346
|
-
*
|
|
347
|
-
* @template T Type of the input value
|
|
348
|
-
* @param input A value to be asserted
|
|
349
|
-
* @returns Parametric input value
|
|
350
|
-
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
351
|
-
*
|
|
352
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
353
|
-
*/
|
|
354
|
-
export function assertEquals<T>(input: T): T;
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Asserts equality between a value and its type.
|
|
358
|
-
*
|
|
359
|
-
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
360
|
-
* reason, if the parametric value is not following the type `T` or some superfluous
|
|
361
|
-
* property that is not listed on the type `T` has been found. Otherwise, the value is
|
|
362
|
-
* following the type `T` without any superfluous property, just input parameter would
|
|
363
|
-
* be returned.
|
|
364
|
-
*
|
|
365
|
-
* If what you want is not asserting but just knowing whether the parametric value is
|
|
366
|
-
* following the type `T` or not, you can choose the {@link equals} function instead.
|
|
367
|
-
* Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
|
|
368
|
-
*
|
|
369
|
-
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
370
|
-
* to the type `T`, you can use {@link assert} function instead.
|
|
371
|
-
*
|
|
372
|
-
* @template T Type of the input value
|
|
373
|
-
* @param input A value to be asserted
|
|
374
|
-
* @returns Parametric input value casted as `T`
|
|
375
|
-
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
376
|
-
*
|
|
377
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
378
|
-
*/
|
|
379
|
-
export function assertEquals<T>(input: unknown): T;
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* @internal
|
|
383
|
-
*/
|
|
384
|
-
export function assertEquals<T>(): never {
|
|
385
|
-
halt("assertEquals");
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* @internal
|
|
390
|
-
*/
|
|
391
|
-
export namespace assertEquals {
|
|
392
|
-
export const is_uuid = $is_uuid;
|
|
393
|
-
export const is_email = $is_email;
|
|
394
|
-
export const is_url = $is_url;
|
|
395
|
-
export const is_ipv4 = $is_ipv4;
|
|
396
|
-
export const is_ipv6 = $is_ipv6;
|
|
397
|
-
|
|
398
|
-
export const join = $join;
|
|
399
|
-
export const every = $every;
|
|
400
|
-
// export const guardV2 = $guardV2("typia.assertEquals");
|
|
401
|
-
export const guard = $guard("typia.assertEquals");
|
|
402
|
-
|
|
403
|
-
// FOR LEGACY FUNCTIONS
|
|
404
|
-
export function predicate(
|
|
405
|
-
matched: boolean,
|
|
406
|
-
exceptionable: boolean,
|
|
407
|
-
closure: () => Omit<TypeGuardError.IProps, "method">,
|
|
408
|
-
): boolean {
|
|
409
|
-
if (matched === false && exceptionable === true)
|
|
410
|
-
throw new TypeGuardError({
|
|
411
|
-
method: "typia.assertEquals",
|
|
412
|
-
...closure(),
|
|
413
|
-
});
|
|
414
|
-
return matched;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* Tests equality between a value and its type.
|
|
420
|
-
*
|
|
421
|
-
* Tests a parametric value type and returns whether it's equivalent to the type `T`
|
|
422
|
-
* or not. If the parametric value is matched with the type `T` and there's not any
|
|
423
|
-
* superfluous property that is not listed on the type `T`, `true` value would be
|
|
424
|
-
* returned. Otherwise, the parametric value is not following the type `T` or some
|
|
425
|
-
* superfluous property exists, `false` value would be returned.
|
|
426
|
-
*
|
|
427
|
-
* If what you want is not just knowing whether the parametric value is following the
|
|
428
|
-
* type `T` or not, but throwing an exception with detailed reason, you can choose
|
|
429
|
-
* {@link assertEquals} function instead. Also, if you want to know all the errors with
|
|
430
|
-
* detailed reasons, {@link validateEquals} function would be useful.
|
|
431
|
-
*
|
|
432
|
-
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
433
|
-
* to the type `T`, you can use {@link is} function instead.
|
|
434
|
-
*
|
|
435
|
-
* @template T Type of the input value
|
|
436
|
-
* @param input A value to be tested
|
|
437
|
-
* @returns Whether the parametric value is equivalent to the type `T` or not
|
|
438
|
-
*
|
|
439
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
440
|
-
*/
|
|
441
|
-
export function equals<T>(input: T): input is T;
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Tests equality between a value and its type.
|
|
445
|
-
*
|
|
446
|
-
* Tests a parametric value type and returns whether it's equivalent to the type `T`
|
|
447
|
-
* or not. If the parametric value is matched with the type `T` and there's not any
|
|
448
|
-
* superfluous property that is not listed on the type `T`, `true` value would be
|
|
449
|
-
* returned. Otherwise, the parametric value is not following the type `T` or some
|
|
450
|
-
* superfluous property exists, `false` value would be returned.
|
|
451
|
-
*
|
|
452
|
-
* If what you want is not just knowing whether the parametric value is following the
|
|
453
|
-
* type `T` or not, but throwing an exception with detailed reason, you can choose
|
|
454
|
-
* {@link assertEquals} function instead. Also, if you want to know all the errors with
|
|
455
|
-
* detailed reasons, {@link validateEquals} function would be useful.
|
|
456
|
-
*
|
|
457
|
-
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
458
|
-
* to the type `T`, you can use {@link is} function instead.
|
|
459
|
-
*
|
|
460
|
-
* @template T Type of the input value
|
|
461
|
-
* @param input A value to be tested
|
|
462
|
-
* @returns Whether the parametric value is equivalent to the type `T` or not
|
|
463
|
-
*
|
|
464
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
465
|
-
*/
|
|
466
|
-
export function equals<T>(input: unknown): input is T;
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* @internal
|
|
470
|
-
*/
|
|
471
|
-
export function equals(): never {
|
|
472
|
-
halt("equals");
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* @internal
|
|
477
|
-
*/
|
|
478
|
-
export namespace equals {
|
|
479
|
-
export const is_uuid = $is_uuid;
|
|
480
|
-
export const is_email = $is_email;
|
|
481
|
-
export const is_url = $is_url;
|
|
482
|
-
export const is_ipv4 = $is_ipv4;
|
|
483
|
-
export const is_ipv6 = $is_ipv6;
|
|
484
|
-
export const join = $join;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
/**
|
|
488
|
-
* Validates equality between a value and its type.
|
|
489
|
-
*
|
|
490
|
-
* Validates a parametric value type and archives all the type errors into an
|
|
491
|
-
* {@link IValidation.errors} array, if the parametric value is not following the
|
|
492
|
-
* type `T` or some superfluous property that is not listed on the type `T` has been
|
|
493
|
-
* found. Of course, if the parametric value is following the type `T` and no
|
|
494
|
-
* superfluous property exists, the {@link IValidation.errors} array would be empty
|
|
495
|
-
* and {@link IValidation.success} would have the `true` value.
|
|
496
|
-
*
|
|
497
|
-
* If what you want is not finding all the error, but asserting the parametric value
|
|
498
|
-
* type with exception throwing, you can choose {@link assert} function instead.
|
|
499
|
-
* Otherwise, you just want to know whether the parametric value is matched with the
|
|
500
|
-
* type `T`, {@link is} function is the way to go.
|
|
501
|
-
*
|
|
502
|
-
* On the other and, if you don't want to allow any superfluous property that is not
|
|
503
|
-
* enrolled to the type `T`, you can use {@link validateEquals} function instead.
|
|
504
|
-
*
|
|
505
|
-
* @template Type of the input value
|
|
506
|
-
* @param input A value to be validated
|
|
507
|
-
* @returns Validation result
|
|
508
|
-
*
|
|
509
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
510
|
-
*/
|
|
511
|
-
export function validateEquals<T>(input: T): IValidation<T>;
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* Validates equality between a value and its type.
|
|
515
|
-
*
|
|
516
|
-
* Validates a parametric value type and archives all the type errors into an
|
|
517
|
-
* {@link IValidation.errors} array, if the parametric value is not following the
|
|
518
|
-
* type `T` or some superfluous property that is not listed on the type `T` has been
|
|
519
|
-
* found. Of course, if the parametric value is following the type `T` and no
|
|
520
|
-
* superfluous property exists, the {@link IValidation.errors} array would be empty
|
|
521
|
-
* and {@link IValidation.success} would have the `true` value.
|
|
522
|
-
*
|
|
523
|
-
* If what you want is not finding all the error, but asserting the parametric value
|
|
524
|
-
* type with exception throwing, you can choose {@link assert} function instead.
|
|
525
|
-
* Otherwise, you just want to know whether the parametric value is matched with the
|
|
526
|
-
* type `T`, {@link is} function is the way to go.
|
|
527
|
-
*
|
|
528
|
-
* On the other and, if you don't want to allow any superfluous property that is not
|
|
529
|
-
* enrolled to the type `T`, you can use {@link validateEquals} function instead.
|
|
530
|
-
*
|
|
531
|
-
* @template Type of the input value
|
|
532
|
-
* @param input A value to be validated
|
|
533
|
-
* @returns Validation result
|
|
534
|
-
*
|
|
535
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
536
|
-
*/
|
|
537
|
-
export function validateEquals<T>(input: unknown): IValidation<T>;
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* @internal
|
|
541
|
-
*/
|
|
542
|
-
export function validateEquals(): never {
|
|
543
|
-
halt("validateEquals");
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
/**
|
|
547
|
-
* @internal
|
|
548
|
-
*/
|
|
549
|
-
export namespace validateEquals {
|
|
550
|
-
export const is_uuid = $is_uuid;
|
|
551
|
-
export const is_email = $is_email;
|
|
552
|
-
export const is_url = $is_url;
|
|
553
|
-
export const is_ipv4 = $is_ipv4;
|
|
554
|
-
export const is_ipv6 = $is_ipv6;
|
|
555
|
-
export const join = $join;
|
|
556
|
-
|
|
557
|
-
export const report = validate.report;
|
|
558
|
-
|
|
559
|
-
// FOR LEGACY FUNCTIONS
|
|
560
|
-
export const predicate =
|
|
561
|
-
(res: IValidation) =>
|
|
562
|
-
(
|
|
563
|
-
matched: boolean,
|
|
564
|
-
exceptionable: boolean,
|
|
565
|
-
closure: () => IValidation.IError,
|
|
566
|
-
) => {
|
|
567
|
-
// CHECK FAILURE
|
|
568
|
-
if (matched === false && exceptionable === true)
|
|
569
|
-
(() => {
|
|
570
|
-
res.success &&= false;
|
|
571
|
-
const errorList = (res as IValidation.IFailure).errors;
|
|
572
|
-
|
|
573
|
-
// TRACE ERROR
|
|
574
|
-
const error = closure();
|
|
575
|
-
if (errorList.length) {
|
|
576
|
-
const last = errorList[errorList.length - 1]!.path;
|
|
577
|
-
if (
|
|
578
|
-
last.length >= error.path.length &&
|
|
579
|
-
last.substring(0, error.path.length) === error.path
|
|
580
|
-
)
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
errorList.push(error);
|
|
584
|
-
return;
|
|
585
|
-
})();
|
|
586
|
-
return matched;
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/* -----------------------------------------------------------
|
|
591
|
-
JSON FUNCTIONS
|
|
592
|
-
----------------------------------------------------------- */
|
|
593
|
-
/**
|
|
594
|
-
* > You must configure the generic argument `T`.
|
|
595
|
-
*
|
|
596
|
-
* JSON Schema Application.
|
|
597
|
-
*
|
|
598
|
-
* Creates a JSON schema application which contains both main JSON schemas and components.
|
|
599
|
-
* Note that, all of the object types are stored in the {@link IJsonApplication.components}
|
|
600
|
-
* property for the `$ref` referencing.
|
|
601
|
-
*
|
|
602
|
-
* Also, `typia.application()` has additional generic arguments, *Purpose*.
|
|
603
|
-
* As JSON schema definitions used by `swagger` and `ajv` are different a little bit,
|
|
604
|
-
* you should configure the *Purpose* appropriately.
|
|
605
|
-
*
|
|
606
|
-
* For an example, `ajv` has an extra property "$recursiveRef" that are not exists
|
|
607
|
-
* in the standard JSON schema definition spec. Otherwise, `swagger` can't identify
|
|
608
|
-
* the tuple definition.
|
|
609
|
-
*
|
|
610
|
-
* @template Types Tuple of target types
|
|
611
|
-
* @template Purpose Purpose of the JSON schema`
|
|
612
|
-
* @template Prefix Prefix of the JSON components referenced by `$ref` tag
|
|
613
|
-
* @return JSON schema application
|
|
614
|
-
*
|
|
615
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
616
|
-
*/
|
|
617
|
-
export function application(): never;
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* JSON Schema Application.
|
|
621
|
-
*
|
|
622
|
-
* Creates a JSON schema application which contains both main JSON schemas and components.
|
|
623
|
-
* Note that, all of the object types are stored in the {@link IJsonApplication.components}
|
|
624
|
-
* property for the `$ref` referencing.
|
|
625
|
-
*
|
|
626
|
-
* Also, `typia.application()` has additional generic arguments, *Purpose*.
|
|
627
|
-
* As JSON schema definitions used by `swagger` and `ajv` are different a little bit,
|
|
628
|
-
* you should configure the *Purpose* appropriately.
|
|
629
|
-
*
|
|
630
|
-
* For an example, `ajv` has an extra property "$recursiveRef" that are not exists
|
|
631
|
-
* in the standard JSON schema definition spec. Otherwise, `swagger` can't identify
|
|
632
|
-
* the tuple definition.
|
|
633
|
-
*
|
|
634
|
-
* @template Types Tuple of target types
|
|
635
|
-
* @template Purpose Purpose of the JSON schema
|
|
636
|
-
* @template Prefix Prefix of the JSON components referenced by `$ref` tag
|
|
637
|
-
* @return JSON schema application
|
|
638
|
-
*
|
|
639
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
640
|
-
*/
|
|
641
|
-
export function application<
|
|
642
|
-
Types extends unknown[],
|
|
643
|
-
Purpose extends "swagger" | "ajv" = "swagger",
|
|
644
|
-
Prefix extends string = Purpose extends "swagger"
|
|
645
|
-
? "#/components/schemas"
|
|
646
|
-
: "components#/schemas",
|
|
647
|
-
>(): IJsonApplication;
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
* @internal
|
|
651
|
-
*/
|
|
652
|
-
export function application(): never {
|
|
653
|
-
halt("application");
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
/**
|
|
657
|
-
* > You must configure the generic argument `T`.
|
|
658
|
-
*
|
|
659
|
-
* Safe `JSON.parse()` function with type assertion.
|
|
660
|
-
*
|
|
661
|
-
* `typia.assertParse()` is a combination function of `JSON.parse()` and {@link assert}.
|
|
662
|
-
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
663
|
-
* instance with type assertion.
|
|
664
|
-
*
|
|
665
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
666
|
-
* throws {@link TypeGuardError}. Otherwise, there's no problem on the parsed value,
|
|
667
|
-
* the parsed value would be returned.
|
|
668
|
-
*
|
|
669
|
-
* @template T Expected type of parsed value
|
|
670
|
-
* @param input JSON string
|
|
671
|
-
* @returns Parsed value
|
|
672
|
-
*
|
|
673
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
674
|
-
*/
|
|
675
|
-
export function assertParse(input: string): never;
|
|
676
|
-
|
|
677
|
-
/**
|
|
678
|
-
* Safe `JSON.parse()` function with type assertion.
|
|
679
|
-
*
|
|
680
|
-
* `typia.assertParse()` is a combination function of `JSON.parse()` and {@link assert}.
|
|
681
|
-
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
682
|
-
* instance with type assertion.
|
|
683
|
-
*
|
|
684
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
685
|
-
* throws {@link TypeGuardError}. Otherwise, there's no problem on the parsed value,
|
|
686
|
-
* the parsed value would be returned.
|
|
687
|
-
*
|
|
688
|
-
* @template T Expected type of parsed value
|
|
689
|
-
* @param input JSON string
|
|
690
|
-
* @returns Parsed value
|
|
691
|
-
*
|
|
692
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
693
|
-
*/
|
|
694
|
-
export function assertParse<T>(input: string): T;
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
* @internal
|
|
698
|
-
*/
|
|
699
|
-
export function assertParse<T>(): T {
|
|
700
|
-
halt("assertParse");
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
/**
|
|
704
|
-
* @internal
|
|
705
|
-
*/
|
|
706
|
-
export namespace assertParse {
|
|
707
|
-
export const is_uuid = $is_uuid;
|
|
708
|
-
export const is_email = $is_email;
|
|
709
|
-
export const is_url = $is_url;
|
|
710
|
-
export const is_ipv4 = $is_ipv4;
|
|
711
|
-
export const is_ipv6 = $is_ipv6;
|
|
712
|
-
|
|
713
|
-
export const join = $join;
|
|
714
|
-
export const every = $every;
|
|
715
|
-
export const guard = $guard("typia.assertParse");
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
/**
|
|
719
|
-
* > You must configure the generic argument `T`.
|
|
720
|
-
*
|
|
721
|
-
* Safe `JSON.parse()` function with type checking.
|
|
722
|
-
*
|
|
723
|
-
* `typia.isParse()` is a combination function of `JSON.parse()` and {@link is}.
|
|
724
|
-
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
725
|
-
* instance with type checking.
|
|
726
|
-
*
|
|
727
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
728
|
-
* returns `null` value. Otherwise, there's no problem on the parsed value, the parsed
|
|
729
|
-
* value would be returned.
|
|
730
|
-
*
|
|
731
|
-
* @template T Expected type of parsed value
|
|
732
|
-
* @param input JSON string
|
|
733
|
-
* @returns Parsed value when exact type, otherwise `null`
|
|
734
|
-
*
|
|
735
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
736
|
-
*/
|
|
737
|
-
export function isParse(input: string): never;
|
|
738
|
-
|
|
739
|
-
/**
|
|
740
|
-
* Safe `JSON.parse()` function with type checking.
|
|
741
|
-
*
|
|
742
|
-
* `typia.isParse()` is a combination function of `JSON.parse()` and {@link is}.
|
|
743
|
-
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
744
|
-
* instance with type checking.
|
|
745
|
-
*
|
|
746
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
747
|
-
* returns `null` value. Otherwise, there's no problem on the parsed value, the parsed
|
|
748
|
-
* value would be returned.
|
|
749
|
-
*
|
|
750
|
-
* @template T Expected type of parsed value
|
|
751
|
-
* @param input JSON string
|
|
752
|
-
* @returns Parsed value when exact type, otherwise `null`
|
|
753
|
-
*
|
|
754
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
755
|
-
*/
|
|
756
|
-
export function isParse<T>(input: string): T | null;
|
|
757
|
-
|
|
758
|
-
/**
|
|
759
|
-
* @internal
|
|
760
|
-
*/
|
|
761
|
-
export function isParse<T>(): T | null {
|
|
762
|
-
halt("isParse");
|
|
763
|
-
}
|
|
764
|
-
Object.assign(isParse, is);
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* > You must configure the generic argument `T`.
|
|
768
|
-
*
|
|
769
|
-
* Safe `JSON.parse()` function with detailed type validation.
|
|
770
|
-
*
|
|
771
|
-
* `typia.validateParse()` is a combination function of `JSON.parse()` and
|
|
772
|
-
* {@link validate}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
773
|
-
* to a `T` typed instance with detailed type validation.
|
|
774
|
-
*
|
|
775
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
776
|
-
* returns {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
777
|
-
* there's no problem on the parsed value, the parsed value would be stored in `data`
|
|
778
|
-
* property of the output {@link IValidation.ISuccess} instance.
|
|
779
|
-
*
|
|
780
|
-
* @template T Expected type of parsed value
|
|
781
|
-
* @param input JSON string
|
|
782
|
-
* @returns Validation result with JSON parsed value
|
|
783
|
-
*
|
|
784
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
785
|
-
*/
|
|
786
|
-
export function validateParse(input: string): never;
|
|
787
|
-
|
|
788
|
-
/**
|
|
789
|
-
* Safe `JSON.parse()` function with detailed type validation.
|
|
790
|
-
*
|
|
791
|
-
* `typia.validateParse()` is a combination function of `JSON.parse()` and
|
|
792
|
-
* {@link validate}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
793
|
-
* to a `T` typed instance with detailed type validation.
|
|
794
|
-
*
|
|
795
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
796
|
-
* returns {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
797
|
-
* there's no problem on the parsed value, the parsed value would be stored in `data`
|
|
798
|
-
* property of the output {@link IValidation.ISuccess} instance.
|
|
799
|
-
*
|
|
800
|
-
* @template T Expected type of parsed value
|
|
801
|
-
* @param input JSON string
|
|
802
|
-
* @returns Validation result with JSON parsed value
|
|
803
|
-
*
|
|
804
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
805
|
-
*/
|
|
806
|
-
export function validateParse<T>(input: string): IValidation<T>;
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* @internal
|
|
810
|
-
*/
|
|
811
|
-
export function validateParse<T>(): IValidation<T> {
|
|
812
|
-
halt("validateParse");
|
|
813
|
-
}
|
|
814
|
-
Object.assign(validateParse, validate);
|
|
815
|
-
|
|
816
|
-
/**
|
|
817
|
-
* 8x faster `JSON.stringify()` function.
|
|
818
|
-
*
|
|
819
|
-
* Converts an input value to a JSON (JavaScript Object Notation) string, about 8x faster
|
|
820
|
-
* than the native `JSON.stringify()` function. The 5x faster principle is because
|
|
821
|
-
* it writes an optimized JSON conversion plan, only for the type `T`.
|
|
822
|
-
*
|
|
823
|
-
* For reference, this `typia.stringify()` does not validate the input value type. It
|
|
824
|
-
* just believes that the input value is following the type `T`. Therefore, if you
|
|
825
|
-
* can't ensure the input value type, it would be better to call one of below functions
|
|
826
|
-
* instead.
|
|
827
|
-
*
|
|
828
|
-
* - {@link assertStringify}
|
|
829
|
-
* - {@link isStringify}
|
|
830
|
-
* - {@link validateStringify}
|
|
831
|
-
*
|
|
832
|
-
* @template T Type of the input value
|
|
833
|
-
* @param input A value to be converted
|
|
834
|
-
* @return JSON string value
|
|
835
|
-
*
|
|
836
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
837
|
-
*/
|
|
838
|
-
export function stringify<T>(input: T): string;
|
|
839
|
-
|
|
840
|
-
/**
|
|
841
|
-
* @internal
|
|
842
|
-
*/
|
|
843
|
-
export function stringify(): never {
|
|
844
|
-
halt("stringify");
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
/**
|
|
848
|
-
* @internal
|
|
849
|
-
*/
|
|
850
|
-
export namespace stringify {
|
|
851
|
-
export const number = $number;
|
|
852
|
-
export const string = $string;
|
|
853
|
-
export const tail = $tail;
|
|
854
|
-
export const rest = $rest;
|
|
855
|
-
|
|
856
|
-
export function throws(
|
|
857
|
-
props: Pick<TypeGuardError.IProps, "expected" | "value">,
|
|
858
|
-
): void {
|
|
859
|
-
throw new TypeGuardError({
|
|
860
|
-
...props,
|
|
861
|
-
method: "typia.stringify",
|
|
862
|
-
});
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
/**
|
|
867
|
-
* 5x faster `JSON.stringify()` function with type assertion.
|
|
868
|
-
*
|
|
869
|
-
* `typia.assertStringify()` is a combination function of {@link assert} and
|
|
870
|
-
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
871
|
-
* Notation) string, with type assertion.
|
|
872
|
-
*
|
|
873
|
-
* In such reason, when `input` value is not matched with the type `T`, it throws an
|
|
874
|
-
* {@link TypeGuardError}. Otherwise, there's no problem on the `input` value, JSON
|
|
875
|
-
* string would be returned.
|
|
876
|
-
*
|
|
877
|
-
* For reference, with type assertion, it is even 5x times faster than the native
|
|
878
|
-
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
879
|
-
* with confidence.
|
|
880
|
-
*
|
|
881
|
-
* @template T Type of the input value
|
|
882
|
-
* @param input A value to be asserted and converted
|
|
883
|
-
* @return JSON string value
|
|
884
|
-
*
|
|
885
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
886
|
-
*/
|
|
887
|
-
export function assertStringify<T>(input: T): string;
|
|
888
|
-
|
|
889
|
-
/**
|
|
890
|
-
* 5x faster `JSON.stringify()` function with type assertion.
|
|
891
|
-
*
|
|
892
|
-
* `typia.assertStringify()` is a combination function of {@link assert} and
|
|
893
|
-
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
894
|
-
* Notation) string, with type assertion.
|
|
895
|
-
*
|
|
896
|
-
* In such reason, when `input` value is not matched with the type `T`, it throws an
|
|
897
|
-
* {@link TypeGuardError}. Otherwise, there's no problem on the `input` value, JSON
|
|
898
|
-
* string would be returned.
|
|
899
|
-
*
|
|
900
|
-
* For reference, with type assertion, it is even 5x times faster than the native
|
|
901
|
-
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
902
|
-
* with confidence.
|
|
903
|
-
*
|
|
904
|
-
* @template T Type of the input value
|
|
905
|
-
* @param input A value to be asserted and converted
|
|
906
|
-
* @return JSON string value
|
|
907
|
-
*
|
|
908
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
909
|
-
*/
|
|
910
|
-
export function assertStringify<T>(input: T): unknown;
|
|
911
|
-
|
|
912
|
-
/**
|
|
913
|
-
* @internal
|
|
914
|
-
*/
|
|
915
|
-
export function assertStringify(): string {
|
|
916
|
-
halt("assertStringify");
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
/**
|
|
920
|
-
* @internal
|
|
921
|
-
*/
|
|
922
|
-
export namespace assertStringify {
|
|
923
|
-
export const is_uuid = $is_uuid;
|
|
924
|
-
export const is_email = $is_email;
|
|
925
|
-
export const is_url = $is_url;
|
|
926
|
-
export const is_ipv4 = $is_ipv4;
|
|
927
|
-
export const is_ipv6 = $is_ipv6;
|
|
928
|
-
|
|
929
|
-
export const number = $number;
|
|
930
|
-
export const string = $string;
|
|
931
|
-
export const tail = $tail;
|
|
932
|
-
export const rest = $rest;
|
|
933
|
-
|
|
934
|
-
export const join = $join;
|
|
935
|
-
export const guard = $guard("typia.assertStringify");
|
|
936
|
-
export const every = $every;
|
|
937
|
-
export const throws = () => {};
|
|
938
|
-
|
|
939
|
-
// FOR LEGACY FUNCTIONS
|
|
940
|
-
export function predicate(
|
|
941
|
-
matched: boolean,
|
|
942
|
-
exceptionable: boolean,
|
|
943
|
-
closure: () => Omit<TypeGuardError.IProps, "method">,
|
|
944
|
-
): boolean {
|
|
945
|
-
if (matched === false && exceptionable === true)
|
|
946
|
-
throw new TypeGuardError({
|
|
947
|
-
method: "typia.assertStringify",
|
|
948
|
-
...closure(),
|
|
949
|
-
});
|
|
950
|
-
return matched;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
/**
|
|
955
|
-
* 7x faster `JSON.stringify()` function with type checking.
|
|
956
|
-
*
|
|
957
|
-
* `typia.stringify()` is a combination function of {@link is} and
|
|
958
|
-
* {@link stringify}. Therefore, it converts an input value to JSON
|
|
959
|
-
* (JavaScript Object Notation) string, with type checking.
|
|
960
|
-
*
|
|
961
|
-
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
962
|
-
* `null` value. Otherwise, there's no problem on the `input` value, JSON string would
|
|
963
|
-
* be returned.
|
|
964
|
-
*
|
|
965
|
-
* For reference, with type checking, it is even 7x times faster than the native
|
|
966
|
-
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
967
|
-
* with confidence.
|
|
968
|
-
*
|
|
969
|
-
* @template T Type of the input value
|
|
970
|
-
* @param input A value to be checked and converted
|
|
971
|
-
* @return JSON string value when exact type, otherwise null
|
|
972
|
-
*
|
|
973
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
974
|
-
*/
|
|
975
|
-
export function isStringify<T>(input: T): string | null;
|
|
976
|
-
|
|
977
|
-
/**
|
|
978
|
-
* 7x faster `JSON.stringify()` function with type checking.
|
|
979
|
-
*
|
|
980
|
-
* `typia.isStringify()` is a combination function of {@link is} and
|
|
981
|
-
* {@link stringify}. Therefore, it converts an input value to JSON
|
|
982
|
-
* (JavaScript Object Notation) string, with type checking.
|
|
983
|
-
*
|
|
984
|
-
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
985
|
-
* `null` value. Otherwise, there's no problem on the `input` value, JSON string would
|
|
986
|
-
* be returned.
|
|
987
|
-
*
|
|
988
|
-
* For reference, with type checking, it is even 7x times faster than the native
|
|
989
|
-
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
990
|
-
* with confidence.
|
|
991
|
-
*
|
|
992
|
-
* @template T Type of the input value
|
|
993
|
-
* @param input A value to be checked and converted
|
|
994
|
-
* @return JSON string value when exact type, otherwise null
|
|
995
|
-
*
|
|
996
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
997
|
-
*/
|
|
998
|
-
export function isStringify<T>(input: unknown): string | null;
|
|
999
|
-
|
|
1000
|
-
/**
|
|
1001
|
-
* @internal
|
|
1002
|
-
*/
|
|
1003
|
-
export function isStringify<T>(): string | null {
|
|
1004
|
-
halt("isStringify");
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
/**
|
|
1008
|
-
* @internal
|
|
1009
|
-
*/
|
|
1010
|
-
export namespace isStringify {
|
|
1011
|
-
export const is_uuid = $is_uuid;
|
|
1012
|
-
export const is_email = $is_email;
|
|
1013
|
-
export const is_url = $is_url;
|
|
1014
|
-
export const is_ipv4 = $is_ipv4;
|
|
1015
|
-
export const is_ipv6 = $is_ipv6;
|
|
1016
|
-
|
|
1017
|
-
export const number = $number;
|
|
1018
|
-
export const string = $string;
|
|
1019
|
-
export const tail = $tail;
|
|
1020
|
-
export const rest = $rest;
|
|
1021
|
-
|
|
1022
|
-
export const throws = () => {};
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
/**
|
|
1026
|
-
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
1027
|
-
*
|
|
1028
|
-
* `typia.validateStringify()` is a combination function of {@link validate} and
|
|
1029
|
-
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
1030
|
-
* Notation) string, with detailed type validation.
|
|
1031
|
-
*
|
|
1032
|
-
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
1033
|
-
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's no
|
|
1034
|
-
* problem on the `input` value, JSON string would be stored in `data` property of
|
|
1035
|
-
* the output {@link IValidation.ISuccess} instance.
|
|
1036
|
-
*
|
|
1037
|
-
* For reference, with detailed type validation, it is even 5x times faster than the
|
|
1038
|
-
* native `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
1039
|
-
* with confidence.
|
|
1040
|
-
*
|
|
1041
|
-
* @template T Type of the input value
|
|
1042
|
-
* @param input A value to be checked and converted
|
|
1043
|
-
* @returns Validation result with JSON string value
|
|
1044
|
-
*
|
|
1045
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1046
|
-
*/
|
|
1047
|
-
export function validateStringify<T>(input: T): IValidation<string>;
|
|
1048
|
-
|
|
1049
|
-
/**
|
|
1050
|
-
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
1051
|
-
*
|
|
1052
|
-
* `typia.validateStringify()` is a combination function of {@link validate} and
|
|
1053
|
-
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
1054
|
-
* Notation) string, with detailed type validation.
|
|
1055
|
-
*
|
|
1056
|
-
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
1057
|
-
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's no
|
|
1058
|
-
* problem on the `input` value, JSON string would be stored in `data` property of
|
|
1059
|
-
* the output {@link IValidation.ISuccess} instance.
|
|
1060
|
-
*
|
|
1061
|
-
* For reference, with detailed type validation, it is even 5x times faster than the
|
|
1062
|
-
* native `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
1063
|
-
* with confidence.
|
|
1064
|
-
*
|
|
1065
|
-
* @template T Type of the input value
|
|
1066
|
-
* @param input A value to be checked and converted
|
|
1067
|
-
* @returns Validation result with JSON string value
|
|
1068
|
-
*
|
|
1069
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1070
|
-
*/
|
|
1071
|
-
export function validateStringify<T>(input: unknown): IValidation<string>;
|
|
1072
|
-
|
|
1073
|
-
/**
|
|
1074
|
-
* @internal
|
|
1075
|
-
*/
|
|
1076
|
-
export function validateStringify(): IValidation<string> {
|
|
1077
|
-
halt("validateStringify");
|
|
1078
|
-
}
|
|
1079
|
-
Object.assign(validateStringify, validate);
|
|
1080
|
-
Object.assign(validateStringify, stringify);
|
|
1081
|
-
|
|
1082
|
-
/* ===========================================================
|
|
1083
|
-
FACTORY FUNCTIONS
|
|
1084
|
-
- BASIC VALIDATORS
|
|
1085
|
-
- STRICT VALIDATORS
|
|
1086
|
-
- JSON FUNCTIONS
|
|
1087
|
-
- MISCELLANEOUS
|
|
1088
|
-
==============================================================
|
|
1089
|
-
BASIC VALIDATORS
|
|
1090
|
-
----------------------------------------------------------- */
|
|
1091
|
-
/**
|
|
1092
|
-
* Creates a reusable {@link assert} function.
|
|
1093
|
-
*
|
|
1094
|
-
* @danger You have to specify the generic argument `T`
|
|
1095
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1096
|
-
* @throws compile error
|
|
1097
|
-
*
|
|
1098
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1099
|
-
*/
|
|
1100
|
-
export function createAssert(): never;
|
|
1101
|
-
|
|
1102
|
-
/**
|
|
1103
|
-
* Creates a reusable {@link assert} function.
|
|
1104
|
-
*
|
|
1105
|
-
* @template T Type of the input value
|
|
1106
|
-
* @returns A reusable `assert` function
|
|
1107
|
-
*
|
|
1108
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1109
|
-
*/
|
|
1110
|
-
export function createAssert<T>(): (input: unknown) => T;
|
|
1111
|
-
|
|
1112
|
-
/**
|
|
1113
|
-
* @internal
|
|
1114
|
-
*/
|
|
1115
|
-
export function createAssert<T>(): (input: unknown) => T {
|
|
1116
|
-
halt("createAssert");
|
|
1117
|
-
}
|
|
1118
|
-
Object.assign(createAssert, assert);
|
|
1119
|
-
|
|
1120
|
-
/**
|
|
1121
|
-
* Creates a reusable {@link assertType} function.
|
|
1122
|
-
*
|
|
1123
|
-
* Duplicated function of {@link createAssert} for `typescript-is` users.
|
|
1124
|
-
*
|
|
1125
|
-
* @danger You have to specify the generic argument `T`
|
|
1126
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1127
|
-
* @throws compile error
|
|
1128
|
-
*
|
|
1129
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1130
|
-
* @deprecated
|
|
1131
|
-
*/
|
|
1132
|
-
export function createAssertType(): never;
|
|
1133
|
-
|
|
1134
|
-
/**
|
|
1135
|
-
* Creates a reusable {@link assertType} function.
|
|
1136
|
-
*
|
|
1137
|
-
* Duplicated function of {@link createAssert} for `typescript-is` users.
|
|
1138
|
-
*
|
|
1139
|
-
* @template T Type of the input value
|
|
1140
|
-
* @returns A reusable `assert` function
|
|
1141
|
-
*
|
|
1142
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1143
|
-
* @deprecated
|
|
1144
|
-
*/
|
|
1145
|
-
export function createAssertType<T>(): (input: unknown) => T;
|
|
1146
|
-
|
|
1147
|
-
/**
|
|
1148
|
-
* @internal
|
|
1149
|
-
*/
|
|
1150
|
-
export function createAssertType<T>(): (input: unknown) => T {
|
|
1151
|
-
halt("createAssertType");
|
|
1152
|
-
}
|
|
1153
|
-
Object.assign(createAssertType, assertType);
|
|
1154
|
-
|
|
1155
|
-
/**
|
|
1156
|
-
* Creates a reusable {@link is} function.
|
|
1157
|
-
*
|
|
1158
|
-
* @danger You have to specify the generic argument `T`
|
|
1159
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1160
|
-
* @throws compile error
|
|
1161
|
-
*
|
|
1162
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1163
|
-
*/
|
|
1164
|
-
export function createIs(): never;
|
|
1165
|
-
|
|
1166
|
-
/**
|
|
1167
|
-
* Creates a reusable {@link is} function.
|
|
1168
|
-
*
|
|
1169
|
-
* @template T Type of the input value
|
|
1170
|
-
* @returns A reusable `is` function
|
|
1171
|
-
*
|
|
1172
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1173
|
-
*/
|
|
1174
|
-
export function createIs<T>(): (input: unknown) => input is T;
|
|
1175
|
-
|
|
1176
|
-
/**
|
|
1177
|
-
* @internal
|
|
1178
|
-
*/
|
|
1179
|
-
export function createIs<T>(): (input: unknown) => input is T {
|
|
1180
|
-
halt("createIs");
|
|
1181
|
-
}
|
|
1182
|
-
Object.assign(createIs, is);
|
|
1183
|
-
|
|
1184
|
-
/**
|
|
1185
|
-
* Creates a reusable {@link validate} function.
|
|
1186
|
-
*
|
|
1187
|
-
* @danger You have to specify the generic argument `T`
|
|
1188
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1189
|
-
* @throws compile error
|
|
1190
|
-
*
|
|
1191
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1192
|
-
*/
|
|
1193
|
-
export function createValidate(): never;
|
|
1194
|
-
|
|
1195
|
-
/**
|
|
1196
|
-
* Creates a reusable {@link validate} function.
|
|
1197
|
-
*
|
|
1198
|
-
* @template T Type of the input value
|
|
1199
|
-
* @returns A reusable `validate` function
|
|
1200
|
-
*
|
|
1201
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1202
|
-
*/
|
|
1203
|
-
export function createValidate<T>(): (input: unknown) => IValidation<T>;
|
|
1204
|
-
|
|
1205
|
-
/**
|
|
1206
|
-
* @internal
|
|
1207
|
-
*/
|
|
1208
|
-
export function createValidate(): (input: unknown) => IValidation {
|
|
1209
|
-
halt("createValidate");
|
|
1210
|
-
}
|
|
1211
|
-
Object.assign(createValidate, validate);
|
|
1212
|
-
|
|
1213
|
-
/* -----------------------------------------------------------
|
|
1214
|
-
STRICT VALIDATORS
|
|
1215
|
-
----------------------------------------------------------- */
|
|
1216
|
-
/**
|
|
1217
|
-
* Creates a reusable {@link assertEquals} function.
|
|
1218
|
-
*
|
|
1219
|
-
* @danger You have to specify the generic argument `T`
|
|
1220
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1221
|
-
* @throws compile error
|
|
1222
|
-
*
|
|
1223
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1224
|
-
*/
|
|
1225
|
-
export function createAssertEquals(): never;
|
|
1226
|
-
|
|
1227
|
-
/**
|
|
1228
|
-
* Creates a reusable {@link assertEquals} function.
|
|
1229
|
-
*
|
|
1230
|
-
* @template T Type of the input value
|
|
1231
|
-
* @returns A reusable `assertEquals` function
|
|
1232
|
-
*
|
|
1233
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1234
|
-
*/
|
|
1235
|
-
export function createAssertEquals<T>(): (input: unknown) => T;
|
|
1236
|
-
|
|
1237
|
-
/**
|
|
1238
|
-
* @internal
|
|
1239
|
-
*/
|
|
1240
|
-
export function createAssertEquals<T>(): (input: unknown) => T {
|
|
1241
|
-
halt("createAssertEquals");
|
|
1242
|
-
}
|
|
1243
|
-
Object.assign(createAssertEquals, assertEquals);
|
|
1244
|
-
|
|
1245
|
-
/**
|
|
1246
|
-
* Creates a reusable {@link equals} function.
|
|
1247
|
-
*
|
|
1248
|
-
* @danger You have to specify the generic argument `T`
|
|
1249
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1250
|
-
* @throws compile error
|
|
1251
|
-
*
|
|
1252
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1253
|
-
*/
|
|
1254
|
-
export function createEquals(): never;
|
|
1255
|
-
|
|
1256
|
-
/**
|
|
1257
|
-
* Creates a reusable {@link equals} function.
|
|
1258
|
-
*
|
|
1259
|
-
* @template T Type of the input value
|
|
1260
|
-
* @returns A reusable `equals` function
|
|
1261
|
-
*
|
|
1262
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1263
|
-
*/
|
|
1264
|
-
export function createEquals<T>(): (input: unknown) => input is T;
|
|
1265
|
-
|
|
1266
|
-
/**
|
|
1267
|
-
* @internal
|
|
1268
|
-
*/
|
|
1269
|
-
export function createEquals<T>(): (input: unknown) => input is T {
|
|
1270
|
-
halt("createEquals");
|
|
1271
|
-
}
|
|
1272
|
-
Object.assign(createEquals, equals);
|
|
1273
|
-
|
|
1274
|
-
/**
|
|
1275
|
-
* Creates a reusable {@link validateEquals} function.
|
|
1276
|
-
*
|
|
1277
|
-
* @danger You have to specify the generic argument `T`
|
|
1278
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1279
|
-
* @throws compile error
|
|
1280
|
-
*
|
|
1281
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1282
|
-
*/
|
|
1283
|
-
export function createValidateEquals(): never;
|
|
1284
|
-
|
|
1285
|
-
/**
|
|
1286
|
-
* Creates a reusable {@link validateEquals} function.
|
|
1287
|
-
*
|
|
1288
|
-
* @template T Type of the input value
|
|
1289
|
-
* @returns A reusable `validateEquals` function
|
|
1290
|
-
*
|
|
1291
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1292
|
-
*/
|
|
1293
|
-
export function createValidateEquals<T>(): (input: unknown) => IValidation;
|
|
1294
|
-
|
|
1295
|
-
/**
|
|
1296
|
-
* @internal
|
|
1297
|
-
*/
|
|
1298
|
-
export function createValidateEquals(): (input: unknown) => IValidation {
|
|
1299
|
-
halt("createValidateEquals");
|
|
1300
|
-
}
|
|
1301
|
-
Object.assign(createValidateEquals, validateEquals);
|
|
1302
|
-
|
|
1303
|
-
/* -----------------------------------------------------------
|
|
1304
|
-
JSON FUNCTIONS
|
|
1305
|
-
----------------------------------------------------------- */
|
|
1306
|
-
/**
|
|
1307
|
-
* Creates a reusable {@link isParse} function.
|
|
1308
|
-
*
|
|
1309
|
-
* @danger You have to specify the generic argument `T`
|
|
1310
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1311
|
-
* @throws compile error
|
|
1312
|
-
*
|
|
1313
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1314
|
-
*/
|
|
1315
|
-
export function createIsParse(): never;
|
|
1316
|
-
|
|
1317
|
-
/**
|
|
1318
|
-
* Creates a reusable {@link isParse} function.
|
|
1319
|
-
*
|
|
1320
|
-
* @template T Expected type of parsed value
|
|
1321
|
-
* @returns A reusable `isParse` function
|
|
1322
|
-
*
|
|
1323
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1324
|
-
*/
|
|
1325
|
-
export function createIsParse<T>(): (input: string) => T | null;
|
|
1326
|
-
|
|
1327
|
-
/**
|
|
1328
|
-
* @internal
|
|
1329
|
-
*/
|
|
1330
|
-
export function createIsParse<T>(): (input: string) => T | null {
|
|
1331
|
-
halt("createIsParse");
|
|
1332
|
-
}
|
|
1333
|
-
Object.assign(createIsParse, isParse);
|
|
1334
|
-
|
|
1335
|
-
/**
|
|
1336
|
-
* Creates a reusable {@link assertParse} function.
|
|
1337
|
-
*
|
|
1338
|
-
* @danger You have to specify the generic argument `T`
|
|
1339
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1340
|
-
* @throws compile error
|
|
1341
|
-
*
|
|
1342
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1343
|
-
*/
|
|
1344
|
-
export function createAssertParse(): never;
|
|
1345
|
-
|
|
1346
|
-
/**
|
|
1347
|
-
* Creates a reusable {@link assertParse} function.
|
|
1348
|
-
*
|
|
1349
|
-
* @template T Expected type of parsed value
|
|
1350
|
-
* @returns A reusable `assertParse` function
|
|
1351
|
-
*
|
|
1352
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1353
|
-
*/
|
|
1354
|
-
export function createAssertParse<T>(): (input: string) => T;
|
|
1355
|
-
|
|
1356
|
-
/**
|
|
1357
|
-
* @internal
|
|
1358
|
-
*/
|
|
1359
|
-
export function createAssertParse<T>(): (input: string) => T {
|
|
1360
|
-
halt("createAssertParse");
|
|
1361
|
-
}
|
|
1362
|
-
Object.assign(createAssertParse, assertParse);
|
|
1363
|
-
|
|
1364
|
-
/**
|
|
1365
|
-
* Creates a reusable {@link validateParse} function.
|
|
1366
|
-
*
|
|
1367
|
-
* @danger You have to specify the generic argument `T`
|
|
1368
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1369
|
-
* @throws compile error
|
|
1370
|
-
*
|
|
1371
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1372
|
-
*/
|
|
1373
|
-
export function createValidateParse(): never;
|
|
1374
|
-
|
|
1375
|
-
/**
|
|
1376
|
-
* Creates a reusable {@link validateParse} function.
|
|
1377
|
-
*
|
|
1378
|
-
* @template T Expected type of parsed value
|
|
1379
|
-
* @returns A reusable `validateParse` function
|
|
1380
|
-
*
|
|
1381
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1382
|
-
*/
|
|
1383
|
-
export function createValidateParse<T>(): (input: string) => IValidation<T>;
|
|
1384
|
-
|
|
1385
|
-
/**
|
|
1386
|
-
* @internal
|
|
1387
|
-
*/
|
|
1388
|
-
export function createValidateParse<T>(): (input: string) => IValidation<T> {
|
|
1389
|
-
halt("createValidateParse");
|
|
1390
|
-
}
|
|
1391
|
-
Object.assign(createValidateParse, validateParse);
|
|
1392
|
-
|
|
1393
|
-
/**
|
|
1394
|
-
* Creates a reusable {@link stringify} function.
|
|
1395
|
-
*
|
|
1396
|
-
* @danger You have to specify the generic argument `T`
|
|
1397
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1398
|
-
* @throws compile error
|
|
1399
|
-
*
|
|
1400
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1401
|
-
*/
|
|
1402
|
-
export function createStringify(): never;
|
|
1403
|
-
|
|
1404
|
-
/**
|
|
1405
|
-
* Creates a reusable {@link stringify} function.
|
|
1406
|
-
*
|
|
1407
|
-
* @template T Type of the input value
|
|
1408
|
-
* @returns A reusable `stringify` function
|
|
1409
|
-
*
|
|
1410
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1411
|
-
*/
|
|
1412
|
-
export function createStringify<T>(): (input: T) => string;
|
|
1413
|
-
|
|
1414
|
-
/**
|
|
1415
|
-
* @internal
|
|
1416
|
-
*/
|
|
1417
|
-
export function createStringify<T>(): (input: T) => string {
|
|
1418
|
-
halt("createStringify");
|
|
1419
|
-
}
|
|
1420
|
-
Object.assign(createStringify, stringify);
|
|
1421
|
-
|
|
1422
|
-
/**
|
|
1423
|
-
* Creates a reusable {@link assertStringify} function.
|
|
1424
|
-
*
|
|
1425
|
-
* @danger You have to specify the generic argument `T`
|
|
1426
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1427
|
-
* @throws compile error
|
|
1428
|
-
*
|
|
1429
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1430
|
-
*/
|
|
1431
|
-
export function createAssertStringify(): never;
|
|
1432
|
-
|
|
1433
|
-
/**
|
|
1434
|
-
* Creates a reusable {@link assertStringify} function.
|
|
1435
|
-
*
|
|
1436
|
-
* @template T Type of the input value
|
|
1437
|
-
* @returns A reusable `assertStringify` function
|
|
1438
|
-
*
|
|
1439
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1440
|
-
*/
|
|
1441
|
-
export function createAssertStringify<T>(): (input: unknown) => string;
|
|
1442
|
-
|
|
1443
|
-
/**
|
|
1444
|
-
* @internal
|
|
1445
|
-
*/
|
|
1446
|
-
export function createAssertStringify(): (input: unknown) => string {
|
|
1447
|
-
halt("createAssertStringify");
|
|
1448
|
-
}
|
|
1449
|
-
Object.assign(createAssertStringify, assertStringify);
|
|
1450
|
-
|
|
1451
|
-
/**
|
|
1452
|
-
* Creates a reusable {@link isStringify} function.
|
|
1453
|
-
*
|
|
1454
|
-
* @danger You have to specify the generic argument `T`
|
|
1455
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1456
|
-
* @throws compile error
|
|
1457
|
-
*
|
|
1458
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1459
|
-
*/
|
|
1460
|
-
export function createIsStringify(): never;
|
|
1461
|
-
|
|
1462
|
-
/**
|
|
1463
|
-
* Creates a reusable {@link isStringify} function.
|
|
1464
|
-
*
|
|
1465
|
-
* @template T Type of the input value
|
|
1466
|
-
* @returns A reusable `isStringify` function
|
|
1467
|
-
*
|
|
1468
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1469
|
-
*/
|
|
1470
|
-
export function createIsStringify<T>(): (input: unknown) => string | null;
|
|
1471
|
-
|
|
1472
|
-
/**
|
|
1473
|
-
* @internal
|
|
1474
|
-
*/
|
|
1475
|
-
export function createIsStringify(): (input: unknown) => string | null {
|
|
1476
|
-
halt("createIsStringify");
|
|
1477
|
-
}
|
|
1478
|
-
Object.assign(createIsStringify, isStringify);
|
|
1479
|
-
|
|
1480
|
-
/**
|
|
1481
|
-
* Creates a reusable {@link validateStringify} function.
|
|
1482
|
-
*
|
|
1483
|
-
* @danger You have to specify the generic argument `T`
|
|
1484
|
-
* @return Nothing until specifying the generic argument `T`
|
|
1485
|
-
* @throws compile error
|
|
1486
|
-
*
|
|
1487
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1488
|
-
*/
|
|
1489
|
-
export function createValidateStringify(): never;
|
|
1490
|
-
|
|
1491
|
-
/**
|
|
1492
|
-
* Creates a reusable {@link validateStringify} function.
|
|
1493
|
-
*
|
|
1494
|
-
* @template T Type of the input value
|
|
1495
|
-
* @returns A reusable `validateStringify` function
|
|
1496
|
-
*
|
|
1497
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
1498
|
-
*/
|
|
1499
|
-
export function createValidateStringify<T>(): (
|
|
1500
|
-
input: unknown,
|
|
1501
|
-
) => IValidation<string>;
|
|
1502
|
-
|
|
1503
|
-
/**
|
|
1504
|
-
* @internal
|
|
1505
|
-
*/
|
|
1506
|
-
export function createValidateStringify(): (
|
|
1507
|
-
input: unknown,
|
|
1508
|
-
) => IValidation<string> {
|
|
1509
|
-
halt("createValidateStringify");
|
|
1510
|
-
}
|
|
1511
|
-
Object.assign(createValidateStringify, validateStringify);
|
|
1512
|
-
|
|
1513
|
-
/* -----------------------------------------------------------
|
|
1514
|
-
MISCELLANEOUS
|
|
1515
|
-
----------------------------------------------------------- */
|
|
1516
|
-
/**
|
|
1517
|
-
* @internal
|
|
1518
|
-
*/
|
|
1519
|
-
export function metadata<Types extends unknown[]>(): IMetadataApplication;
|
|
1520
|
-
|
|
1521
|
-
/**
|
|
1522
|
-
* @internal
|
|
1523
|
-
*/
|
|
1524
|
-
export function metadata(): never {
|
|
1525
|
-
halt("metadata");
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
/**
|
|
1529
|
-
* @internal
|
|
1530
|
-
*/
|
|
1531
|
-
function halt(name: string): never {
|
|
1532
|
-
throw new Error(
|
|
1533
|
-
`Error on typia.${name}(): no transform has been configured. Configure the "tsconfig.json" file following the [README.md#setup](https://github.com/samchon/typia#setup)`,
|
|
1534
|
-
);
|
|
1535
|
-
}
|
|
1
|
+
import { $every } from "./functional/$every";
|
|
2
|
+
import { $guard } from "./functional/$guard";
|
|
3
|
+
import { $is_email } from "./functional/$is_email";
|
|
4
|
+
import { $is_ipv4 } from "./functional/$is_ipv4";
|
|
5
|
+
import { $is_ipv6 } from "./functional/$is_ipv6";
|
|
6
|
+
import { $is_url } from "./functional/$is_url";
|
|
7
|
+
import { $is_uuid } from "./functional/$is_uuid";
|
|
8
|
+
import { $join } from "./functional/$join";
|
|
9
|
+
import { $number } from "./functional/$number";
|
|
10
|
+
import { $report } from "./functional/$report";
|
|
11
|
+
import { $rest } from "./functional/$rest";
|
|
12
|
+
import { $string } from "./functional/$string";
|
|
13
|
+
import { $tail } from "./functional/$tail";
|
|
14
|
+
|
|
15
|
+
import { IMetadataApplication } from "./metadata/IMetadataApplication";
|
|
16
|
+
import { IJsonApplication } from "./schemas/IJsonApplication";
|
|
17
|
+
|
|
18
|
+
import { IValidation } from "./IValidation";
|
|
19
|
+
import { TypeGuardError } from "./TypeGuardError";
|
|
20
|
+
|
|
21
|
+
export * from "./schemas/IJsonApplication";
|
|
22
|
+
export * from "./schemas/IJsonComponents";
|
|
23
|
+
export * from "./schemas/IJsonSchema";
|
|
24
|
+
export * from "./Primitive";
|
|
25
|
+
export * from "./TypeGuardError";
|
|
26
|
+
export * from "./IValidation";
|
|
27
|
+
|
|
28
|
+
/* ===========================================================
|
|
29
|
+
SINGLE FUNCTIONS
|
|
30
|
+
- BASIC VALIDATORS
|
|
31
|
+
- STRICT VALIDATORS
|
|
32
|
+
- JSON FUNCTIONS
|
|
33
|
+
==============================================================
|
|
34
|
+
BASIC VALIDATORS
|
|
35
|
+
----------------------------------------------------------- */
|
|
36
|
+
/**
|
|
37
|
+
* Asserts a value type.
|
|
38
|
+
*
|
|
39
|
+
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
40
|
+
* reason, if the parametric value is not following the type `T`. Otherwise, the
|
|
41
|
+
* value is following the type `T`, just input parameter would be returned.
|
|
42
|
+
*
|
|
43
|
+
* If what you want is not asserting but just knowing whether the parametric value is
|
|
44
|
+
* following the type `T` or not, you can choose the {@link is} function instead.
|
|
45
|
+
* Otherwise you want to know all the errors, {@link validate} is the way to go.
|
|
46
|
+
*
|
|
47
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
48
|
+
* enrolled to the type `T`, you can use {@link assertEquals} function instead.
|
|
49
|
+
*
|
|
50
|
+
* @template T Type of the input value
|
|
51
|
+
* @param input A value to be asserted
|
|
52
|
+
* @returns Parametric input value
|
|
53
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
54
|
+
*
|
|
55
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
56
|
+
*/
|
|
57
|
+
export function assert<T>(input: T): T;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Asserts a value type.
|
|
61
|
+
*
|
|
62
|
+
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
63
|
+
* reason, if the parametric value is not following the type `T`. Otherwise, the
|
|
64
|
+
* value is following the type `T`, just input parameter would be returned.
|
|
65
|
+
*
|
|
66
|
+
* If what you want is not asserting but just knowing whether the parametric value is
|
|
67
|
+
* following the type `T` or not, you can choose the {@link is} function instead.
|
|
68
|
+
* Otherwise, you want to know all the errors, {@link validate} is the way to go.
|
|
69
|
+
*
|
|
70
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
71
|
+
* enrolled to the type `T`, you can use {@link assertEquals} function instead.
|
|
72
|
+
*
|
|
73
|
+
* @template T Type of the input value
|
|
74
|
+
* @param input A value to be asserted
|
|
75
|
+
* @returns Parametric input value casted as `T`
|
|
76
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
77
|
+
*
|
|
78
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
79
|
+
*/
|
|
80
|
+
export function assert<T>(input: unknown): T;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
85
|
+
export function assert(): never {
|
|
86
|
+
halt("assert");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
export namespace assert {
|
|
93
|
+
export const is_uuid = $is_uuid;
|
|
94
|
+
export const is_email = $is_email;
|
|
95
|
+
export const is_url = $is_url;
|
|
96
|
+
export const is_ipv4 = $is_ipv4;
|
|
97
|
+
export const is_ipv6 = $is_ipv6;
|
|
98
|
+
|
|
99
|
+
export const join = $join;
|
|
100
|
+
export const every = $every;
|
|
101
|
+
export const guard = $guard("typia.assert");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Asserts a value type.
|
|
106
|
+
*
|
|
107
|
+
* Duplicated function of {@link assert} for `typescript-is` users.
|
|
108
|
+
*
|
|
109
|
+
* @template T Type of the input value
|
|
110
|
+
* @param input A value to be asserted
|
|
111
|
+
* @returns Parametric input value
|
|
112
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
113
|
+
*
|
|
114
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
115
|
+
* @deprecated
|
|
116
|
+
*/
|
|
117
|
+
export function assertType<T>(input: T): T;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Asserts a value type.
|
|
121
|
+
*
|
|
122
|
+
* Duplicated function of {@link assert} for `typescript-is` users.
|
|
123
|
+
*
|
|
124
|
+
* @template T Type of the input value
|
|
125
|
+
* @param input A value to be asserted
|
|
126
|
+
* @returns Parametric input value
|
|
127
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
128
|
+
*
|
|
129
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
130
|
+
* @deprecated
|
|
131
|
+
*/
|
|
132
|
+
export function assertType<T>(input: unknown): T;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @internal
|
|
136
|
+
*/
|
|
137
|
+
export function assertType(): never {
|
|
138
|
+
halt("assertType");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
export namespace assertType {
|
|
145
|
+
// FOR LEGACY FUNCTIONS
|
|
146
|
+
export function predicate(
|
|
147
|
+
matched: boolean,
|
|
148
|
+
exceptionable: boolean,
|
|
149
|
+
closure: () => Omit<TypeGuardError.IProps, "method">,
|
|
150
|
+
): boolean {
|
|
151
|
+
if (matched === false && exceptionable === true)
|
|
152
|
+
throw new TypeGuardError({
|
|
153
|
+
method: "typia.assertType",
|
|
154
|
+
...closure(),
|
|
155
|
+
});
|
|
156
|
+
return matched;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
Object.assign(assertType, assert);
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Tests a value type.
|
|
163
|
+
*
|
|
164
|
+
* Tests a parametric value type and returns whether it's following the type `T` or not.
|
|
165
|
+
* If the parametric value is matched with the type `T`, `true` value would be returned.
|
|
166
|
+
* Otherwise, the parametric value is not following the type `T`, `false` value would be
|
|
167
|
+
* returned.
|
|
168
|
+
*
|
|
169
|
+
* If what you want is not just knowing whether the parametric value is following the
|
|
170
|
+
* type `T` or not, but throwing an exception with detailed reason, you can choose
|
|
171
|
+
* {@link assert} function instead. Also, if you want to know all the errors with
|
|
172
|
+
* detailed reasons, {@link validate} function would be useful.
|
|
173
|
+
*
|
|
174
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
175
|
+
* enrolled to the type `T`, you can use {@link equals} function instead.
|
|
176
|
+
*
|
|
177
|
+
* @template T Type of the input value
|
|
178
|
+
* @param input A value to be tested
|
|
179
|
+
* @returns Whether the parametric value is following the type `T` or not
|
|
180
|
+
*
|
|
181
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
182
|
+
*/
|
|
183
|
+
export function is<T>(input: T): input is T;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Tests a value type.
|
|
187
|
+
*
|
|
188
|
+
* Tests a parametric value type and returns whether it's following the type `T` or not.
|
|
189
|
+
* If the parametric value is matched with the type `T`, `true` value would be returned.
|
|
190
|
+
* Otherwise, the parametric value is not following the type `T`, `false` value would be
|
|
191
|
+
* returned.
|
|
192
|
+
*
|
|
193
|
+
* If what you want is not just knowing whether the parametric value is following the
|
|
194
|
+
* type `T` or not, but throwing an exception with detailed reason, you can choose
|
|
195
|
+
* {@link assert} function instead. Also, if you want to know all the errors with
|
|
196
|
+
* detailed reasons, {@link validate} function would be useful.
|
|
197
|
+
*
|
|
198
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
199
|
+
* enrolled to the type `T`, you can use {@link equals} function instead.
|
|
200
|
+
*
|
|
201
|
+
* @template T Type of the input value
|
|
202
|
+
* @param input A value to be tested
|
|
203
|
+
* @returns Whether the parametric value is following the type `T` or not
|
|
204
|
+
*
|
|
205
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
206
|
+
*/
|
|
207
|
+
export function is<T>(input: unknown): input is T;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* @internal
|
|
211
|
+
*/
|
|
212
|
+
export function is(): never {
|
|
213
|
+
halt("is");
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @internal
|
|
218
|
+
*/
|
|
219
|
+
export namespace is {
|
|
220
|
+
export const is_uuid = $is_uuid;
|
|
221
|
+
export const is_email = $is_email;
|
|
222
|
+
export const is_url = $is_url;
|
|
223
|
+
export const is_ipv4 = $is_ipv4;
|
|
224
|
+
export const is_ipv6 = $is_ipv6;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Validates a value type.
|
|
229
|
+
*
|
|
230
|
+
* Validates a parametric value type and archives all the type errors into an
|
|
231
|
+
* {@link IValidation.errors} array, if the parametric value is not following the
|
|
232
|
+
* type `T`. Of course, if the parametric value is following the type `T`, the
|
|
233
|
+
* {@link IValidation.errors} array would be empty and {@link IValidation.success}
|
|
234
|
+
* would have the `true` value.
|
|
235
|
+
*
|
|
236
|
+
* If what you want is not finding all the error, but asserting the parametric value
|
|
237
|
+
* type with exception throwing, you can choose {@link assert} function instead.
|
|
238
|
+
* Otherwise, you just want to know whether the parametric value is matched with the
|
|
239
|
+
* type `T`, {@link is} function is the way to go.
|
|
240
|
+
*
|
|
241
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
242
|
+
* enrolled to the type `T`, you can use {@link validateEquals} function instead.
|
|
243
|
+
*
|
|
244
|
+
* @template Type of the input value
|
|
245
|
+
* @param input A value to be validated
|
|
246
|
+
* @returns Validation result
|
|
247
|
+
*
|
|
248
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
249
|
+
*/
|
|
250
|
+
export function validate<T>(input: T): IValidation<T>;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Validates a value type.
|
|
254
|
+
*
|
|
255
|
+
* Validates a parametric value type and archives all the type errors into an
|
|
256
|
+
* {@link IValidation.errors} array, if the parametric value is not following the
|
|
257
|
+
* type `T`. Of course, if the parametric value is following the type `T`, the
|
|
258
|
+
* {@link IValidation.errors} array would be empty and {@link IValidation.success}
|
|
259
|
+
* would have the `true` value.
|
|
260
|
+
*
|
|
261
|
+
* If what you want is not finding all the error, but asserting the parametric value
|
|
262
|
+
* type with exception throwing, you can choose {@link assert} function instead.
|
|
263
|
+
* Otherwise, you just want to know whether the parametric value is matched with the
|
|
264
|
+
* type `T`, {@link is} function is the way to go.
|
|
265
|
+
*
|
|
266
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
267
|
+
* enrolled to the type `T`, you can use {@link validateEquals} function instead.
|
|
268
|
+
*
|
|
269
|
+
* @template Type of the input value
|
|
270
|
+
* @param input A value to be validated
|
|
271
|
+
* @returns Validation result
|
|
272
|
+
*
|
|
273
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
274
|
+
*/
|
|
275
|
+
export function validate<T>(input: unknown): IValidation<T>;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @internal
|
|
279
|
+
*/
|
|
280
|
+
export function validate(): never {
|
|
281
|
+
halt("validate");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @internal
|
|
286
|
+
*/
|
|
287
|
+
export namespace validate {
|
|
288
|
+
export const is_uuid = $is_uuid;
|
|
289
|
+
export const is_email = $is_email;
|
|
290
|
+
export const is_url = $is_url;
|
|
291
|
+
export const is_ipv4 = $is_ipv4;
|
|
292
|
+
export const is_ipv6 = $is_ipv6;
|
|
293
|
+
|
|
294
|
+
export const join = $join;
|
|
295
|
+
export const report = $report;
|
|
296
|
+
|
|
297
|
+
// FOR LEGACY FUNCTIONS
|
|
298
|
+
export const predicate =
|
|
299
|
+
(res: IValidation) =>
|
|
300
|
+
(
|
|
301
|
+
matched: boolean,
|
|
302
|
+
exceptionable: boolean,
|
|
303
|
+
closure: () => IValidation.IError,
|
|
304
|
+
) => {
|
|
305
|
+
// CHECK FAILURE
|
|
306
|
+
if (matched === false && exceptionable === true)
|
|
307
|
+
(() => {
|
|
308
|
+
res.success &&= false;
|
|
309
|
+
const errorList = (res as IValidation.IFailure).errors;
|
|
310
|
+
|
|
311
|
+
// TRACE ERROR
|
|
312
|
+
const error = closure();
|
|
313
|
+
if (errorList.length) {
|
|
314
|
+
const last = errorList[errorList.length - 1]!.path;
|
|
315
|
+
if (
|
|
316
|
+
last.length >= error.path.length &&
|
|
317
|
+
last.substring(0, error.path.length) === error.path
|
|
318
|
+
)
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
errorList.push(error);
|
|
322
|
+
return;
|
|
323
|
+
})();
|
|
324
|
+
return matched;
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/* -----------------------------------------------------------
|
|
329
|
+
STRICT VALIDATORS
|
|
330
|
+
----------------------------------------------------------- */
|
|
331
|
+
/**
|
|
332
|
+
* Asserts equality between a value and its type.
|
|
333
|
+
*
|
|
334
|
+
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
335
|
+
* reason, if the parametric value is not following the type `T` or some superfluous
|
|
336
|
+
* property that is not listed on the type `T` has been found. Otherwise, the value is
|
|
337
|
+
* following the type `T` without any superfluous property, just input parameter would
|
|
338
|
+
* be returned.
|
|
339
|
+
*
|
|
340
|
+
* If what you want is not asserting but just knowing whether the parametric value is
|
|
341
|
+
* following the type `T` or not, you can choose the {@link equals} function instead.
|
|
342
|
+
* Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
|
|
343
|
+
*
|
|
344
|
+
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
345
|
+
* to the type `T`, you can use {@link assert} function instead.
|
|
346
|
+
*
|
|
347
|
+
* @template T Type of the input value
|
|
348
|
+
* @param input A value to be asserted
|
|
349
|
+
* @returns Parametric input value
|
|
350
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
351
|
+
*
|
|
352
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
353
|
+
*/
|
|
354
|
+
export function assertEquals<T>(input: T): T;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Asserts equality between a value and its type.
|
|
358
|
+
*
|
|
359
|
+
* Asserts a parametric value type and throws a {@link TypeGuardError} with detailed
|
|
360
|
+
* reason, if the parametric value is not following the type `T` or some superfluous
|
|
361
|
+
* property that is not listed on the type `T` has been found. Otherwise, the value is
|
|
362
|
+
* following the type `T` without any superfluous property, just input parameter would
|
|
363
|
+
* be returned.
|
|
364
|
+
*
|
|
365
|
+
* If what you want is not asserting but just knowing whether the parametric value is
|
|
366
|
+
* following the type `T` or not, you can choose the {@link equals} function instead.
|
|
367
|
+
* Otherwise, you want to know all the errors, {@link validateEquals} is the way to go.
|
|
368
|
+
*
|
|
369
|
+
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
370
|
+
* to the type `T`, you can use {@link assert} function instead.
|
|
371
|
+
*
|
|
372
|
+
* @template T Type of the input value
|
|
373
|
+
* @param input A value to be asserted
|
|
374
|
+
* @returns Parametric input value casted as `T`
|
|
375
|
+
* @throws A {@link TypeGuardError} instance with detailed reason
|
|
376
|
+
*
|
|
377
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
378
|
+
*/
|
|
379
|
+
export function assertEquals<T>(input: unknown): T;
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* @internal
|
|
383
|
+
*/
|
|
384
|
+
export function assertEquals<T>(): never {
|
|
385
|
+
halt("assertEquals");
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* @internal
|
|
390
|
+
*/
|
|
391
|
+
export namespace assertEquals {
|
|
392
|
+
export const is_uuid = $is_uuid;
|
|
393
|
+
export const is_email = $is_email;
|
|
394
|
+
export const is_url = $is_url;
|
|
395
|
+
export const is_ipv4 = $is_ipv4;
|
|
396
|
+
export const is_ipv6 = $is_ipv6;
|
|
397
|
+
|
|
398
|
+
export const join = $join;
|
|
399
|
+
export const every = $every;
|
|
400
|
+
// export const guardV2 = $guardV2("typia.assertEquals");
|
|
401
|
+
export const guard = $guard("typia.assertEquals");
|
|
402
|
+
|
|
403
|
+
// FOR LEGACY FUNCTIONS
|
|
404
|
+
export function predicate(
|
|
405
|
+
matched: boolean,
|
|
406
|
+
exceptionable: boolean,
|
|
407
|
+
closure: () => Omit<TypeGuardError.IProps, "method">,
|
|
408
|
+
): boolean {
|
|
409
|
+
if (matched === false && exceptionable === true)
|
|
410
|
+
throw new TypeGuardError({
|
|
411
|
+
method: "typia.assertEquals",
|
|
412
|
+
...closure(),
|
|
413
|
+
});
|
|
414
|
+
return matched;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Tests equality between a value and its type.
|
|
420
|
+
*
|
|
421
|
+
* Tests a parametric value type and returns whether it's equivalent to the type `T`
|
|
422
|
+
* or not. If the parametric value is matched with the type `T` and there's not any
|
|
423
|
+
* superfluous property that is not listed on the type `T`, `true` value would be
|
|
424
|
+
* returned. Otherwise, the parametric value is not following the type `T` or some
|
|
425
|
+
* superfluous property exists, `false` value would be returned.
|
|
426
|
+
*
|
|
427
|
+
* If what you want is not just knowing whether the parametric value is following the
|
|
428
|
+
* type `T` or not, but throwing an exception with detailed reason, you can choose
|
|
429
|
+
* {@link assertEquals} function instead. Also, if you want to know all the errors with
|
|
430
|
+
* detailed reasons, {@link validateEquals} function would be useful.
|
|
431
|
+
*
|
|
432
|
+
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
433
|
+
* to the type `T`, you can use {@link is} function instead.
|
|
434
|
+
*
|
|
435
|
+
* @template T Type of the input value
|
|
436
|
+
* @param input A value to be tested
|
|
437
|
+
* @returns Whether the parametric value is equivalent to the type `T` or not
|
|
438
|
+
*
|
|
439
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
440
|
+
*/
|
|
441
|
+
export function equals<T>(input: T): input is T;
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Tests equality between a value and its type.
|
|
445
|
+
*
|
|
446
|
+
* Tests a parametric value type and returns whether it's equivalent to the type `T`
|
|
447
|
+
* or not. If the parametric value is matched with the type `T` and there's not any
|
|
448
|
+
* superfluous property that is not listed on the type `T`, `true` value would be
|
|
449
|
+
* returned. Otherwise, the parametric value is not following the type `T` or some
|
|
450
|
+
* superfluous property exists, `false` value would be returned.
|
|
451
|
+
*
|
|
452
|
+
* If what you want is not just knowing whether the parametric value is following the
|
|
453
|
+
* type `T` or not, but throwing an exception with detailed reason, you can choose
|
|
454
|
+
* {@link assertEquals} function instead. Also, if you want to know all the errors with
|
|
455
|
+
* detailed reasons, {@link validateEquals} function would be useful.
|
|
456
|
+
*
|
|
457
|
+
* On the other hand, if you want to allow superfluous property that is not enrolled
|
|
458
|
+
* to the type `T`, you can use {@link is} function instead.
|
|
459
|
+
*
|
|
460
|
+
* @template T Type of the input value
|
|
461
|
+
* @param input A value to be tested
|
|
462
|
+
* @returns Whether the parametric value is equivalent to the type `T` or not
|
|
463
|
+
*
|
|
464
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
465
|
+
*/
|
|
466
|
+
export function equals<T>(input: unknown): input is T;
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @internal
|
|
470
|
+
*/
|
|
471
|
+
export function equals(): never {
|
|
472
|
+
halt("equals");
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* @internal
|
|
477
|
+
*/
|
|
478
|
+
export namespace equals {
|
|
479
|
+
export const is_uuid = $is_uuid;
|
|
480
|
+
export const is_email = $is_email;
|
|
481
|
+
export const is_url = $is_url;
|
|
482
|
+
export const is_ipv4 = $is_ipv4;
|
|
483
|
+
export const is_ipv6 = $is_ipv6;
|
|
484
|
+
export const join = $join;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Validates equality between a value and its type.
|
|
489
|
+
*
|
|
490
|
+
* Validates a parametric value type and archives all the type errors into an
|
|
491
|
+
* {@link IValidation.errors} array, if the parametric value is not following the
|
|
492
|
+
* type `T` or some superfluous property that is not listed on the type `T` has been
|
|
493
|
+
* found. Of course, if the parametric value is following the type `T` and no
|
|
494
|
+
* superfluous property exists, the {@link IValidation.errors} array would be empty
|
|
495
|
+
* and {@link IValidation.success} would have the `true` value.
|
|
496
|
+
*
|
|
497
|
+
* If what you want is not finding all the error, but asserting the parametric value
|
|
498
|
+
* type with exception throwing, you can choose {@link assert} function instead.
|
|
499
|
+
* Otherwise, you just want to know whether the parametric value is matched with the
|
|
500
|
+
* type `T`, {@link is} function is the way to go.
|
|
501
|
+
*
|
|
502
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
503
|
+
* enrolled to the type `T`, you can use {@link validateEquals} function instead.
|
|
504
|
+
*
|
|
505
|
+
* @template Type of the input value
|
|
506
|
+
* @param input A value to be validated
|
|
507
|
+
* @returns Validation result
|
|
508
|
+
*
|
|
509
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
510
|
+
*/
|
|
511
|
+
export function validateEquals<T>(input: T): IValidation<T>;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Validates equality between a value and its type.
|
|
515
|
+
*
|
|
516
|
+
* Validates a parametric value type and archives all the type errors into an
|
|
517
|
+
* {@link IValidation.errors} array, if the parametric value is not following the
|
|
518
|
+
* type `T` or some superfluous property that is not listed on the type `T` has been
|
|
519
|
+
* found. Of course, if the parametric value is following the type `T` and no
|
|
520
|
+
* superfluous property exists, the {@link IValidation.errors} array would be empty
|
|
521
|
+
* and {@link IValidation.success} would have the `true` value.
|
|
522
|
+
*
|
|
523
|
+
* If what you want is not finding all the error, but asserting the parametric value
|
|
524
|
+
* type with exception throwing, you can choose {@link assert} function instead.
|
|
525
|
+
* Otherwise, you just want to know whether the parametric value is matched with the
|
|
526
|
+
* type `T`, {@link is} function is the way to go.
|
|
527
|
+
*
|
|
528
|
+
* On the other and, if you don't want to allow any superfluous property that is not
|
|
529
|
+
* enrolled to the type `T`, you can use {@link validateEquals} function instead.
|
|
530
|
+
*
|
|
531
|
+
* @template Type of the input value
|
|
532
|
+
* @param input A value to be validated
|
|
533
|
+
* @returns Validation result
|
|
534
|
+
*
|
|
535
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
536
|
+
*/
|
|
537
|
+
export function validateEquals<T>(input: unknown): IValidation<T>;
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* @internal
|
|
541
|
+
*/
|
|
542
|
+
export function validateEquals(): never {
|
|
543
|
+
halt("validateEquals");
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* @internal
|
|
548
|
+
*/
|
|
549
|
+
export namespace validateEquals {
|
|
550
|
+
export const is_uuid = $is_uuid;
|
|
551
|
+
export const is_email = $is_email;
|
|
552
|
+
export const is_url = $is_url;
|
|
553
|
+
export const is_ipv4 = $is_ipv4;
|
|
554
|
+
export const is_ipv6 = $is_ipv6;
|
|
555
|
+
export const join = $join;
|
|
556
|
+
|
|
557
|
+
export const report = validate.report;
|
|
558
|
+
|
|
559
|
+
// FOR LEGACY FUNCTIONS
|
|
560
|
+
export const predicate =
|
|
561
|
+
(res: IValidation) =>
|
|
562
|
+
(
|
|
563
|
+
matched: boolean,
|
|
564
|
+
exceptionable: boolean,
|
|
565
|
+
closure: () => IValidation.IError,
|
|
566
|
+
) => {
|
|
567
|
+
// CHECK FAILURE
|
|
568
|
+
if (matched === false && exceptionable === true)
|
|
569
|
+
(() => {
|
|
570
|
+
res.success &&= false;
|
|
571
|
+
const errorList = (res as IValidation.IFailure).errors;
|
|
572
|
+
|
|
573
|
+
// TRACE ERROR
|
|
574
|
+
const error = closure();
|
|
575
|
+
if (errorList.length) {
|
|
576
|
+
const last = errorList[errorList.length - 1]!.path;
|
|
577
|
+
if (
|
|
578
|
+
last.length >= error.path.length &&
|
|
579
|
+
last.substring(0, error.path.length) === error.path
|
|
580
|
+
)
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
errorList.push(error);
|
|
584
|
+
return;
|
|
585
|
+
})();
|
|
586
|
+
return matched;
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
/* -----------------------------------------------------------
|
|
591
|
+
JSON FUNCTIONS
|
|
592
|
+
----------------------------------------------------------- */
|
|
593
|
+
/**
|
|
594
|
+
* > You must configure the generic argument `T`.
|
|
595
|
+
*
|
|
596
|
+
* JSON Schema Application.
|
|
597
|
+
*
|
|
598
|
+
* Creates a JSON schema application which contains both main JSON schemas and components.
|
|
599
|
+
* Note that, all of the object types are stored in the {@link IJsonApplication.components}
|
|
600
|
+
* property for the `$ref` referencing.
|
|
601
|
+
*
|
|
602
|
+
* Also, `typia.application()` has additional generic arguments, *Purpose*.
|
|
603
|
+
* As JSON schema definitions used by `swagger` and `ajv` are different a little bit,
|
|
604
|
+
* you should configure the *Purpose* appropriately.
|
|
605
|
+
*
|
|
606
|
+
* For an example, `ajv` has an extra property "$recursiveRef" that are not exists
|
|
607
|
+
* in the standard JSON schema definition spec. Otherwise, `swagger` can't identify
|
|
608
|
+
* the tuple definition.
|
|
609
|
+
*
|
|
610
|
+
* @template Types Tuple of target types
|
|
611
|
+
* @template Purpose Purpose of the JSON schema`
|
|
612
|
+
* @template Prefix Prefix of the JSON components referenced by `$ref` tag
|
|
613
|
+
* @return JSON schema application
|
|
614
|
+
*
|
|
615
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
616
|
+
*/
|
|
617
|
+
export function application(): never;
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* JSON Schema Application.
|
|
621
|
+
*
|
|
622
|
+
* Creates a JSON schema application which contains both main JSON schemas and components.
|
|
623
|
+
* Note that, all of the object types are stored in the {@link IJsonApplication.components}
|
|
624
|
+
* property for the `$ref` referencing.
|
|
625
|
+
*
|
|
626
|
+
* Also, `typia.application()` has additional generic arguments, *Purpose*.
|
|
627
|
+
* As JSON schema definitions used by `swagger` and `ajv` are different a little bit,
|
|
628
|
+
* you should configure the *Purpose* appropriately.
|
|
629
|
+
*
|
|
630
|
+
* For an example, `ajv` has an extra property "$recursiveRef" that are not exists
|
|
631
|
+
* in the standard JSON schema definition spec. Otherwise, `swagger` can't identify
|
|
632
|
+
* the tuple definition.
|
|
633
|
+
*
|
|
634
|
+
* @template Types Tuple of target types
|
|
635
|
+
* @template Purpose Purpose of the JSON schema
|
|
636
|
+
* @template Prefix Prefix of the JSON components referenced by `$ref` tag
|
|
637
|
+
* @return JSON schema application
|
|
638
|
+
*
|
|
639
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
640
|
+
*/
|
|
641
|
+
export function application<
|
|
642
|
+
Types extends unknown[],
|
|
643
|
+
Purpose extends "swagger" | "ajv" = "swagger",
|
|
644
|
+
Prefix extends string = Purpose extends "swagger"
|
|
645
|
+
? "#/components/schemas"
|
|
646
|
+
: "components#/schemas",
|
|
647
|
+
>(): IJsonApplication;
|
|
648
|
+
|
|
649
|
+
/**
|
|
650
|
+
* @internal
|
|
651
|
+
*/
|
|
652
|
+
export function application(): never {
|
|
653
|
+
halt("application");
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* > You must configure the generic argument `T`.
|
|
658
|
+
*
|
|
659
|
+
* Safe `JSON.parse()` function with type assertion.
|
|
660
|
+
*
|
|
661
|
+
* `typia.assertParse()` is a combination function of `JSON.parse()` and {@link assert}.
|
|
662
|
+
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
663
|
+
* instance with type assertion.
|
|
664
|
+
*
|
|
665
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
666
|
+
* throws {@link TypeGuardError}. Otherwise, there's no problem on the parsed value,
|
|
667
|
+
* the parsed value would be returned.
|
|
668
|
+
*
|
|
669
|
+
* @template T Expected type of parsed value
|
|
670
|
+
* @param input JSON string
|
|
671
|
+
* @returns Parsed value
|
|
672
|
+
*
|
|
673
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
674
|
+
*/
|
|
675
|
+
export function assertParse(input: string): never;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Safe `JSON.parse()` function with type assertion.
|
|
679
|
+
*
|
|
680
|
+
* `typia.assertParse()` is a combination function of `JSON.parse()` and {@link assert}.
|
|
681
|
+
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
682
|
+
* instance with type assertion.
|
|
683
|
+
*
|
|
684
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
685
|
+
* throws {@link TypeGuardError}. Otherwise, there's no problem on the parsed value,
|
|
686
|
+
* the parsed value would be returned.
|
|
687
|
+
*
|
|
688
|
+
* @template T Expected type of parsed value
|
|
689
|
+
* @param input JSON string
|
|
690
|
+
* @returns Parsed value
|
|
691
|
+
*
|
|
692
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
693
|
+
*/
|
|
694
|
+
export function assertParse<T>(input: string): T;
|
|
695
|
+
|
|
696
|
+
/**
|
|
697
|
+
* @internal
|
|
698
|
+
*/
|
|
699
|
+
export function assertParse<T>(): T {
|
|
700
|
+
halt("assertParse");
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* @internal
|
|
705
|
+
*/
|
|
706
|
+
export namespace assertParse {
|
|
707
|
+
export const is_uuid = $is_uuid;
|
|
708
|
+
export const is_email = $is_email;
|
|
709
|
+
export const is_url = $is_url;
|
|
710
|
+
export const is_ipv4 = $is_ipv4;
|
|
711
|
+
export const is_ipv6 = $is_ipv6;
|
|
712
|
+
|
|
713
|
+
export const join = $join;
|
|
714
|
+
export const every = $every;
|
|
715
|
+
export const guard = $guard("typia.assertParse");
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* > You must configure the generic argument `T`.
|
|
720
|
+
*
|
|
721
|
+
* Safe `JSON.parse()` function with type checking.
|
|
722
|
+
*
|
|
723
|
+
* `typia.isParse()` is a combination function of `JSON.parse()` and {@link is}.
|
|
724
|
+
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
725
|
+
* instance with type checking.
|
|
726
|
+
*
|
|
727
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
728
|
+
* returns `null` value. Otherwise, there's no problem on the parsed value, the parsed
|
|
729
|
+
* value would be returned.
|
|
730
|
+
*
|
|
731
|
+
* @template T Expected type of parsed value
|
|
732
|
+
* @param input JSON string
|
|
733
|
+
* @returns Parsed value when exact type, otherwise `null`
|
|
734
|
+
*
|
|
735
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
736
|
+
*/
|
|
737
|
+
export function isParse(input: string): never;
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Safe `JSON.parse()` function with type checking.
|
|
741
|
+
*
|
|
742
|
+
* `typia.isParse()` is a combination function of `JSON.parse()` and {@link is}.
|
|
743
|
+
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
744
|
+
* instance with type checking.
|
|
745
|
+
*
|
|
746
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
747
|
+
* returns `null` value. Otherwise, there's no problem on the parsed value, the parsed
|
|
748
|
+
* value would be returned.
|
|
749
|
+
*
|
|
750
|
+
* @template T Expected type of parsed value
|
|
751
|
+
* @param input JSON string
|
|
752
|
+
* @returns Parsed value when exact type, otherwise `null`
|
|
753
|
+
*
|
|
754
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
755
|
+
*/
|
|
756
|
+
export function isParse<T>(input: string): T | null;
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* @internal
|
|
760
|
+
*/
|
|
761
|
+
export function isParse<T>(): T | null {
|
|
762
|
+
halt("isParse");
|
|
763
|
+
}
|
|
764
|
+
Object.assign(isParse, is);
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* > You must configure the generic argument `T`.
|
|
768
|
+
*
|
|
769
|
+
* Safe `JSON.parse()` function with detailed type validation.
|
|
770
|
+
*
|
|
771
|
+
* `typia.validateParse()` is a combination function of `JSON.parse()` and
|
|
772
|
+
* {@link validate}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
773
|
+
* to a `T` typed instance with detailed type validation.
|
|
774
|
+
*
|
|
775
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
776
|
+
* returns {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
777
|
+
* there's no problem on the parsed value, the parsed value would be stored in `data`
|
|
778
|
+
* property of the output {@link IValidation.ISuccess} instance.
|
|
779
|
+
*
|
|
780
|
+
* @template T Expected type of parsed value
|
|
781
|
+
* @param input JSON string
|
|
782
|
+
* @returns Validation result with JSON parsed value
|
|
783
|
+
*
|
|
784
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
785
|
+
*/
|
|
786
|
+
export function validateParse(input: string): never;
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Safe `JSON.parse()` function with detailed type validation.
|
|
790
|
+
*
|
|
791
|
+
* `typia.validateParse()` is a combination function of `JSON.parse()` and
|
|
792
|
+
* {@link validate}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
793
|
+
* to a `T` typed instance with detailed type validation.
|
|
794
|
+
*
|
|
795
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
796
|
+
* returns {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
797
|
+
* there's no problem on the parsed value, the parsed value would be stored in `data`
|
|
798
|
+
* property of the output {@link IValidation.ISuccess} instance.
|
|
799
|
+
*
|
|
800
|
+
* @template T Expected type of parsed value
|
|
801
|
+
* @param input JSON string
|
|
802
|
+
* @returns Validation result with JSON parsed value
|
|
803
|
+
*
|
|
804
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
805
|
+
*/
|
|
806
|
+
export function validateParse<T>(input: string): IValidation<T>;
|
|
807
|
+
|
|
808
|
+
/**
|
|
809
|
+
* @internal
|
|
810
|
+
*/
|
|
811
|
+
export function validateParse<T>(): IValidation<T> {
|
|
812
|
+
halt("validateParse");
|
|
813
|
+
}
|
|
814
|
+
Object.assign(validateParse, validate);
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* 8x faster `JSON.stringify()` function.
|
|
818
|
+
*
|
|
819
|
+
* Converts an input value to a JSON (JavaScript Object Notation) string, about 8x faster
|
|
820
|
+
* than the native `JSON.stringify()` function. The 5x faster principle is because
|
|
821
|
+
* it writes an optimized JSON conversion plan, only for the type `T`.
|
|
822
|
+
*
|
|
823
|
+
* For reference, this `typia.stringify()` does not validate the input value type. It
|
|
824
|
+
* just believes that the input value is following the type `T`. Therefore, if you
|
|
825
|
+
* can't ensure the input value type, it would be better to call one of below functions
|
|
826
|
+
* instead.
|
|
827
|
+
*
|
|
828
|
+
* - {@link assertStringify}
|
|
829
|
+
* - {@link isStringify}
|
|
830
|
+
* - {@link validateStringify}
|
|
831
|
+
*
|
|
832
|
+
* @template T Type of the input value
|
|
833
|
+
* @param input A value to be converted
|
|
834
|
+
* @return JSON string value
|
|
835
|
+
*
|
|
836
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
837
|
+
*/
|
|
838
|
+
export function stringify<T>(input: T): string;
|
|
839
|
+
|
|
840
|
+
/**
|
|
841
|
+
* @internal
|
|
842
|
+
*/
|
|
843
|
+
export function stringify(): never {
|
|
844
|
+
halt("stringify");
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* @internal
|
|
849
|
+
*/
|
|
850
|
+
export namespace stringify {
|
|
851
|
+
export const number = $number;
|
|
852
|
+
export const string = $string;
|
|
853
|
+
export const tail = $tail;
|
|
854
|
+
export const rest = $rest;
|
|
855
|
+
|
|
856
|
+
export function throws(
|
|
857
|
+
props: Pick<TypeGuardError.IProps, "expected" | "value">,
|
|
858
|
+
): void {
|
|
859
|
+
throw new TypeGuardError({
|
|
860
|
+
...props,
|
|
861
|
+
method: "typia.stringify",
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* 5x faster `JSON.stringify()` function with type assertion.
|
|
868
|
+
*
|
|
869
|
+
* `typia.assertStringify()` is a combination function of {@link assert} and
|
|
870
|
+
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
871
|
+
* Notation) string, with type assertion.
|
|
872
|
+
*
|
|
873
|
+
* In such reason, when `input` value is not matched with the type `T`, it throws an
|
|
874
|
+
* {@link TypeGuardError}. Otherwise, there's no problem on the `input` value, JSON
|
|
875
|
+
* string would be returned.
|
|
876
|
+
*
|
|
877
|
+
* For reference, with type assertion, it is even 5x times faster than the native
|
|
878
|
+
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
879
|
+
* with confidence.
|
|
880
|
+
*
|
|
881
|
+
* @template T Type of the input value
|
|
882
|
+
* @param input A value to be asserted and converted
|
|
883
|
+
* @return JSON string value
|
|
884
|
+
*
|
|
885
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
886
|
+
*/
|
|
887
|
+
export function assertStringify<T>(input: T): string;
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* 5x faster `JSON.stringify()` function with type assertion.
|
|
891
|
+
*
|
|
892
|
+
* `typia.assertStringify()` is a combination function of {@link assert} and
|
|
893
|
+
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
894
|
+
* Notation) string, with type assertion.
|
|
895
|
+
*
|
|
896
|
+
* In such reason, when `input` value is not matched with the type `T`, it throws an
|
|
897
|
+
* {@link TypeGuardError}. Otherwise, there's no problem on the `input` value, JSON
|
|
898
|
+
* string would be returned.
|
|
899
|
+
*
|
|
900
|
+
* For reference, with type assertion, it is even 5x times faster than the native
|
|
901
|
+
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
902
|
+
* with confidence.
|
|
903
|
+
*
|
|
904
|
+
* @template T Type of the input value
|
|
905
|
+
* @param input A value to be asserted and converted
|
|
906
|
+
* @return JSON string value
|
|
907
|
+
*
|
|
908
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
909
|
+
*/
|
|
910
|
+
export function assertStringify<T>(input: T): unknown;
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* @internal
|
|
914
|
+
*/
|
|
915
|
+
export function assertStringify(): string {
|
|
916
|
+
halt("assertStringify");
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* @internal
|
|
921
|
+
*/
|
|
922
|
+
export namespace assertStringify {
|
|
923
|
+
export const is_uuid = $is_uuid;
|
|
924
|
+
export const is_email = $is_email;
|
|
925
|
+
export const is_url = $is_url;
|
|
926
|
+
export const is_ipv4 = $is_ipv4;
|
|
927
|
+
export const is_ipv6 = $is_ipv6;
|
|
928
|
+
|
|
929
|
+
export const number = $number;
|
|
930
|
+
export const string = $string;
|
|
931
|
+
export const tail = $tail;
|
|
932
|
+
export const rest = $rest;
|
|
933
|
+
|
|
934
|
+
export const join = $join;
|
|
935
|
+
export const guard = $guard("typia.assertStringify");
|
|
936
|
+
export const every = $every;
|
|
937
|
+
export const throws = () => {};
|
|
938
|
+
|
|
939
|
+
// FOR LEGACY FUNCTIONS
|
|
940
|
+
export function predicate(
|
|
941
|
+
matched: boolean,
|
|
942
|
+
exceptionable: boolean,
|
|
943
|
+
closure: () => Omit<TypeGuardError.IProps, "method">,
|
|
944
|
+
): boolean {
|
|
945
|
+
if (matched === false && exceptionable === true)
|
|
946
|
+
throw new TypeGuardError({
|
|
947
|
+
method: "typia.assertStringify",
|
|
948
|
+
...closure(),
|
|
949
|
+
});
|
|
950
|
+
return matched;
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
/**
|
|
955
|
+
* 7x faster `JSON.stringify()` function with type checking.
|
|
956
|
+
*
|
|
957
|
+
* `typia.stringify()` is a combination function of {@link is} and
|
|
958
|
+
* {@link stringify}. Therefore, it converts an input value to JSON
|
|
959
|
+
* (JavaScript Object Notation) string, with type checking.
|
|
960
|
+
*
|
|
961
|
+
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
962
|
+
* `null` value. Otherwise, there's no problem on the `input` value, JSON string would
|
|
963
|
+
* be returned.
|
|
964
|
+
*
|
|
965
|
+
* For reference, with type checking, it is even 7x times faster than the native
|
|
966
|
+
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
967
|
+
* with confidence.
|
|
968
|
+
*
|
|
969
|
+
* @template T Type of the input value
|
|
970
|
+
* @param input A value to be checked and converted
|
|
971
|
+
* @return JSON string value when exact type, otherwise null
|
|
972
|
+
*
|
|
973
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
974
|
+
*/
|
|
975
|
+
export function isStringify<T>(input: T): string | null;
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* 7x faster `JSON.stringify()` function with type checking.
|
|
979
|
+
*
|
|
980
|
+
* `typia.isStringify()` is a combination function of {@link is} and
|
|
981
|
+
* {@link stringify}. Therefore, it converts an input value to JSON
|
|
982
|
+
* (JavaScript Object Notation) string, with type checking.
|
|
983
|
+
*
|
|
984
|
+
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
985
|
+
* `null` value. Otherwise, there's no problem on the `input` value, JSON string would
|
|
986
|
+
* be returned.
|
|
987
|
+
*
|
|
988
|
+
* For reference, with type checking, it is even 7x times faster than the native
|
|
989
|
+
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
990
|
+
* with confidence.
|
|
991
|
+
*
|
|
992
|
+
* @template T Type of the input value
|
|
993
|
+
* @param input A value to be checked and converted
|
|
994
|
+
* @return JSON string value when exact type, otherwise null
|
|
995
|
+
*
|
|
996
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
997
|
+
*/
|
|
998
|
+
export function isStringify<T>(input: unknown): string | null;
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* @internal
|
|
1002
|
+
*/
|
|
1003
|
+
export function isStringify<T>(): string | null {
|
|
1004
|
+
halt("isStringify");
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* @internal
|
|
1009
|
+
*/
|
|
1010
|
+
export namespace isStringify {
|
|
1011
|
+
export const is_uuid = $is_uuid;
|
|
1012
|
+
export const is_email = $is_email;
|
|
1013
|
+
export const is_url = $is_url;
|
|
1014
|
+
export const is_ipv4 = $is_ipv4;
|
|
1015
|
+
export const is_ipv6 = $is_ipv6;
|
|
1016
|
+
|
|
1017
|
+
export const number = $number;
|
|
1018
|
+
export const string = $string;
|
|
1019
|
+
export const tail = $tail;
|
|
1020
|
+
export const rest = $rest;
|
|
1021
|
+
|
|
1022
|
+
export const throws = () => {};
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
1027
|
+
*
|
|
1028
|
+
* `typia.validateStringify()` is a combination function of {@link validate} and
|
|
1029
|
+
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
1030
|
+
* Notation) string, with detailed type validation.
|
|
1031
|
+
*
|
|
1032
|
+
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
1033
|
+
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's no
|
|
1034
|
+
* problem on the `input` value, JSON string would be stored in `data` property of
|
|
1035
|
+
* the output {@link IValidation.ISuccess} instance.
|
|
1036
|
+
*
|
|
1037
|
+
* For reference, with detailed type validation, it is even 5x times faster than the
|
|
1038
|
+
* native `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
1039
|
+
* with confidence.
|
|
1040
|
+
*
|
|
1041
|
+
* @template T Type of the input value
|
|
1042
|
+
* @param input A value to be checked and converted
|
|
1043
|
+
* @returns Validation result with JSON string value
|
|
1044
|
+
*
|
|
1045
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1046
|
+
*/
|
|
1047
|
+
export function validateStringify<T>(input: T): IValidation<string>;
|
|
1048
|
+
|
|
1049
|
+
/**
|
|
1050
|
+
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
1051
|
+
*
|
|
1052
|
+
* `typia.validateStringify()` is a combination function of {@link validate} and
|
|
1053
|
+
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
1054
|
+
* Notation) string, with detailed type validation.
|
|
1055
|
+
*
|
|
1056
|
+
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
1057
|
+
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise, there's no
|
|
1058
|
+
* problem on the `input` value, JSON string would be stored in `data` property of
|
|
1059
|
+
* the output {@link IValidation.ISuccess} instance.
|
|
1060
|
+
*
|
|
1061
|
+
* For reference, with detailed type validation, it is even 5x times faster than the
|
|
1062
|
+
* native `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
1063
|
+
* with confidence.
|
|
1064
|
+
*
|
|
1065
|
+
* @template T Type of the input value
|
|
1066
|
+
* @param input A value to be checked and converted
|
|
1067
|
+
* @returns Validation result with JSON string value
|
|
1068
|
+
*
|
|
1069
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1070
|
+
*/
|
|
1071
|
+
export function validateStringify<T>(input: unknown): IValidation<string>;
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* @internal
|
|
1075
|
+
*/
|
|
1076
|
+
export function validateStringify(): IValidation<string> {
|
|
1077
|
+
halt("validateStringify");
|
|
1078
|
+
}
|
|
1079
|
+
Object.assign(validateStringify, validate);
|
|
1080
|
+
Object.assign(validateStringify, stringify);
|
|
1081
|
+
|
|
1082
|
+
/* ===========================================================
|
|
1083
|
+
FACTORY FUNCTIONS
|
|
1084
|
+
- BASIC VALIDATORS
|
|
1085
|
+
- STRICT VALIDATORS
|
|
1086
|
+
- JSON FUNCTIONS
|
|
1087
|
+
- MISCELLANEOUS
|
|
1088
|
+
==============================================================
|
|
1089
|
+
BASIC VALIDATORS
|
|
1090
|
+
----------------------------------------------------------- */
|
|
1091
|
+
/**
|
|
1092
|
+
* Creates a reusable {@link assert} function.
|
|
1093
|
+
*
|
|
1094
|
+
* @danger You have to specify the generic argument `T`
|
|
1095
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1096
|
+
* @throws compile error
|
|
1097
|
+
*
|
|
1098
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1099
|
+
*/
|
|
1100
|
+
export function createAssert(): never;
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Creates a reusable {@link assert} function.
|
|
1104
|
+
*
|
|
1105
|
+
* @template T Type of the input value
|
|
1106
|
+
* @returns A reusable `assert` function
|
|
1107
|
+
*
|
|
1108
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1109
|
+
*/
|
|
1110
|
+
export function createAssert<T>(): (input: unknown) => T;
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* @internal
|
|
1114
|
+
*/
|
|
1115
|
+
export function createAssert<T>(): (input: unknown) => T {
|
|
1116
|
+
halt("createAssert");
|
|
1117
|
+
}
|
|
1118
|
+
Object.assign(createAssert, assert);
|
|
1119
|
+
|
|
1120
|
+
/**
|
|
1121
|
+
* Creates a reusable {@link assertType} function.
|
|
1122
|
+
*
|
|
1123
|
+
* Duplicated function of {@link createAssert} for `typescript-is` users.
|
|
1124
|
+
*
|
|
1125
|
+
* @danger You have to specify the generic argument `T`
|
|
1126
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1127
|
+
* @throws compile error
|
|
1128
|
+
*
|
|
1129
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1130
|
+
* @deprecated
|
|
1131
|
+
*/
|
|
1132
|
+
export function createAssertType(): never;
|
|
1133
|
+
|
|
1134
|
+
/**
|
|
1135
|
+
* Creates a reusable {@link assertType} function.
|
|
1136
|
+
*
|
|
1137
|
+
* Duplicated function of {@link createAssert} for `typescript-is` users.
|
|
1138
|
+
*
|
|
1139
|
+
* @template T Type of the input value
|
|
1140
|
+
* @returns A reusable `assert` function
|
|
1141
|
+
*
|
|
1142
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1143
|
+
* @deprecated
|
|
1144
|
+
*/
|
|
1145
|
+
export function createAssertType<T>(): (input: unknown) => T;
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* @internal
|
|
1149
|
+
*/
|
|
1150
|
+
export function createAssertType<T>(): (input: unknown) => T {
|
|
1151
|
+
halt("createAssertType");
|
|
1152
|
+
}
|
|
1153
|
+
Object.assign(createAssertType, assertType);
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* Creates a reusable {@link is} function.
|
|
1157
|
+
*
|
|
1158
|
+
* @danger You have to specify the generic argument `T`
|
|
1159
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1160
|
+
* @throws compile error
|
|
1161
|
+
*
|
|
1162
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1163
|
+
*/
|
|
1164
|
+
export function createIs(): never;
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Creates a reusable {@link is} function.
|
|
1168
|
+
*
|
|
1169
|
+
* @template T Type of the input value
|
|
1170
|
+
* @returns A reusable `is` function
|
|
1171
|
+
*
|
|
1172
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1173
|
+
*/
|
|
1174
|
+
export function createIs<T>(): (input: unknown) => input is T;
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* @internal
|
|
1178
|
+
*/
|
|
1179
|
+
export function createIs<T>(): (input: unknown) => input is T {
|
|
1180
|
+
halt("createIs");
|
|
1181
|
+
}
|
|
1182
|
+
Object.assign(createIs, is);
|
|
1183
|
+
|
|
1184
|
+
/**
|
|
1185
|
+
* Creates a reusable {@link validate} function.
|
|
1186
|
+
*
|
|
1187
|
+
* @danger You have to specify the generic argument `T`
|
|
1188
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1189
|
+
* @throws compile error
|
|
1190
|
+
*
|
|
1191
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1192
|
+
*/
|
|
1193
|
+
export function createValidate(): never;
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* Creates a reusable {@link validate} function.
|
|
1197
|
+
*
|
|
1198
|
+
* @template T Type of the input value
|
|
1199
|
+
* @returns A reusable `validate` function
|
|
1200
|
+
*
|
|
1201
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1202
|
+
*/
|
|
1203
|
+
export function createValidate<T>(): (input: unknown) => IValidation<T>;
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* @internal
|
|
1207
|
+
*/
|
|
1208
|
+
export function createValidate(): (input: unknown) => IValidation {
|
|
1209
|
+
halt("createValidate");
|
|
1210
|
+
}
|
|
1211
|
+
Object.assign(createValidate, validate);
|
|
1212
|
+
|
|
1213
|
+
/* -----------------------------------------------------------
|
|
1214
|
+
STRICT VALIDATORS
|
|
1215
|
+
----------------------------------------------------------- */
|
|
1216
|
+
/**
|
|
1217
|
+
* Creates a reusable {@link assertEquals} function.
|
|
1218
|
+
*
|
|
1219
|
+
* @danger You have to specify the generic argument `T`
|
|
1220
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1221
|
+
* @throws compile error
|
|
1222
|
+
*
|
|
1223
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1224
|
+
*/
|
|
1225
|
+
export function createAssertEquals(): never;
|
|
1226
|
+
|
|
1227
|
+
/**
|
|
1228
|
+
* Creates a reusable {@link assertEquals} function.
|
|
1229
|
+
*
|
|
1230
|
+
* @template T Type of the input value
|
|
1231
|
+
* @returns A reusable `assertEquals` function
|
|
1232
|
+
*
|
|
1233
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1234
|
+
*/
|
|
1235
|
+
export function createAssertEquals<T>(): (input: unknown) => T;
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* @internal
|
|
1239
|
+
*/
|
|
1240
|
+
export function createAssertEquals<T>(): (input: unknown) => T {
|
|
1241
|
+
halt("createAssertEquals");
|
|
1242
|
+
}
|
|
1243
|
+
Object.assign(createAssertEquals, assertEquals);
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* Creates a reusable {@link equals} function.
|
|
1247
|
+
*
|
|
1248
|
+
* @danger You have to specify the generic argument `T`
|
|
1249
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1250
|
+
* @throws compile error
|
|
1251
|
+
*
|
|
1252
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1253
|
+
*/
|
|
1254
|
+
export function createEquals(): never;
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Creates a reusable {@link equals} function.
|
|
1258
|
+
*
|
|
1259
|
+
* @template T Type of the input value
|
|
1260
|
+
* @returns A reusable `equals` function
|
|
1261
|
+
*
|
|
1262
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1263
|
+
*/
|
|
1264
|
+
export function createEquals<T>(): (input: unknown) => input is T;
|
|
1265
|
+
|
|
1266
|
+
/**
|
|
1267
|
+
* @internal
|
|
1268
|
+
*/
|
|
1269
|
+
export function createEquals<T>(): (input: unknown) => input is T {
|
|
1270
|
+
halt("createEquals");
|
|
1271
|
+
}
|
|
1272
|
+
Object.assign(createEquals, equals);
|
|
1273
|
+
|
|
1274
|
+
/**
|
|
1275
|
+
* Creates a reusable {@link validateEquals} function.
|
|
1276
|
+
*
|
|
1277
|
+
* @danger You have to specify the generic argument `T`
|
|
1278
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1279
|
+
* @throws compile error
|
|
1280
|
+
*
|
|
1281
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1282
|
+
*/
|
|
1283
|
+
export function createValidateEquals(): never;
|
|
1284
|
+
|
|
1285
|
+
/**
|
|
1286
|
+
* Creates a reusable {@link validateEquals} function.
|
|
1287
|
+
*
|
|
1288
|
+
* @template T Type of the input value
|
|
1289
|
+
* @returns A reusable `validateEquals` function
|
|
1290
|
+
*
|
|
1291
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1292
|
+
*/
|
|
1293
|
+
export function createValidateEquals<T>(): (input: unknown) => IValidation;
|
|
1294
|
+
|
|
1295
|
+
/**
|
|
1296
|
+
* @internal
|
|
1297
|
+
*/
|
|
1298
|
+
export function createValidateEquals(): (input: unknown) => IValidation {
|
|
1299
|
+
halt("createValidateEquals");
|
|
1300
|
+
}
|
|
1301
|
+
Object.assign(createValidateEquals, validateEquals);
|
|
1302
|
+
|
|
1303
|
+
/* -----------------------------------------------------------
|
|
1304
|
+
JSON FUNCTIONS
|
|
1305
|
+
----------------------------------------------------------- */
|
|
1306
|
+
/**
|
|
1307
|
+
* Creates a reusable {@link isParse} function.
|
|
1308
|
+
*
|
|
1309
|
+
* @danger You have to specify the generic argument `T`
|
|
1310
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1311
|
+
* @throws compile error
|
|
1312
|
+
*
|
|
1313
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1314
|
+
*/
|
|
1315
|
+
export function createIsParse(): never;
|
|
1316
|
+
|
|
1317
|
+
/**
|
|
1318
|
+
* Creates a reusable {@link isParse} function.
|
|
1319
|
+
*
|
|
1320
|
+
* @template T Expected type of parsed value
|
|
1321
|
+
* @returns A reusable `isParse` function
|
|
1322
|
+
*
|
|
1323
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1324
|
+
*/
|
|
1325
|
+
export function createIsParse<T>(): (input: string) => T | null;
|
|
1326
|
+
|
|
1327
|
+
/**
|
|
1328
|
+
* @internal
|
|
1329
|
+
*/
|
|
1330
|
+
export function createIsParse<T>(): (input: string) => T | null {
|
|
1331
|
+
halt("createIsParse");
|
|
1332
|
+
}
|
|
1333
|
+
Object.assign(createIsParse, isParse);
|
|
1334
|
+
|
|
1335
|
+
/**
|
|
1336
|
+
* Creates a reusable {@link assertParse} function.
|
|
1337
|
+
*
|
|
1338
|
+
* @danger You have to specify the generic argument `T`
|
|
1339
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1340
|
+
* @throws compile error
|
|
1341
|
+
*
|
|
1342
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1343
|
+
*/
|
|
1344
|
+
export function createAssertParse(): never;
|
|
1345
|
+
|
|
1346
|
+
/**
|
|
1347
|
+
* Creates a reusable {@link assertParse} function.
|
|
1348
|
+
*
|
|
1349
|
+
* @template T Expected type of parsed value
|
|
1350
|
+
* @returns A reusable `assertParse` function
|
|
1351
|
+
*
|
|
1352
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1353
|
+
*/
|
|
1354
|
+
export function createAssertParse<T>(): (input: string) => T;
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* @internal
|
|
1358
|
+
*/
|
|
1359
|
+
export function createAssertParse<T>(): (input: string) => T {
|
|
1360
|
+
halt("createAssertParse");
|
|
1361
|
+
}
|
|
1362
|
+
Object.assign(createAssertParse, assertParse);
|
|
1363
|
+
|
|
1364
|
+
/**
|
|
1365
|
+
* Creates a reusable {@link validateParse} function.
|
|
1366
|
+
*
|
|
1367
|
+
* @danger You have to specify the generic argument `T`
|
|
1368
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1369
|
+
* @throws compile error
|
|
1370
|
+
*
|
|
1371
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1372
|
+
*/
|
|
1373
|
+
export function createValidateParse(): never;
|
|
1374
|
+
|
|
1375
|
+
/**
|
|
1376
|
+
* Creates a reusable {@link validateParse} function.
|
|
1377
|
+
*
|
|
1378
|
+
* @template T Expected type of parsed value
|
|
1379
|
+
* @returns A reusable `validateParse` function
|
|
1380
|
+
*
|
|
1381
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1382
|
+
*/
|
|
1383
|
+
export function createValidateParse<T>(): (input: string) => IValidation<T>;
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
* @internal
|
|
1387
|
+
*/
|
|
1388
|
+
export function createValidateParse<T>(): (input: string) => IValidation<T> {
|
|
1389
|
+
halt("createValidateParse");
|
|
1390
|
+
}
|
|
1391
|
+
Object.assign(createValidateParse, validateParse);
|
|
1392
|
+
|
|
1393
|
+
/**
|
|
1394
|
+
* Creates a reusable {@link stringify} function.
|
|
1395
|
+
*
|
|
1396
|
+
* @danger You have to specify the generic argument `T`
|
|
1397
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1398
|
+
* @throws compile error
|
|
1399
|
+
*
|
|
1400
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1401
|
+
*/
|
|
1402
|
+
export function createStringify(): never;
|
|
1403
|
+
|
|
1404
|
+
/**
|
|
1405
|
+
* Creates a reusable {@link stringify} function.
|
|
1406
|
+
*
|
|
1407
|
+
* @template T Type of the input value
|
|
1408
|
+
* @returns A reusable `stringify` function
|
|
1409
|
+
*
|
|
1410
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1411
|
+
*/
|
|
1412
|
+
export function createStringify<T>(): (input: T) => string;
|
|
1413
|
+
|
|
1414
|
+
/**
|
|
1415
|
+
* @internal
|
|
1416
|
+
*/
|
|
1417
|
+
export function createStringify<T>(): (input: T) => string {
|
|
1418
|
+
halt("createStringify");
|
|
1419
|
+
}
|
|
1420
|
+
Object.assign(createStringify, stringify);
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* Creates a reusable {@link assertStringify} function.
|
|
1424
|
+
*
|
|
1425
|
+
* @danger You have to specify the generic argument `T`
|
|
1426
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1427
|
+
* @throws compile error
|
|
1428
|
+
*
|
|
1429
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1430
|
+
*/
|
|
1431
|
+
export function createAssertStringify(): never;
|
|
1432
|
+
|
|
1433
|
+
/**
|
|
1434
|
+
* Creates a reusable {@link assertStringify} function.
|
|
1435
|
+
*
|
|
1436
|
+
* @template T Type of the input value
|
|
1437
|
+
* @returns A reusable `assertStringify` function
|
|
1438
|
+
*
|
|
1439
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1440
|
+
*/
|
|
1441
|
+
export function createAssertStringify<T>(): (input: unknown) => string;
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* @internal
|
|
1445
|
+
*/
|
|
1446
|
+
export function createAssertStringify(): (input: unknown) => string {
|
|
1447
|
+
halt("createAssertStringify");
|
|
1448
|
+
}
|
|
1449
|
+
Object.assign(createAssertStringify, assertStringify);
|
|
1450
|
+
|
|
1451
|
+
/**
|
|
1452
|
+
* Creates a reusable {@link isStringify} function.
|
|
1453
|
+
*
|
|
1454
|
+
* @danger You have to specify the generic argument `T`
|
|
1455
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1456
|
+
* @throws compile error
|
|
1457
|
+
*
|
|
1458
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1459
|
+
*/
|
|
1460
|
+
export function createIsStringify(): never;
|
|
1461
|
+
|
|
1462
|
+
/**
|
|
1463
|
+
* Creates a reusable {@link isStringify} function.
|
|
1464
|
+
*
|
|
1465
|
+
* @template T Type of the input value
|
|
1466
|
+
* @returns A reusable `isStringify` function
|
|
1467
|
+
*
|
|
1468
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1469
|
+
*/
|
|
1470
|
+
export function createIsStringify<T>(): (input: unknown) => string | null;
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* @internal
|
|
1474
|
+
*/
|
|
1475
|
+
export function createIsStringify(): (input: unknown) => string | null {
|
|
1476
|
+
halt("createIsStringify");
|
|
1477
|
+
}
|
|
1478
|
+
Object.assign(createIsStringify, isStringify);
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* Creates a reusable {@link validateStringify} function.
|
|
1482
|
+
*
|
|
1483
|
+
* @danger You have to specify the generic argument `T`
|
|
1484
|
+
* @return Nothing until specifying the generic argument `T`
|
|
1485
|
+
* @throws compile error
|
|
1486
|
+
*
|
|
1487
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1488
|
+
*/
|
|
1489
|
+
export function createValidateStringify(): never;
|
|
1490
|
+
|
|
1491
|
+
/**
|
|
1492
|
+
* Creates a reusable {@link validateStringify} function.
|
|
1493
|
+
*
|
|
1494
|
+
* @template T Type of the input value
|
|
1495
|
+
* @returns A reusable `validateStringify` function
|
|
1496
|
+
*
|
|
1497
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
1498
|
+
*/
|
|
1499
|
+
export function createValidateStringify<T>(): (
|
|
1500
|
+
input: unknown,
|
|
1501
|
+
) => IValidation<string>;
|
|
1502
|
+
|
|
1503
|
+
/**
|
|
1504
|
+
* @internal
|
|
1505
|
+
*/
|
|
1506
|
+
export function createValidateStringify(): (
|
|
1507
|
+
input: unknown,
|
|
1508
|
+
) => IValidation<string> {
|
|
1509
|
+
halt("createValidateStringify");
|
|
1510
|
+
}
|
|
1511
|
+
Object.assign(createValidateStringify, validateStringify);
|
|
1512
|
+
|
|
1513
|
+
/* -----------------------------------------------------------
|
|
1514
|
+
MISCELLANEOUS
|
|
1515
|
+
----------------------------------------------------------- */
|
|
1516
|
+
/**
|
|
1517
|
+
* @internal
|
|
1518
|
+
*/
|
|
1519
|
+
export function metadata<Types extends unknown[]>(): IMetadataApplication;
|
|
1520
|
+
|
|
1521
|
+
/**
|
|
1522
|
+
* @internal
|
|
1523
|
+
*/
|
|
1524
|
+
export function metadata(): never {
|
|
1525
|
+
halt("metadata");
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
/**
|
|
1529
|
+
* @internal
|
|
1530
|
+
*/
|
|
1531
|
+
function halt(name: string): never {
|
|
1532
|
+
throw new Error(
|
|
1533
|
+
`Error on typia.${name}(): no transform has been configured. Configure the "tsconfig.json" file following the [README.md#setup](https://github.com/samchon/typia#setup)`,
|
|
1534
|
+
);
|
|
1535
|
+
}
|