typia 3.5.0-dev.20221219 → 3.5.0-dev.20221222
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 +58 -16
- package/lib/executable/internal/TypiaSetupWizard.js +2 -1
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -77
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/MetadataTagFactory.js +4 -1
- package/lib/factories/MetadataTagFactory.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +0 -1
- package/lib/factories/ProtocolFactory.js +0 -6
- package/lib/factories/ProtocolFactory.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_object.js +4 -2
- package/lib/factories/internal/metadata/iterate_metadata_object.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_main.js +2 -3
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -1
- package/lib/functional/$number.js +2 -9
- package/lib/functional/$number.js.map +1 -1
- package/lib/programmers/AssertParseProgrammer.js +12 -1
- package/lib/programmers/AssertParseProgrammer.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +2 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/AssertStringifyProgrammer.js +13 -2
- package/lib/programmers/AssertStringifyProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +6 -0
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/IsParseProgrammer.js +12 -1
- package/lib/programmers/IsParseProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.js +5 -2
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/IsStringifyProgrammer.js +13 -2
- package/lib/programmers/IsStringifyProgrammer.js.map +1 -1
- package/lib/programmers/MessageProgrammer.js +11 -6
- package/lib/programmers/MessageProgrammer.js.map +1 -1
- package/lib/programmers/StringifyProgrammer.js +6 -1
- package/lib/programmers/StringifyProgrammer.js.map +1 -1
- package/lib/programmers/ValidateParseProgrammer.js +12 -1
- package/lib/programmers/ValidateParseProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +2 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/ValidateStringifyProgrammer.js +13 -2
- package/lib/programmers/ValidateStringifyProgrammer.js.map +1 -1
- package/lib/programmers/helpers/OptionPredicator.d.ts +2 -1
- package/lib/programmers/helpers/OptionPredicator.js +8 -6
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/internal/application_object.js +9 -9
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +12 -6
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_bigint.d.ts +3 -0
- package/lib/programmers/internal/check_bigint.js +97 -0
- package/lib/programmers/internal/check_bigint.js.map +1 -0
- package/lib/programmers/internal/check_number.js +21 -23
- package/lib/programmers/internal/check_number.js.map +1 -1
- package/lib/schemas/IJsonSchema.d.ts +3 -5
- package/lib/transformers/ITransformOptions.d.ts +43 -2
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +5 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/stringifiers/StringifyTransformer.js +12 -1
- package/lib/transformers/features/stringifiers/StringifyTransformer.js.map +1 -1
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +3 -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/executable/internal/TypiaSetupWizard.ts +7 -3
- package/src/executable/typia.ts +46 -46
- 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/MetadataCollection.ts +2 -43
- package/src/factories/MetadataTagFactory.ts +5 -1
- package/src/factories/ProtocolFactory.ts +0 -5
- 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/factories/internal/metadata/iterate_metadata_object.ts +6 -3
- package/src/factories/internal/protocols/iterate_protocol_main.ts +2 -3
- package/src/factories/internal/protocols/iterate_protocol_map.ts +3 -5
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +1 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +3 -6
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +3 -6
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- 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/$number.ts +2 -9
- 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/AssertParseProgrammer.ts +11 -1
- package/src/programmers/AssertProgrammer.ts +3 -2
- package/src/programmers/AssertStringifyProgrammer.ts +22 -2
- package/src/programmers/CheckerProgrammer.ts +6 -0
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +11 -1
- package/src/programmers/IsProgrammer.ts +5 -2
- package/src/programmers/IsStringifyProgrammer.ts +22 -2
- package/src/programmers/MessageProgrammer.ts +12 -6
- package/src/programmers/StringifyProgrammer.ts +7 -1
- package/src/programmers/ValidateParseProgrammer.ts +11 -1
- package/src/programmers/ValidateProgrammer.ts +2 -1
- package/src/programmers/ValidateStringifyProgrammer.ts +22 -2
- 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 +7 -10
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +437 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default.ts +1 -1
- 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_object.ts +103 -103
- package/src/programmers/internal/application_schema.ts +15 -5
- 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 +25 -25
- package/src/programmers/internal/check_array.ts +44 -44
- package/src/programmers/internal/check_bigint.ts +85 -0
- package/src/programmers/internal/check_dynamic_properties.ts +146 -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_number.ts +45 -51
- package/src/programmers/internal/check_object.ts +42 -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 +24 -24
- package/src/schemas/IJsonSchema.ts +4 -6
- 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 +45 -2
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +6 -3
- 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/StringifyTransformer.ts +11 -1
- 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/NameEncoder.ts +32 -0
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.d.ts +0 -5
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.js +0 -29
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.js.map +0 -1
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +0 -41
|
@@ -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
|
+
}
|
|
@@ -16,10 +16,13 @@ export const iterate_metadata_object =
|
|
|
16
16
|
(collection: MetadataCollection) =>
|
|
17
17
|
(meta: Metadata, type: ts.Type, parentResolved: boolean): boolean => {
|
|
18
18
|
const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
|
|
19
|
-
if (
|
|
19
|
+
if (
|
|
20
|
+
!filter(ts.TypeFlags.Object) &&
|
|
21
|
+
!type.isIntersection() &&
|
|
22
|
+
(type as any).intrinsicName !== "object"
|
|
23
|
+
)
|
|
20
24
|
return false;
|
|
21
|
-
|
|
22
|
-
if (type.isIntersection()) {
|
|
25
|
+
else if (type.isIntersection()) {
|
|
23
26
|
const fakeCollection = new MetadataCollection();
|
|
24
27
|
const fakeSchema: Metadata = Metadata.initialize();
|
|
25
28
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Metadata } from "../../../metadata/Metadata";
|
|
2
2
|
|
|
3
3
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
4
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
5
4
|
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
6
5
|
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
7
6
|
|
|
@@ -10,11 +9,11 @@ export const iterate_protocol_main =
|
|
|
10
9
|
(meta: Metadata): string => {
|
|
11
10
|
// ONLY ONE OBJECT TYPE
|
|
12
11
|
if (ProtocolMetadataUtil.standalone(meta) && meta.objects.length === 1)
|
|
13
|
-
return
|
|
12
|
+
return meta.getName();
|
|
14
13
|
|
|
15
14
|
const obj = ProtocolMetadataUtil.object("__Main", dict.size);
|
|
16
15
|
obj.properties.push(ProtocolMetadataUtil.property("value", meta, []));
|
|
17
16
|
emplace_protocol_object(dict)(obj);
|
|
18
17
|
|
|
19
|
-
return
|
|
18
|
+
return obj.name;
|
|
20
19
|
};
|
|
@@ -2,7 +2,6 @@ import { Metadata } from "../../../metadata/Metadata";
|
|
|
2
2
|
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
3
3
|
|
|
4
4
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
5
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
6
5
|
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
7
6
|
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
8
7
|
import { iterate_protocol_atomic } from "./iterate_protocol_atomic";
|
|
@@ -27,14 +26,13 @@ const getValueName =
|
|
|
27
26
|
(container: "Object" | "Map") =>
|
|
28
27
|
(dict: Map<string, IProtocolMessage>) =>
|
|
29
28
|
(meta: Metadata) => {
|
|
30
|
-
if (ProtocolMetadataUtil.standalone(meta))
|
|
31
|
-
return MetadataCollection.escape(meta.getName());
|
|
29
|
+
if (ProtocolMetadataUtil.standalone(meta)) return meta.getName();
|
|
32
30
|
|
|
33
31
|
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
34
|
-
|
|
32
|
+
`${container}.Value<${meta.getName()}>`,
|
|
35
33
|
dict.size,
|
|
36
34
|
);
|
|
37
35
|
obj.properties.push(ProtocolMetadataUtil.property("value", meta, []));
|
|
38
36
|
emplace_protocol_object(dict)(obj);
|
|
39
|
-
return
|
|
37
|
+
return obj.name;
|
|
40
38
|
};
|
|
@@ -44,6 +44,7 @@ export const iterate_protocol_metadata =
|
|
|
44
44
|
add(iterate_protocol_atomic(tags)(type));
|
|
45
45
|
for (const constant of meta.constants)
|
|
46
46
|
add(iterate_protocol_constant(constant));
|
|
47
|
+
if (meta.templates.length) add("string");
|
|
47
48
|
|
|
48
49
|
// INSTANCE TYPES
|
|
49
50
|
for (const obj of meta.objects)
|
|
@@ -3,7 +3,6 @@ import { Metadata } from "../../../metadata/Metadata";
|
|
|
3
3
|
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
4
4
|
|
|
5
5
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
6
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
7
6
|
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
8
7
|
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
9
8
|
|
|
@@ -14,15 +13,13 @@ export const iterate_protocol_repeated =
|
|
|
14
13
|
(meta: Metadata) =>
|
|
15
14
|
(tags: IMetadataTag[]): string => {
|
|
16
15
|
sole &&= ProtocolMetadataUtil.standalone(meta);
|
|
17
|
-
if (sole === true) return
|
|
16
|
+
if (sole === true) return meta.getName();
|
|
18
17
|
|
|
19
18
|
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
20
|
-
|
|
21
|
-
`${container}.Element<${meta.getName()}>`,
|
|
22
|
-
),
|
|
19
|
+
`${container}.Element<${meta.getName()}>`,
|
|
23
20
|
dict.size,
|
|
24
21
|
);
|
|
25
22
|
obj.properties.push(ProtocolMetadataUtil.property("value", meta, tags));
|
|
26
23
|
emplace_protocol_object(dict)(obj);
|
|
27
|
-
return
|
|
24
|
+
return obj.name;
|
|
28
25
|
};
|
|
@@ -2,17 +2,14 @@ import { Metadata } from "../../../metadata/Metadata";
|
|
|
2
2
|
import { MetadataObject } from "../../../metadata/MetadataObject";
|
|
3
3
|
|
|
4
4
|
import { IProtocolMessage } from "../../../messages/IProtocolMessage";
|
|
5
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
6
5
|
import { ProtocolMetadataUtil } from "./ProtocolMetadataUtil";
|
|
7
6
|
import { emplace_protocol_object } from "./emplace_protocol_object";
|
|
8
7
|
|
|
9
8
|
export const iterate_protocol_tuple =
|
|
10
9
|
(dict: Map<string, IProtocolMessage>) =>
|
|
11
10
|
(tuple: Metadata[]): string => {
|
|
12
|
-
const name: string =
|
|
13
|
-
|
|
14
|
-
);
|
|
15
|
-
if (dict.has(name)) return MetadataCollection.escape(name);
|
|
11
|
+
const name: string = `[${tuple.map((m) => m.getName()).join(", ")}]`;
|
|
12
|
+
if (dict.has(name)) return name;
|
|
16
13
|
|
|
17
14
|
const obj: MetadataObject = ProtocolMetadataUtil.object(
|
|
18
15
|
name,
|
|
@@ -24,5 +21,5 @@ export const iterate_protocol_tuple =
|
|
|
24
21
|
),
|
|
25
22
|
);
|
|
26
23
|
emplace_protocol_object(dict)(obj);
|
|
27
|
-
return
|
|
24
|
+
return obj.name;
|
|
28
25
|
};
|
package/src/functional/$every.ts
CHANGED
|
@@ -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
|
+
};
|
package/src/functional/$guard.ts
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { TypeGuardError } from "../TypeGuardError";
|
|
2
|
-
|
|
3
|
-
/* -----------------------------------------------------------
|
|
4
|
-
ASSERT V2 -> USE (NULL OR ERROR) CONDITION
|
|
5
|
-
----------------------------------------------------------- */
|
|
6
|
-
// /**
|
|
7
|
-
// * @internal
|
|
8
|
-
// */
|
|
9
|
-
// export const $guardV2 =
|
|
10
|
-
// (method: string) => (props: Omit<TypeGuardError.IProps, "method">) =>
|
|
11
|
-
// new TypeGuardError({
|
|
12
|
-
// method,
|
|
13
|
-
// path: props.path,
|
|
14
|
-
// expected: props.expected,
|
|
15
|
-
// value: props.value,
|
|
16
|
-
// });
|
|
17
|
-
|
|
18
|
-
/* -----------------------------------------------------------
|
|
19
|
-
ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
|
|
20
|
-
----------------------------------------------------------- */
|
|
21
|
-
/**
|
|
22
|
-
* @internal
|
|
23
|
-
*/
|
|
24
|
-
export const $guard =
|
|
25
|
-
(method: string) =>
|
|
26
|
-
(exceptionable: boolean, props: Omit<TypeGuardError.IProps, "method">) => {
|
|
27
|
-
if (exceptionable === true)
|
|
28
|
-
throw new TypeGuardError({
|
|
29
|
-
method,
|
|
30
|
-
path: props.path,
|
|
31
|
-
expected: props.expected,
|
|
32
|
-
value: props.value,
|
|
33
|
-
});
|
|
34
|
-
return false;
|
|
35
|
-
};
|
|
1
|
+
import { TypeGuardError } from "../TypeGuardError";
|
|
2
|
+
|
|
3
|
+
/* -----------------------------------------------------------
|
|
4
|
+
ASSERT V2 -> USE (NULL OR ERROR) CONDITION
|
|
5
|
+
----------------------------------------------------------- */
|
|
6
|
+
// /**
|
|
7
|
+
// * @internal
|
|
8
|
+
// */
|
|
9
|
+
// export const $guardV2 =
|
|
10
|
+
// (method: string) => (props: Omit<TypeGuardError.IProps, "method">) =>
|
|
11
|
+
// new TypeGuardError({
|
|
12
|
+
// method,
|
|
13
|
+
// path: props.path,
|
|
14
|
+
// expected: props.expected,
|
|
15
|
+
// value: props.value,
|
|
16
|
+
// });
|
|
17
|
+
|
|
18
|
+
/* -----------------------------------------------------------
|
|
19
|
+
ASSERT V3 -> (CONDITION OR THROW(exceptable): FALSE)
|
|
20
|
+
----------------------------------------------------------- */
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export const $guard =
|
|
25
|
+
(method: string) =>
|
|
26
|
+
(exceptionable: boolean, props: Omit<TypeGuardError.IProps, "method">) => {
|
|
27
|
+
if (exceptionable === true)
|
|
28
|
+
throw new TypeGuardError({
|
|
29
|
+
method,
|
|
30
|
+
path: props.path,
|
|
31
|
+
expected: props.expected,
|
|
32
|
+
value: props.value,
|
|
33
|
+
});
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
@@ -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;
|