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.
Files changed (124) hide show
  1. package/README.md +57 -23
  2. package/lib/programmers/AssertProgrammer.js +79 -70
  3. package/lib/programmers/AssertProgrammer.js.map +1 -1
  4. package/lib/programmers/IsProgrammer.d.ts +1 -0
  5. package/lib/programmers/IsProgrammer.js +4 -0
  6. package/lib/programmers/IsProgrammer.js.map +1 -1
  7. package/lib/programmers/ValidateProgrammer.js +68 -59
  8. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  9. package/lib/programmers/helpers/OptionPredicator.d.ts +1 -0
  10. package/lib/programmers/helpers/OptionPredicator.js +4 -0
  11. package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
  12. package/lib/programmers/internal/check_dynamic_properties.js +5 -0
  13. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  14. package/lib/programmers/internal/check_object.d.ts +1 -0
  15. package/lib/programmers/internal/check_object.js.map +1 -1
  16. package/lib/transformers/ITransformOptions.d.ts +10 -0
  17. package/package.json +2 -2
  18. package/src/IValidation.ts +21 -21
  19. package/src/Primitive.ts +82 -82
  20. package/src/TypeGuardError.ts +36 -36
  21. package/src/executable/internal/CommandParser.ts +15 -15
  22. package/src/factories/CommentFactory.ts +10 -10
  23. package/src/factories/ExpressionFactory.ts +66 -66
  24. package/src/factories/IdentifierFactory.ts +72 -72
  25. package/src/factories/LiteralFactory.ts +44 -44
  26. package/src/factories/StatementFactory.ts +60 -60
  27. package/src/factories/TemplateFactory.ts +56 -56
  28. package/src/factories/TypeFactory.ts +101 -101
  29. package/src/factories/ValueFactory.ts +12 -12
  30. package/src/functional/$every.ts +11 -11
  31. package/src/functional/$is_email.ts +5 -5
  32. package/src/functional/$is_ipv4.ts +5 -5
  33. package/src/functional/$is_ipv6.ts +5 -5
  34. package/src/functional/$is_url.ts +5 -5
  35. package/src/functional/$is_uuid.ts +5 -5
  36. package/src/functional/$join.ts +50 -50
  37. package/src/functional/$report.ts +15 -15
  38. package/src/functional/$rest.ts +3 -3
  39. package/src/functional/$string.ts +37 -37
  40. package/src/functional/$tail.ts +6 -6
  41. package/src/index.ts +4 -4
  42. package/src/metadata/IJsDocTagInfo.ts +10 -10
  43. package/src/metadata/IMetadata.ts +25 -25
  44. package/src/metadata/IMetadataApplication.ts +7 -7
  45. package/src/metadata/IMetadataConstant.ts +16 -16
  46. package/src/metadata/IMetadataEntry.ts +6 -6
  47. package/src/metadata/IMetadataObject.ts +29 -29
  48. package/src/metadata/IMetadataProperty.ts +11 -11
  49. package/src/metadata/MetadataConstant.ts +3 -3
  50. package/src/metadata/MetadataObject.ts +131 -131
  51. package/src/metadata/MetadataProperty.ts +64 -64
  52. package/src/programmers/ApplicationProgrammer.ts +55 -55
  53. package/src/programmers/AssertProgrammer.ts +36 -29
  54. package/src/programmers/IsProgrammer.ts +5 -0
  55. package/src/programmers/ValidateProgrammer.ts +36 -29
  56. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  57. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  58. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  59. package/src/programmers/helpers/OptionPredicator.ts +4 -0
  60. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  61. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  62. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  63. package/src/programmers/internal/application_array.ts +47 -47
  64. package/src/programmers/internal/application_boolean.ts +17 -17
  65. package/src/programmers/internal/application_constant.ts +29 -29
  66. package/src/programmers/internal/application_default_string.ts +32 -32
  67. package/src/programmers/internal/application_native.ts +29 -29
  68. package/src/programmers/internal/application_number.ts +76 -76
  69. package/src/programmers/internal/application_string.ts +49 -49
  70. package/src/programmers/internal/application_templates.ts +27 -27
  71. package/src/programmers/internal/application_tuple.ts +29 -29
  72. package/src/programmers/internal/check_dynamic_properties.ts +164 -146
  73. package/src/programmers/internal/check_everything.ts +25 -25
  74. package/src/programmers/internal/check_length.ts +46 -46
  75. package/src/programmers/internal/check_native.ts +9 -9
  76. package/src/programmers/internal/check_object.ts +43 -42
  77. package/src/programmers/internal/check_string.ts +24 -24
  78. package/src/programmers/internal/check_string_tags.ts +63 -63
  79. package/src/programmers/internal/check_template.ts +50 -50
  80. package/src/programmers/internal/decode_union_object.ts +73 -73
  81. package/src/programmers/internal/feature_object_entries.ts +49 -49
  82. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  83. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  84. package/src/programmers/internal/stringify_native.ts +8 -8
  85. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  86. package/src/programmers/internal/template_to_pattern.ts +15 -15
  87. package/src/schemas/IJsonApplication.ts +9 -9
  88. package/src/schemas/IJsonComponents.ts +26 -26
  89. package/src/transform.ts +20 -20
  90. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  91. package/src/transformers/FileTransformer.ts +49 -49
  92. package/src/transformers/IProject.ts +11 -11
  93. package/src/transformers/ITransformOptions.ts +11 -0
  94. package/src/transformers/NodeTransformer.ts +19 -19
  95. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  96. package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
  97. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
  98. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
  99. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
  100. package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
  101. package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
  102. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
  103. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
  104. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
  105. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
  106. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
  107. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
  108. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
  109. package/src/transformers/features/validators/AssertTransformer.ts +43 -43
  110. package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
  111. package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
  112. package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
  113. package/src/transformers/features/validators/IsTransformer.ts +43 -43
  114. package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
  115. package/src/typings/Atomic.ts +17 -17
  116. package/src/typings/ClassProperties.ts +5 -5
  117. package/src/typings/OmitNever.ts +3 -3
  118. package/src/typings/SpecialFields.ts +3 -3
  119. package/src/typings/Writable.ts +11 -11
  120. package/src/utils/ArrayUtil.ts +49 -49
  121. package/src/utils/Escaper.ts +50 -50
  122. package/src/utils/MapUtil.ts +14 -14
  123. package/src/utils/PatternUtil.ts +30 -30
  124. package/src/utils/Singleton.ts +17 -17
@@ -1,44 +1,44 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "./IdentifierFactory";
4
-
5
- export namespace LiteralFactory {
6
- export function generate(input: any): ts.Expression {
7
- if (input === null) return ts.factory.createNull();
8
- else if (ts.isIdentifier(input)) return input;
9
- else if (input instanceof Array) return generate_array(input);
10
- else if (typeof input === "object") return generate_object(input);
11
- else if (typeof input === "string") return generate_string(input);
12
- else if (typeof input === "boolean") return generate_value(input);
13
- else if (typeof input === "number") return generate_value(input);
14
- else if (typeof input === "bigint") return generate_value(input);
15
- else throw new Error("Unknown type.");
16
- }
17
-
18
- function generate_object(obj: object): ts.ObjectLiteralExpression {
19
- const properties = Object.entries(obj)
20
- .filter((tuple) => tuple[1] !== undefined)
21
- .map(([key, value]) =>
22
- ts.factory.createPropertyAssignment(
23
- IdentifierFactory.generate(key),
24
- generate(value),
25
- ),
26
- );
27
- return ts.factory.createObjectLiteralExpression(properties, true);
28
- }
29
-
30
- function generate_array(array: any[]): ts.ArrayLiteralExpression {
31
- return ts.factory.createArrayLiteralExpression(
32
- array.map(generate),
33
- true,
34
- );
35
- }
36
-
37
- function generate_value(value: number | boolean | bigint): ts.Identifier {
38
- return ts.factory.createIdentifier(value.toString());
39
- }
40
-
41
- function generate_string(value: string): ts.StringLiteral {
42
- return ts.factory.createStringLiteral(value);
43
- }
44
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "./IdentifierFactory";
4
+
5
+ export namespace LiteralFactory {
6
+ export function generate(input: any): ts.Expression {
7
+ if (input === null) return ts.factory.createNull();
8
+ else if (ts.isIdentifier(input)) return input;
9
+ else if (input instanceof Array) return generate_array(input);
10
+ else if (typeof input === "object") return generate_object(input);
11
+ else if (typeof input === "string") return generate_string(input);
12
+ else if (typeof input === "boolean") return generate_value(input);
13
+ else if (typeof input === "number") return generate_value(input);
14
+ else if (typeof input === "bigint") return generate_value(input);
15
+ else throw new Error("Unknown type.");
16
+ }
17
+
18
+ function generate_object(obj: object): ts.ObjectLiteralExpression {
19
+ const properties = Object.entries(obj)
20
+ .filter((tuple) => tuple[1] !== undefined)
21
+ .map(([key, value]) =>
22
+ ts.factory.createPropertyAssignment(
23
+ IdentifierFactory.generate(key),
24
+ generate(value),
25
+ ),
26
+ );
27
+ return ts.factory.createObjectLiteralExpression(properties, true);
28
+ }
29
+
30
+ function generate_array(array: any[]): ts.ArrayLiteralExpression {
31
+ return ts.factory.createArrayLiteralExpression(
32
+ array.map(generate),
33
+ true,
34
+ );
35
+ }
36
+
37
+ function generate_value(value: number | boolean | bigint): ts.Identifier {
38
+ return ts.factory.createIdentifier(value.toString());
39
+ }
40
+
41
+ function generate_string(value: string): ts.StringLiteral {
42
+ return ts.factory.createStringLiteral(value);
43
+ }
44
+ }
@@ -1,60 +1,60 @@
1
- import ts from "typescript";
2
-
3
- export namespace StatementFactory {
4
- export function constant(name: string, initializer?: ts.Expression) {
5
- return ts.factory.createVariableStatement(
6
- undefined,
7
- ts.factory.createVariableDeclarationList(
8
- [
9
- ts.factory.createVariableDeclaration(
10
- name,
11
- undefined,
12
- undefined,
13
- initializer,
14
- ),
15
- ],
16
- ts.NodeFlags.Const,
17
- ),
18
- );
19
- }
20
-
21
- export function transpile(script: string) {
22
- return ts.factory.createExpressionStatement(
23
- ts.factory.createIdentifier(ts.transpile(script)),
24
- );
25
- }
26
-
27
- // export function require(variable: string, location: string) {
28
- // return ts.factory.createImportDeclaration(
29
- // undefined,
30
- // undefined,
31
- // ts.factory.createImportClause(
32
- // false,
33
- // undefined,
34
- // ts.factory.createNamespaceImport(
35
- // ts.factory.createIdentifier(variable),
36
- // ),
37
- // ),
38
- // ts.factory.createStringLiteral(location),
39
- // );
40
- // }
41
-
42
- // export function importModulo(variable: string, location: string) {
43
- // return ts.factory.createImportDeclaration(
44
- // undefined,
45
- // undefined,
46
- // ts.factory.createImportClause(
47
- // false,
48
- // undefined,
49
- // ts.factory.createNamedImports([
50
- // ts.factory.createImportSpecifier(
51
- // false,
52
- // undefined,
53
- // ts.factory.createIdentifier(variable),
54
- // ),
55
- // ]),
56
- // ),
57
- // ts.factory.createStringLiteral(location),
58
- // );
59
- // }
60
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace StatementFactory {
4
+ export function constant(name: string, initializer?: ts.Expression) {
5
+ return ts.factory.createVariableStatement(
6
+ undefined,
7
+ ts.factory.createVariableDeclarationList(
8
+ [
9
+ ts.factory.createVariableDeclaration(
10
+ name,
11
+ undefined,
12
+ undefined,
13
+ initializer,
14
+ ),
15
+ ],
16
+ ts.NodeFlags.Const,
17
+ ),
18
+ );
19
+ }
20
+
21
+ export function transpile(script: string) {
22
+ return ts.factory.createExpressionStatement(
23
+ ts.factory.createIdentifier(ts.transpile(script)),
24
+ );
25
+ }
26
+
27
+ // export function require(variable: string, location: string) {
28
+ // return ts.factory.createImportDeclaration(
29
+ // undefined,
30
+ // undefined,
31
+ // ts.factory.createImportClause(
32
+ // false,
33
+ // undefined,
34
+ // ts.factory.createNamespaceImport(
35
+ // ts.factory.createIdentifier(variable),
36
+ // ),
37
+ // ),
38
+ // ts.factory.createStringLiteral(location),
39
+ // );
40
+ // }
41
+
42
+ // export function importModulo(variable: string, location: string) {
43
+ // return ts.factory.createImportDeclaration(
44
+ // undefined,
45
+ // undefined,
46
+ // ts.factory.createImportClause(
47
+ // false,
48
+ // undefined,
49
+ // ts.factory.createNamedImports([
50
+ // ts.factory.createImportSpecifier(
51
+ // false,
52
+ // undefined,
53
+ // ts.factory.createIdentifier(variable),
54
+ // ),
55
+ // ]),
56
+ // ),
57
+ // ts.factory.createStringLiteral(location),
58
+ // );
59
+ // }
60
+ }
@@ -1,56 +1,56 @@
1
- import ts from "typescript";
2
-
3
- export namespace TemplateFactory {
4
- export function generate(expressions: ts.Expression[]): ts.Expression {
5
- if (expressions.every((exp) => ts.isStringLiteral(exp)))
6
- return ts.factory.createStringLiteral(
7
- (expressions as ts.StringLiteral[])
8
- .map((str) => str.text)
9
- .join(""),
10
- );
11
-
12
- const it: IIerator = {
13
- value: "",
14
- index: 0,
15
- };
16
- gather(expressions, it);
17
-
18
- const head: ts.TemplateHead = ts.factory.createTemplateHead(it.value);
19
- const spans: ts.TemplateSpan[] = [];
20
-
21
- while (true) {
22
- const elem: ts.Expression = expressions[it.index++]!;
23
- gather(expressions, it);
24
-
25
- const broken: boolean = it.index === expressions.length;
26
- spans.push(
27
- ts.factory.createTemplateSpan(
28
- elem,
29
- broken
30
- ? ts.factory.createTemplateTail(it.value)
31
- : ts.factory.createTemplateMiddle(it.value),
32
- ),
33
- );
34
- if (broken === true) break;
35
- }
36
- return ts.factory.createTemplateExpression(head, spans);
37
- }
38
-
39
- function gather(expressions: ts.Expression[], it: IIerator): void {
40
- const found: number = expressions.findIndex(
41
- (elem, index) => index >= it.index && !ts.isStringLiteral(elem),
42
- );
43
-
44
- const last: number = found !== -1 ? found : expressions.length;
45
- it.value = expressions
46
- .slice(it.index, last)
47
- .map((elem) => (elem as ts.StringLiteral).text)
48
- .reduce((x, y) => x + y, "");
49
- it.index = last;
50
- }
51
-
52
- interface IIerator {
53
- value: string;
54
- index: number;
55
- }
56
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace TemplateFactory {
4
+ export function generate(expressions: ts.Expression[]): ts.Expression {
5
+ if (expressions.every((exp) => ts.isStringLiteral(exp)))
6
+ return ts.factory.createStringLiteral(
7
+ (expressions as ts.StringLiteral[])
8
+ .map((str) => str.text)
9
+ .join(""),
10
+ );
11
+
12
+ const it: IIerator = {
13
+ value: "",
14
+ index: 0,
15
+ };
16
+ gather(expressions, it);
17
+
18
+ const head: ts.TemplateHead = ts.factory.createTemplateHead(it.value);
19
+ const spans: ts.TemplateSpan[] = [];
20
+
21
+ while (true) {
22
+ const elem: ts.Expression = expressions[it.index++]!;
23
+ gather(expressions, it);
24
+
25
+ const broken: boolean = it.index === expressions.length;
26
+ spans.push(
27
+ ts.factory.createTemplateSpan(
28
+ elem,
29
+ broken
30
+ ? ts.factory.createTemplateTail(it.value)
31
+ : ts.factory.createTemplateMiddle(it.value),
32
+ ),
33
+ );
34
+ if (broken === true) break;
35
+ }
36
+ return ts.factory.createTemplateExpression(head, spans);
37
+ }
38
+
39
+ function gather(expressions: ts.Expression[], it: IIerator): void {
40
+ const found: number = expressions.findIndex(
41
+ (elem, index) => index >= it.index && !ts.isStringLiteral(elem),
42
+ );
43
+
44
+ const last: number = found !== -1 ? found : expressions.length;
45
+ it.value = expressions
46
+ .slice(it.index, last)
47
+ .map((elem) => (elem as ts.StringLiteral).text)
48
+ .reduce((x, y) => x + y, "");
49
+ it.index = last;
50
+ }
51
+
52
+ interface IIerator {
53
+ value: string;
54
+ index: number;
55
+ }
56
+ }
@@ -1,101 +1,101 @@
1
- import ts from "typescript";
2
-
3
- export namespace TypeFactory {
4
- export function resolve(
5
- checker: ts.TypeChecker,
6
- type: ts.Type,
7
- ): ts.Type | null {
8
- return getReturnType(checker, type, "toJSON");
9
- }
10
-
11
- export function isFunction(type: ts.Type): boolean {
12
- return getFunction(type) !== null;
13
- }
14
- function getFunction(type: ts.Type) {
15
- const node = type.symbol?.declarations?.[0];
16
- if (node === undefined) return null;
17
-
18
- return ts.isFunctionLike(node)
19
- ? node
20
- : ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
21
- ? ts.isFunctionLike(node.initializer)
22
- ? node.initializer
23
- : null
24
- : null;
25
- }
26
-
27
- export function getReturnType(
28
- checker: ts.TypeChecker,
29
- type: ts.Type,
30
- name: string,
31
- ): ts.Type | null {
32
- // FIND TO-JSON METHOD
33
- const symbol: ts.Symbol | undefined = type.getProperty(name);
34
- if (!symbol) return null;
35
- else if (!symbol.valueDeclaration) return null;
36
-
37
- // GET FUNCTION DECLARATION
38
- const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
39
- symbol,
40
- symbol.valueDeclaration,
41
- );
42
-
43
- // RETURNS THE RETURN-TYPE
44
- const signature: ts.Signature | undefined = checker.getSignaturesOfType(
45
- functor,
46
- ts.SignatureKind.Call,
47
- )[0];
48
- return signature ? signature.getReturnType() : null;
49
- }
50
-
51
- export function getFullName(
52
- checker: ts.TypeChecker,
53
- type: ts.Type,
54
- symbol?: ts.Symbol,
55
- ): string {
56
- // PRIMITIVE
57
- symbol ||= type.aliasSymbol || type.getSymbol();
58
- if (symbol === undefined) return checker.typeToString(type);
59
-
60
- // UNION OR INTERSECT
61
- if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
62
- const joiner: string = type.isIntersection() ? " & " : " | ";
63
- return type.types
64
- .map((child) => getFullName(checker, child))
65
- .join(joiner);
66
- }
67
-
68
- //----
69
- // SPECIALIZATION
70
- //----
71
- const name: string = get_name(symbol);
72
-
73
- // CHECK GENERIC
74
- const generic: readonly ts.Type[] = type.aliasSymbol
75
- ? type.aliasTypeArguments || []
76
- : checker.getTypeArguments(type as ts.TypeReference);
77
- return generic.length
78
- ? name === "Promise"
79
- ? getFullName(checker, generic[0]!)
80
- : `${name}<${generic
81
- .map((child) => getFullName(checker, child))
82
- .join(", ")}>`
83
- : name;
84
- }
85
-
86
- function explore_name(name: string, decl: ts.Node): string {
87
- return ts.isModuleBlock(decl)
88
- ? explore_name(
89
- `${decl.parent.name.getText()}.${name}`,
90
- decl.parent.parent,
91
- )
92
- : name;
93
- }
94
-
95
- function get_name(symbol: ts.Symbol): string {
96
- const parent = symbol.getDeclarations()?.[0]?.parent;
97
- return parent
98
- ? explore_name(symbol.escapedName.toString(), parent)
99
- : "__type";
100
- }
101
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace TypeFactory {
4
+ export function resolve(
5
+ checker: ts.TypeChecker,
6
+ type: ts.Type,
7
+ ): ts.Type | null {
8
+ return getReturnType(checker, type, "toJSON");
9
+ }
10
+
11
+ export function isFunction(type: ts.Type): boolean {
12
+ return getFunction(type) !== null;
13
+ }
14
+ function getFunction(type: ts.Type) {
15
+ const node = type.symbol?.declarations?.[0];
16
+ if (node === undefined) return null;
17
+
18
+ return ts.isFunctionLike(node)
19
+ ? node
20
+ : ts.isPropertyAssignment(node) || ts.isPropertyDeclaration(node)
21
+ ? ts.isFunctionLike(node.initializer)
22
+ ? node.initializer
23
+ : null
24
+ : null;
25
+ }
26
+
27
+ export function getReturnType(
28
+ checker: ts.TypeChecker,
29
+ type: ts.Type,
30
+ name: string,
31
+ ): ts.Type | null {
32
+ // FIND TO-JSON METHOD
33
+ const symbol: ts.Symbol | undefined = type.getProperty(name);
34
+ if (!symbol) return null;
35
+ else if (!symbol.valueDeclaration) return null;
36
+
37
+ // GET FUNCTION DECLARATION
38
+ const functor: ts.Type = checker.getTypeOfSymbolAtLocation(
39
+ symbol,
40
+ symbol.valueDeclaration,
41
+ );
42
+
43
+ // RETURNS THE RETURN-TYPE
44
+ const signature: ts.Signature | undefined = checker.getSignaturesOfType(
45
+ functor,
46
+ ts.SignatureKind.Call,
47
+ )[0];
48
+ return signature ? signature.getReturnType() : null;
49
+ }
50
+
51
+ export function getFullName(
52
+ checker: ts.TypeChecker,
53
+ type: ts.Type,
54
+ symbol?: ts.Symbol,
55
+ ): string {
56
+ // PRIMITIVE
57
+ symbol ||= type.aliasSymbol || type.getSymbol();
58
+ if (symbol === undefined) return checker.typeToString(type);
59
+
60
+ // UNION OR INTERSECT
61
+ if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
62
+ const joiner: string = type.isIntersection() ? " & " : " | ";
63
+ return type.types
64
+ .map((child) => getFullName(checker, child))
65
+ .join(joiner);
66
+ }
67
+
68
+ //----
69
+ // SPECIALIZATION
70
+ //----
71
+ const name: string = get_name(symbol);
72
+
73
+ // CHECK GENERIC
74
+ const generic: readonly ts.Type[] = type.aliasSymbol
75
+ ? type.aliasTypeArguments || []
76
+ : checker.getTypeArguments(type as ts.TypeReference);
77
+ return generic.length
78
+ ? name === "Promise"
79
+ ? getFullName(checker, generic[0]!)
80
+ : `${name}<${generic
81
+ .map((child) => getFullName(checker, child))
82
+ .join(", ")}>`
83
+ : name;
84
+ }
85
+
86
+ function explore_name(name: string, decl: ts.Node): string {
87
+ return ts.isModuleBlock(decl)
88
+ ? explore_name(
89
+ `${decl.parent.name.getText()}.${name}`,
90
+ decl.parent.parent,
91
+ )
92
+ : name;
93
+ }
94
+
95
+ function get_name(symbol: ts.Symbol): string {
96
+ const parent = symbol.getDeclarations()?.[0]?.parent;
97
+ return parent
98
+ ? explore_name(symbol.escapedName.toString(), parent)
99
+ : "__type";
100
+ }
101
+ }
@@ -1,12 +1,12 @@
1
- import ts from "typescript";
2
-
3
- export namespace ValueFactory {
4
- export const NULL = () => ts.factory.createNull();
5
- export const UNDEFINED = () => ts.factory.createIdentifier("undefined");
6
- export const BOOLEAN = (value: boolean) =>
7
- value ? ts.factory.createTrue() : ts.factory.createFalse();
8
- export const INPUT = (str: string = "input") =>
9
- ts.factory.createIdentifier(str);
10
- export const TYPEOF = (input: ts.Expression) =>
11
- ts.factory.createTypeOfExpression(input);
12
- }
1
+ import ts from "typescript";
2
+
3
+ export namespace ValueFactory {
4
+ export const NULL = () => ts.factory.createNull();
5
+ export const UNDEFINED = () => ts.factory.createIdentifier("undefined");
6
+ export const BOOLEAN = (value: boolean) =>
7
+ value ? ts.factory.createTrue() : ts.factory.createFalse();
8
+ export const INPUT = (str: string = "input") =>
9
+ ts.factory.createIdentifier(str);
10
+ export const TYPEOF = (input: ts.Expression) =>
11
+ ts.factory.createTypeOfExpression(input);
12
+ }
@@ -1,11 +1,11 @@
1
- import { TypeGuardError } from "../TypeGuardError";
2
-
3
- export const $every = <T>(
4
- array: T[],
5
- pred: (value: T, i: number) => null | Omit<TypeGuardError.IProps, "method">,
6
- ): null | Omit<TypeGuardError.IProps, "method"> => {
7
- let error: null | Omit<TypeGuardError.IProps, "method"> = null;
8
- for (let i: number = 0; i < array.length; ++i)
9
- if (null !== (error = pred(array[i]!, i))) return error;
10
- return null;
11
- };
1
+ import { TypeGuardError } from "../TypeGuardError";
2
+
3
+ export const $every = <T>(
4
+ array: T[],
5
+ pred: (value: T, i: number) => null | Omit<TypeGuardError.IProps, "method">,
6
+ ): null | Omit<TypeGuardError.IProps, "method"> => {
7
+ let error: null | Omit<TypeGuardError.IProps, "method"> = null;
8
+ for (let i: number = 0; i < array.length; ++i)
9
+ if (null !== (error = pred(array[i]!, i))) return error;
10
+ return null;
11
+ };
@@ -1,5 +1,5 @@
1
- export function $is_email(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
1
+ export function $is_email(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i;
@@ -1,5 +1,5 @@
1
- export function $is_ipv4(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
1
+ export function $is_ipv4(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
@@ -1,5 +1,5 @@
1
- export function $is_ipv6(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
1
+ export function $is_ipv6(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
@@ -1,5 +1,5 @@
1
- export function $is_url(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /^[a-zA-Z0-9]+:\/\/(?:www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/;
1
+ export function $is_url(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /^[a-zA-Z0-9]+:\/\/(?:www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/;
@@ -1,5 +1,5 @@
1
- export function $is_uuid(str: string): boolean {
2
- return REGEX.test(str);
3
- }
4
- const REGEX =
5
- /[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
1
+ export function $is_uuid(str: string): boolean {
2
+ return REGEX.test(str);
3
+ }
4
+ const REGEX =
5
+ /[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;