typia 6.9.0-dev.20240821 → 6.10.0-dev.20240823
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/lib/json.d.ts +1 -1
- package/lib/schemas/json/IJsonApplication.d.ts +5 -3
- package/package.json +1 -1
- package/src/factories/MetadataCommentTagFactory.ts +534 -534
- package/src/json.ts +738 -738
- package/src/schemas/json/IJsonApplication.ts +22 -16
- package/src/utils/Escaper.ts +46 -46
package/src/json.ts
CHANGED
|
@@ -1,738 +1,738 @@
|
|
|
1
|
-
import * as Namespace from "./functional/Namespace";
|
|
2
|
-
|
|
3
|
-
import { IJsonApplication } from "./schemas/json/IJsonApplication";
|
|
4
|
-
|
|
5
|
-
import { IValidation } from "./IValidation";
|
|
6
|
-
import { Primitive } from "./Primitive";
|
|
7
|
-
import { TypeGuardError } from "./TypeGuardError";
|
|
8
|
-
|
|
9
|
-
/* ===========================================================
|
|
10
|
-
JSON
|
|
11
|
-
- SCHEMA
|
|
12
|
-
- PARSE
|
|
13
|
-
- STRINGIFY
|
|
14
|
-
- FACTORY FUNCTIONS
|
|
15
|
-
==============================================================
|
|
16
|
-
SCHEMA
|
|
17
|
-
----------------------------------------------------------- */
|
|
18
|
-
/**
|
|
19
|
-
* > You must configure the generic argument `Types`.
|
|
20
|
-
*
|
|
21
|
-
* JSON Schema Application.
|
|
22
|
-
*
|
|
23
|
-
* Creates a JSON schema application which contains both main JSON schemas and
|
|
24
|
-
* components. Note that, all of the named types are stored in the
|
|
25
|
-
* {@link IJsonApplication.components} property for the `$ref` referencing.
|
|
26
|
-
*
|
|
27
|
-
* Also, you can specify the OpenAPI version by configuring the second generic
|
|
28
|
-
* argument `Version`. For reference, the default version is `"3.1"`, and key
|
|
29
|
-
* different of `"3.0"` and `"3.1"` is whether supporting the tuple type or not.
|
|
30
|
-
*
|
|
31
|
-
* @template Types Tuple of target types
|
|
32
|
-
* @template Purpose Purpose of the JSON schema
|
|
33
|
-
* @template Surplus Allow surplus properties starting with `x-typia-` or not
|
|
34
|
-
* @return JSON schema application
|
|
35
|
-
*
|
|
36
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
37
|
-
*/
|
|
38
|
-
export function application(): never;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* JSON Schema Application.
|
|
42
|
-
*
|
|
43
|
-
* Creates a JSON schema application which contains both main JSON schemas and
|
|
44
|
-
* components. Note that, all of the named types are stored in the
|
|
45
|
-
* {@link IJsonApplication.components} property for the `$ref` referencing.
|
|
46
|
-
*
|
|
47
|
-
* Also, you can specify the OpenAPI version by configuring the second generic
|
|
48
|
-
* argument `Version`. For reference, the default version is `"3.1"`, and key
|
|
49
|
-
* different of `"3.0"` and `"3.1"` is whether supporting the tuple type or not.
|
|
50
|
-
*
|
|
51
|
-
* @template Types Tuple of target types
|
|
52
|
-
* @template Version Version of OpenAPI specification. Default is 3.1
|
|
53
|
-
* @return JSON schema application
|
|
54
|
-
*
|
|
55
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
56
|
-
*/
|
|
57
|
-
export function application<
|
|
58
|
-
Types extends unknown[],
|
|
59
|
-
Version extends "3.0" | "3.1" = "3.1",
|
|
60
|
-
>(): IJsonApplication<Version>;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @internal
|
|
64
|
-
*/
|
|
65
|
-
export function application(): never {
|
|
66
|
-
halt("application");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/* -----------------------------------------------------------
|
|
70
|
-
PARSE
|
|
71
|
-
----------------------------------------------------------- */
|
|
72
|
-
/**
|
|
73
|
-
* > You must configure the generic argument `T`.
|
|
74
|
-
*
|
|
75
|
-
* Safe `JSON.parse()` function with type assertion.
|
|
76
|
-
*
|
|
77
|
-
* `typia.json.assertParse()` is a combination function of `JSON.parse()` and
|
|
78
|
-
* {@link assert}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
79
|
-
* to a `T` typed instance with type assertion.
|
|
80
|
-
*
|
|
81
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
82
|
-
* throws {@link TypeGuardError} or custom error generated by *errorFactory*. Otherwise,
|
|
83
|
-
* there's no problem on the parsed value, the parsed value would be returned.
|
|
84
|
-
*
|
|
85
|
-
* @template T Expected type of parsed value
|
|
86
|
-
* @param input JSON string
|
|
87
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
88
|
-
* @returns Parsed value
|
|
89
|
-
*
|
|
90
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
91
|
-
*/
|
|
92
|
-
function assertParse(
|
|
93
|
-
input: string,
|
|
94
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
95
|
-
): never;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Safe `JSON.parse()` function with type assertion.
|
|
99
|
-
*
|
|
100
|
-
* `typia.json.assertParse()` is a combination function of `JSON.parse()` and
|
|
101
|
-
* {@link assert}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
102
|
-
* to a `T` typed instance with type assertion.
|
|
103
|
-
*
|
|
104
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`,
|
|
105
|
-
* it throws {@link TypeGuardError} or custom error generated by *errorFactory*.
|
|
106
|
-
* Otherwise, there's no problem on the parsed value, the parsed value would be
|
|
107
|
-
* returned.
|
|
108
|
-
*
|
|
109
|
-
* @template T Expected type of parsed value
|
|
110
|
-
* @param input JSON string
|
|
111
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
112
|
-
* @returns Parsed value
|
|
113
|
-
*
|
|
114
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
115
|
-
*/
|
|
116
|
-
function assertParse<T>(
|
|
117
|
-
input: string,
|
|
118
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
119
|
-
): Primitive<T>;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @internal
|
|
123
|
-
*/
|
|
124
|
-
function assertParse<T>(): Primitive<T> {
|
|
125
|
-
halt("assertParse");
|
|
126
|
-
}
|
|
127
|
-
const assertParsePure = /** @__PURE__ */ Object.assign<typeof assertParse, {}>(
|
|
128
|
-
assertParse,
|
|
129
|
-
/** @__PURE__ */ Namespace.assert("json.assertParse"),
|
|
130
|
-
);
|
|
131
|
-
export { assertParsePure as assertParse };
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* > You must configure the generic argument `T`.
|
|
135
|
-
*
|
|
136
|
-
* Safe `JSON.parse()` function with type checking.
|
|
137
|
-
*
|
|
138
|
-
* `typia.json.isParse()` is a combination function of `JSON.parse()` and {@link is}.
|
|
139
|
-
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
140
|
-
* instance with type checking.
|
|
141
|
-
*
|
|
142
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
143
|
-
* returns `null` value. Otherwise, there's no problem on the parsed value, the parsed
|
|
144
|
-
* value would be returned.
|
|
145
|
-
*
|
|
146
|
-
* @template T Expected type of parsed value
|
|
147
|
-
* @param input JSON string
|
|
148
|
-
* @returns Parsed value when exact type, otherwise `null`
|
|
149
|
-
*
|
|
150
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
151
|
-
*/
|
|
152
|
-
function isParse(input: string): never;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Safe `JSON.parse()` function with type checking.
|
|
156
|
-
*
|
|
157
|
-
* `typia.json.isParse()` is a combination function of `JSON.parse()` and {@link is}.
|
|
158
|
-
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
159
|
-
* instance with type checking.
|
|
160
|
-
*
|
|
161
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
162
|
-
* returns `null` value. Otherwise, there's no problem on the parsed value, the parsed
|
|
163
|
-
* value would be returned.
|
|
164
|
-
*
|
|
165
|
-
* @template T Expected type of parsed value
|
|
166
|
-
* @param input JSON string
|
|
167
|
-
* @returns Parsed value when exact type, otherwise `null`
|
|
168
|
-
*
|
|
169
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
170
|
-
*/
|
|
171
|
-
function isParse<T>(input: string): Primitive<T> | null;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @internal
|
|
175
|
-
*/
|
|
176
|
-
function isParse<T>(): Primitive<T> | null {
|
|
177
|
-
halt("isParse");
|
|
178
|
-
}
|
|
179
|
-
const isParsePure = /** @__PURE__ */ Object.assign<typeof isParse, {}>(
|
|
180
|
-
isParse,
|
|
181
|
-
/** @__PURE__ */ Namespace.is(),
|
|
182
|
-
);
|
|
183
|
-
export { isParsePure as isParse };
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* > You must configure the generic argument `T`.
|
|
187
|
-
*
|
|
188
|
-
* Safe `JSON.parse()` function with detailed type validation.
|
|
189
|
-
*
|
|
190
|
-
* `typia.json.validateParse()` is a combination function of `JSON.parse()` and
|
|
191
|
-
* {@link validate}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
192
|
-
* to a `T` typed instance with detailed type validation.
|
|
193
|
-
*
|
|
194
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
195
|
-
* returns {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
196
|
-
* there's no problem on the parsed value, the parsed value would be stored in `data`
|
|
197
|
-
* property of the output {@link IValidation.ISuccess} instance.
|
|
198
|
-
*
|
|
199
|
-
* @template T Expected type of parsed value
|
|
200
|
-
* @param input JSON string
|
|
201
|
-
* @returns Validation result with JSON parsed value
|
|
202
|
-
*
|
|
203
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
204
|
-
*/
|
|
205
|
-
function validateParse(input: string): never;
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Safe `JSON.parse()` function with detailed type validation.
|
|
209
|
-
*
|
|
210
|
-
* `typia.json.validateParse()` is a combination function of `JSON.parse()` and
|
|
211
|
-
* {@link validate}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
212
|
-
* to a `T` typed instance with detailed type validation.
|
|
213
|
-
*
|
|
214
|
-
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
215
|
-
* returns {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
216
|
-
* there's no problem on the parsed value, the parsed value would be stored in `data`
|
|
217
|
-
* property of the output {@link IValidation.ISuccess} instance.
|
|
218
|
-
*
|
|
219
|
-
* @template T Expected type of parsed value
|
|
220
|
-
* @param input JSON string
|
|
221
|
-
* @returns Validation result with JSON parsed value
|
|
222
|
-
*
|
|
223
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
224
|
-
*/
|
|
225
|
-
function validateParse<T>(input: string): IValidation<Primitive<T>>;
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* @internal
|
|
229
|
-
*/
|
|
230
|
-
function validateParse<T>(): IValidation<Primitive<T>> {
|
|
231
|
-
halt("validateParse");
|
|
232
|
-
}
|
|
233
|
-
const validateParsePure = /** @__PURE__ */ Object.assign<
|
|
234
|
-
typeof validateParse,
|
|
235
|
-
{}
|
|
236
|
-
>(validateParse, /** @__PURE__ */ Namespace.validate());
|
|
237
|
-
export { validateParsePure as validateParse };
|
|
238
|
-
|
|
239
|
-
/* -----------------------------------------------------------
|
|
240
|
-
STRINGIFY
|
|
241
|
-
----------------------------------------------------------- */
|
|
242
|
-
/**
|
|
243
|
-
* 8x faster `JSON.stringify()` function.
|
|
244
|
-
*
|
|
245
|
-
* Converts an input value to a JSON (JavaScript Object Notation) string, about 8x
|
|
246
|
-
* faster than the native `JSON.stringify()` function. The 5x faster principle is
|
|
247
|
-
* because it writes an optimized JSON conversion plan, only for the type `T`.
|
|
248
|
-
*
|
|
249
|
-
* For reference, this `typia.json.stringify()` does not validate the input value type.
|
|
250
|
-
* It just believes that the input value is following the type `T`. Therefore, if you
|
|
251
|
-
* can't ensure the input value type, it would be better to call one of below
|
|
252
|
-
* functions instead.
|
|
253
|
-
*
|
|
254
|
-
* - {@link assertStringify}
|
|
255
|
-
* - {@link isStringify}
|
|
256
|
-
* - {@link validateStringify}
|
|
257
|
-
*
|
|
258
|
-
* @template T Type of the input value
|
|
259
|
-
* @param input A value to be converted
|
|
260
|
-
* @return JSON string value
|
|
261
|
-
*
|
|
262
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
263
|
-
*/
|
|
264
|
-
function stringify<T>(input: T): string;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* @internal
|
|
268
|
-
*/
|
|
269
|
-
function stringify(): never {
|
|
270
|
-
halt("stringify");
|
|
271
|
-
}
|
|
272
|
-
const stringifyPure = /** @__PURE__ */ Object.assign<typeof stringify, {}>(
|
|
273
|
-
stringify,
|
|
274
|
-
/** @__PURE__ */ Namespace.json.stringify("stringify"),
|
|
275
|
-
);
|
|
276
|
-
export { stringifyPure as stringify };
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* 5x faster `JSON.stringify()` function with type assertion.
|
|
280
|
-
*
|
|
281
|
-
* `typia.json.assertStringify()` is a combination function of {@link assert} and
|
|
282
|
-
* {@link stringify}. Therefore, it converts an input value to
|
|
283
|
-
* JSON (JavaScript Object Notation) string, with type assertion.
|
|
284
|
-
*
|
|
285
|
-
* In such reason, when `input` value is not matched with the type `T`, it throws an
|
|
286
|
-
* {@link TypeGuardError} or custom error generated by *errorFactory*. Otherwise,
|
|
287
|
-
* there's no problem on the `input` value, JSON string would be returned.
|
|
288
|
-
*
|
|
289
|
-
* For reference, with type assertion, it is even 5x times faster than the native
|
|
290
|
-
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
291
|
-
* with confidence.
|
|
292
|
-
*
|
|
293
|
-
* @template T Type of the input value
|
|
294
|
-
* @param input A value to be asserted and converted
|
|
295
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
296
|
-
* @return JSON string value
|
|
297
|
-
*
|
|
298
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
299
|
-
*/
|
|
300
|
-
function assertStringify<T>(
|
|
301
|
-
input: T,
|
|
302
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
303
|
-
): string;
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* 5x faster `JSON.stringify()` function with type assertion.
|
|
307
|
-
*
|
|
308
|
-
* `typia.json.assertStringify()` is a combination function of {@link assert} and
|
|
309
|
-
* {@link stringify}. Therefore, it converts an input value to
|
|
310
|
-
* JSON (JavaScript Object Notation) string, with type assertion.
|
|
311
|
-
*
|
|
312
|
-
* In such reason, when `input` value is not matched with the type `T`, it throws an
|
|
313
|
-
* {@link TypeGuardError} or custom error generated by *errorFactory*. Otherwise,
|
|
314
|
-
* there's no problem on the `input` value, JSON string would be returned.
|
|
315
|
-
*
|
|
316
|
-
* For reference, with type assertion, it is even 5x times faster than the native
|
|
317
|
-
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
318
|
-
* with confidence.
|
|
319
|
-
*
|
|
320
|
-
* @template T Type of the input value
|
|
321
|
-
* @param input A value to be asserted and converted
|
|
322
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
323
|
-
* @return JSON string value
|
|
324
|
-
*
|
|
325
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
326
|
-
*/
|
|
327
|
-
function assertStringify<T>(
|
|
328
|
-
input: T,
|
|
329
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
330
|
-
): unknown;
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* @internal
|
|
334
|
-
*/
|
|
335
|
-
function assertStringify(): string {
|
|
336
|
-
halt("assertStringify");
|
|
337
|
-
}
|
|
338
|
-
const assertStringifyPure = /** @__PURE__ */ Object.assign<
|
|
339
|
-
typeof assertStringify,
|
|
340
|
-
{},
|
|
341
|
-
{}
|
|
342
|
-
>(
|
|
343
|
-
assertStringify,
|
|
344
|
-
/** @__PURE__ */ Namespace.assert("json.assertStringify"),
|
|
345
|
-
/** @__PURE__ */ Namespace.json.stringify("assertStringify"),
|
|
346
|
-
);
|
|
347
|
-
export { assertStringifyPure as assertStringify };
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
* 7x faster `JSON.stringify()` function with type checking.
|
|
351
|
-
*
|
|
352
|
-
* `typia.json.stringify()` is a combination function of {@link is} and
|
|
353
|
-
* {@link stringify}. Therefore, it converts an input value to JSON
|
|
354
|
-
* (JavaScript Object Notation) string, with type checking.
|
|
355
|
-
*
|
|
356
|
-
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
357
|
-
* `null` value. Otherwise, there's no problem on the `input` value, JSON string
|
|
358
|
-
* would be returned.
|
|
359
|
-
*
|
|
360
|
-
* For reference, with type checking, it is even 7x times faster than the native
|
|
361
|
-
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
362
|
-
* with confidence.
|
|
363
|
-
*
|
|
364
|
-
* @template T Type of the input value
|
|
365
|
-
* @param input A value to be checked and converted
|
|
366
|
-
* @return JSON string value when exact type, otherwise null
|
|
367
|
-
*
|
|
368
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
369
|
-
*/
|
|
370
|
-
function isStringify<T>(input: T): string | null;
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* 7x faster `JSON.stringify()` function with type checking.
|
|
374
|
-
*
|
|
375
|
-
* `typia.json.isStringify()` is a combination function of {@link is} and
|
|
376
|
-
* {@link stringify}. Therefore, it converts an input value to JSON
|
|
377
|
-
* (JavaScript Object Notation) string, with type checking.
|
|
378
|
-
*
|
|
379
|
-
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
380
|
-
* `null` value. Otherwise, there's no problem on the `input` value, JSON string
|
|
381
|
-
* would be returned.
|
|
382
|
-
*
|
|
383
|
-
* For reference, with type checking, it is even 7x times faster than the native
|
|
384
|
-
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
385
|
-
* with confidence.
|
|
386
|
-
*
|
|
387
|
-
* @template T Type of the input value
|
|
388
|
-
* @param input A value to be checked and converted
|
|
389
|
-
* @return JSON string value when exact type, otherwise null
|
|
390
|
-
*
|
|
391
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
392
|
-
*/
|
|
393
|
-
function isStringify<T>(input: unknown): string | null;
|
|
394
|
-
|
|
395
|
-
/**
|
|
396
|
-
* @internal
|
|
397
|
-
*/
|
|
398
|
-
function isStringify(): string | null {
|
|
399
|
-
halt("isStringify");
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
const isStringifyPure = /** @__PURE__ */ Object.assign<
|
|
403
|
-
typeof isStringify,
|
|
404
|
-
{},
|
|
405
|
-
{}
|
|
406
|
-
>(
|
|
407
|
-
isStringify,
|
|
408
|
-
/** @__PURE__ */ Namespace.is(),
|
|
409
|
-
/** @__PURE__ */ Namespace.json.stringify("isStringify"),
|
|
410
|
-
);
|
|
411
|
-
export { isStringifyPure as isStringify };
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
415
|
-
*
|
|
416
|
-
* `typia.json.validateStringify()` is a combination function of {@link validate} and
|
|
417
|
-
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
418
|
-
* Notation) string, with detailed type validation.
|
|
419
|
-
*
|
|
420
|
-
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
421
|
-
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
422
|
-
* there's no problem on the `input` value, JSON string would be stored in `data`
|
|
423
|
-
* property of the output {@link IValidation.ISuccess} instance.
|
|
424
|
-
*
|
|
425
|
-
* For reference, with detailed type validation, it is even 5x times faster than the
|
|
426
|
-
* native `JSON.stringify()` function. So, just enjoy the safe and fast JSON
|
|
427
|
-
* conversion with confidence.
|
|
428
|
-
*
|
|
429
|
-
* @template T Type of the input value
|
|
430
|
-
* @param input A value to be checked and converted
|
|
431
|
-
* @returns Validation result with JSON string value
|
|
432
|
-
*
|
|
433
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
434
|
-
*/
|
|
435
|
-
function validateStringify<T>(input: T): IValidation<string>;
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
439
|
-
*
|
|
440
|
-
* `typia.json.validateStringify()` is a combination function of {@link validate} and
|
|
441
|
-
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
442
|
-
* Notation) string, with detailed type validation.
|
|
443
|
-
*
|
|
444
|
-
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
445
|
-
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
446
|
-
* there's no problem on the `input` value, JSON string would be stored in `data`
|
|
447
|
-
* property of the output {@link IValidation.ISuccess} instance.
|
|
448
|
-
*
|
|
449
|
-
* For reference, with detailed type validation, it is even 5x times faster than the
|
|
450
|
-
* native `JSON.stringify()` function. So, just enjoy the safe and fast JSON
|
|
451
|
-
* conversion with confidence.
|
|
452
|
-
*
|
|
453
|
-
* @template T Type of the input value
|
|
454
|
-
* @param input A value to be checked and converted
|
|
455
|
-
* @returns Validation result with JSON string value
|
|
456
|
-
*
|
|
457
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
458
|
-
*/
|
|
459
|
-
function validateStringify<T>(input: unknown): IValidation<string>;
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* @internal
|
|
463
|
-
*/
|
|
464
|
-
function validateStringify(): IValidation<string> {
|
|
465
|
-
halt("validateStringify");
|
|
466
|
-
}
|
|
467
|
-
const validateStringifyPure = /** @__PURE__ */ Object.assign<
|
|
468
|
-
typeof validateStringify,
|
|
469
|
-
{},
|
|
470
|
-
{}
|
|
471
|
-
>(
|
|
472
|
-
validateStringify,
|
|
473
|
-
/** @__PURE__ */ Namespace.validate(),
|
|
474
|
-
/** @__PURE__ */ Namespace.json.stringify("validateStringify"),
|
|
475
|
-
);
|
|
476
|
-
export { validateStringifyPure as validateStringify };
|
|
477
|
-
|
|
478
|
-
/* -----------------------------------------------------------
|
|
479
|
-
FACTORY FUNCTIONS
|
|
480
|
-
----------------------------------------------------------- */
|
|
481
|
-
/**
|
|
482
|
-
* Creates a reusable {@link isParse} function.
|
|
483
|
-
*
|
|
484
|
-
* @danger You must configure the generic argument `T`
|
|
485
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
486
|
-
* @throws compile error
|
|
487
|
-
*
|
|
488
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
489
|
-
*/
|
|
490
|
-
function createIsParse(): never;
|
|
491
|
-
|
|
492
|
-
/**
|
|
493
|
-
* Creates a reusable {@link isParse} function.
|
|
494
|
-
*
|
|
495
|
-
* @template T Expected type of parsed value
|
|
496
|
-
* @returns A reusable `isParse` function
|
|
497
|
-
*
|
|
498
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
499
|
-
*/
|
|
500
|
-
function createIsParse<T>(): (input: string) => Primitive<T> | null;
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* @internal
|
|
504
|
-
*/
|
|
505
|
-
function createIsParse<T>(): (input: string) => Primitive<T> | null {
|
|
506
|
-
halt("createIsParse");
|
|
507
|
-
}
|
|
508
|
-
const createIsParsePure = /** @__PURE__ */ Object.assign<
|
|
509
|
-
typeof createIsParse,
|
|
510
|
-
{}
|
|
511
|
-
>(createIsParse, isParsePure);
|
|
512
|
-
export { createIsParsePure as createIsParse };
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Creates a reusable {@link assertParse} function.
|
|
516
|
-
*
|
|
517
|
-
* @danger You must configure the generic argument `T`
|
|
518
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
519
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
520
|
-
* @throws compile error
|
|
521
|
-
*
|
|
522
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
523
|
-
*/
|
|
524
|
-
function createAssertParse(
|
|
525
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
526
|
-
): never;
|
|
527
|
-
|
|
528
|
-
/**
|
|
529
|
-
* Creates a reusable {@link assertParse} function.
|
|
530
|
-
*
|
|
531
|
-
* @template T Expected type of parsed value
|
|
532
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
533
|
-
* @returns A reusable `assertParse` function
|
|
534
|
-
*
|
|
535
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
536
|
-
*/
|
|
537
|
-
function createAssertParse<T>(
|
|
538
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
539
|
-
): (input: string) => Primitive<T>;
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
* @internal
|
|
543
|
-
*/
|
|
544
|
-
function createAssertParse<T>(): (input: string) => Primitive<T> {
|
|
545
|
-
halt("createAssertParse");
|
|
546
|
-
}
|
|
547
|
-
const createAssertParsePure = /** @__PURE__ */ Object.assign<
|
|
548
|
-
typeof createAssertParse,
|
|
549
|
-
{}
|
|
550
|
-
>(createAssertParse, assertParsePure);
|
|
551
|
-
export { createAssertParsePure as createAssertParse };
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* Creates a reusable {@link validateParse} function.
|
|
555
|
-
*
|
|
556
|
-
* @danger You must configure the generic argument `T`
|
|
557
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
558
|
-
* @throws compile error
|
|
559
|
-
*
|
|
560
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
561
|
-
*/
|
|
562
|
-
function createValidateParse(): never;
|
|
563
|
-
|
|
564
|
-
/**
|
|
565
|
-
* Creates a reusable {@link validateParse} function.
|
|
566
|
-
*
|
|
567
|
-
* @template T Expected type of parsed value
|
|
568
|
-
* @returns A reusable `validateParse` function
|
|
569
|
-
*
|
|
570
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
571
|
-
*/
|
|
572
|
-
function createValidateParse<T>(): (input: string) => IValidation<Primitive<T>>;
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* @internal
|
|
576
|
-
*/
|
|
577
|
-
function createValidateParse<T>(): (
|
|
578
|
-
input: string,
|
|
579
|
-
) => IValidation<Primitive<T>> {
|
|
580
|
-
halt("createValidateParse");
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
const createValidateParsePure = /** @__PURE__ */ Object.assign<
|
|
584
|
-
typeof createValidateParse,
|
|
585
|
-
{}
|
|
586
|
-
>(createValidateParse, validateParsePure);
|
|
587
|
-
export { createValidateParsePure as createValidateParse };
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Creates a reusable {@link stringify} function.
|
|
591
|
-
*
|
|
592
|
-
* @danger You must configure the generic argument `T`
|
|
593
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
594
|
-
* @throws compile error
|
|
595
|
-
*
|
|
596
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
597
|
-
*/
|
|
598
|
-
function createStringify(): never;
|
|
599
|
-
|
|
600
|
-
/**
|
|
601
|
-
* Creates a reusable {@link stringify} function.
|
|
602
|
-
*
|
|
603
|
-
* @template T Type of the input value
|
|
604
|
-
* @returns A reusable `stringify` function
|
|
605
|
-
*
|
|
606
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
607
|
-
*/
|
|
608
|
-
function createStringify<T>(): (input: T) => string;
|
|
609
|
-
|
|
610
|
-
/**
|
|
611
|
-
* @internal
|
|
612
|
-
*/
|
|
613
|
-
function createStringify<T>(): (input: T) => string {
|
|
614
|
-
halt("createStringify");
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
const createStringifyPure = /** @__PURE__ */ Object.assign<
|
|
618
|
-
typeof createStringify,
|
|
619
|
-
{}
|
|
620
|
-
>(createStringify, stringifyPure);
|
|
621
|
-
export { createStringifyPure as createStringify };
|
|
622
|
-
|
|
623
|
-
/**
|
|
624
|
-
* Creates a reusable {@link assertStringify} function.
|
|
625
|
-
*
|
|
626
|
-
* @danger You must configure the generic argument `T`
|
|
627
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
628
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
629
|
-
* @throws compile error
|
|
630
|
-
*
|
|
631
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
632
|
-
*/
|
|
633
|
-
function createAssertStringify(
|
|
634
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
635
|
-
): never;
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* Creates a reusable {@link assertStringify} function.
|
|
639
|
-
*
|
|
640
|
-
* @template T Type of the input value
|
|
641
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
642
|
-
* @returns A reusable `assertStringify` function
|
|
643
|
-
*
|
|
644
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
645
|
-
*/
|
|
646
|
-
function createAssertStringify<T>(
|
|
647
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
648
|
-
): (input: unknown) => string;
|
|
649
|
-
|
|
650
|
-
/**
|
|
651
|
-
* @internal
|
|
652
|
-
*/
|
|
653
|
-
function createAssertStringify(): (input: unknown) => string {
|
|
654
|
-
halt("createAssertStringify");
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
const createAssertStringifyPure = /** @__PURE__ */ Object.assign<
|
|
658
|
-
typeof createAssertStringify,
|
|
659
|
-
{}
|
|
660
|
-
>(createAssertStringify, assertStringifyPure);
|
|
661
|
-
export { createAssertStringifyPure as createAssertStringify };
|
|
662
|
-
|
|
663
|
-
/**
|
|
664
|
-
* Creates a reusable {@link isStringify} function.
|
|
665
|
-
*
|
|
666
|
-
* @danger You must configure the generic argument `T`
|
|
667
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
668
|
-
* @throws compile error
|
|
669
|
-
*
|
|
670
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
671
|
-
*/
|
|
672
|
-
function createIsStringify(): never;
|
|
673
|
-
|
|
674
|
-
/**
|
|
675
|
-
* Creates a reusable {@link isStringify} function.
|
|
676
|
-
*
|
|
677
|
-
* @template T Type of the input value
|
|
678
|
-
* @returns A reusable `isStringify` function
|
|
679
|
-
*
|
|
680
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
681
|
-
*/
|
|
682
|
-
function createIsStringify<T>(): (input: unknown) => string | null;
|
|
683
|
-
|
|
684
|
-
/**
|
|
685
|
-
* @internal
|
|
686
|
-
*/
|
|
687
|
-
function createIsStringify(): (input: unknown) => string | null {
|
|
688
|
-
halt("createIsStringify");
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
const createIsStringifyPure = /** @__PURE__ */ Object.assign<
|
|
692
|
-
typeof createIsStringify,
|
|
693
|
-
{}
|
|
694
|
-
>(createIsStringify, isStringifyPure);
|
|
695
|
-
export { createIsStringifyPure as createIsStringify };
|
|
696
|
-
|
|
697
|
-
/**
|
|
698
|
-
* Creates a reusable {@link validateStringify} function.
|
|
699
|
-
*
|
|
700
|
-
* @danger You must configure the generic argument `T`
|
|
701
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
702
|
-
* @throws compile error
|
|
703
|
-
*
|
|
704
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
705
|
-
*/
|
|
706
|
-
function createValidateStringify(): never;
|
|
707
|
-
|
|
708
|
-
/**
|
|
709
|
-
* Creates a reusable {@link validateStringify} function.
|
|
710
|
-
*
|
|
711
|
-
* @template T Type of the input value
|
|
712
|
-
* @returns A reusable `validateStringify` function
|
|
713
|
-
|
|
714
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
715
|
-
*/
|
|
716
|
-
function createValidateStringify<T>(): (input: unknown) => IValidation<string>;
|
|
717
|
-
|
|
718
|
-
/**
|
|
719
|
-
* @internal
|
|
720
|
-
*/
|
|
721
|
-
function createValidateStringify(): (input: unknown) => IValidation<string> {
|
|
722
|
-
halt("createValidateStringify");
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
const createValidateStringifyPure = /** @__PURE__ */ Object.assign<
|
|
726
|
-
typeof createValidateStringify,
|
|
727
|
-
{}
|
|
728
|
-
>(createValidateStringify, validateStringifyPure);
|
|
729
|
-
export { createValidateStringifyPure as createValidateStringify };
|
|
730
|
-
|
|
731
|
-
/**
|
|
732
|
-
* @internal
|
|
733
|
-
*/
|
|
734
|
-
function halt(name: string): never {
|
|
735
|
-
throw new Error(
|
|
736
|
-
`Error on typia.json.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
737
|
-
);
|
|
738
|
-
}
|
|
1
|
+
import * as Namespace from "./functional/Namespace";
|
|
2
|
+
|
|
3
|
+
import { IJsonApplication } from "./schemas/json/IJsonApplication";
|
|
4
|
+
|
|
5
|
+
import { IValidation } from "./IValidation";
|
|
6
|
+
import { Primitive } from "./Primitive";
|
|
7
|
+
import { TypeGuardError } from "./TypeGuardError";
|
|
8
|
+
|
|
9
|
+
/* ===========================================================
|
|
10
|
+
JSON
|
|
11
|
+
- SCHEMA
|
|
12
|
+
- PARSE
|
|
13
|
+
- STRINGIFY
|
|
14
|
+
- FACTORY FUNCTIONS
|
|
15
|
+
==============================================================
|
|
16
|
+
SCHEMA
|
|
17
|
+
----------------------------------------------------------- */
|
|
18
|
+
/**
|
|
19
|
+
* > You must configure the generic argument `Types`.
|
|
20
|
+
*
|
|
21
|
+
* JSON Schema Application.
|
|
22
|
+
*
|
|
23
|
+
* Creates a JSON schema application which contains both main JSON schemas and
|
|
24
|
+
* components. Note that, all of the named types are stored in the
|
|
25
|
+
* {@link IJsonApplication.components} property for the `$ref` referencing.
|
|
26
|
+
*
|
|
27
|
+
* Also, you can specify the OpenAPI version by configuring the second generic
|
|
28
|
+
* argument `Version`. For reference, the default version is `"3.1"`, and key
|
|
29
|
+
* different of `"3.0"` and `"3.1"` is whether supporting the tuple type or not.
|
|
30
|
+
*
|
|
31
|
+
* @template Types Tuple of target types
|
|
32
|
+
* @template Purpose Purpose of the JSON schema
|
|
33
|
+
* @template Surplus Allow surplus properties starting with `x-typia-` or not
|
|
34
|
+
* @return JSON schema application
|
|
35
|
+
*
|
|
36
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
37
|
+
*/
|
|
38
|
+
export function application(): never;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* JSON Schema Application.
|
|
42
|
+
*
|
|
43
|
+
* Creates a JSON schema application which contains both main JSON schemas and
|
|
44
|
+
* components. Note that, all of the named types are stored in the
|
|
45
|
+
* {@link IJsonApplication.components} property for the `$ref` referencing.
|
|
46
|
+
*
|
|
47
|
+
* Also, you can specify the OpenAPI version by configuring the second generic
|
|
48
|
+
* argument `Version`. For reference, the default version is `"3.1"`, and key
|
|
49
|
+
* different of `"3.0"` and `"3.1"` is whether supporting the tuple type or not.
|
|
50
|
+
*
|
|
51
|
+
* @template Types Tuple of target types
|
|
52
|
+
* @template Version Version of OpenAPI specification. Default is 3.1
|
|
53
|
+
* @return JSON schema application
|
|
54
|
+
*
|
|
55
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
56
|
+
*/
|
|
57
|
+
export function application<
|
|
58
|
+
Types extends unknown[],
|
|
59
|
+
Version extends "3.0" | "3.1" = "3.1",
|
|
60
|
+
>(): IJsonApplication<Version, Types>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export function application(): never {
|
|
66
|
+
halt("application");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* -----------------------------------------------------------
|
|
70
|
+
PARSE
|
|
71
|
+
----------------------------------------------------------- */
|
|
72
|
+
/**
|
|
73
|
+
* > You must configure the generic argument `T`.
|
|
74
|
+
*
|
|
75
|
+
* Safe `JSON.parse()` function with type assertion.
|
|
76
|
+
*
|
|
77
|
+
* `typia.json.assertParse()` is a combination function of `JSON.parse()` and
|
|
78
|
+
* {@link assert}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
79
|
+
* to a `T` typed instance with type assertion.
|
|
80
|
+
*
|
|
81
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
82
|
+
* throws {@link TypeGuardError} or custom error generated by *errorFactory*. Otherwise,
|
|
83
|
+
* there's no problem on the parsed value, the parsed value would be returned.
|
|
84
|
+
*
|
|
85
|
+
* @template T Expected type of parsed value
|
|
86
|
+
* @param input JSON string
|
|
87
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
88
|
+
* @returns Parsed value
|
|
89
|
+
*
|
|
90
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
91
|
+
*/
|
|
92
|
+
function assertParse(
|
|
93
|
+
input: string,
|
|
94
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
95
|
+
): never;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Safe `JSON.parse()` function with type assertion.
|
|
99
|
+
*
|
|
100
|
+
* `typia.json.assertParse()` is a combination function of `JSON.parse()` and
|
|
101
|
+
* {@link assert}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
102
|
+
* to a `T` typed instance with type assertion.
|
|
103
|
+
*
|
|
104
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`,
|
|
105
|
+
* it throws {@link TypeGuardError} or custom error generated by *errorFactory*.
|
|
106
|
+
* Otherwise, there's no problem on the parsed value, the parsed value would be
|
|
107
|
+
* returned.
|
|
108
|
+
*
|
|
109
|
+
* @template T Expected type of parsed value
|
|
110
|
+
* @param input JSON string
|
|
111
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
112
|
+
* @returns Parsed value
|
|
113
|
+
*
|
|
114
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
115
|
+
*/
|
|
116
|
+
function assertParse<T>(
|
|
117
|
+
input: string,
|
|
118
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
119
|
+
): Primitive<T>;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
function assertParse<T>(): Primitive<T> {
|
|
125
|
+
halt("assertParse");
|
|
126
|
+
}
|
|
127
|
+
const assertParsePure = /** @__PURE__ */ Object.assign<typeof assertParse, {}>(
|
|
128
|
+
assertParse,
|
|
129
|
+
/** @__PURE__ */ Namespace.assert("json.assertParse"),
|
|
130
|
+
);
|
|
131
|
+
export { assertParsePure as assertParse };
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* > You must configure the generic argument `T`.
|
|
135
|
+
*
|
|
136
|
+
* Safe `JSON.parse()` function with type checking.
|
|
137
|
+
*
|
|
138
|
+
* `typia.json.isParse()` is a combination function of `JSON.parse()` and {@link is}.
|
|
139
|
+
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
140
|
+
* instance with type checking.
|
|
141
|
+
*
|
|
142
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
143
|
+
* returns `null` value. Otherwise, there's no problem on the parsed value, the parsed
|
|
144
|
+
* value would be returned.
|
|
145
|
+
*
|
|
146
|
+
* @template T Expected type of parsed value
|
|
147
|
+
* @param input JSON string
|
|
148
|
+
* @returns Parsed value when exact type, otherwise `null`
|
|
149
|
+
*
|
|
150
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
151
|
+
*/
|
|
152
|
+
function isParse(input: string): never;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Safe `JSON.parse()` function with type checking.
|
|
156
|
+
*
|
|
157
|
+
* `typia.json.isParse()` is a combination function of `JSON.parse()` and {@link is}.
|
|
158
|
+
* Therefore, it convers a JSON (JavaScript Object Notation) string to a `T` typed
|
|
159
|
+
* instance with type checking.
|
|
160
|
+
*
|
|
161
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
162
|
+
* returns `null` value. Otherwise, there's no problem on the parsed value, the parsed
|
|
163
|
+
* value would be returned.
|
|
164
|
+
*
|
|
165
|
+
* @template T Expected type of parsed value
|
|
166
|
+
* @param input JSON string
|
|
167
|
+
* @returns Parsed value when exact type, otherwise `null`
|
|
168
|
+
*
|
|
169
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
170
|
+
*/
|
|
171
|
+
function isParse<T>(input: string): Primitive<T> | null;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
function isParse<T>(): Primitive<T> | null {
|
|
177
|
+
halt("isParse");
|
|
178
|
+
}
|
|
179
|
+
const isParsePure = /** @__PURE__ */ Object.assign<typeof isParse, {}>(
|
|
180
|
+
isParse,
|
|
181
|
+
/** @__PURE__ */ Namespace.is(),
|
|
182
|
+
);
|
|
183
|
+
export { isParsePure as isParse };
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* > You must configure the generic argument `T`.
|
|
187
|
+
*
|
|
188
|
+
* Safe `JSON.parse()` function with detailed type validation.
|
|
189
|
+
*
|
|
190
|
+
* `typia.json.validateParse()` is a combination function of `JSON.parse()` and
|
|
191
|
+
* {@link validate}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
192
|
+
* to a `T` typed instance with detailed type validation.
|
|
193
|
+
*
|
|
194
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
195
|
+
* returns {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
196
|
+
* there's no problem on the parsed value, the parsed value would be stored in `data`
|
|
197
|
+
* property of the output {@link IValidation.ISuccess} instance.
|
|
198
|
+
*
|
|
199
|
+
* @template T Expected type of parsed value
|
|
200
|
+
* @param input JSON string
|
|
201
|
+
* @returns Validation result with JSON parsed value
|
|
202
|
+
*
|
|
203
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
204
|
+
*/
|
|
205
|
+
function validateParse(input: string): never;
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Safe `JSON.parse()` function with detailed type validation.
|
|
209
|
+
*
|
|
210
|
+
* `typia.json.validateParse()` is a combination function of `JSON.parse()` and
|
|
211
|
+
* {@link validate}. Therefore, it convers a JSON (JavaScript Object Notation) string
|
|
212
|
+
* to a `T` typed instance with detailed type validation.
|
|
213
|
+
*
|
|
214
|
+
* In such reason, when parsed JSON string value is not matched with the type `T`, it
|
|
215
|
+
* returns {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
216
|
+
* there's no problem on the parsed value, the parsed value would be stored in `data`
|
|
217
|
+
* property of the output {@link IValidation.ISuccess} instance.
|
|
218
|
+
*
|
|
219
|
+
* @template T Expected type of parsed value
|
|
220
|
+
* @param input JSON string
|
|
221
|
+
* @returns Validation result with JSON parsed value
|
|
222
|
+
*
|
|
223
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
224
|
+
*/
|
|
225
|
+
function validateParse<T>(input: string): IValidation<Primitive<T>>;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @internal
|
|
229
|
+
*/
|
|
230
|
+
function validateParse<T>(): IValidation<Primitive<T>> {
|
|
231
|
+
halt("validateParse");
|
|
232
|
+
}
|
|
233
|
+
const validateParsePure = /** @__PURE__ */ Object.assign<
|
|
234
|
+
typeof validateParse,
|
|
235
|
+
{}
|
|
236
|
+
>(validateParse, /** @__PURE__ */ Namespace.validate());
|
|
237
|
+
export { validateParsePure as validateParse };
|
|
238
|
+
|
|
239
|
+
/* -----------------------------------------------------------
|
|
240
|
+
STRINGIFY
|
|
241
|
+
----------------------------------------------------------- */
|
|
242
|
+
/**
|
|
243
|
+
* 8x faster `JSON.stringify()` function.
|
|
244
|
+
*
|
|
245
|
+
* Converts an input value to a JSON (JavaScript Object Notation) string, about 8x
|
|
246
|
+
* faster than the native `JSON.stringify()` function. The 5x faster principle is
|
|
247
|
+
* because it writes an optimized JSON conversion plan, only for the type `T`.
|
|
248
|
+
*
|
|
249
|
+
* For reference, this `typia.json.stringify()` does not validate the input value type.
|
|
250
|
+
* It just believes that the input value is following the type `T`. Therefore, if you
|
|
251
|
+
* can't ensure the input value type, it would be better to call one of below
|
|
252
|
+
* functions instead.
|
|
253
|
+
*
|
|
254
|
+
* - {@link assertStringify}
|
|
255
|
+
* - {@link isStringify}
|
|
256
|
+
* - {@link validateStringify}
|
|
257
|
+
*
|
|
258
|
+
* @template T Type of the input value
|
|
259
|
+
* @param input A value to be converted
|
|
260
|
+
* @return JSON string value
|
|
261
|
+
*
|
|
262
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
263
|
+
*/
|
|
264
|
+
function stringify<T>(input: T): string;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* @internal
|
|
268
|
+
*/
|
|
269
|
+
function stringify(): never {
|
|
270
|
+
halt("stringify");
|
|
271
|
+
}
|
|
272
|
+
const stringifyPure = /** @__PURE__ */ Object.assign<typeof stringify, {}>(
|
|
273
|
+
stringify,
|
|
274
|
+
/** @__PURE__ */ Namespace.json.stringify("stringify"),
|
|
275
|
+
);
|
|
276
|
+
export { stringifyPure as stringify };
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* 5x faster `JSON.stringify()` function with type assertion.
|
|
280
|
+
*
|
|
281
|
+
* `typia.json.assertStringify()` is a combination function of {@link assert} and
|
|
282
|
+
* {@link stringify}. Therefore, it converts an input value to
|
|
283
|
+
* JSON (JavaScript Object Notation) string, with type assertion.
|
|
284
|
+
*
|
|
285
|
+
* In such reason, when `input` value is not matched with the type `T`, it throws an
|
|
286
|
+
* {@link TypeGuardError} or custom error generated by *errorFactory*. Otherwise,
|
|
287
|
+
* there's no problem on the `input` value, JSON string would be returned.
|
|
288
|
+
*
|
|
289
|
+
* For reference, with type assertion, it is even 5x times faster than the native
|
|
290
|
+
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
291
|
+
* with confidence.
|
|
292
|
+
*
|
|
293
|
+
* @template T Type of the input value
|
|
294
|
+
* @param input A value to be asserted and converted
|
|
295
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
296
|
+
* @return JSON string value
|
|
297
|
+
*
|
|
298
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
299
|
+
*/
|
|
300
|
+
function assertStringify<T>(
|
|
301
|
+
input: T,
|
|
302
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
303
|
+
): string;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* 5x faster `JSON.stringify()` function with type assertion.
|
|
307
|
+
*
|
|
308
|
+
* `typia.json.assertStringify()` is a combination function of {@link assert} and
|
|
309
|
+
* {@link stringify}. Therefore, it converts an input value to
|
|
310
|
+
* JSON (JavaScript Object Notation) string, with type assertion.
|
|
311
|
+
*
|
|
312
|
+
* In such reason, when `input` value is not matched with the type `T`, it throws an
|
|
313
|
+
* {@link TypeGuardError} or custom error generated by *errorFactory*. Otherwise,
|
|
314
|
+
* there's no problem on the `input` value, JSON string would be returned.
|
|
315
|
+
*
|
|
316
|
+
* For reference, with type assertion, it is even 5x times faster than the native
|
|
317
|
+
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
318
|
+
* with confidence.
|
|
319
|
+
*
|
|
320
|
+
* @template T Type of the input value
|
|
321
|
+
* @param input A value to be asserted and converted
|
|
322
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
323
|
+
* @return JSON string value
|
|
324
|
+
*
|
|
325
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
326
|
+
*/
|
|
327
|
+
function assertStringify<T>(
|
|
328
|
+
input: T,
|
|
329
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
330
|
+
): unknown;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
335
|
+
function assertStringify(): string {
|
|
336
|
+
halt("assertStringify");
|
|
337
|
+
}
|
|
338
|
+
const assertStringifyPure = /** @__PURE__ */ Object.assign<
|
|
339
|
+
typeof assertStringify,
|
|
340
|
+
{},
|
|
341
|
+
{}
|
|
342
|
+
>(
|
|
343
|
+
assertStringify,
|
|
344
|
+
/** @__PURE__ */ Namespace.assert("json.assertStringify"),
|
|
345
|
+
/** @__PURE__ */ Namespace.json.stringify("assertStringify"),
|
|
346
|
+
);
|
|
347
|
+
export { assertStringifyPure as assertStringify };
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* 7x faster `JSON.stringify()` function with type checking.
|
|
351
|
+
*
|
|
352
|
+
* `typia.json.stringify()` is a combination function of {@link is} and
|
|
353
|
+
* {@link stringify}. Therefore, it converts an input value to JSON
|
|
354
|
+
* (JavaScript Object Notation) string, with type checking.
|
|
355
|
+
*
|
|
356
|
+
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
357
|
+
* `null` value. Otherwise, there's no problem on the `input` value, JSON string
|
|
358
|
+
* would be returned.
|
|
359
|
+
*
|
|
360
|
+
* For reference, with type checking, it is even 7x times faster than the native
|
|
361
|
+
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
362
|
+
* with confidence.
|
|
363
|
+
*
|
|
364
|
+
* @template T Type of the input value
|
|
365
|
+
* @param input A value to be checked and converted
|
|
366
|
+
* @return JSON string value when exact type, otherwise null
|
|
367
|
+
*
|
|
368
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
369
|
+
*/
|
|
370
|
+
function isStringify<T>(input: T): string | null;
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 7x faster `JSON.stringify()` function with type checking.
|
|
374
|
+
*
|
|
375
|
+
* `typia.json.isStringify()` is a combination function of {@link is} and
|
|
376
|
+
* {@link stringify}. Therefore, it converts an input value to JSON
|
|
377
|
+
* (JavaScript Object Notation) string, with type checking.
|
|
378
|
+
*
|
|
379
|
+
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
380
|
+
* `null` value. Otherwise, there's no problem on the `input` value, JSON string
|
|
381
|
+
* would be returned.
|
|
382
|
+
*
|
|
383
|
+
* For reference, with type checking, it is even 7x times faster than the native
|
|
384
|
+
* `JSON.stringify()` function. So, just enjoy the safe and fast JSON conversion
|
|
385
|
+
* with confidence.
|
|
386
|
+
*
|
|
387
|
+
* @template T Type of the input value
|
|
388
|
+
* @param input A value to be checked and converted
|
|
389
|
+
* @return JSON string value when exact type, otherwise null
|
|
390
|
+
*
|
|
391
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
392
|
+
*/
|
|
393
|
+
function isStringify<T>(input: unknown): string | null;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* @internal
|
|
397
|
+
*/
|
|
398
|
+
function isStringify(): string | null {
|
|
399
|
+
halt("isStringify");
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
const isStringifyPure = /** @__PURE__ */ Object.assign<
|
|
403
|
+
typeof isStringify,
|
|
404
|
+
{},
|
|
405
|
+
{}
|
|
406
|
+
>(
|
|
407
|
+
isStringify,
|
|
408
|
+
/** @__PURE__ */ Namespace.is(),
|
|
409
|
+
/** @__PURE__ */ Namespace.json.stringify("isStringify"),
|
|
410
|
+
);
|
|
411
|
+
export { isStringifyPure as isStringify };
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
415
|
+
*
|
|
416
|
+
* `typia.json.validateStringify()` is a combination function of {@link validate} and
|
|
417
|
+
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
418
|
+
* Notation) string, with detailed type validation.
|
|
419
|
+
*
|
|
420
|
+
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
421
|
+
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
422
|
+
* there's no problem on the `input` value, JSON string would be stored in `data`
|
|
423
|
+
* property of the output {@link IValidation.ISuccess} instance.
|
|
424
|
+
*
|
|
425
|
+
* For reference, with detailed type validation, it is even 5x times faster than the
|
|
426
|
+
* native `JSON.stringify()` function. So, just enjoy the safe and fast JSON
|
|
427
|
+
* conversion with confidence.
|
|
428
|
+
*
|
|
429
|
+
* @template T Type of the input value
|
|
430
|
+
* @param input A value to be checked and converted
|
|
431
|
+
* @returns Validation result with JSON string value
|
|
432
|
+
*
|
|
433
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
434
|
+
*/
|
|
435
|
+
function validateStringify<T>(input: T): IValidation<string>;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* 5x faster `JSON.stringify()` function with detailed type validation.
|
|
439
|
+
*
|
|
440
|
+
* `typia.json.validateStringify()` is a combination function of {@link validate} and
|
|
441
|
+
* {@link stringify}. Therefore, it converts an input value to JSON (JavaScript Object
|
|
442
|
+
* Notation) string, with detailed type validation.
|
|
443
|
+
*
|
|
444
|
+
* In such reason, when `input` value is not matched with the type `T`, it returns
|
|
445
|
+
* {@link IValidation.IFailure} value with detailed error reasons. Otherwise,
|
|
446
|
+
* there's no problem on the `input` value, JSON string would be stored in `data`
|
|
447
|
+
* property of the output {@link IValidation.ISuccess} instance.
|
|
448
|
+
*
|
|
449
|
+
* For reference, with detailed type validation, it is even 5x times faster than the
|
|
450
|
+
* native `JSON.stringify()` function. So, just enjoy the safe and fast JSON
|
|
451
|
+
* conversion with confidence.
|
|
452
|
+
*
|
|
453
|
+
* @template T Type of the input value
|
|
454
|
+
* @param input A value to be checked and converted
|
|
455
|
+
* @returns Validation result with JSON string value
|
|
456
|
+
*
|
|
457
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
458
|
+
*/
|
|
459
|
+
function validateStringify<T>(input: unknown): IValidation<string>;
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* @internal
|
|
463
|
+
*/
|
|
464
|
+
function validateStringify(): IValidation<string> {
|
|
465
|
+
halt("validateStringify");
|
|
466
|
+
}
|
|
467
|
+
const validateStringifyPure = /** @__PURE__ */ Object.assign<
|
|
468
|
+
typeof validateStringify,
|
|
469
|
+
{},
|
|
470
|
+
{}
|
|
471
|
+
>(
|
|
472
|
+
validateStringify,
|
|
473
|
+
/** @__PURE__ */ Namespace.validate(),
|
|
474
|
+
/** @__PURE__ */ Namespace.json.stringify("validateStringify"),
|
|
475
|
+
);
|
|
476
|
+
export { validateStringifyPure as validateStringify };
|
|
477
|
+
|
|
478
|
+
/* -----------------------------------------------------------
|
|
479
|
+
FACTORY FUNCTIONS
|
|
480
|
+
----------------------------------------------------------- */
|
|
481
|
+
/**
|
|
482
|
+
* Creates a reusable {@link isParse} function.
|
|
483
|
+
*
|
|
484
|
+
* @danger You must configure the generic argument `T`
|
|
485
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
486
|
+
* @throws compile error
|
|
487
|
+
*
|
|
488
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
489
|
+
*/
|
|
490
|
+
function createIsParse(): never;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Creates a reusable {@link isParse} function.
|
|
494
|
+
*
|
|
495
|
+
* @template T Expected type of parsed value
|
|
496
|
+
* @returns A reusable `isParse` function
|
|
497
|
+
*
|
|
498
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
499
|
+
*/
|
|
500
|
+
function createIsParse<T>(): (input: string) => Primitive<T> | null;
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* @internal
|
|
504
|
+
*/
|
|
505
|
+
function createIsParse<T>(): (input: string) => Primitive<T> | null {
|
|
506
|
+
halt("createIsParse");
|
|
507
|
+
}
|
|
508
|
+
const createIsParsePure = /** @__PURE__ */ Object.assign<
|
|
509
|
+
typeof createIsParse,
|
|
510
|
+
{}
|
|
511
|
+
>(createIsParse, isParsePure);
|
|
512
|
+
export { createIsParsePure as createIsParse };
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Creates a reusable {@link assertParse} function.
|
|
516
|
+
*
|
|
517
|
+
* @danger You must configure the generic argument `T`
|
|
518
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
519
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
520
|
+
* @throws compile error
|
|
521
|
+
*
|
|
522
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
523
|
+
*/
|
|
524
|
+
function createAssertParse(
|
|
525
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
526
|
+
): never;
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Creates a reusable {@link assertParse} function.
|
|
530
|
+
*
|
|
531
|
+
* @template T Expected type of parsed value
|
|
532
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
533
|
+
* @returns A reusable `assertParse` function
|
|
534
|
+
*
|
|
535
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
536
|
+
*/
|
|
537
|
+
function createAssertParse<T>(
|
|
538
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
539
|
+
): (input: string) => Primitive<T>;
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* @internal
|
|
543
|
+
*/
|
|
544
|
+
function createAssertParse<T>(): (input: string) => Primitive<T> {
|
|
545
|
+
halt("createAssertParse");
|
|
546
|
+
}
|
|
547
|
+
const createAssertParsePure = /** @__PURE__ */ Object.assign<
|
|
548
|
+
typeof createAssertParse,
|
|
549
|
+
{}
|
|
550
|
+
>(createAssertParse, assertParsePure);
|
|
551
|
+
export { createAssertParsePure as createAssertParse };
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Creates a reusable {@link validateParse} function.
|
|
555
|
+
*
|
|
556
|
+
* @danger You must configure the generic argument `T`
|
|
557
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
558
|
+
* @throws compile error
|
|
559
|
+
*
|
|
560
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
561
|
+
*/
|
|
562
|
+
function createValidateParse(): never;
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Creates a reusable {@link validateParse} function.
|
|
566
|
+
*
|
|
567
|
+
* @template T Expected type of parsed value
|
|
568
|
+
* @returns A reusable `validateParse` function
|
|
569
|
+
*
|
|
570
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
571
|
+
*/
|
|
572
|
+
function createValidateParse<T>(): (input: string) => IValidation<Primitive<T>>;
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* @internal
|
|
576
|
+
*/
|
|
577
|
+
function createValidateParse<T>(): (
|
|
578
|
+
input: string,
|
|
579
|
+
) => IValidation<Primitive<T>> {
|
|
580
|
+
halt("createValidateParse");
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
const createValidateParsePure = /** @__PURE__ */ Object.assign<
|
|
584
|
+
typeof createValidateParse,
|
|
585
|
+
{}
|
|
586
|
+
>(createValidateParse, validateParsePure);
|
|
587
|
+
export { createValidateParsePure as createValidateParse };
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Creates a reusable {@link stringify} function.
|
|
591
|
+
*
|
|
592
|
+
* @danger You must configure the generic argument `T`
|
|
593
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
594
|
+
* @throws compile error
|
|
595
|
+
*
|
|
596
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
597
|
+
*/
|
|
598
|
+
function createStringify(): never;
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Creates a reusable {@link stringify} function.
|
|
602
|
+
*
|
|
603
|
+
* @template T Type of the input value
|
|
604
|
+
* @returns A reusable `stringify` function
|
|
605
|
+
*
|
|
606
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
607
|
+
*/
|
|
608
|
+
function createStringify<T>(): (input: T) => string;
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* @internal
|
|
612
|
+
*/
|
|
613
|
+
function createStringify<T>(): (input: T) => string {
|
|
614
|
+
halt("createStringify");
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const createStringifyPure = /** @__PURE__ */ Object.assign<
|
|
618
|
+
typeof createStringify,
|
|
619
|
+
{}
|
|
620
|
+
>(createStringify, stringifyPure);
|
|
621
|
+
export { createStringifyPure as createStringify };
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Creates a reusable {@link assertStringify} function.
|
|
625
|
+
*
|
|
626
|
+
* @danger You must configure the generic argument `T`
|
|
627
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
628
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
629
|
+
* @throws compile error
|
|
630
|
+
*
|
|
631
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
632
|
+
*/
|
|
633
|
+
function createAssertStringify(
|
|
634
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
635
|
+
): never;
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* Creates a reusable {@link assertStringify} function.
|
|
639
|
+
*
|
|
640
|
+
* @template T Type of the input value
|
|
641
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
642
|
+
* @returns A reusable `assertStringify` function
|
|
643
|
+
*
|
|
644
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
645
|
+
*/
|
|
646
|
+
function createAssertStringify<T>(
|
|
647
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
648
|
+
): (input: unknown) => string;
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* @internal
|
|
652
|
+
*/
|
|
653
|
+
function createAssertStringify(): (input: unknown) => string {
|
|
654
|
+
halt("createAssertStringify");
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
const createAssertStringifyPure = /** @__PURE__ */ Object.assign<
|
|
658
|
+
typeof createAssertStringify,
|
|
659
|
+
{}
|
|
660
|
+
>(createAssertStringify, assertStringifyPure);
|
|
661
|
+
export { createAssertStringifyPure as createAssertStringify };
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Creates a reusable {@link isStringify} function.
|
|
665
|
+
*
|
|
666
|
+
* @danger You must configure the generic argument `T`
|
|
667
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
668
|
+
* @throws compile error
|
|
669
|
+
*
|
|
670
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
671
|
+
*/
|
|
672
|
+
function createIsStringify(): never;
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Creates a reusable {@link isStringify} function.
|
|
676
|
+
*
|
|
677
|
+
* @template T Type of the input value
|
|
678
|
+
* @returns A reusable `isStringify` function
|
|
679
|
+
*
|
|
680
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
681
|
+
*/
|
|
682
|
+
function createIsStringify<T>(): (input: unknown) => string | null;
|
|
683
|
+
|
|
684
|
+
/**
|
|
685
|
+
* @internal
|
|
686
|
+
*/
|
|
687
|
+
function createIsStringify(): (input: unknown) => string | null {
|
|
688
|
+
halt("createIsStringify");
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
const createIsStringifyPure = /** @__PURE__ */ Object.assign<
|
|
692
|
+
typeof createIsStringify,
|
|
693
|
+
{}
|
|
694
|
+
>(createIsStringify, isStringifyPure);
|
|
695
|
+
export { createIsStringifyPure as createIsStringify };
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* Creates a reusable {@link validateStringify} function.
|
|
699
|
+
*
|
|
700
|
+
* @danger You must configure the generic argument `T`
|
|
701
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
702
|
+
* @throws compile error
|
|
703
|
+
*
|
|
704
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
705
|
+
*/
|
|
706
|
+
function createValidateStringify(): never;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Creates a reusable {@link validateStringify} function.
|
|
710
|
+
*
|
|
711
|
+
* @template T Type of the input value
|
|
712
|
+
* @returns A reusable `validateStringify` function
|
|
713
|
+
|
|
714
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
715
|
+
*/
|
|
716
|
+
function createValidateStringify<T>(): (input: unknown) => IValidation<string>;
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* @internal
|
|
720
|
+
*/
|
|
721
|
+
function createValidateStringify(): (input: unknown) => IValidation<string> {
|
|
722
|
+
halt("createValidateStringify");
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
const createValidateStringifyPure = /** @__PURE__ */ Object.assign<
|
|
726
|
+
typeof createValidateStringify,
|
|
727
|
+
{}
|
|
728
|
+
>(createValidateStringify, validateStringifyPure);
|
|
729
|
+
export { createValidateStringifyPure as createValidateStringify };
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* @internal
|
|
733
|
+
*/
|
|
734
|
+
function halt(name: string): never {
|
|
735
|
+
throw new Error(
|
|
736
|
+
`Error on typia.json.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
737
|
+
);
|
|
738
|
+
}
|