typia 3.8.0-dev.20230416 → 3.8.0-dev.20230418

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.
@@ -1,67 +1,67 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
-
5
- import { IMetadataTag } from "../../metadata/IMetadataTag";
6
-
7
- import { FunctionImporter } from "../helpers/FunctionImporeter";
8
- import { ICheckEntry } from "../helpers/ICheckEntry";
9
-
10
- /**
11
- * @internal
12
- */
13
- export const check_string_tags =
14
- (importer: FunctionImporter) =>
15
- (tagList: IMetadataTag[]) =>
16
- (input: ts.Expression): ICheckEntry.ITag[] => {
17
- const conditions: [IMetadataTag, ts.Expression][] = [];
18
- for (const tag of tagList)
19
- if (tag.kind === "format")
20
- conditions.push([
21
- tag,
22
- ts.factory.createCallExpression(
23
- importer.use(`is_${tag.value}`),
24
- undefined,
25
- [input],
26
- ),
27
- ]);
28
- else if (tag.kind === "pattern")
29
- conditions.push([
30
- tag,
31
- ts.factory.createCallExpression(
32
- ts.factory.createIdentifier(
33
- `RegExp(/${tag.value}/).test`,
34
- ),
35
- undefined,
36
- [input],
37
- ),
38
- ]);
39
- else if (tag.kind === "length")
40
- conditions.push([
41
- tag,
42
- ts.factory.createStrictEquality(
43
- ts.factory.createNumericLiteral(tag.value),
44
- IdentifierFactory.join(input, "length"),
45
- ),
46
- ]);
47
- else if (tag.kind === "minLength")
48
- conditions.push([
49
- tag,
50
- ts.factory.createLessThanEquals(
51
- ts.factory.createNumericLiteral(tag.value),
52
- IdentifierFactory.join(input, "length"),
53
- ),
54
- ]);
55
- else if (tag.kind === "maxLength")
56
- conditions.push([
57
- tag,
58
- ts.factory.createGreaterThanEquals(
59
- ts.factory.createNumericLiteral(tag.value),
60
- IdentifierFactory.join(input, "length"),
61
- ),
62
- ]);
63
- return conditions.map(([tag, expression]) => ({
64
- expected: `string (@${tag.kind} ${tag.value})`,
65
- expression,
66
- }));
67
- };
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
4
+
5
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
6
+
7
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
8
+ import { ICheckEntry } from "../helpers/ICheckEntry";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export const check_string_tags =
14
+ (importer: FunctionImporter) =>
15
+ (tagList: IMetadataTag[]) =>
16
+ (input: ts.Expression): ICheckEntry.ITag[] => {
17
+ const conditions: [IMetadataTag, ts.Expression][] = [];
18
+ for (const tag of tagList)
19
+ if (tag.kind === "format")
20
+ conditions.push([
21
+ tag,
22
+ ts.factory.createCallExpression(
23
+ importer.use(`is_${tag.value}`),
24
+ undefined,
25
+ [input],
26
+ ),
27
+ ]);
28
+ else if (tag.kind === "pattern")
29
+ conditions.push([
30
+ tag,
31
+ ts.factory.createCallExpression(
32
+ ts.factory.createIdentifier(
33
+ `RegExp(/${tag.value}/).test`,
34
+ ),
35
+ undefined,
36
+ [input],
37
+ ),
38
+ ]);
39
+ else if (tag.kind === "length")
40
+ conditions.push([
41
+ tag,
42
+ ts.factory.createStrictEquality(
43
+ ts.factory.createNumericLiteral(tag.value),
44
+ IdentifierFactory.join(input, "length"),
45
+ ),
46
+ ]);
47
+ else if (tag.kind === "minLength")
48
+ conditions.push([
49
+ tag,
50
+ ts.factory.createLessThanEquals(
51
+ ts.factory.createNumericLiteral(tag.value),
52
+ IdentifierFactory.join(input, "length"),
53
+ ),
54
+ ]);
55
+ else if (tag.kind === "maxLength")
56
+ conditions.push([
57
+ tag,
58
+ ts.factory.createGreaterThanEquals(
59
+ ts.factory.createNumericLiteral(tag.value),
60
+ IdentifierFactory.join(input, "length"),
61
+ ),
62
+ ]);
63
+ return conditions.map(([tag, expression]) => ({
64
+ expected: `string (@${tag.kind} ${tag.value})`,
65
+ expression,
66
+ }));
67
+ };
@@ -1,56 +1,56 @@
1
- import ts from "typescript";
2
-
3
- import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
4
- import { IMetadataTag } from "../../metadata/IMetadataTag";
5
- import { Metadata } from "../../metadata/Metadata";
6
-
7
- import { FunctionImporter } from "../helpers/FunctionImporeter";
8
- import { ICheckEntry } from "../helpers/ICheckEntry";
9
- import { check_custom } from "./check_custom";
10
- import { check_string_tags } from "./check_string_tags";
11
- import { template_to_pattern } from "./template_to_pattern";
12
-
13
- /**
14
- * @internal
15
- */
16
- export const check_template =
17
- (importer: FunctionImporter) =>
18
- (metaTags: IMetadataTag[]) =>
19
- (jsDocTags: IJsDocTagInfo[]) =>
20
- (templates: Metadata[][]) =>
21
- (input: ts.Expression): ICheckEntry => {
22
- // TYPEOF STRING & TAGS
23
- const conditions: ts.Expression[] = [
24
- ts.factory.createStrictEquality(
25
- ts.factory.createStringLiteral("string"),
26
- ts.factory.createTypeOfExpression(input),
27
- ),
28
- ];
29
-
30
- // TEMPLATES
31
- const internal: ts.Expression[] = templates.map((tpl) =>
32
- ts.factory.createCallExpression(
33
- ts.factory.createIdentifier(
34
- `RegExp(/${template_to_pattern(true)(tpl)}/).test`,
35
- ),
36
- undefined,
37
- [input],
38
- ),
39
- );
40
- conditions.push(
41
- internal.length === 1
42
- ? internal[0]!
43
- : internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
44
- );
45
-
46
- // COMBINATION
47
- return {
48
- expression: conditions.reduce((x, y) =>
49
- ts.factory.createLogicalAnd(x, y),
50
- ),
51
- tags: [
52
- ...check_string_tags(importer)(metaTags)(input),
53
- ...check_custom("string")(importer)(jsDocTags)(input),
54
- ],
55
- };
56
- };
1
+ import ts from "typescript";
2
+
3
+ import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
4
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
5
+ import { Metadata } from "../../metadata/Metadata";
6
+
7
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
8
+ import { ICheckEntry } from "../helpers/ICheckEntry";
9
+ import { check_custom } from "./check_custom";
10
+ import { check_string_tags } from "./check_string_tags";
11
+ import { template_to_pattern } from "./template_to_pattern";
12
+
13
+ /**
14
+ * @internal
15
+ */
16
+ export const check_template =
17
+ (importer: FunctionImporter) =>
18
+ (metaTags: IMetadataTag[]) =>
19
+ (jsDocTags: IJsDocTagInfo[]) =>
20
+ (templates: Metadata[][]) =>
21
+ (input: ts.Expression): ICheckEntry => {
22
+ // TYPEOF STRING & TAGS
23
+ const conditions: ts.Expression[] = [
24
+ ts.factory.createStrictEquality(
25
+ ts.factory.createStringLiteral("string"),
26
+ ts.factory.createTypeOfExpression(input),
27
+ ),
28
+ ];
29
+
30
+ // TEMPLATES
31
+ const internal: ts.Expression[] = templates.map((tpl) =>
32
+ ts.factory.createCallExpression(
33
+ ts.factory.createIdentifier(
34
+ `RegExp(/${template_to_pattern(true)(tpl)}/).test`,
35
+ ),
36
+ undefined,
37
+ [input],
38
+ ),
39
+ );
40
+ conditions.push(
41
+ internal.length === 1
42
+ ? internal[0]!
43
+ : internal.reduce((x, y) => ts.factory.createLogicalOr(x, y)),
44
+ );
45
+
46
+ // COMBINATION
47
+ return {
48
+ expression: conditions.reduce((x, y) =>
49
+ ts.factory.createLogicalAnd(x, y),
50
+ ),
51
+ tags: [
52
+ ...check_string_tags(importer)(metaTags)(input),
53
+ ...check_custom("string")(importer)(jsDocTags)(input),
54
+ ],
55
+ };
56
+ };
@@ -1,5 +1,5 @@
1
- export interface Customizable {
2
- number: number;
3
- string: string;
4
- bigint: bigint;
5
- }
1
+ export type Customizable = {
2
+ number: number;
3
+ string: string;
4
+ bigint: bigint;
5
+ };
@@ -1,93 +1,96 @@
1
- import RandExp from "randexp";
2
-
3
- export namespace RandomGenerator {
4
- const ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
5
-
6
- /* -----------------------------------------------------------
7
- REGULAR
8
- ----------------------------------------------------------- */
9
- export function boolean(): boolean {
10
- return Math.random() < 0.5;
11
- }
12
-
13
- export function integer(min?: number, max?: number): number {
14
- min ??= 0;
15
- max ??= 100;
16
- return Math.floor(Math.random() * (max - min + 1)) + min;
17
- }
18
-
19
- export function bigint(min?: bigint, max?: bigint): bigint {
20
- min ??= BigInt(0);
21
- max ??= BigInt(100);
22
- return BigInt(integer(Number(min), Number(max)));
23
- }
24
-
25
- export function number(min?: number, max?: number): number {
26
- min ??= 0;
27
- max ??= 100;
28
- return Math.random() * (max - min) + min;
29
- }
30
-
31
- export function string(length?: number): string {
32
- return new Array(length ?? integer(5, 10))
33
- .fill(0)
34
- .map(() => ALPHABETS[integer(0, ALPHABETS.length - 1)])
35
- .join("");
36
- }
37
-
38
- export function array<T>(
39
- closure: (index: number) => T,
40
- count?: number,
41
- ): T[] {
42
- return new Array(count ?? integer(0, 3))
43
- .fill(0)
44
- .map((_e, index) => closure(index));
45
- }
46
-
47
- export function pick<T>(array: T[]): T {
48
- return array[integer(0, array.length - 1)]!;
49
- }
50
-
51
- /* -----------------------------------------------------------
52
- SECIAL FORMATS
53
- ----------------------------------------------------------- */
54
- export function uuid(): string {
55
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
56
- const r = (Math.random() * 16) | 0;
57
- const v = c === "x" ? r : (r & 0x3) | 0x8;
58
- return v.toString(16);
59
- });
60
- }
61
-
62
- export function email(): string {
63
- return `${string(10)}@${string(10)}.${string(3)}`;
64
- }
65
-
66
- export function url(): string {
67
- return `https://${string(10)}.${string(3)}`;
68
- }
69
-
70
- export function ipv4(): string {
71
- return array(() => integer(0, 255), 4).join(".");
72
- }
73
-
74
- export function ipv6(): string {
75
- return array(() => integer(0, 65535).toString(16), 8).join(":");
76
- }
77
-
78
- export function pattern(regex: RegExp): string {
79
- return new RandExp(regex).gen();
80
- }
81
-
82
- export function date(min?: number, max?: number): string {
83
- min ??= 0;
84
- max ??= Date.now() * 2;
85
- return new Date(number(min, max)).toISOString().substring(0, 10);
86
- }
87
-
88
- export function datetime(min?: number, max?: number): string {
89
- min ??= 0;
90
- max ??= Date.now() * 2;
91
- return new Date(number(min, max)).toISOString();
92
- }
93
- }
1
+ import RandExp from "randexp";
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ export namespace RandomGenerator {
7
+ const ALPHABETS = "abcdefghijklmnopqrstuvwxyz";
8
+
9
+ /* -----------------------------------------------------------
10
+ REGULAR
11
+ ----------------------------------------------------------- */
12
+ export function boolean(): boolean {
13
+ return Math.random() < 0.5;
14
+ }
15
+
16
+ export function integer(min?: number, max?: number): number {
17
+ min ??= 0;
18
+ max ??= 100;
19
+ return Math.floor(Math.random() * (max - min + 1)) + min;
20
+ }
21
+
22
+ export function bigint(min?: bigint, max?: bigint): bigint {
23
+ min ??= BigInt(0);
24
+ max ??= BigInt(100);
25
+ return BigInt(integer(Number(min), Number(max)));
26
+ }
27
+
28
+ export function number(min?: number, max?: number): number {
29
+ min ??= 0;
30
+ max ??= 100;
31
+ return Math.random() * (max - min) + min;
32
+ }
33
+
34
+ export function string(length?: number): string {
35
+ return new Array(length ?? integer(5, 10))
36
+ .fill(0)
37
+ .map(() => ALPHABETS[integer(0, ALPHABETS.length - 1)])
38
+ .join("");
39
+ }
40
+
41
+ export function array<T>(
42
+ closure: (index: number) => T,
43
+ count?: number,
44
+ ): T[] {
45
+ return new Array(count ?? integer(0, 3))
46
+ .fill(0)
47
+ .map((_e, index) => closure(index));
48
+ }
49
+
50
+ export function pick<T>(array: T[]): T {
51
+ return array[integer(0, array.length - 1)]!;
52
+ }
53
+
54
+ /* -----------------------------------------------------------
55
+ SECIAL FORMATS
56
+ ----------------------------------------------------------- */
57
+ export function uuid(): string {
58
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
59
+ const r = (Math.random() * 16) | 0;
60
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
61
+ return v.toString(16);
62
+ });
63
+ }
64
+
65
+ export function email(): string {
66
+ return `${string(10)}@${string(10)}.${string(3)}`;
67
+ }
68
+
69
+ export function url(): string {
70
+ return `https://${string(10)}.${string(3)}`;
71
+ }
72
+
73
+ export function ipv4(): string {
74
+ return array(() => integer(0, 255), 4).join(".");
75
+ }
76
+
77
+ export function ipv6(): string {
78
+ return array(() => integer(0, 65535).toString(16), 8).join(":");
79
+ }
80
+
81
+ export function pattern(regex: RegExp): string {
82
+ return new RandExp(regex).gen();
83
+ }
84
+
85
+ export function date(min?: number, max?: number): string {
86
+ min ??= 0;
87
+ max ??= Date.now() * 2;
88
+ return new Date(number(min, max)).toISOString().substring(0, 10);
89
+ }
90
+
91
+ export function datetime(min?: number, max?: number): string {
92
+ min ??= 0;
93
+ max ??= Date.now() * 2;
94
+ return new Date(number(min, max)).toISOString();
95
+ }
96
+ }