typia 9.7.2 → 10.0.0-dev.20251107
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/LICENSE +21 -21
- package/README.md +153 -153
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.mjs +1 -1
- package/lib/programmers/internal/json_schema_station.d.mts +2 -2
- package/lib/programmers/internal/json_schema_station.d.ts +2 -2
- package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
- package/package.json +121 -121
- package/src/AssertionGuard.ts +41 -41
- package/src/CamelCase.ts +75 -75
- package/src/IRandomGenerator.ts +337 -337
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +90 -90
- package/src/Resolved.ts +72 -72
- package/src/SnakeCase.ts +127 -127
- package/src/TypeGuardError.ts +216 -216
- package/src/factories/MetadataCollection.ts +270 -270
- package/src/factories/MetadataCommentTagFactory.ts +632 -632
- package/src/factories/MetadataFactory.ts +402 -402
- package/src/factories/ProtobufFactory.ts +873 -873
- package/src/functional.ts +705 -705
- package/src/http.ts +972 -972
- package/src/internal/_ProtobufReader.ts +188 -188
- package/src/internal/_ProtobufSizer.ts +137 -137
- package/src/internal/_ProtobufWriter.ts +135 -135
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/json.ts +643 -643
- package/src/llm.ts +615 -615
- package/src/misc.ts +594 -594
- package/src/module.ts +889 -889
- package/src/notations.ts +751 -751
- package/src/programmers/FeatureProgrammer.ts +605 -605
- package/src/programmers/ImportProgrammer.ts +179 -179
- package/src/programmers/RandomProgrammer.ts +1195 -1195
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/internal/check_array_length.ts +43 -43
- package/src/programmers/internal/check_bigint.ts +46 -46
- package/src/programmers/internal/check_dynamic_key.ts +197 -197
- package/src/programmers/internal/check_dynamic_properties.ts +231 -231
- package/src/programmers/internal/check_everything.ts +21 -21
- package/src/programmers/internal/check_native.ts +23 -23
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_object.ts +72 -72
- package/src/programmers/internal/check_string.ts +46 -46
- package/src/programmers/internal/check_template.ts +46 -46
- package/src/programmers/internal/check_union_array_like.ts +331 -331
- package/src/programmers/internal/decode_union_object.ts +110 -110
- package/src/programmers/internal/feature_object_entries.ts +59 -59
- package/src/programmers/internal/json_schema_escaped.ts +78 -78
- package/src/programmers/internal/json_schema_object.ts +150 -150
- package/src/programmers/internal/json_schema_station.ts +2 -2
- package/src/programmers/internal/metadata_to_pattern.ts +40 -40
- package/src/programmers/internal/postfix_of_tuple.ts +3 -3
- package/src/programmers/internal/prune_object_properties.ts +69 -69
- package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
- package/src/programmers/internal/stringify_native.ts +5 -5
- package/src/programmers/internal/stringify_regular_properties.ts +77 -77
- package/src/programmers/internal/template_to_pattern.ts +21 -21
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
- package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
- package/src/protobuf.ts +820 -820
- package/src/reflect.ts +46 -46
- package/src/schemas/json/IJsonApplication.ts +77 -77
- package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
- package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
- package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
- package/src/schemas/metadata/Metadata.ts +669 -669
- package/src/schemas/metadata/MetadataAliasType.ts +57 -57
- package/src/schemas/metadata/MetadataApplication.ts +40 -40
- package/src/schemas/metadata/MetadataArray.ts +47 -47
- package/src/schemas/metadata/MetadataArrayType.ts +51 -51
- package/src/schemas/metadata/MetadataAtomic.ts +85 -85
- package/src/schemas/metadata/MetadataEscaped.ts +45 -45
- package/src/schemas/metadata/MetadataFunction.ts +45 -45
- package/src/schemas/metadata/MetadataObject.ts +46 -46
- package/src/schemas/metadata/MetadataObjectType.ts +137 -137
- package/src/schemas/metadata/MetadataParameter.ts +52 -52
- package/src/schemas/metadata/MetadataProperty.ts +53 -53
- package/src/schemas/metadata/MetadataTemplate.ts +78 -78
- package/src/schemas/metadata/MetadataTuple.ts +28 -28
- package/src/schemas/metadata/MetadataTupleType.ts +61 -61
- package/src/tags/Constant.ts +47 -47
- package/src/tags/ContentMediaType.ts +27 -27
- package/src/tags/Default.ts +52 -52
- package/src/tags/Example.ts +56 -56
- package/src/tags/Examples.ts +56 -56
- package/src/tags/ExclusiveMaximum.ts +44 -44
- package/src/tags/ExclusiveMinimum.ts +44 -44
- package/src/tags/Format.ts +78 -78
- package/src/tags/JsonSchemaPlugin.ts +36 -36
- package/src/tags/MaxItems.ts +31 -31
- package/src/tags/MaxLength.ts +25 -25
- package/src/tags/Maximum.ts +39 -39
- package/src/tags/MinItems.ts +31 -31
- package/src/tags/MinLength.ts +25 -25
- package/src/tags/Minimum.ts +39 -39
- package/src/tags/MultipleOf.ts +42 -42
- package/src/tags/Pattern.ts +49 -49
- package/src/tags/Sequence.ts +37 -37
- package/src/tags/TagBase.ts +102 -102
- package/src/tags/Type.ts +64 -64
- package/src/tags/UniqueItems.ts +34 -34
- package/src/tags/internal/FormatCheatSheet.ts +71 -71
- package/src/transformers/ITransformOptions.ts +70 -70
- package/src/transformers/ImportTransformer.ts +253 -253
- package/src/transformers/NoTransformConfigurationError.ts +16 -16
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
- package/src/typings/Equal.ts +18 -18
package/src/misc.ts
CHANGED
|
@@ -1,594 +1,594 @@
|
|
|
1
|
-
/* ===========================================================
|
|
2
|
-
MISCELLANEOUS
|
|
3
|
-
- LITERALS
|
|
4
|
-
- CLONE
|
|
5
|
-
- PRUNE
|
|
6
|
-
- FACTORY FUNCTIONS
|
|
7
|
-
==============================================================
|
|
8
|
-
LITERALS
|
|
9
|
-
----------------------------------------------------------- */
|
|
10
|
-
import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
|
|
11
|
-
|
|
12
|
-
import { Atomic } from "./typings/Atomic";
|
|
13
|
-
|
|
14
|
-
import { IValidation } from "./IValidation";
|
|
15
|
-
import { Resolved } from "./Resolved";
|
|
16
|
-
import { TypeGuardError } from "./TypeGuardError";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* > You must configure the generic argument `T`.
|
|
20
|
-
*
|
|
21
|
-
* Union literal type to array.
|
|
22
|
-
*
|
|
23
|
-
* Converts a union literal type to an array of its members.
|
|
24
|
-
*
|
|
25
|
-
* ```typescript
|
|
26
|
-
* literals<"A" | "B" | 1>; // ["A", "B", 1]
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
30
|
-
* @template T Union literal type
|
|
31
|
-
* @returns Array of union literal type's members
|
|
32
|
-
*/
|
|
33
|
-
export function literals(): never;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Union literal type to array.
|
|
37
|
-
*
|
|
38
|
-
* Converts a union literal type to an array of its members.
|
|
39
|
-
*
|
|
40
|
-
* ```typescript
|
|
41
|
-
* literals<"A" | "B" | 1>; // ["A", "B", 1]
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
45
|
-
* @template T Union literal type
|
|
46
|
-
* @returns Array of union literal type's members
|
|
47
|
-
*/
|
|
48
|
-
export function literals<T extends Atomic.Type | null>(): T[];
|
|
49
|
-
|
|
50
|
-
/** @internal */
|
|
51
|
-
export function literals(): never {
|
|
52
|
-
NoTransformConfigurationError("misc.literals");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/* -----------------------------------------------------------
|
|
56
|
-
CLONE
|
|
57
|
-
----------------------------------------------------------- */
|
|
58
|
-
/**
|
|
59
|
-
* Clone data.
|
|
60
|
-
*
|
|
61
|
-
* Clones an instance following type `T`. If the target _input_ value or its
|
|
62
|
-
* member variable contains a class instance having methods, those methods would
|
|
63
|
-
* not be cloned.
|
|
64
|
-
*
|
|
65
|
-
* For reference, this `typia.misc.clone()` function does not validate the input
|
|
66
|
-
* value type. It just believes that the input value is following the type `T`.
|
|
67
|
-
* Therefore, if you can't ensure the input value type, it would be better to
|
|
68
|
-
* call {@link assertClone} function instead.
|
|
69
|
-
*
|
|
70
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
71
|
-
* @template T Type of the input value
|
|
72
|
-
* @param input A value to be cloned
|
|
73
|
-
* @returns Cloned data
|
|
74
|
-
*/
|
|
75
|
-
export function clone<T>(input: T): Resolved<T>;
|
|
76
|
-
|
|
77
|
-
/** @internal */
|
|
78
|
-
export function clone(): never {
|
|
79
|
-
NoTransformConfigurationError("misc.clone");
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Clone data with type assertion.
|
|
84
|
-
*
|
|
85
|
-
* Clones an instance following type `T`, with type assertion. If the target
|
|
86
|
-
* `input` value or its member variable contains a class instance having
|
|
87
|
-
* methods, those methods would not be cloned.
|
|
88
|
-
*
|
|
89
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
90
|
-
* throws an {@link TypeGuardError} or custom error generated by _errorFactory_.
|
|
91
|
-
* Otherwise, there's no problem on the `input` value, cloned data would be
|
|
92
|
-
* returned.
|
|
93
|
-
*
|
|
94
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
95
|
-
* @template T Type of the input value
|
|
96
|
-
* @param input A value to be cloned
|
|
97
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
98
|
-
* @returns Cloned data
|
|
99
|
-
*/
|
|
100
|
-
export function assertClone<T>(
|
|
101
|
-
input: T,
|
|
102
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
103
|
-
): Resolved<T>;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Clone data with type assertion.
|
|
107
|
-
*
|
|
108
|
-
* Clones an instance following type `T`, with type assertion. If the target
|
|
109
|
-
* `input` value or its member variable contains a class instance having
|
|
110
|
-
* methods, those methods would not be cloned.
|
|
111
|
-
*
|
|
112
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
113
|
-
* throws an {@link TypeGuardError} or custom error generated by _errorFactory_.
|
|
114
|
-
* Otherwise, there's no problem on the `input` value, cloned data would be
|
|
115
|
-
* returned.
|
|
116
|
-
*
|
|
117
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
118
|
-
* @template T Type of the input value
|
|
119
|
-
* @param input A value to be cloned
|
|
120
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
121
|
-
* @returns Cloned data
|
|
122
|
-
*/
|
|
123
|
-
export function assertClone<T>(
|
|
124
|
-
input: unknown,
|
|
125
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
126
|
-
): Resolved<T>;
|
|
127
|
-
|
|
128
|
-
/** @internal */
|
|
129
|
-
export function assertClone(): never {
|
|
130
|
-
NoTransformConfigurationError("misc.assertClone");
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Clone data with type checking.
|
|
135
|
-
*
|
|
136
|
-
* Clones an instance following type `T`, with type checking. If the target
|
|
137
|
-
* `input` value or its member variable contains a class instance having
|
|
138
|
-
* methods, those methods would not be cloned.
|
|
139
|
-
*
|
|
140
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
141
|
-
* returns `null` value instead. Otherwise, there's no problem on the `input`
|
|
142
|
-
* value, cloned data would be returned.
|
|
143
|
-
*
|
|
144
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
145
|
-
* @template T Type of the input value
|
|
146
|
-
* @param input A value to be cloned
|
|
147
|
-
* @returns Cloned data when exact type, otherwise null
|
|
148
|
-
*/
|
|
149
|
-
export function isClone<T>(input: T): Resolved<T> | null;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Clone data with type checking.
|
|
153
|
-
*
|
|
154
|
-
* Clones an instance following type `T`, with type checking. If the target
|
|
155
|
-
* `input` value or its member variable contains a class instance having
|
|
156
|
-
* methods, those methods would not be cloned.
|
|
157
|
-
*
|
|
158
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
159
|
-
* returns `null` value instead. Otherwise, there's no problem on the `input`
|
|
160
|
-
* value, cloned data would be returned.
|
|
161
|
-
*
|
|
162
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
163
|
-
* @template T Type of the input value
|
|
164
|
-
* @param input A value to be cloned
|
|
165
|
-
* @returns Cloned data when exact type, otherwise null
|
|
166
|
-
*/
|
|
167
|
-
export function isClone<T>(input: unknown): Resolved<T> | null;
|
|
168
|
-
|
|
169
|
-
/** @internal */
|
|
170
|
-
export function isClone(): never {
|
|
171
|
-
NoTransformConfigurationError("misc.isClone");
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Clone data with detailed type validation.
|
|
176
|
-
*
|
|
177
|
-
* Clones an instance following type `T`, with detailed type validation. If the
|
|
178
|
-
* target `input` value or its member variable contains a class instance having
|
|
179
|
-
* methods, those methods would not be cloned.
|
|
180
|
-
*
|
|
181
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
182
|
-
* returns {@link IValidation.Failure} value. Otherwise, there's no problem on
|
|
183
|
-
* the `input` value, cloned data would be stored in `data` property of the
|
|
184
|
-
* output {@link IValidation.Success} instance.
|
|
185
|
-
*
|
|
186
|
-
* @template T Type of the input value
|
|
187
|
-
* @param input A value to be cloned
|
|
188
|
-
* @returns Validation result with cloned value
|
|
189
|
-
*/
|
|
190
|
-
export function validateClone<T>(input: T): IValidation<Resolved<T>>;
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Clone data with detailed type validation.
|
|
194
|
-
*
|
|
195
|
-
* Clones an instance following type `T`, with detailed type validation. If the
|
|
196
|
-
* target `input` value or its member variable contains a class instance having
|
|
197
|
-
* methods, those methods would not be cloned.
|
|
198
|
-
*
|
|
199
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
200
|
-
* returns {@link IValidation.Failure} value. Otherwise, there's no problem on
|
|
201
|
-
* the `input` value, cloned data would be stored in `data` property of the
|
|
202
|
-
* output {@link IValidation.Success} instance.
|
|
203
|
-
*
|
|
204
|
-
* @template T Type of the input value
|
|
205
|
-
* @param input A value to be cloned
|
|
206
|
-
* @returns Validation result with cloned value
|
|
207
|
-
*/
|
|
208
|
-
export function validateClone<T>(input: unknown): IValidation<Resolved<T>>;
|
|
209
|
-
|
|
210
|
-
/** @internal */
|
|
211
|
-
export function validateClone(): never {
|
|
212
|
-
NoTransformConfigurationError("misc.validateClone");
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/* -----------------------------------------------------------
|
|
216
|
-
PRUNE
|
|
217
|
-
----------------------------------------------------------- */
|
|
218
|
-
/**
|
|
219
|
-
* Prune, erase superfluous properties.
|
|
220
|
-
*
|
|
221
|
-
* Remove all superfluous properties from the `input` object, even including
|
|
222
|
-
* nested objects. Note that, as all superfluous properties would be deleted,
|
|
223
|
-
* you never can read those superfluous properties after calling this `prune()`
|
|
224
|
-
* function.
|
|
225
|
-
*
|
|
226
|
-
* For reference, this `typia.misc.prune()` function does not validate the input
|
|
227
|
-
* value type. It just believes that the input value is following the type `T`.
|
|
228
|
-
* Therefore, if you can't ensure the input value type, it would better to call
|
|
229
|
-
* one of below functions instead.
|
|
230
|
-
*
|
|
231
|
-
* - {@link assertPrune}
|
|
232
|
-
* - {@link isPrune}
|
|
233
|
-
* - {@link validatePrune}
|
|
234
|
-
*
|
|
235
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
236
|
-
* @template T Type of the input value
|
|
237
|
-
* @param input Target instance to prune
|
|
238
|
-
*/
|
|
239
|
-
export function prune<T extends object>(input: T): void;
|
|
240
|
-
|
|
241
|
-
/** @internal */
|
|
242
|
-
export function prune(): never {
|
|
243
|
-
NoTransformConfigurationError("misc.prune");
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Prune, erase superfluous properties, with type assertion.
|
|
248
|
-
*
|
|
249
|
-
* `typia.misc.assertPrune()` is a combination function of {@link assert} and
|
|
250
|
-
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
251
|
-
* `input` object including nested objects, with type assertion.
|
|
252
|
-
*
|
|
253
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
254
|
-
* throws an {@link TypeGuardError} or custom error generated by _errorFactory_.
|
|
255
|
-
* Otherwise, there's no problem on the `input` value, its all superfluous
|
|
256
|
-
* properties would be removed, including nested objects.
|
|
257
|
-
*
|
|
258
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
259
|
-
* @template T Type of the input value
|
|
260
|
-
* @param input Target instance to assert and prune
|
|
261
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
262
|
-
*/
|
|
263
|
-
export function assertPrune<T>(
|
|
264
|
-
input: T,
|
|
265
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
266
|
-
): T;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Prune, erase superfluous properties, with type assertion.
|
|
270
|
-
*
|
|
271
|
-
* `typia.misc.assertPrune()` is a combination function of {@link assert} and
|
|
272
|
-
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
273
|
-
* `input` object including nested objects, with type assertion.
|
|
274
|
-
*
|
|
275
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
276
|
-
* throws an {@link TypeGuardError} or custom error generated by _errorFactory_.
|
|
277
|
-
* Otherwise, there's no problem on the `input` value, its all superfluous
|
|
278
|
-
* properties would be removed, including nested objects.
|
|
279
|
-
*
|
|
280
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
281
|
-
* @template T Type of the input value
|
|
282
|
-
* @param input Target instance to assert and prune
|
|
283
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
284
|
-
*/
|
|
285
|
-
export function assertPrune<T>(
|
|
286
|
-
input: unknown,
|
|
287
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
288
|
-
): T;
|
|
289
|
-
|
|
290
|
-
/** @internal */
|
|
291
|
-
export function assertPrune(): unknown {
|
|
292
|
-
NoTransformConfigurationError("misc.assertPrune");
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Prune, erase superfluous properties, with type checking.
|
|
297
|
-
*
|
|
298
|
-
* `typia.misc.isPrune()` is a combination function of {@link is} and
|
|
299
|
-
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
300
|
-
* `input` object including nested objects, with type checking.
|
|
301
|
-
*
|
|
302
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
303
|
-
* returns `false` value. Otherwise, there's no problem on the `input` value, it
|
|
304
|
-
* returns `true` after removing all superfluous properties, including nested
|
|
305
|
-
* objects.
|
|
306
|
-
*
|
|
307
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
308
|
-
* @template T Type of the input value
|
|
309
|
-
* @param input Target instance to check and prune
|
|
310
|
-
* @returns Whether the parametric value is following the type `T` or not
|
|
311
|
-
*/
|
|
312
|
-
export function isPrune<T>(input: T): input is T;
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Prune, erase superfluous properties, with type checking.
|
|
316
|
-
*
|
|
317
|
-
* `typia.misc.isPrune()` is a combination function of {@link is} and
|
|
318
|
-
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
319
|
-
* `input` object including nested objects, with type checking.
|
|
320
|
-
*
|
|
321
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
322
|
-
* returns `false` value. Otherwise, there's no problem on the `input` value, it
|
|
323
|
-
* returns `true` after removing all superfluous properties, including nested
|
|
324
|
-
* objects.
|
|
325
|
-
*
|
|
326
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
327
|
-
* @template T Type of the input value
|
|
328
|
-
* @param input Target instance to check and prune
|
|
329
|
-
* @returns Whether the parametric value is following the type `T` or not
|
|
330
|
-
*/
|
|
331
|
-
export function isPrune<T>(input: unknown): input is T;
|
|
332
|
-
|
|
333
|
-
/** @internal */
|
|
334
|
-
export function isPrune(): never {
|
|
335
|
-
NoTransformConfigurationError("misc.isPrune");
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Prune, erase superfluous properties, with type validation.
|
|
340
|
-
*
|
|
341
|
-
* `typia.misc.validatePrune()` is a combination function of {@link validate} and
|
|
342
|
-
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
343
|
-
* `input` object including nested objects, with type validation.
|
|
344
|
-
*
|
|
345
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
346
|
-
* returns {@link IValidation.IFailure} value with detailed error reasons.
|
|
347
|
-
* Otherwise, there's no problem on the `input` value, it returns
|
|
348
|
-
* {@link IValidation.ISuccess} value after removing all superfluous properties,
|
|
349
|
-
* including nested objects.
|
|
350
|
-
*
|
|
351
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
352
|
-
* @template T Type of the input value
|
|
353
|
-
* @param input Target instance to validate and prune
|
|
354
|
-
* @returns Validation result
|
|
355
|
-
*/
|
|
356
|
-
export function validatePrune<T>(input: T): IValidation<T>;
|
|
357
|
-
|
|
358
|
-
/**
|
|
359
|
-
* Prune, erase superfluous properties, with type validation.
|
|
360
|
-
*
|
|
361
|
-
* `typia.misc.validatePrune()` is a combination function of {@link validate} and
|
|
362
|
-
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
363
|
-
* `input` object including nested objects, with type validation.
|
|
364
|
-
*
|
|
365
|
-
* In such reason, when `input` value is not matched with the type `T`, it
|
|
366
|
-
* returns {@link IValidation.IFailure} value with detailed error reasons.
|
|
367
|
-
* Otherwise, there's no problem on the `input` value, it returns
|
|
368
|
-
* {@link IValidation.ISuccess} value after removing all superfluous properties,
|
|
369
|
-
* including nested objects.
|
|
370
|
-
*
|
|
371
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
372
|
-
* @template T Type of the input value
|
|
373
|
-
* @param input Target instance to validate and prune
|
|
374
|
-
* @returns Validation result
|
|
375
|
-
*/
|
|
376
|
-
export function validatePrune<T>(input: unknown): IValidation<T>;
|
|
377
|
-
|
|
378
|
-
/** @internal */
|
|
379
|
-
export function validatePrune<T>(): IValidation<T> {
|
|
380
|
-
NoTransformConfigurationError("misc.validatePrune");
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/* -----------------------------------------------------------
|
|
384
|
-
FACTORY FUNCTIONS
|
|
385
|
-
----------------------------------------------------------- */
|
|
386
|
-
/**
|
|
387
|
-
* Creates a reusable {@link clone} function.
|
|
388
|
-
*
|
|
389
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
390
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
391
|
-
* @throws Compile error
|
|
392
|
-
* @danger You must configure the generic argument `T`
|
|
393
|
-
*/
|
|
394
|
-
export function createClone(): never;
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Creates a reusable {@link clone} function.
|
|
398
|
-
*
|
|
399
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
400
|
-
* @template T Type of the input value
|
|
401
|
-
* @returns A reusable `clone` function
|
|
402
|
-
*/
|
|
403
|
-
export function createClone<T>(): (input: T) => Resolved<T>;
|
|
404
|
-
|
|
405
|
-
/** @internal */
|
|
406
|
-
export function createClone(): never {
|
|
407
|
-
NoTransformConfigurationError("misc.createClone");
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Creates a reusable {@link assertClone} function.
|
|
412
|
-
*
|
|
413
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
414
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
415
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
416
|
-
* @throws Compile error
|
|
417
|
-
* @danger You must configure the generic argument `T`
|
|
418
|
-
*/
|
|
419
|
-
export function createAssertClone(
|
|
420
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
421
|
-
): never;
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Creates a reusable {@link assertClone} function.
|
|
425
|
-
*
|
|
426
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
427
|
-
* @template T Type of the input value
|
|
428
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
429
|
-
* @returns A reusable `clone` function
|
|
430
|
-
*/
|
|
431
|
-
export function createAssertClone<T>(
|
|
432
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
433
|
-
): (input: unknown) => Resolved<T>;
|
|
434
|
-
|
|
435
|
-
/** @internal */
|
|
436
|
-
export function createAssertClone(): never {
|
|
437
|
-
NoTransformConfigurationError("misc.createAssertClone");
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Creates a reusable {@link isClone} function.
|
|
442
|
-
*
|
|
443
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
444
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
445
|
-
* @throws Compile error
|
|
446
|
-
* @danger You must configure the generic argument `T`
|
|
447
|
-
*/
|
|
448
|
-
export function createIsClone(): never;
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Creates a reusable {@link isClone} function.
|
|
452
|
-
*
|
|
453
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
454
|
-
* @template T Type of the input value
|
|
455
|
-
* @returns A reusable `clone` function
|
|
456
|
-
*/
|
|
457
|
-
export function createIsClone<T>(): (input: unknown) => Resolved<T> | null;
|
|
458
|
-
|
|
459
|
-
/** @internal */
|
|
460
|
-
export function createIsClone(): never {
|
|
461
|
-
NoTransformConfigurationError("misc.createIsClone");
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* Creates a reusable {@link validateClone} function.
|
|
466
|
-
*
|
|
467
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
468
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
469
|
-
* @throws Compile error
|
|
470
|
-
* @danger You must configure the generic argument `T`
|
|
471
|
-
*/
|
|
472
|
-
export function createValidateClone(): never;
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* Creates a reusable {@link validateClone} function.
|
|
476
|
-
*
|
|
477
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
478
|
-
* @template T Type of the input value
|
|
479
|
-
* @returns A reusable `clone` function
|
|
480
|
-
*/
|
|
481
|
-
export function createValidateClone<T>(): (
|
|
482
|
-
input: unknown,
|
|
483
|
-
) => IValidation<Resolved<T>>;
|
|
484
|
-
|
|
485
|
-
/** @internal */
|
|
486
|
-
export function createValidateClone(): never {
|
|
487
|
-
NoTransformConfigurationError("misc.createValidateClone");
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Creates a reusable {@link prune} function.
|
|
492
|
-
*
|
|
493
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
494
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
495
|
-
* @throws Compile error
|
|
496
|
-
* @danger You must configure the generic argument `T`
|
|
497
|
-
*/
|
|
498
|
-
export function createPrune(): never;
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Creates a reusable {@link prune} function.
|
|
502
|
-
*
|
|
503
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
504
|
-
* @template T Type of the input value
|
|
505
|
-
* @returns A reusable `prune` function
|
|
506
|
-
*/
|
|
507
|
-
export function createPrune<T extends object>(): (input: T) => void;
|
|
508
|
-
|
|
509
|
-
/** @internal */
|
|
510
|
-
export function createPrune<T extends object>(): (input: T) => void {
|
|
511
|
-
NoTransformConfigurationError("misc.createPrune");
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Creates a reusable {@link assertPrune} function.
|
|
516
|
-
*
|
|
517
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
518
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
519
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
520
|
-
* @throws Compile error
|
|
521
|
-
* @danger You must configure the generic argument `T`
|
|
522
|
-
*/
|
|
523
|
-
export function createAssertPrune(
|
|
524
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
525
|
-
): never;
|
|
526
|
-
|
|
527
|
-
/**
|
|
528
|
-
* Creates a reusable {@link assertPrune} function.
|
|
529
|
-
*
|
|
530
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
531
|
-
* @template T Type of the input value
|
|
532
|
-
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
533
|
-
* @returns A reusable `isPrune` function
|
|
534
|
-
*/
|
|
535
|
-
export function createAssertPrune<T extends object>(
|
|
536
|
-
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
537
|
-
): (input: T) => T;
|
|
538
|
-
|
|
539
|
-
/** @internal */
|
|
540
|
-
export function createAssertPrune<T extends object>(): (input: T) => T {
|
|
541
|
-
NoTransformConfigurationError("misc.createAssertPrune");
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Creates a reusable {@link isPrune} function.
|
|
546
|
-
*
|
|
547
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
548
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
549
|
-
* @throws Compile error
|
|
550
|
-
* @danger You must configure the generic argument `T`
|
|
551
|
-
*/
|
|
552
|
-
export function createIsPrune(): never;
|
|
553
|
-
|
|
554
|
-
/**
|
|
555
|
-
* Creates a reusable {@link isPrune} function.
|
|
556
|
-
*
|
|
557
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
558
|
-
* @template T Type of the input value
|
|
559
|
-
* @returns A reusable `isPrune` function
|
|
560
|
-
*/
|
|
561
|
-
export function createIsPrune<T extends object>(): (input: T) => input is T;
|
|
562
|
-
|
|
563
|
-
/** @internal */
|
|
564
|
-
export function createIsPrune<T extends object>(): (input: T) => input is T {
|
|
565
|
-
NoTransformConfigurationError("misc.createIsPrune");
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* Creates a reusable {@link validatePrune} function.
|
|
570
|
-
*
|
|
571
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
572
|
-
* @returns Nothing until you configure the generic argument `T`
|
|
573
|
-
* @throws Compile error
|
|
574
|
-
* @danger You must configure the generic argument `T`
|
|
575
|
-
*/
|
|
576
|
-
export function createValidatePrune(): never;
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Creates a reusable {@link validatePrune} function.
|
|
580
|
-
*
|
|
581
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
582
|
-
* @template T Type of the input value
|
|
583
|
-
* @returns A reusable `validatePrune` function
|
|
584
|
-
*/
|
|
585
|
-
export function createValidatePrune<T extends object>(): (
|
|
586
|
-
input: T,
|
|
587
|
-
) => IValidation<T>;
|
|
588
|
-
|
|
589
|
-
/** @internal */
|
|
590
|
-
export function createValidatePrune<T extends object>(): (
|
|
591
|
-
input: T,
|
|
592
|
-
) => IValidation<T> {
|
|
593
|
-
NoTransformConfigurationError("misc.createValidatePrune");
|
|
594
|
-
}
|
|
1
|
+
/* ===========================================================
|
|
2
|
+
MISCELLANEOUS
|
|
3
|
+
- LITERALS
|
|
4
|
+
- CLONE
|
|
5
|
+
- PRUNE
|
|
6
|
+
- FACTORY FUNCTIONS
|
|
7
|
+
==============================================================
|
|
8
|
+
LITERALS
|
|
9
|
+
----------------------------------------------------------- */
|
|
10
|
+
import { NoTransformConfigurationError } from "./transformers/NoTransformConfigurationError";
|
|
11
|
+
|
|
12
|
+
import { Atomic } from "./typings/Atomic";
|
|
13
|
+
|
|
14
|
+
import { IValidation } from "./IValidation";
|
|
15
|
+
import { Resolved } from "./Resolved";
|
|
16
|
+
import { TypeGuardError } from "./TypeGuardError";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* > You must configure the generic argument `T`.
|
|
20
|
+
*
|
|
21
|
+
* Union literal type to array.
|
|
22
|
+
*
|
|
23
|
+
* Converts a union literal type to an array of its members.
|
|
24
|
+
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* literals<"A" | "B" | 1>; // ["A", "B", 1]
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
30
|
+
* @template T Union literal type
|
|
31
|
+
* @returns Array of union literal type's members
|
|
32
|
+
*/
|
|
33
|
+
export function literals(): never;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Union literal type to array.
|
|
37
|
+
*
|
|
38
|
+
* Converts a union literal type to an array of its members.
|
|
39
|
+
*
|
|
40
|
+
* ```typescript
|
|
41
|
+
* literals<"A" | "B" | 1>; // ["A", "B", 1]
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
45
|
+
* @template T Union literal type
|
|
46
|
+
* @returns Array of union literal type's members
|
|
47
|
+
*/
|
|
48
|
+
export function literals<T extends Atomic.Type | null>(): T[];
|
|
49
|
+
|
|
50
|
+
/** @internal */
|
|
51
|
+
export function literals(): never {
|
|
52
|
+
NoTransformConfigurationError("misc.literals");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* -----------------------------------------------------------
|
|
56
|
+
CLONE
|
|
57
|
+
----------------------------------------------------------- */
|
|
58
|
+
/**
|
|
59
|
+
* Clone data.
|
|
60
|
+
*
|
|
61
|
+
* Clones an instance following type `T`. If the target _input_ value or its
|
|
62
|
+
* member variable contains a class instance having methods, those methods would
|
|
63
|
+
* not be cloned.
|
|
64
|
+
*
|
|
65
|
+
* For reference, this `typia.misc.clone()` function does not validate the input
|
|
66
|
+
* value type. It just believes that the input value is following the type `T`.
|
|
67
|
+
* Therefore, if you can't ensure the input value type, it would be better to
|
|
68
|
+
* call {@link assertClone} function instead.
|
|
69
|
+
*
|
|
70
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
71
|
+
* @template T Type of the input value
|
|
72
|
+
* @param input A value to be cloned
|
|
73
|
+
* @returns Cloned data
|
|
74
|
+
*/
|
|
75
|
+
export function clone<T>(input: T): Resolved<T>;
|
|
76
|
+
|
|
77
|
+
/** @internal */
|
|
78
|
+
export function clone(): never {
|
|
79
|
+
NoTransformConfigurationError("misc.clone");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Clone data with type assertion.
|
|
84
|
+
*
|
|
85
|
+
* Clones an instance following type `T`, with type assertion. If the target
|
|
86
|
+
* `input` value or its member variable contains a class instance having
|
|
87
|
+
* methods, those methods would not be cloned.
|
|
88
|
+
*
|
|
89
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
90
|
+
* throws an {@link TypeGuardError} or custom error generated by _errorFactory_.
|
|
91
|
+
* Otherwise, there's no problem on the `input` value, cloned data would be
|
|
92
|
+
* returned.
|
|
93
|
+
*
|
|
94
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
95
|
+
* @template T Type of the input value
|
|
96
|
+
* @param input A value to be cloned
|
|
97
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
98
|
+
* @returns Cloned data
|
|
99
|
+
*/
|
|
100
|
+
export function assertClone<T>(
|
|
101
|
+
input: T,
|
|
102
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
103
|
+
): Resolved<T>;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Clone data with type assertion.
|
|
107
|
+
*
|
|
108
|
+
* Clones an instance following type `T`, with type assertion. If the target
|
|
109
|
+
* `input` value or its member variable contains a class instance having
|
|
110
|
+
* methods, those methods would not be cloned.
|
|
111
|
+
*
|
|
112
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
113
|
+
* throws an {@link TypeGuardError} or custom error generated by _errorFactory_.
|
|
114
|
+
* Otherwise, there's no problem on the `input` value, cloned data would be
|
|
115
|
+
* returned.
|
|
116
|
+
*
|
|
117
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
118
|
+
* @template T Type of the input value
|
|
119
|
+
* @param input A value to be cloned
|
|
120
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
121
|
+
* @returns Cloned data
|
|
122
|
+
*/
|
|
123
|
+
export function assertClone<T>(
|
|
124
|
+
input: unknown,
|
|
125
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
126
|
+
): Resolved<T>;
|
|
127
|
+
|
|
128
|
+
/** @internal */
|
|
129
|
+
export function assertClone(): never {
|
|
130
|
+
NoTransformConfigurationError("misc.assertClone");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Clone data with type checking.
|
|
135
|
+
*
|
|
136
|
+
* Clones an instance following type `T`, with type checking. If the target
|
|
137
|
+
* `input` value or its member variable contains a class instance having
|
|
138
|
+
* methods, those methods would not be cloned.
|
|
139
|
+
*
|
|
140
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
141
|
+
* returns `null` value instead. Otherwise, there's no problem on the `input`
|
|
142
|
+
* value, cloned data would be returned.
|
|
143
|
+
*
|
|
144
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
145
|
+
* @template T Type of the input value
|
|
146
|
+
* @param input A value to be cloned
|
|
147
|
+
* @returns Cloned data when exact type, otherwise null
|
|
148
|
+
*/
|
|
149
|
+
export function isClone<T>(input: T): Resolved<T> | null;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Clone data with type checking.
|
|
153
|
+
*
|
|
154
|
+
* Clones an instance following type `T`, with type checking. If the target
|
|
155
|
+
* `input` value or its member variable contains a class instance having
|
|
156
|
+
* methods, those methods would not be cloned.
|
|
157
|
+
*
|
|
158
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
159
|
+
* returns `null` value instead. Otherwise, there's no problem on the `input`
|
|
160
|
+
* value, cloned data would be returned.
|
|
161
|
+
*
|
|
162
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
163
|
+
* @template T Type of the input value
|
|
164
|
+
* @param input A value to be cloned
|
|
165
|
+
* @returns Cloned data when exact type, otherwise null
|
|
166
|
+
*/
|
|
167
|
+
export function isClone<T>(input: unknown): Resolved<T> | null;
|
|
168
|
+
|
|
169
|
+
/** @internal */
|
|
170
|
+
export function isClone(): never {
|
|
171
|
+
NoTransformConfigurationError("misc.isClone");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Clone data with detailed type validation.
|
|
176
|
+
*
|
|
177
|
+
* Clones an instance following type `T`, with detailed type validation. If the
|
|
178
|
+
* target `input` value or its member variable contains a class instance having
|
|
179
|
+
* methods, those methods would not be cloned.
|
|
180
|
+
*
|
|
181
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
182
|
+
* returns {@link IValidation.Failure} value. Otherwise, there's no problem on
|
|
183
|
+
* the `input` value, cloned data would be stored in `data` property of the
|
|
184
|
+
* output {@link IValidation.Success} instance.
|
|
185
|
+
*
|
|
186
|
+
* @template T Type of the input value
|
|
187
|
+
* @param input A value to be cloned
|
|
188
|
+
* @returns Validation result with cloned value
|
|
189
|
+
*/
|
|
190
|
+
export function validateClone<T>(input: T): IValidation<Resolved<T>>;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Clone data with detailed type validation.
|
|
194
|
+
*
|
|
195
|
+
* Clones an instance following type `T`, with detailed type validation. If the
|
|
196
|
+
* target `input` value or its member variable contains a class instance having
|
|
197
|
+
* methods, those methods would not be cloned.
|
|
198
|
+
*
|
|
199
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
200
|
+
* returns {@link IValidation.Failure} value. Otherwise, there's no problem on
|
|
201
|
+
* the `input` value, cloned data would be stored in `data` property of the
|
|
202
|
+
* output {@link IValidation.Success} instance.
|
|
203
|
+
*
|
|
204
|
+
* @template T Type of the input value
|
|
205
|
+
* @param input A value to be cloned
|
|
206
|
+
* @returns Validation result with cloned value
|
|
207
|
+
*/
|
|
208
|
+
export function validateClone<T>(input: unknown): IValidation<Resolved<T>>;
|
|
209
|
+
|
|
210
|
+
/** @internal */
|
|
211
|
+
export function validateClone(): never {
|
|
212
|
+
NoTransformConfigurationError("misc.validateClone");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/* -----------------------------------------------------------
|
|
216
|
+
PRUNE
|
|
217
|
+
----------------------------------------------------------- */
|
|
218
|
+
/**
|
|
219
|
+
* Prune, erase superfluous properties.
|
|
220
|
+
*
|
|
221
|
+
* Remove all superfluous properties from the `input` object, even including
|
|
222
|
+
* nested objects. Note that, as all superfluous properties would be deleted,
|
|
223
|
+
* you never can read those superfluous properties after calling this `prune()`
|
|
224
|
+
* function.
|
|
225
|
+
*
|
|
226
|
+
* For reference, this `typia.misc.prune()` function does not validate the input
|
|
227
|
+
* value type. It just believes that the input value is following the type `T`.
|
|
228
|
+
* Therefore, if you can't ensure the input value type, it would better to call
|
|
229
|
+
* one of below functions instead.
|
|
230
|
+
*
|
|
231
|
+
* - {@link assertPrune}
|
|
232
|
+
* - {@link isPrune}
|
|
233
|
+
* - {@link validatePrune}
|
|
234
|
+
*
|
|
235
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
236
|
+
* @template T Type of the input value
|
|
237
|
+
* @param input Target instance to prune
|
|
238
|
+
*/
|
|
239
|
+
export function prune<T extends object>(input: T): void;
|
|
240
|
+
|
|
241
|
+
/** @internal */
|
|
242
|
+
export function prune(): never {
|
|
243
|
+
NoTransformConfigurationError("misc.prune");
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Prune, erase superfluous properties, with type assertion.
|
|
248
|
+
*
|
|
249
|
+
* `typia.misc.assertPrune()` is a combination function of {@link assert} and
|
|
250
|
+
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
251
|
+
* `input` object including nested objects, with type assertion.
|
|
252
|
+
*
|
|
253
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
254
|
+
* throws an {@link TypeGuardError} or custom error generated by _errorFactory_.
|
|
255
|
+
* Otherwise, there's no problem on the `input` value, its all superfluous
|
|
256
|
+
* properties would be removed, including nested objects.
|
|
257
|
+
*
|
|
258
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
259
|
+
* @template T Type of the input value
|
|
260
|
+
* @param input Target instance to assert and prune
|
|
261
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
262
|
+
*/
|
|
263
|
+
export function assertPrune<T>(
|
|
264
|
+
input: T,
|
|
265
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
266
|
+
): T;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Prune, erase superfluous properties, with type assertion.
|
|
270
|
+
*
|
|
271
|
+
* `typia.misc.assertPrune()` is a combination function of {@link assert} and
|
|
272
|
+
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
273
|
+
* `input` object including nested objects, with type assertion.
|
|
274
|
+
*
|
|
275
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
276
|
+
* throws an {@link TypeGuardError} or custom error generated by _errorFactory_.
|
|
277
|
+
* Otherwise, there's no problem on the `input` value, its all superfluous
|
|
278
|
+
* properties would be removed, including nested objects.
|
|
279
|
+
*
|
|
280
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
281
|
+
* @template T Type of the input value
|
|
282
|
+
* @param input Target instance to assert and prune
|
|
283
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
284
|
+
*/
|
|
285
|
+
export function assertPrune<T>(
|
|
286
|
+
input: unknown,
|
|
287
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
288
|
+
): T;
|
|
289
|
+
|
|
290
|
+
/** @internal */
|
|
291
|
+
export function assertPrune(): unknown {
|
|
292
|
+
NoTransformConfigurationError("misc.assertPrune");
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Prune, erase superfluous properties, with type checking.
|
|
297
|
+
*
|
|
298
|
+
* `typia.misc.isPrune()` is a combination function of {@link is} and
|
|
299
|
+
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
300
|
+
* `input` object including nested objects, with type checking.
|
|
301
|
+
*
|
|
302
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
303
|
+
* returns `false` value. Otherwise, there's no problem on the `input` value, it
|
|
304
|
+
* returns `true` after removing all superfluous properties, including nested
|
|
305
|
+
* objects.
|
|
306
|
+
*
|
|
307
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
308
|
+
* @template T Type of the input value
|
|
309
|
+
* @param input Target instance to check and prune
|
|
310
|
+
* @returns Whether the parametric value is following the type `T` or not
|
|
311
|
+
*/
|
|
312
|
+
export function isPrune<T>(input: T): input is T;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Prune, erase superfluous properties, with type checking.
|
|
316
|
+
*
|
|
317
|
+
* `typia.misc.isPrune()` is a combination function of {@link is} and
|
|
318
|
+
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
319
|
+
* `input` object including nested objects, with type checking.
|
|
320
|
+
*
|
|
321
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
322
|
+
* returns `false` value. Otherwise, there's no problem on the `input` value, it
|
|
323
|
+
* returns `true` after removing all superfluous properties, including nested
|
|
324
|
+
* objects.
|
|
325
|
+
*
|
|
326
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
327
|
+
* @template T Type of the input value
|
|
328
|
+
* @param input Target instance to check and prune
|
|
329
|
+
* @returns Whether the parametric value is following the type `T` or not
|
|
330
|
+
*/
|
|
331
|
+
export function isPrune<T>(input: unknown): input is T;
|
|
332
|
+
|
|
333
|
+
/** @internal */
|
|
334
|
+
export function isPrune(): never {
|
|
335
|
+
NoTransformConfigurationError("misc.isPrune");
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Prune, erase superfluous properties, with type validation.
|
|
340
|
+
*
|
|
341
|
+
* `typia.misc.validatePrune()` is a combination function of {@link validate} and
|
|
342
|
+
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
343
|
+
* `input` object including nested objects, with type validation.
|
|
344
|
+
*
|
|
345
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
346
|
+
* returns {@link IValidation.IFailure} value with detailed error reasons.
|
|
347
|
+
* Otherwise, there's no problem on the `input` value, it returns
|
|
348
|
+
* {@link IValidation.ISuccess} value after removing all superfluous properties,
|
|
349
|
+
* including nested objects.
|
|
350
|
+
*
|
|
351
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
352
|
+
* @template T Type of the input value
|
|
353
|
+
* @param input Target instance to validate and prune
|
|
354
|
+
* @returns Validation result
|
|
355
|
+
*/
|
|
356
|
+
export function validatePrune<T>(input: T): IValidation<T>;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Prune, erase superfluous properties, with type validation.
|
|
360
|
+
*
|
|
361
|
+
* `typia.misc.validatePrune()` is a combination function of {@link validate} and
|
|
362
|
+
* {@link prune}. Therefore, it removes all superfluous properties from the
|
|
363
|
+
* `input` object including nested objects, with type validation.
|
|
364
|
+
*
|
|
365
|
+
* In such reason, when `input` value is not matched with the type `T`, it
|
|
366
|
+
* returns {@link IValidation.IFailure} value with detailed error reasons.
|
|
367
|
+
* Otherwise, there's no problem on the `input` value, it returns
|
|
368
|
+
* {@link IValidation.ISuccess} value after removing all superfluous properties,
|
|
369
|
+
* including nested objects.
|
|
370
|
+
*
|
|
371
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
372
|
+
* @template T Type of the input value
|
|
373
|
+
* @param input Target instance to validate and prune
|
|
374
|
+
* @returns Validation result
|
|
375
|
+
*/
|
|
376
|
+
export function validatePrune<T>(input: unknown): IValidation<T>;
|
|
377
|
+
|
|
378
|
+
/** @internal */
|
|
379
|
+
export function validatePrune<T>(): IValidation<T> {
|
|
380
|
+
NoTransformConfigurationError("misc.validatePrune");
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/* -----------------------------------------------------------
|
|
384
|
+
FACTORY FUNCTIONS
|
|
385
|
+
----------------------------------------------------------- */
|
|
386
|
+
/**
|
|
387
|
+
* Creates a reusable {@link clone} function.
|
|
388
|
+
*
|
|
389
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
390
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
391
|
+
* @throws Compile error
|
|
392
|
+
* @danger You must configure the generic argument `T`
|
|
393
|
+
*/
|
|
394
|
+
export function createClone(): never;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Creates a reusable {@link clone} function.
|
|
398
|
+
*
|
|
399
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
400
|
+
* @template T Type of the input value
|
|
401
|
+
* @returns A reusable `clone` function
|
|
402
|
+
*/
|
|
403
|
+
export function createClone<T>(): (input: T) => Resolved<T>;
|
|
404
|
+
|
|
405
|
+
/** @internal */
|
|
406
|
+
export function createClone(): never {
|
|
407
|
+
NoTransformConfigurationError("misc.createClone");
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Creates a reusable {@link assertClone} function.
|
|
412
|
+
*
|
|
413
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
414
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
415
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
416
|
+
* @throws Compile error
|
|
417
|
+
* @danger You must configure the generic argument `T`
|
|
418
|
+
*/
|
|
419
|
+
export function createAssertClone(
|
|
420
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
421
|
+
): never;
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Creates a reusable {@link assertClone} function.
|
|
425
|
+
*
|
|
426
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
427
|
+
* @template T Type of the input value
|
|
428
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
429
|
+
* @returns A reusable `clone` function
|
|
430
|
+
*/
|
|
431
|
+
export function createAssertClone<T>(
|
|
432
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
433
|
+
): (input: unknown) => Resolved<T>;
|
|
434
|
+
|
|
435
|
+
/** @internal */
|
|
436
|
+
export function createAssertClone(): never {
|
|
437
|
+
NoTransformConfigurationError("misc.createAssertClone");
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Creates a reusable {@link isClone} function.
|
|
442
|
+
*
|
|
443
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
444
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
445
|
+
* @throws Compile error
|
|
446
|
+
* @danger You must configure the generic argument `T`
|
|
447
|
+
*/
|
|
448
|
+
export function createIsClone(): never;
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Creates a reusable {@link isClone} function.
|
|
452
|
+
*
|
|
453
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
454
|
+
* @template T Type of the input value
|
|
455
|
+
* @returns A reusable `clone` function
|
|
456
|
+
*/
|
|
457
|
+
export function createIsClone<T>(): (input: unknown) => Resolved<T> | null;
|
|
458
|
+
|
|
459
|
+
/** @internal */
|
|
460
|
+
export function createIsClone(): never {
|
|
461
|
+
NoTransformConfigurationError("misc.createIsClone");
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Creates a reusable {@link validateClone} function.
|
|
466
|
+
*
|
|
467
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
468
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
469
|
+
* @throws Compile error
|
|
470
|
+
* @danger You must configure the generic argument `T`
|
|
471
|
+
*/
|
|
472
|
+
export function createValidateClone(): never;
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Creates a reusable {@link validateClone} function.
|
|
476
|
+
*
|
|
477
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
478
|
+
* @template T Type of the input value
|
|
479
|
+
* @returns A reusable `clone` function
|
|
480
|
+
*/
|
|
481
|
+
export function createValidateClone<T>(): (
|
|
482
|
+
input: unknown,
|
|
483
|
+
) => IValidation<Resolved<T>>;
|
|
484
|
+
|
|
485
|
+
/** @internal */
|
|
486
|
+
export function createValidateClone(): never {
|
|
487
|
+
NoTransformConfigurationError("misc.createValidateClone");
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Creates a reusable {@link prune} function.
|
|
492
|
+
*
|
|
493
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
494
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
495
|
+
* @throws Compile error
|
|
496
|
+
* @danger You must configure the generic argument `T`
|
|
497
|
+
*/
|
|
498
|
+
export function createPrune(): never;
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* Creates a reusable {@link prune} function.
|
|
502
|
+
*
|
|
503
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
504
|
+
* @template T Type of the input value
|
|
505
|
+
* @returns A reusable `prune` function
|
|
506
|
+
*/
|
|
507
|
+
export function createPrune<T extends object>(): (input: T) => void;
|
|
508
|
+
|
|
509
|
+
/** @internal */
|
|
510
|
+
export function createPrune<T extends object>(): (input: T) => void {
|
|
511
|
+
NoTransformConfigurationError("misc.createPrune");
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Creates a reusable {@link assertPrune} function.
|
|
516
|
+
*
|
|
517
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
518
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
519
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
520
|
+
* @throws Compile error
|
|
521
|
+
* @danger You must configure the generic argument `T`
|
|
522
|
+
*/
|
|
523
|
+
export function createAssertPrune(
|
|
524
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
525
|
+
): never;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Creates a reusable {@link assertPrune} function.
|
|
529
|
+
*
|
|
530
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
531
|
+
* @template T Type of the input value
|
|
532
|
+
* @param errorFactory Custom error factory. Default is `TypeGuardError`
|
|
533
|
+
* @returns A reusable `isPrune` function
|
|
534
|
+
*/
|
|
535
|
+
export function createAssertPrune<T extends object>(
|
|
536
|
+
errorFactory?: undefined | ((props: TypeGuardError.IProps) => Error),
|
|
537
|
+
): (input: T) => T;
|
|
538
|
+
|
|
539
|
+
/** @internal */
|
|
540
|
+
export function createAssertPrune<T extends object>(): (input: T) => T {
|
|
541
|
+
NoTransformConfigurationError("misc.createAssertPrune");
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Creates a reusable {@link isPrune} function.
|
|
546
|
+
*
|
|
547
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
548
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
549
|
+
* @throws Compile error
|
|
550
|
+
* @danger You must configure the generic argument `T`
|
|
551
|
+
*/
|
|
552
|
+
export function createIsPrune(): never;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* Creates a reusable {@link isPrune} function.
|
|
556
|
+
*
|
|
557
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
558
|
+
* @template T Type of the input value
|
|
559
|
+
* @returns A reusable `isPrune` function
|
|
560
|
+
*/
|
|
561
|
+
export function createIsPrune<T extends object>(): (input: T) => input is T;
|
|
562
|
+
|
|
563
|
+
/** @internal */
|
|
564
|
+
export function createIsPrune<T extends object>(): (input: T) => input is T {
|
|
565
|
+
NoTransformConfigurationError("misc.createIsPrune");
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Creates a reusable {@link validatePrune} function.
|
|
570
|
+
*
|
|
571
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
572
|
+
* @returns Nothing until you configure the generic argument `T`
|
|
573
|
+
* @throws Compile error
|
|
574
|
+
* @danger You must configure the generic argument `T`
|
|
575
|
+
*/
|
|
576
|
+
export function createValidatePrune(): never;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Creates a reusable {@link validatePrune} function.
|
|
580
|
+
*
|
|
581
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
582
|
+
* @template T Type of the input value
|
|
583
|
+
* @returns A reusable `validatePrune` function
|
|
584
|
+
*/
|
|
585
|
+
export function createValidatePrune<T extends object>(): (
|
|
586
|
+
input: T,
|
|
587
|
+
) => IValidation<T>;
|
|
588
|
+
|
|
589
|
+
/** @internal */
|
|
590
|
+
export function createValidatePrune<T extends object>(): (
|
|
591
|
+
input: T,
|
|
592
|
+
) => IValidation<T> {
|
|
593
|
+
NoTransformConfigurationError("misc.createValidatePrune");
|
|
594
|
+
}
|