typia 3.4.21 → 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/application_schema.js +23 -21
- package/lib/programmers/internal/application_schema.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_schema.ts +9 -6
- 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
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ValidateProgrammer } from "../../../programmers/ValidateProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../../IProject";
|
|
6
|
-
|
|
7
|
-
export namespace CreateValidateTransformer {
|
|
8
|
-
export function transform(equals: boolean) {
|
|
9
|
-
const SYMBOL = equals ? "createValidateEquals" : "createValidate";
|
|
10
|
-
const MESSAGES = {
|
|
11
|
-
NOT_SPECIFIED: `Error on typia.${SYMBOL}(): generic argument is not specified.`,
|
|
12
|
-
GENERIC_ARGUMENT: `Error on typia.${SYMBOL}(): non-specified generic argument.`,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return function (
|
|
16
|
-
project: IProject,
|
|
17
|
-
modulo: ts.LeftHandSideExpression,
|
|
18
|
-
expression: ts.CallExpression,
|
|
19
|
-
): ts.Expression {
|
|
20
|
-
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
21
|
-
if (!expression.typeArguments || !expression.typeArguments[0])
|
|
22
|
-
throw new Error(MESSAGES.NOT_SPECIFIED);
|
|
23
|
-
|
|
24
|
-
// GET TYPE INFO
|
|
25
|
-
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
26
|
-
expression.typeArguments[0],
|
|
27
|
-
);
|
|
28
|
-
if (type.isTypeParameter())
|
|
29
|
-
throw new Error(MESSAGES.GENERIC_ARGUMENT);
|
|
30
|
-
|
|
31
|
-
// DO TRANSFORM
|
|
32
|
-
return ValidateProgrammer.generate(project, modulo, equals)(type);
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ValidateProgrammer } from "../../../programmers/ValidateProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace CreateValidateTransformer {
|
|
8
|
+
export function transform(equals: boolean) {
|
|
9
|
+
const SYMBOL = equals ? "createValidateEquals" : "createValidate";
|
|
10
|
+
const MESSAGES = {
|
|
11
|
+
NOT_SPECIFIED: `Error on typia.${SYMBOL}(): generic argument is not specified.`,
|
|
12
|
+
GENERIC_ARGUMENT: `Error on typia.${SYMBOL}(): non-specified generic argument.`,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return function (
|
|
16
|
+
project: IProject,
|
|
17
|
+
modulo: ts.LeftHandSideExpression,
|
|
18
|
+
expression: ts.CallExpression,
|
|
19
|
+
): ts.Expression {
|
|
20
|
+
// CHECK GENERIC ARGUMENT EXISTENCE
|
|
21
|
+
if (!expression.typeArguments || !expression.typeArguments[0])
|
|
22
|
+
throw new Error(MESSAGES.NOT_SPECIFIED);
|
|
23
|
+
|
|
24
|
+
// GET TYPE INFO
|
|
25
|
+
const type: ts.Type = project.checker.getTypeFromTypeNode(
|
|
26
|
+
expression.typeArguments[0],
|
|
27
|
+
);
|
|
28
|
+
if (type.isTypeParameter())
|
|
29
|
+
throw new Error(MESSAGES.GENERIC_ARGUMENT);
|
|
30
|
+
|
|
31
|
+
// DO TRANSFORM
|
|
32
|
+
return ValidateProgrammer.generate(project, modulo, equals)(type);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IsProgrammer } from "../../../programmers/IsProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../../IProject";
|
|
6
|
-
|
|
7
|
-
export namespace IsTransformer {
|
|
8
|
-
export function transform(equals: boolean) {
|
|
9
|
-
const SYMBOL = equals ? "equals" : "is";
|
|
10
|
-
const MESSAGES = {
|
|
11
|
-
NO_INPUT_VALUE: `Error on typia.${SYMBOL}(): no input value.`,
|
|
12
|
-
GENERIC_ARGUMENT: `Error on typia.${SYMBOL}(): non-specified generic argument.`,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return function (
|
|
16
|
-
project: IProject,
|
|
17
|
-
modulo: ts.LeftHandSideExpression,
|
|
18
|
-
expression: ts.CallExpression,
|
|
19
|
-
): ts.Expression {
|
|
20
|
-
if (expression.arguments.length !== 1)
|
|
21
|
-
throw new Error(MESSAGES.NO_INPUT_VALUE);
|
|
22
|
-
|
|
23
|
-
// GET TYPE INFO
|
|
24
|
-
const type: ts.Type =
|
|
25
|
-
expression.typeArguments && expression.typeArguments[0]
|
|
26
|
-
? project.checker.getTypeFromTypeNode(
|
|
27
|
-
expression.typeArguments[0],
|
|
28
|
-
)
|
|
29
|
-
: project.checker.getTypeAtLocation(
|
|
30
|
-
expression.arguments[0]!,
|
|
31
|
-
);
|
|
32
|
-
if (type.isTypeParameter())
|
|
33
|
-
throw new Error(MESSAGES.GENERIC_ARGUMENT);
|
|
34
|
-
|
|
35
|
-
// DO TRANSFORM
|
|
36
|
-
return ts.factory.createCallExpression(
|
|
37
|
-
IsProgrammer.generate(project, modulo, equals)(type),
|
|
38
|
-
undefined,
|
|
39
|
-
[expression.arguments[0]!],
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IsProgrammer } from "../../../programmers/IsProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace IsTransformer {
|
|
8
|
+
export function transform(equals: boolean) {
|
|
9
|
+
const SYMBOL = equals ? "equals" : "is";
|
|
10
|
+
const MESSAGES = {
|
|
11
|
+
NO_INPUT_VALUE: `Error on typia.${SYMBOL}(): no input value.`,
|
|
12
|
+
GENERIC_ARGUMENT: `Error on typia.${SYMBOL}(): non-specified generic argument.`,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return function (
|
|
16
|
+
project: IProject,
|
|
17
|
+
modulo: ts.LeftHandSideExpression,
|
|
18
|
+
expression: ts.CallExpression,
|
|
19
|
+
): ts.Expression {
|
|
20
|
+
if (expression.arguments.length !== 1)
|
|
21
|
+
throw new Error(MESSAGES.NO_INPUT_VALUE);
|
|
22
|
+
|
|
23
|
+
// GET TYPE INFO
|
|
24
|
+
const type: ts.Type =
|
|
25
|
+
expression.typeArguments && expression.typeArguments[0]
|
|
26
|
+
? project.checker.getTypeFromTypeNode(
|
|
27
|
+
expression.typeArguments[0],
|
|
28
|
+
)
|
|
29
|
+
: project.checker.getTypeAtLocation(
|
|
30
|
+
expression.arguments[0]!,
|
|
31
|
+
);
|
|
32
|
+
if (type.isTypeParameter())
|
|
33
|
+
throw new Error(MESSAGES.GENERIC_ARGUMENT);
|
|
34
|
+
|
|
35
|
+
// DO TRANSFORM
|
|
36
|
+
return ts.factory.createCallExpression(
|
|
37
|
+
IsProgrammer.generate(project, modulo, equals)(type),
|
|
38
|
+
undefined,
|
|
39
|
+
[expression.arguments[0]!],
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ValidateProgrammer } from "../../../programmers/ValidateProgrammer";
|
|
4
|
-
|
|
5
|
-
import { IProject } from "../../IProject";
|
|
6
|
-
|
|
7
|
-
export namespace ValidateTransformer {
|
|
8
|
-
export function transform(equals: boolean) {
|
|
9
|
-
const SYMBOL = equals ? "validateEquals" : "validate";
|
|
10
|
-
const MESSAGES = {
|
|
11
|
-
NO_INPUT_VALUE: `Error on typia.${SYMBOL}(): no input value.`,
|
|
12
|
-
GENERIC_ARGUMENT: `Error on typia.${SYMBOL}(): non-specified generic argument.`,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
return function (
|
|
16
|
-
project: IProject,
|
|
17
|
-
modulo: ts.LeftHandSideExpression,
|
|
18
|
-
expression: ts.CallExpression,
|
|
19
|
-
): ts.Expression {
|
|
20
|
-
if (expression.arguments.length !== 1)
|
|
21
|
-
throw new Error(MESSAGES.NO_INPUT_VALUE);
|
|
22
|
-
|
|
23
|
-
// GET TYPE INFO
|
|
24
|
-
const type: ts.Type =
|
|
25
|
-
expression.typeArguments && expression.typeArguments[0]
|
|
26
|
-
? project.checker.getTypeFromTypeNode(
|
|
27
|
-
expression.typeArguments[0],
|
|
28
|
-
)
|
|
29
|
-
: project.checker.getTypeAtLocation(
|
|
30
|
-
expression.arguments[0]!,
|
|
31
|
-
);
|
|
32
|
-
if (type.isTypeParameter())
|
|
33
|
-
throw new Error(MESSAGES.GENERIC_ARGUMENT);
|
|
34
|
-
|
|
35
|
-
// DO TRANSFORM
|
|
36
|
-
return ts.factory.createCallExpression(
|
|
37
|
-
ValidateProgrammer.generate(project, modulo, equals)(type),
|
|
38
|
-
undefined,
|
|
39
|
-
[expression.arguments[0]!],
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ValidateProgrammer } from "../../../programmers/ValidateProgrammer";
|
|
4
|
+
|
|
5
|
+
import { IProject } from "../../IProject";
|
|
6
|
+
|
|
7
|
+
export namespace ValidateTransformer {
|
|
8
|
+
export function transform(equals: boolean) {
|
|
9
|
+
const SYMBOL = equals ? "validateEquals" : "validate";
|
|
10
|
+
const MESSAGES = {
|
|
11
|
+
NO_INPUT_VALUE: `Error on typia.${SYMBOL}(): no input value.`,
|
|
12
|
+
GENERIC_ARGUMENT: `Error on typia.${SYMBOL}(): non-specified generic argument.`,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return function (
|
|
16
|
+
project: IProject,
|
|
17
|
+
modulo: ts.LeftHandSideExpression,
|
|
18
|
+
expression: ts.CallExpression,
|
|
19
|
+
): ts.Expression {
|
|
20
|
+
if (expression.arguments.length !== 1)
|
|
21
|
+
throw new Error(MESSAGES.NO_INPUT_VALUE);
|
|
22
|
+
|
|
23
|
+
// GET TYPE INFO
|
|
24
|
+
const type: ts.Type =
|
|
25
|
+
expression.typeArguments && expression.typeArguments[0]
|
|
26
|
+
? project.checker.getTypeFromTypeNode(
|
|
27
|
+
expression.typeArguments[0],
|
|
28
|
+
)
|
|
29
|
+
: project.checker.getTypeAtLocation(
|
|
30
|
+
expression.arguments[0]!,
|
|
31
|
+
);
|
|
32
|
+
if (type.isTypeParameter())
|
|
33
|
+
throw new Error(MESSAGES.GENERIC_ARGUMENT);
|
|
34
|
+
|
|
35
|
+
// DO TRANSFORM
|
|
36
|
+
return ts.factory.createCallExpression(
|
|
37
|
+
ValidateProgrammer.generate(project, modulo, equals)(type),
|
|
38
|
+
undefined,
|
|
39
|
+
[expression.arguments[0]!],
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/typings/Atomic.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export namespace Atomic {
|
|
2
|
-
export type Type = boolean | number | string | bigint;
|
|
3
|
-
export type Literal =
|
|
4
|
-
| "boolean"
|
|
5
|
-
| "integer"
|
|
6
|
-
| "number"
|
|
7
|
-
| "string"
|
|
8
|
-
| "bigint";
|
|
9
|
-
|
|
10
|
-
export type Mapper = {
|
|
11
|
-
boolean: boolean;
|
|
12
|
-
integer: number;
|
|
13
|
-
number: number;
|
|
14
|
-
string: string;
|
|
15
|
-
bigint: bigint;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
1
|
+
export namespace Atomic {
|
|
2
|
+
export type Type = boolean | number | string | bigint;
|
|
3
|
+
export type Literal =
|
|
4
|
+
| "boolean"
|
|
5
|
+
| "integer"
|
|
6
|
+
| "number"
|
|
7
|
+
| "string"
|
|
8
|
+
| "bigint";
|
|
9
|
+
|
|
10
|
+
export type Mapper = {
|
|
11
|
+
boolean: boolean;
|
|
12
|
+
integer: number;
|
|
13
|
+
number: number;
|
|
14
|
+
string: string;
|
|
15
|
+
bigint: bigint;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { OmitNever } from "./OmitNever";
|
|
2
|
-
|
|
3
|
-
export type ClassProperties<T extends object> = OmitNever<{
|
|
4
|
-
[K in keyof T]: T[K] extends Function ? never : T[K];
|
|
5
|
-
}>;
|
|
1
|
+
import { OmitNever } from "./OmitNever";
|
|
2
|
+
|
|
3
|
+
export type ClassProperties<T extends object> = OmitNever<{
|
|
4
|
+
[K in keyof T]: T[K] extends Function ? never : T[K];
|
|
5
|
+
}>;
|
package/src/typings/OmitNever.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SpecialFields } from "./SpecialFields";
|
|
2
|
-
|
|
3
|
-
export type OmitNever<T extends object> = Omit<T, SpecialFields<T, never>>;
|
|
1
|
+
import { SpecialFields } from "./SpecialFields";
|
|
2
|
+
|
|
3
|
+
export type OmitNever<T extends object> = Omit<T, SpecialFields<T, never>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export type SpecialFields<Instance extends object, Target> = {
|
|
2
|
-
[P in keyof Instance]: Instance[P] extends Target ? P : never;
|
|
3
|
-
}[keyof Instance & string];
|
|
1
|
+
export type SpecialFields<Instance extends object, Target> = {
|
|
2
|
+
[P in keyof Instance]: Instance[P] extends Target ? P : never;
|
|
3
|
+
}[keyof Instance & string];
|
package/src/typings/Writable.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ClassProperties } from "./ClassProperties";
|
|
2
|
-
|
|
3
|
-
export type Writable<T extends object> = {
|
|
4
|
-
-readonly [P in keyof T]: T[P];
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
export function Writable<T extends object>(
|
|
8
|
-
elem: T,
|
|
9
|
-
): Writable<ClassProperties<T>> {
|
|
10
|
-
return elem as any;
|
|
11
|
-
}
|
|
1
|
+
import { ClassProperties } from "./ClassProperties";
|
|
2
|
+
|
|
3
|
+
export type Writable<T extends object> = {
|
|
4
|
+
-readonly [P in keyof T]: T[P];
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export function Writable<T extends object>(
|
|
8
|
+
elem: T,
|
|
9
|
+
): Writable<ClassProperties<T>> {
|
|
10
|
+
return elem as any;
|
|
11
|
+
}
|
package/src/utils/ArrayUtil.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
export namespace ArrayUtil {
|
|
2
|
-
export function has<T>(array: T[], pred: (elem: T) => boolean): boolean {
|
|
3
|
-
return array.some(pred);
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function add<T>(
|
|
7
|
-
array: T[],
|
|
8
|
-
value: T,
|
|
9
|
-
pred: (x: T, y: T) => boolean = (x, y) => x === y,
|
|
10
|
-
): void {
|
|
11
|
-
if (array.some((elem) => pred(elem, value))) return;
|
|
12
|
-
array.push(value);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function set<Key, T>(
|
|
16
|
-
array: T[],
|
|
17
|
-
value: T,
|
|
18
|
-
key: (elem: T) => Key,
|
|
19
|
-
): void {
|
|
20
|
-
if (array.some((elem) => key(elem) === key(value))) return;
|
|
21
|
-
array.push(value);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function take<T>(
|
|
25
|
-
array: T[],
|
|
26
|
-
pred: (elem: T) => boolean,
|
|
27
|
-
init: () => T,
|
|
28
|
-
): T {
|
|
29
|
-
const index: number = array.findIndex(pred);
|
|
30
|
-
if (index !== -1) return array[index]!;
|
|
31
|
-
|
|
32
|
-
const elem: T = init();
|
|
33
|
-
array.push(elem);
|
|
34
|
-
return elem;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function repeat<T>(
|
|
38
|
-
count: number,
|
|
39
|
-
closure: (index: number, count: number) => T,
|
|
40
|
-
): T[] {
|
|
41
|
-
return new Array(count)
|
|
42
|
-
.fill("")
|
|
43
|
-
.map((_, index) => closure(index, count));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function flat<T>(matrix: T[][]): T[] {
|
|
47
|
-
return ([] as T[]).concat(...matrix);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
export namespace ArrayUtil {
|
|
2
|
+
export function has<T>(array: T[], pred: (elem: T) => boolean): boolean {
|
|
3
|
+
return array.some(pred);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function add<T>(
|
|
7
|
+
array: T[],
|
|
8
|
+
value: T,
|
|
9
|
+
pred: (x: T, y: T) => boolean = (x, y) => x === y,
|
|
10
|
+
): void {
|
|
11
|
+
if (array.some((elem) => pred(elem, value))) return;
|
|
12
|
+
array.push(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function set<Key, T>(
|
|
16
|
+
array: T[],
|
|
17
|
+
value: T,
|
|
18
|
+
key: (elem: T) => Key,
|
|
19
|
+
): void {
|
|
20
|
+
if (array.some((elem) => key(elem) === key(value))) return;
|
|
21
|
+
array.push(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function take<T>(
|
|
25
|
+
array: T[],
|
|
26
|
+
pred: (elem: T) => boolean,
|
|
27
|
+
init: () => T,
|
|
28
|
+
): T {
|
|
29
|
+
const index: number = array.findIndex(pred);
|
|
30
|
+
if (index !== -1) return array[index]!;
|
|
31
|
+
|
|
32
|
+
const elem: T = init();
|
|
33
|
+
array.push(elem);
|
|
34
|
+
return elem;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function repeat<T>(
|
|
38
|
+
count: number,
|
|
39
|
+
closure: (index: number, count: number) => T,
|
|
40
|
+
): T[] {
|
|
41
|
+
return new Array(count)
|
|
42
|
+
.fill("")
|
|
43
|
+
.map((_, index) => closure(index, count));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function flat<T>(matrix: T[][]): T[] {
|
|
47
|
+
return ([] as T[]).concat(...matrix);
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/utils/Escaper.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
export namespace Escaper {
|
|
2
|
-
export function variable(str: string): boolean {
|
|
3
|
-
return (
|
|
4
|
-
reserved(str) === false && /^[a-zA-Z_$][a-zA-Z_$0-9]*$/g.test(str)
|
|
5
|
-
);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function reserved(str: string): boolean {
|
|
9
|
-
return RESERVED.has(str);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const RESERVED: Set<string> = new Set([
|
|
14
|
-
"break",
|
|
15
|
-
"case",
|
|
16
|
-
"catch",
|
|
17
|
-
"class",
|
|
18
|
-
"const",
|
|
19
|
-
"continue",
|
|
20
|
-
"debugger",
|
|
21
|
-
"default",
|
|
22
|
-
"delete",
|
|
23
|
-
"do",
|
|
24
|
-
"else",
|
|
25
|
-
"enum",
|
|
26
|
-
"export",
|
|
27
|
-
"extends",
|
|
28
|
-
"false",
|
|
29
|
-
"finally",
|
|
30
|
-
"for",
|
|
31
|
-
"function",
|
|
32
|
-
"if",
|
|
33
|
-
"import",
|
|
34
|
-
"in",
|
|
35
|
-
"instanceof",
|
|
36
|
-
"new",
|
|
37
|
-
"null",
|
|
38
|
-
"return",
|
|
39
|
-
"super",
|
|
40
|
-
"switch",
|
|
41
|
-
"this",
|
|
42
|
-
"throw",
|
|
43
|
-
"true",
|
|
44
|
-
"try",
|
|
45
|
-
"typeof",
|
|
46
|
-
"var",
|
|
47
|
-
"void",
|
|
48
|
-
"while",
|
|
49
|
-
"with",
|
|
50
|
-
]);
|
|
1
|
+
export namespace Escaper {
|
|
2
|
+
export function variable(str: string): boolean {
|
|
3
|
+
return (
|
|
4
|
+
reserved(str) === false && /^[a-zA-Z_$][a-zA-Z_$0-9]*$/g.test(str)
|
|
5
|
+
);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function reserved(str: string): boolean {
|
|
9
|
+
return RESERVED.has(str);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const RESERVED: Set<string> = new Set([
|
|
14
|
+
"break",
|
|
15
|
+
"case",
|
|
16
|
+
"catch",
|
|
17
|
+
"class",
|
|
18
|
+
"const",
|
|
19
|
+
"continue",
|
|
20
|
+
"debugger",
|
|
21
|
+
"default",
|
|
22
|
+
"delete",
|
|
23
|
+
"do",
|
|
24
|
+
"else",
|
|
25
|
+
"enum",
|
|
26
|
+
"export",
|
|
27
|
+
"extends",
|
|
28
|
+
"false",
|
|
29
|
+
"finally",
|
|
30
|
+
"for",
|
|
31
|
+
"function",
|
|
32
|
+
"if",
|
|
33
|
+
"import",
|
|
34
|
+
"in",
|
|
35
|
+
"instanceof",
|
|
36
|
+
"new",
|
|
37
|
+
"null",
|
|
38
|
+
"return",
|
|
39
|
+
"super",
|
|
40
|
+
"switch",
|
|
41
|
+
"this",
|
|
42
|
+
"throw",
|
|
43
|
+
"true",
|
|
44
|
+
"try",
|
|
45
|
+
"typeof",
|
|
46
|
+
"var",
|
|
47
|
+
"void",
|
|
48
|
+
"while",
|
|
49
|
+
"with",
|
|
50
|
+
]);
|
package/src/utils/MapUtil.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export namespace MapUtil {
|
|
2
|
-
export function take<Key, T>(
|
|
3
|
-
dict: Map<Key, T>,
|
|
4
|
-
key: Key,
|
|
5
|
-
generator: () => T,
|
|
6
|
-
): T {
|
|
7
|
-
const oldbie: T | undefined = dict.get(key);
|
|
8
|
-
if (oldbie) return oldbie;
|
|
9
|
-
|
|
10
|
-
const value: T = generator();
|
|
11
|
-
dict.set(key, value);
|
|
12
|
-
return value;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
1
|
+
export namespace MapUtil {
|
|
2
|
+
export function take<Key, T>(
|
|
3
|
+
dict: Map<Key, T>,
|
|
4
|
+
key: Key,
|
|
5
|
+
generator: () => T,
|
|
6
|
+
): T {
|
|
7
|
+
const oldbie: T | undefined = dict.get(key);
|
|
8
|
+
if (oldbie) return oldbie;
|
|
9
|
+
|
|
10
|
+
const value: T = generator();
|
|
11
|
+
dict.set(key, value);
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
}
|
package/src/utils/PatternUtil.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
export namespace PatternUtil {
|
|
2
|
-
export function fix(str: string): string {
|
|
3
|
-
const first: number = str.indexOf(STRING);
|
|
4
|
-
const last: number = str.lastIndexOf(STRING);
|
|
5
|
-
return [
|
|
6
|
-
first === -1 || none("(")(str.slice(0, first)) ? "^" : "",
|
|
7
|
-
str,
|
|
8
|
-
last === -1 || none(")")(str.slice(last + STRING.length))
|
|
9
|
-
? "$"
|
|
10
|
-
: "",
|
|
11
|
-
].join("");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function escape(str: string): string {
|
|
15
|
-
return str
|
|
16
|
-
.replace(/[|\\/{}()[\]^$+*?.]/g, "\\$&")
|
|
17
|
-
.replace(/-/g, "\\x2d");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export const NUMBER = "-?\\d+\\.?\\d*";
|
|
21
|
-
export const BOOLEAN = "true|false";
|
|
22
|
-
export const STRING = "(.*)";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const none =
|
|
26
|
-
(parenthesis: string) =>
|
|
27
|
-
(str: string): boolean => {
|
|
28
|
-
for (const ch of str) if (ch !== parenthesis) return true;
|
|
29
|
-
return false;
|
|
30
|
-
};
|
|
1
|
+
export namespace PatternUtil {
|
|
2
|
+
export function fix(str: string): string {
|
|
3
|
+
const first: number = str.indexOf(STRING);
|
|
4
|
+
const last: number = str.lastIndexOf(STRING);
|
|
5
|
+
return [
|
|
6
|
+
first === -1 || none("(")(str.slice(0, first)) ? "^" : "",
|
|
7
|
+
str,
|
|
8
|
+
last === -1 || none(")")(str.slice(last + STRING.length))
|
|
9
|
+
? "$"
|
|
10
|
+
: "",
|
|
11
|
+
].join("");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function escape(str: string): string {
|
|
15
|
+
return str
|
|
16
|
+
.replace(/[|\\/{}()[\]^$+*?.]/g, "\\$&")
|
|
17
|
+
.replace(/-/g, "\\x2d");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const NUMBER = "-?\\d+\\.?\\d*";
|
|
21
|
+
export const BOOLEAN = "true|false";
|
|
22
|
+
export const STRING = "(.*)";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const none =
|
|
26
|
+
(parenthesis: string) =>
|
|
27
|
+
(str: string): boolean => {
|
|
28
|
+
for (const ch of str) if (ch !== parenthesis) return true;
|
|
29
|
+
return false;
|
|
30
|
+
};
|
package/src/utils/Singleton.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export class Singleton<T, Args extends any[] = []> {
|
|
2
|
-
private readonly closure_: (...args: Args) => T;
|
|
3
|
-
private value_: T | object;
|
|
4
|
-
|
|
5
|
-
public constructor(closure: (...args: Args) => T) {
|
|
6
|
-
this.closure_ = closure;
|
|
7
|
-
this.value_ = NOT_MOUNTED_YET;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public get(...args: Args): T {
|
|
11
|
-
if (this.value_ === NOT_MOUNTED_YET)
|
|
12
|
-
this.value_ = this.closure_(...args);
|
|
13
|
-
return this.value_ as T;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const NOT_MOUNTED_YET = {};
|
|
1
|
+
export class Singleton<T, Args extends any[] = []> {
|
|
2
|
+
private readonly closure_: (...args: Args) => T;
|
|
3
|
+
private value_: T | object;
|
|
4
|
+
|
|
5
|
+
public constructor(closure: (...args: Args) => T) {
|
|
6
|
+
this.closure_ = closure;
|
|
7
|
+
this.value_ = NOT_MOUNTED_YET;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public get(...args: Args): T {
|
|
11
|
+
if (this.value_ === NOT_MOUNTED_YET)
|
|
12
|
+
this.value_ = this.closure_(...args);
|
|
13
|
+
return this.value_ as T;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const NOT_MOUNTED_YET = {};
|