typia 3.4.22 → 3.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -23
- package/lib/programmers/AssertProgrammer.js +79 -70
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.d.ts +1 -0
- package/lib/programmers/IsProgrammer.js +4 -0
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +68 -59
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
- package/lib/programmers/helpers/OptionPredicator.js +4 -0
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/internal/check_dynamic_properties.js +5 -0
- package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
- package/lib/programmers/internal/check_object.d.ts +1 -0
- package/lib/programmers/internal/check_object.js.map +1 -1
- package/lib/transformers/ITransformOptions.d.ts +10 -0
- package/package.json +2 -2
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/functional/$every.ts +11 -11
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +36 -29
- package/src/programmers/IsProgrammer.ts +5 -0
- package/src/programmers/ValidateProgrammer.ts +36 -29
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/OptionPredicator.ts +4 -0
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +47 -47
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -29
- package/src/programmers/internal/check_dynamic_properties.ts +164 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_object.ts +43 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -26
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/ITransformOptions.ts +11 -0
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
|
@@ -42,4 +42,14 @@ export interface ITransformOptions {
|
|
|
42
42
|
* @default false
|
|
43
43
|
*/
|
|
44
44
|
functional?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Whether to check undefined value or not.
|
|
47
|
+
*
|
|
48
|
+
* JavaScript can assign `undefined` value to a specific property and it is an
|
|
49
|
+
* issue when validating without allowing superfluous properties. Should undefined
|
|
50
|
+
* value assigned superfluous property be allowed or not?
|
|
51
|
+
*
|
|
52
|
+
* @default true
|
|
53
|
+
*/
|
|
54
|
+
undefined?: boolean;
|
|
45
55
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typia",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.23",
|
|
4
4
|
"description": "Runtime type checkers and 5x faster JSON.stringify() function",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"suppress-warnings": "^1.0.2",
|
|
104
104
|
"ts-node": "^10.9.1",
|
|
105
105
|
"ttypescript": "^1.5.15",
|
|
106
|
-
"typescript": "^4.9.
|
|
106
|
+
"typescript": "^4.9.5",
|
|
107
107
|
"uuid": "^8.3.2",
|
|
108
108
|
"zod": "^3.19.1"
|
|
109
109
|
},
|
package/src/IValidation.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export type IValidation<T = unknown> =
|
|
2
|
-
| IValidation.ISuccess<T>
|
|
3
|
-
| IValidation.IFailure;
|
|
4
|
-
export namespace IValidation {
|
|
5
|
-
export interface ISuccess<T = unknown> {
|
|
6
|
-
success: true;
|
|
7
|
-
data: T;
|
|
8
|
-
errors: [];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface IFailure {
|
|
12
|
-
success: false;
|
|
13
|
-
errors: IError[];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface IError {
|
|
17
|
-
path: string;
|
|
18
|
-
expected: string;
|
|
19
|
-
value: any;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
export type IValidation<T = unknown> =
|
|
2
|
+
| IValidation.ISuccess<T>
|
|
3
|
+
| IValidation.IFailure;
|
|
4
|
+
export namespace IValidation {
|
|
5
|
+
export interface ISuccess<T = unknown> {
|
|
6
|
+
success: true;
|
|
7
|
+
data: T;
|
|
8
|
+
errors: [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IFailure {
|
|
12
|
+
success: false;
|
|
13
|
+
errors: IError[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IError {
|
|
17
|
+
path: string;
|
|
18
|
+
expected: string;
|
|
19
|
+
value: any;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/Primitive.ts
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Primitive type.
|
|
3
|
-
*
|
|
4
|
-
* `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
|
|
5
|
-
* primitive type.
|
|
6
|
-
*
|
|
7
|
-
* If the target argument is a built-in class who returns its origin primitive type through
|
|
8
|
-
* the `valueOf()` method like the `String` or `Number`, its return type would be the
|
|
9
|
-
* `string` or `number`.
|
|
10
|
-
*
|
|
11
|
-
* Otherwise, the target argument is a type of custom class, all of its custom method would
|
|
12
|
-
* be erased and its prototype would be changed to the primitive `object`. Therefore, return
|
|
13
|
-
* type of the TMP type finally be the primitive object.
|
|
14
|
-
*
|
|
15
|
-
* In addition, if the target argument is a type of custom class and it has a special
|
|
16
|
-
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
17
|
-
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
18
|
-
*
|
|
19
|
-
* Before | After
|
|
20
|
-
* ------------------------|----------------------------------------
|
|
21
|
-
* `Boolean` | `boolean`
|
|
22
|
-
* `Number` | `number`
|
|
23
|
-
* `String` | `string`
|
|
24
|
-
* `Class` | `object`
|
|
25
|
-
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
26
|
-
* Others | No change
|
|
27
|
-
*
|
|
28
|
-
* @template Instance Target argument type.
|
|
29
|
-
* @author Jenogho Nam - https://github.com/samchon
|
|
30
|
-
*/
|
|
31
|
-
export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
|
|
32
|
-
? T
|
|
33
|
-
: _Primitive<T>;
|
|
34
|
-
|
|
35
|
-
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
36
|
-
|
|
37
|
-
type _Primitive<Instance> = _ValueOf<Instance> extends object
|
|
38
|
-
? Instance extends object
|
|
39
|
-
? Instance extends IJsonable<infer Raw>
|
|
40
|
-
? _ValueOf<Raw> extends object
|
|
41
|
-
? Raw extends object
|
|
42
|
-
? _PrimitiveObject<Raw> // object would be primitified
|
|
43
|
-
: never // cannot be
|
|
44
|
-
: _ValueOf<Raw> // atomic value
|
|
45
|
-
: _PrimitiveObject<Instance> // object would be primitified
|
|
46
|
-
: never // cannot be
|
|
47
|
-
: _ValueOf<Instance>;
|
|
48
|
-
|
|
49
|
-
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
50
|
-
? _Primitive<T>[]
|
|
51
|
-
: {
|
|
52
|
-
[P in keyof Instance]: Instance[P] extends Function
|
|
53
|
-
? never
|
|
54
|
-
: _Primitive<Instance[P]>;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
|
|
58
|
-
? boolean
|
|
59
|
-
: _IsValueOf<Instance, Number> extends true
|
|
60
|
-
? number
|
|
61
|
-
: _IsValueOf<Instance, String> extends true
|
|
62
|
-
? string
|
|
63
|
-
: Instance;
|
|
64
|
-
|
|
65
|
-
type _IsValueOf<
|
|
66
|
-
Instance,
|
|
67
|
-
Object extends IValueOf<any>,
|
|
68
|
-
> = Instance extends Object
|
|
69
|
-
? Object extends IValueOf<infer Primitive>
|
|
70
|
-
? Instance extends Primitive
|
|
71
|
-
? false
|
|
72
|
-
: true // not Primitive, but Object
|
|
73
|
-
: false // cannot be
|
|
74
|
-
: false;
|
|
75
|
-
|
|
76
|
-
interface IValueOf<T> {
|
|
77
|
-
valueOf(): T;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
interface IJsonable<T> {
|
|
81
|
-
toJSON(): T;
|
|
82
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Primitive type.
|
|
3
|
+
*
|
|
4
|
+
* `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
|
|
5
|
+
* primitive type.
|
|
6
|
+
*
|
|
7
|
+
* If the target argument is a built-in class who returns its origin primitive type through
|
|
8
|
+
* the `valueOf()` method like the `String` or `Number`, its return type would be the
|
|
9
|
+
* `string` or `number`.
|
|
10
|
+
*
|
|
11
|
+
* Otherwise, the target argument is a type of custom class, all of its custom method would
|
|
12
|
+
* be erased and its prototype would be changed to the primitive `object`. Therefore, return
|
|
13
|
+
* type of the TMP type finally be the primitive object.
|
|
14
|
+
*
|
|
15
|
+
* In addition, if the target argument is a type of custom class and it has a special
|
|
16
|
+
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
17
|
+
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
18
|
+
*
|
|
19
|
+
* Before | After
|
|
20
|
+
* ------------------------|----------------------------------------
|
|
21
|
+
* `Boolean` | `boolean`
|
|
22
|
+
* `Number` | `number`
|
|
23
|
+
* `String` | `string`
|
|
24
|
+
* `Class` | `object`
|
|
25
|
+
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
26
|
+
* Others | No change
|
|
27
|
+
*
|
|
28
|
+
* @template Instance Target argument type.
|
|
29
|
+
* @author Jenogho Nam - https://github.com/samchon
|
|
30
|
+
*/
|
|
31
|
+
export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
|
|
32
|
+
? T
|
|
33
|
+
: _Primitive<T>;
|
|
34
|
+
|
|
35
|
+
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
36
|
+
|
|
37
|
+
type _Primitive<Instance> = _ValueOf<Instance> extends object
|
|
38
|
+
? Instance extends object
|
|
39
|
+
? Instance extends IJsonable<infer Raw>
|
|
40
|
+
? _ValueOf<Raw> extends object
|
|
41
|
+
? Raw extends object
|
|
42
|
+
? _PrimitiveObject<Raw> // object would be primitified
|
|
43
|
+
: never // cannot be
|
|
44
|
+
: _ValueOf<Raw> // atomic value
|
|
45
|
+
: _PrimitiveObject<Instance> // object would be primitified
|
|
46
|
+
: never // cannot be
|
|
47
|
+
: _ValueOf<Instance>;
|
|
48
|
+
|
|
49
|
+
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
50
|
+
? _Primitive<T>[]
|
|
51
|
+
: {
|
|
52
|
+
[P in keyof Instance]: Instance[P] extends Function
|
|
53
|
+
? never
|
|
54
|
+
: _Primitive<Instance[P]>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
|
|
58
|
+
? boolean
|
|
59
|
+
: _IsValueOf<Instance, Number> extends true
|
|
60
|
+
? number
|
|
61
|
+
: _IsValueOf<Instance, String> extends true
|
|
62
|
+
? string
|
|
63
|
+
: Instance;
|
|
64
|
+
|
|
65
|
+
type _IsValueOf<
|
|
66
|
+
Instance,
|
|
67
|
+
Object extends IValueOf<any>,
|
|
68
|
+
> = Instance extends Object
|
|
69
|
+
? Object extends IValueOf<infer Primitive>
|
|
70
|
+
? Instance extends Primitive
|
|
71
|
+
? false
|
|
72
|
+
: true // not Primitive, but Object
|
|
73
|
+
: false // cannot be
|
|
74
|
+
: false;
|
|
75
|
+
|
|
76
|
+
interface IValueOf<T> {
|
|
77
|
+
valueOf(): T;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface IJsonable<T> {
|
|
81
|
+
toJSON(): T;
|
|
82
|
+
}
|
package/src/TypeGuardError.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export class TypeGuardError extends Error {
|
|
2
|
-
public readonly method: string;
|
|
3
|
-
public readonly path: string | undefined;
|
|
4
|
-
public readonly expected: string;
|
|
5
|
-
public readonly value: any;
|
|
6
|
-
|
|
7
|
-
public constructor(props: TypeGuardError.IProps) {
|
|
8
|
-
// MESSAGE CONSTRUCTION
|
|
9
|
-
super(
|
|
10
|
-
props.message ||
|
|
11
|
-
`Error on ${props.method}(): invalid type${
|
|
12
|
-
props.path ? ` on ${props.path}` : ""
|
|
13
|
-
}, expect to be ${props.expected}`,
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// INHERITANCE POLYFILL
|
|
17
|
-
const proto = new.target.prototype;
|
|
18
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
19
|
-
else (this as any).__proto__ = proto;
|
|
20
|
-
|
|
21
|
-
// ASSIGN MEMBERS
|
|
22
|
-
this.method = props.method;
|
|
23
|
-
this.path = props.path;
|
|
24
|
-
this.expected = props.expected;
|
|
25
|
-
this.value = props.value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export namespace TypeGuardError {
|
|
29
|
-
export interface IProps {
|
|
30
|
-
method: string;
|
|
31
|
-
path?: string;
|
|
32
|
-
expected: string;
|
|
33
|
-
value: any;
|
|
34
|
-
message?: string;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
export class TypeGuardError extends Error {
|
|
2
|
+
public readonly method: string;
|
|
3
|
+
public readonly path: string | undefined;
|
|
4
|
+
public readonly expected: string;
|
|
5
|
+
public readonly value: any;
|
|
6
|
+
|
|
7
|
+
public constructor(props: TypeGuardError.IProps) {
|
|
8
|
+
// MESSAGE CONSTRUCTION
|
|
9
|
+
super(
|
|
10
|
+
props.message ||
|
|
11
|
+
`Error on ${props.method}(): invalid type${
|
|
12
|
+
props.path ? ` on ${props.path}` : ""
|
|
13
|
+
}, expect to be ${props.expected}`,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// INHERITANCE POLYFILL
|
|
17
|
+
const proto = new.target.prototype;
|
|
18
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
19
|
+
else (this as any).__proto__ = proto;
|
|
20
|
+
|
|
21
|
+
// ASSIGN MEMBERS
|
|
22
|
+
this.method = props.method;
|
|
23
|
+
this.path = props.path;
|
|
24
|
+
this.expected = props.expected;
|
|
25
|
+
this.value = props.value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export namespace TypeGuardError {
|
|
29
|
+
export interface IProps {
|
|
30
|
+
method: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
expected: string;
|
|
33
|
+
value: any;
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export namespace CommandParser {
|
|
2
|
-
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
-
const output: Record<string, string> = {};
|
|
4
|
-
argList.forEach((arg, i) => {
|
|
5
|
-
if (arg.startsWith("--") === false) return;
|
|
6
|
-
|
|
7
|
-
const key = arg.slice(2);
|
|
8
|
-
const value: string | undefined = argList[i + 1];
|
|
9
|
-
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
-
|
|
11
|
-
output[key] = value;
|
|
12
|
-
});
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
export namespace CommandParser {
|
|
2
|
+
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
+
const output: Record<string, string> = {};
|
|
4
|
+
argList.forEach((arg, i) => {
|
|
5
|
+
if (arg.startsWith("--") === false) return;
|
|
6
|
+
|
|
7
|
+
const key = arg.slice(2);
|
|
8
|
+
const value: string | undefined = argList[i + 1];
|
|
9
|
+
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
+
|
|
11
|
+
output[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace CommentFactory {
|
|
4
|
-
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
-
return comments
|
|
6
|
-
.map((part) => part.text)
|
|
7
|
-
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
-
.join("");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace CommentFactory {
|
|
4
|
+
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
+
return comments
|
|
6
|
+
.map((part) => part.text)
|
|
7
|
+
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
+
.join("");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace ExpressionFactory {
|
|
4
|
-
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
-
return ts.factory.createStrictInequality(
|
|
6
|
-
ts.factory.createIdentifier("undefined"),
|
|
7
|
-
input,
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
-
return ts.factory.createCallExpression(
|
|
13
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
-
undefined,
|
|
15
|
-
[input],
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isObject(
|
|
20
|
-
input: ts.Expression,
|
|
21
|
-
options: {
|
|
22
|
-
checkNull: boolean;
|
|
23
|
-
checkArray: boolean;
|
|
24
|
-
},
|
|
25
|
-
): ts.Expression {
|
|
26
|
-
const conditions: ts.Expression[] = [
|
|
27
|
-
ts.factory.createStrictEquality(
|
|
28
|
-
ts.factory.createStringLiteral("object"),
|
|
29
|
-
ts.factory.createTypeOfExpression(input),
|
|
30
|
-
),
|
|
31
|
-
];
|
|
32
|
-
if (options.checkNull === true)
|
|
33
|
-
conditions.push(
|
|
34
|
-
ts.factory.createStrictInequality(
|
|
35
|
-
ts.factory.createNull(),
|
|
36
|
-
input,
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
if (options.checkArray === true)
|
|
40
|
-
conditions.push(
|
|
41
|
-
ts.factory.createStrictEquality(
|
|
42
|
-
ts.factory.createFalse(),
|
|
43
|
-
ts.factory.createCallExpression(
|
|
44
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
-
undefined,
|
|
46
|
-
[input],
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return conditions.length === 1
|
|
52
|
-
? conditions[0]!
|
|
53
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function isInstanceOf(
|
|
57
|
-
input: ts.Expression,
|
|
58
|
-
type: string,
|
|
59
|
-
): ts.Expression {
|
|
60
|
-
return ts.factory.createBinaryExpression(
|
|
61
|
-
input,
|
|
62
|
-
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
-
ts.factory.createIdentifier(type),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace ExpressionFactory {
|
|
4
|
+
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
+
return ts.factory.createStrictInequality(
|
|
6
|
+
ts.factory.createIdentifier("undefined"),
|
|
7
|
+
input,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
+
return ts.factory.createCallExpression(
|
|
13
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
+
undefined,
|
|
15
|
+
[input],
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isObject(
|
|
20
|
+
input: ts.Expression,
|
|
21
|
+
options: {
|
|
22
|
+
checkNull: boolean;
|
|
23
|
+
checkArray: boolean;
|
|
24
|
+
},
|
|
25
|
+
): ts.Expression {
|
|
26
|
+
const conditions: ts.Expression[] = [
|
|
27
|
+
ts.factory.createStrictEquality(
|
|
28
|
+
ts.factory.createStringLiteral("object"),
|
|
29
|
+
ts.factory.createTypeOfExpression(input),
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
if (options.checkNull === true)
|
|
33
|
+
conditions.push(
|
|
34
|
+
ts.factory.createStrictInequality(
|
|
35
|
+
ts.factory.createNull(),
|
|
36
|
+
input,
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
if (options.checkArray === true)
|
|
40
|
+
conditions.push(
|
|
41
|
+
ts.factory.createStrictEquality(
|
|
42
|
+
ts.factory.createFalse(),
|
|
43
|
+
ts.factory.createCallExpression(
|
|
44
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
+
undefined,
|
|
46
|
+
[input],
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return conditions.length === 1
|
|
52
|
+
? conditions[0]!
|
|
53
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isInstanceOf(
|
|
57
|
+
input: ts.Expression,
|
|
58
|
+
type: string,
|
|
59
|
+
): ts.Expression {
|
|
60
|
+
return ts.factory.createBinaryExpression(
|
|
61
|
+
input,
|
|
62
|
+
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
+
ts.factory.createIdentifier(type),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Escaper } from "../utils/Escaper";
|
|
4
|
-
|
|
5
|
-
export namespace IdentifierFactory {
|
|
6
|
-
export function generate(name: string) {
|
|
7
|
-
return Escaper.variable(name)
|
|
8
|
-
? ts.factory.createIdentifier(name)
|
|
9
|
-
: ts.factory.createStringLiteral(name);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function join(prefix: ts.Expression, name: string) {
|
|
13
|
-
const postfix = generate(name);
|
|
14
|
-
return ts.isStringLiteral(postfix)
|
|
15
|
-
? ts.factory.createElementAccessExpression(prefix, postfix)
|
|
16
|
-
: ts.factory.createPropertyAccessExpression(prefix, postfix);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function postfix(str: string): string {
|
|
20
|
-
return Escaper.variable(str)
|
|
21
|
-
? `".${str}"`
|
|
22
|
-
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function parameter(
|
|
26
|
-
name: string | ts.BindingName,
|
|
27
|
-
init?: ts.Expression,
|
|
28
|
-
) {
|
|
29
|
-
if (ts.version >= "4.8")
|
|
30
|
-
return ts.factory.createParameterDeclaration(
|
|
31
|
-
undefined,
|
|
32
|
-
undefined,
|
|
33
|
-
name,
|
|
34
|
-
undefined,
|
|
35
|
-
undefined,
|
|
36
|
-
init,
|
|
37
|
-
);
|
|
38
|
-
// eslint-disable-next-line
|
|
39
|
-
return ts.factory.createParameterDeclaration(
|
|
40
|
-
undefined,
|
|
41
|
-
undefined,
|
|
42
|
-
undefined,
|
|
43
|
-
name,
|
|
44
|
-
undefined,
|
|
45
|
-
undefined,
|
|
46
|
-
init,
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// export function property(
|
|
51
|
-
// name: string | ts.PropertyName,
|
|
52
|
-
// value: ts.Expression,
|
|
53
|
-
// ): ts.PropertyDeclaration {
|
|
54
|
-
// if (ts.version >= "4.8")
|
|
55
|
-
// return ts.factory.createPropertyDeclaration(
|
|
56
|
-
// undefined,
|
|
57
|
-
// name,
|
|
58
|
-
// undefined,
|
|
59
|
-
// undefined,
|
|
60
|
-
// value,
|
|
61
|
-
// );
|
|
62
|
-
// // eslint-disable-next-line
|
|
63
|
-
// return ts.factory.createPropertyDeclaration(
|
|
64
|
-
// undefined,
|
|
65
|
-
// undefined,
|
|
66
|
-
// name,
|
|
67
|
-
// undefined,
|
|
68
|
-
// undefined,
|
|
69
|
-
// value,
|
|
70
|
-
// );
|
|
71
|
-
// }
|
|
72
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Escaper } from "../utils/Escaper";
|
|
4
|
+
|
|
5
|
+
export namespace IdentifierFactory {
|
|
6
|
+
export function generate(name: string) {
|
|
7
|
+
return Escaper.variable(name)
|
|
8
|
+
? ts.factory.createIdentifier(name)
|
|
9
|
+
: ts.factory.createStringLiteral(name);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function join(prefix: ts.Expression, name: string) {
|
|
13
|
+
const postfix = generate(name);
|
|
14
|
+
return ts.isStringLiteral(postfix)
|
|
15
|
+
? ts.factory.createElementAccessExpression(prefix, postfix)
|
|
16
|
+
: ts.factory.createPropertyAccessExpression(prefix, postfix);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function postfix(str: string): string {
|
|
20
|
+
return Escaper.variable(str)
|
|
21
|
+
? `".${str}"`
|
|
22
|
+
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function parameter(
|
|
26
|
+
name: string | ts.BindingName,
|
|
27
|
+
init?: ts.Expression,
|
|
28
|
+
) {
|
|
29
|
+
if (ts.version >= "4.8")
|
|
30
|
+
return ts.factory.createParameterDeclaration(
|
|
31
|
+
undefined,
|
|
32
|
+
undefined,
|
|
33
|
+
name,
|
|
34
|
+
undefined,
|
|
35
|
+
undefined,
|
|
36
|
+
init,
|
|
37
|
+
);
|
|
38
|
+
// eslint-disable-next-line
|
|
39
|
+
return ts.factory.createParameterDeclaration(
|
|
40
|
+
undefined,
|
|
41
|
+
undefined,
|
|
42
|
+
undefined,
|
|
43
|
+
name,
|
|
44
|
+
undefined,
|
|
45
|
+
undefined,
|
|
46
|
+
init,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// export function property(
|
|
51
|
+
// name: string | ts.PropertyName,
|
|
52
|
+
// value: ts.Expression,
|
|
53
|
+
// ): ts.PropertyDeclaration {
|
|
54
|
+
// if (ts.version >= "4.8")
|
|
55
|
+
// return ts.factory.createPropertyDeclaration(
|
|
56
|
+
// undefined,
|
|
57
|
+
// name,
|
|
58
|
+
// undefined,
|
|
59
|
+
// undefined,
|
|
60
|
+
// value,
|
|
61
|
+
// );
|
|
62
|
+
// // eslint-disable-next-line
|
|
63
|
+
// return ts.factory.createPropertyDeclaration(
|
|
64
|
+
// undefined,
|
|
65
|
+
// undefined,
|
|
66
|
+
// name,
|
|
67
|
+
// undefined,
|
|
68
|
+
// undefined,
|
|
69
|
+
// value,
|
|
70
|
+
// );
|
|
71
|
+
// }
|
|
72
|
+
}
|