typia 7.0.0-dev.20241009-2 → 7.0.0-dev.20241010
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/lib/factories/JsonMetadataFactory.d.ts +5 -1
- package/lib/factories/JsonMetadataFactory.js +4 -1
- package/lib/factories/JsonMetadataFactory.js.map +1 -1
- package/lib/internal/{$httpFormDataReadArray.js → $httpFormdataReadArray.js} +1 -1
- package/lib/internal/$httpFormdataReadArray.js.map +1 -0
- package/lib/programmers/CheckerProgrammer.js +4 -1
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +4 -1
- package/lib/programmers/FeatureProgrammer.js +2 -2
- package/lib/programmers/FeatureProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +12 -9
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/TypiaProgrammer.js +4 -1
- package/lib/programmers/TypiaProgrammer.js.map +1 -1
- package/lib/programmers/internal/prune_object_properties.js +3 -2
- package/lib/programmers/internal/prune_object_properties.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +2 -2
- package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +4 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/transformers/FileTransformer.js +0 -6
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/ImportTransformer.d.ts +4 -1
- package/lib/transformers/ImportTransformer.js +34 -30
- package/lib/transformers/ImportTransformer.js.map +1 -1
- package/package.json +1 -1
- package/src/IRandomGenerator.ts +49 -49
- package/src/factories/ExpressionFactory.ts +164 -164
- package/src/factories/JsonMetadataFactory.ts +25 -15
- package/src/factories/LiteralFactory.ts +50 -50
- package/src/factories/MetadataCommentTagFactory.ts +650 -650
- package/src/functional.ts +750 -750
- package/src/http.ts +1042 -1042
- package/src/internal/$IProtobufWriter.ts +18 -18
- package/src/internal/$ProtobufReader.ts +194 -194
- package/src/internal/$ProtobufSizer.ts +151 -151
- package/src/internal/$ProtobufWriter.ts +145 -145
- package/src/internal/$accessExpressionAsString.ts +46 -46
- package/src/internal/$assertGuard.ts +13 -13
- package/src/internal/$functionalTypeGuardErrorFactory.ts +4 -4
- package/src/internal/$httpFormDataReadBigint.ts +18 -18
- package/src/internal/$httpFormDataReadBlob.ts +10 -10
- package/src/internal/$httpFormDataReadBoolean.ts +16 -16
- package/src/internal/$httpFormDataReadFile.ts +10 -10
- package/src/internal/$httpFormDataReadNumber.ts +15 -15
- package/src/internal/$httpFormDataReadString.ts +10 -10
- package/src/internal/{$httpFormDataReadArray.ts → $httpFormdataReadArray.ts} +4 -4
- package/src/internal/$httpHeaderReadBigint.ts +10 -10
- package/src/internal/$httpHeaderReadBoolean.ts +8 -8
- package/src/internal/$httpHeaderReadNumber.ts +7 -7
- package/src/internal/$httpParameterBigint.ts +10 -10
- package/src/internal/$httpParameterBoolean.ts +8 -8
- package/src/internal/$httpParameterNumber.ts +7 -7
- package/src/internal/$httpParameterString.ts +2 -2
- package/src/internal/$httpQueryParseURLSearchParams.ts +10 -10
- package/src/internal/$httpQueryReadArray.ts +4 -4
- package/src/internal/$httpQueryReadBigint.ts +12 -12
- package/src/internal/$httpQueryReadBoolean.ts +14 -14
- package/src/internal/$httpQueryReadNumber.ts +9 -9
- package/src/internal/$httpQueryReadString.ts +4 -4
- package/src/internal/$isBetween.ts +2 -2
- package/src/internal/$isBigintString.ts +8 -8
- package/src/internal/$jsonStringifyNumber.ts +12 -12
- package/src/internal/$jsonStringifyRest.ts +3 -3
- package/src/internal/$jsonStringifyString.ts +42 -42
- package/src/internal/$jsonStringifyTail.ts +2 -2
- package/src/internal/$llmApplicationFinalize.ts +18 -18
- package/src/internal/$miscCloneAny.ts +48 -48
- package/src/internal/$notationAny.ts +37 -37
- package/src/internal/$notationCamel.ts +13 -13
- package/src/internal/$notationPascal.ts +8 -8
- package/src/internal/$notationSnake.ts +43 -43
- package/src/internal/$randomArray.ts +21 -21
- package/src/internal/$randomBigint.ts +6 -6
- package/src/internal/$randomBoolean.ts +1 -1
- package/src/internal/$randomFormatByte.ts +3 -3
- package/src/internal/$randomFormatDate.ts +18 -18
- package/src/internal/$randomFormatDatetime.ts +16 -16
- package/src/internal/$randomFormatDuration.ts +27 -27
- package/src/internal/$randomFormatEmail.ts +11 -11
- package/src/internal/$randomFormatHostname.ts +6 -6
- package/src/internal/$randomFormatIdnEmail.ts +3 -3
- package/src/internal/$randomFormatIdnHostname.ts +3 -3
- package/src/internal/$randomFormatIpv4.ts +11 -11
- package/src/internal/$randomFormatIpv6.ts +11 -11
- package/src/internal/$randomFormatIri.ts +3 -3
- package/src/internal/$randomFormatIriReference.ts +3 -3
- package/src/internal/$randomFormatJsonPointer.ts +7 -7
- package/src/internal/$randomFormatPassword.ts +8 -8
- package/src/internal/$randomFormatRegex.ts +4 -4
- package/src/internal/$randomFormatRelativeJsonPointer.ts +8 -8
- package/src/internal/$randomFormatTime.ts +14 -14
- package/src/internal/$randomFormatUri.ts +3 -3
- package/src/internal/$randomFormatUriReference.ts +3 -3
- package/src/internal/$randomFormatUriTemplate.ts +3 -3
- package/src/internal/$randomFormatUrl.ts +11 -11
- package/src/internal/$randomFormatUuid.ts +6 -6
- package/src/internal/$randomInteger.ts +47 -47
- package/src/internal/$randomNumber.ts +74 -74
- package/src/internal/$randomPattern.ts +10 -10
- package/src/internal/$randomPick.ts +9 -9
- package/src/internal/$randomString.ts +24 -24
- package/src/internal/$throwTypeGuardError.ts +5 -5
- package/src/internal/$validateReport.ts +13 -13
- package/src/internal/private/$__notationCapitalize.ts +2 -2
- package/src/internal/private/$__notationUnsnake.ts +24 -24
- package/src/json.ts +651 -651
- package/src/llm.ts +178 -178
- package/src/misc.ts +658 -658
- package/src/module.ts +933 -933
- package/src/notations.ts +827 -827
- package/src/programmers/CheckerProgrammer.ts +4 -1
- package/src/programmers/FeatureProgrammer.ts +619 -616
- package/src/programmers/RandomProgrammer.ts +24 -16
- package/src/programmers/TypiaProgrammer.ts +4 -1
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +153 -153
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +125 -125
- package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +115 -115
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +119 -119
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +274 -274
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +135 -135
- package/src/programmers/helpers/FunctionProgrammer.ts +67 -67
- package/src/programmers/helpers/RandomJoiner.ts +168 -168
- package/src/programmers/helpers/StringifyJoinder.ts +115 -115
- package/src/programmers/helpers/disable_function_programmer_declare.ts +32 -32
- package/src/programmers/internal/check_dynamic_key.ts +201 -201
- package/src/programmers/internal/check_dynamic_properties.ts +208 -208
- package/src/programmers/internal/check_object.ts +75 -75
- package/src/programmers/internal/feature_object_entries.ts +61 -61
- package/src/programmers/internal/prune_object_properties.ts +71 -63
- package/src/programmers/json/JsonAssertParseProgrammer.ts +14 -11
- package/src/programmers/llm/LlmApplicationProgrammer.ts +235 -235
- package/src/programmers/llm/LlmSchemaProgrammer.ts +51 -51
- package/src/programmers/misc/MiscCloneProgrammer.ts +4 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +4 -1
- package/src/programmers/notations/NotationGeneralProgrammer.ts +4 -1
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -1
- package/src/protobuf.ts +868 -868
- package/src/reflect.ts +57 -57
- package/src/transformers/FileTransformer.ts +0 -6
- package/src/transformers/ImportTransformer.ts +59 -44
- package/src/utils/NamingConvention.ts +94 -94
- package/src/utils/StringUtil.ts +16 -16
- package/lib/internal/$httpFormDataReadArray.js.map +0 -1
- /package/lib/internal/{$httpFormDataReadArray.d.ts → $httpFormdataReadArray.d.ts} +0 -0
package/src/reflect.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { IMetadataApplication } from "./schemas/metadata/IMetadataApplication";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* > You must configure the generic argument `Types`.
|
|
5
|
-
*
|
|
6
|
-
* Metadata Application.
|
|
7
|
-
*
|
|
8
|
-
* Creates a Metadata application which contains the metadata and components.
|
|
9
|
-
*
|
|
10
|
-
* Note that, all of the collection types like Array, Tuple and Objects are
|
|
11
|
-
* stored in the {@link IMetadataApplication.components} property. Also, alias
|
|
12
|
-
* types are stored in the {@link IMetadataApplication.aliases} property, too.
|
|
13
|
-
*
|
|
14
|
-
* @template Types Tuple of target types
|
|
15
|
-
* @returns Metadata application
|
|
16
|
-
*
|
|
17
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
18
|
-
*/
|
|
19
|
-
export function metadata(): never;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Metadata Application.
|
|
23
|
-
*
|
|
24
|
-
* Creates a Metadata application which contains the metadata and components.
|
|
25
|
-
*
|
|
26
|
-
* Note that, all of the collection types like Array, Tuple and Objects are
|
|
27
|
-
* stored in the {@link IMetadataApplication.components} property. Also, alias
|
|
28
|
-
* types are stored in the {@link IMetadataApplication.aliases} property, too.
|
|
29
|
-
*
|
|
30
|
-
* @template Types Tuple of target types
|
|
31
|
-
* @returns Metadata application
|
|
32
|
-
*
|
|
33
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
34
|
-
*/
|
|
35
|
-
export function metadata<Types extends unknown[]>(): IMetadataApplication;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
export function metadata(): never {
|
|
41
|
-
halt("metadata");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function name<T, Regular extends boolean = false>(): string;
|
|
45
|
-
export function name(): never;
|
|
46
|
-
export function name(): never {
|
|
47
|
-
halt("name");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @internal
|
|
52
|
-
*/
|
|
53
|
-
function halt(name: string): never {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Error on typia.reflect.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
1
|
+
import { IMetadataApplication } from "./schemas/metadata/IMetadataApplication";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* > You must configure the generic argument `Types`.
|
|
5
|
+
*
|
|
6
|
+
* Metadata Application.
|
|
7
|
+
*
|
|
8
|
+
* Creates a Metadata application which contains the metadata and components.
|
|
9
|
+
*
|
|
10
|
+
* Note that, all of the collection types like Array, Tuple and Objects are
|
|
11
|
+
* stored in the {@link IMetadataApplication.components} property. Also, alias
|
|
12
|
+
* types are stored in the {@link IMetadataApplication.aliases} property, too.
|
|
13
|
+
*
|
|
14
|
+
* @template Types Tuple of target types
|
|
15
|
+
* @returns Metadata application
|
|
16
|
+
*
|
|
17
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
18
|
+
*/
|
|
19
|
+
export function metadata(): never;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Metadata Application.
|
|
23
|
+
*
|
|
24
|
+
* Creates a Metadata application which contains the metadata and components.
|
|
25
|
+
*
|
|
26
|
+
* Note that, all of the collection types like Array, Tuple and Objects are
|
|
27
|
+
* stored in the {@link IMetadataApplication.components} property. Also, alias
|
|
28
|
+
* types are stored in the {@link IMetadataApplication.aliases} property, too.
|
|
29
|
+
*
|
|
30
|
+
* @template Types Tuple of target types
|
|
31
|
+
* @returns Metadata application
|
|
32
|
+
*
|
|
33
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
34
|
+
*/
|
|
35
|
+
export function metadata<Types extends unknown[]>(): IMetadataApplication;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export function metadata(): never {
|
|
41
|
+
halt("metadata");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function name<T, Regular extends boolean = false>(): string;
|
|
45
|
+
export function name(): never;
|
|
46
|
+
export function name(): never {
|
|
47
|
+
halt("name");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
function halt(name: string): never {
|
|
54
|
+
throw new Error(
|
|
55
|
+
`Error on typia.reflect.${name}(): no transform has been configured. Read and follow https://typia.io/docs/setup please.`,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -41,12 +41,6 @@ export namespace FileTransformer {
|
|
|
41
41
|
file.hasNoDefaultLib,
|
|
42
42
|
file.libReferenceDirectives,
|
|
43
43
|
);
|
|
44
|
-
// return ts.factory.createSourceFile(
|
|
45
|
-
// file.statements,
|
|
46
|
-
// // [...importer.toStatements(), ...file.statements],
|
|
47
|
-
// file.endOfFileToken as any,
|
|
48
|
-
// file.flags,
|
|
49
|
-
// );
|
|
50
44
|
};
|
|
51
45
|
|
|
52
46
|
const iterate_node = (props: {
|
|
@@ -3,60 +3,75 @@ import ts from "typescript";
|
|
|
3
3
|
|
|
4
4
|
export namespace ImportTransformer {
|
|
5
5
|
export const transform =
|
|
6
|
-
(from: string) =>
|
|
7
|
-
(to: string) =>
|
|
6
|
+
(props: { from: string; to: string }) =>
|
|
8
7
|
(context: ts.TransformationContext) =>
|
|
9
8
|
(file: ts.SourceFile) =>
|
|
10
|
-
transform_file(
|
|
9
|
+
transform_file({
|
|
10
|
+
top: props.from,
|
|
11
|
+
to: props.to,
|
|
12
|
+
context,
|
|
13
|
+
file,
|
|
14
|
+
});
|
|
11
15
|
|
|
12
|
-
const transform_file =
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const transform_file = (props: {
|
|
17
|
+
top: string;
|
|
18
|
+
to: string;
|
|
19
|
+
context: ts.TransformationContext;
|
|
20
|
+
file: ts.SourceFile;
|
|
21
|
+
}): ts.SourceFile => {
|
|
22
|
+
if (props.file.isDeclarationFile) return props.file;
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
const from: string = get_directory_path(
|
|
25
|
+
path.resolve(props.file.getSourceFile().fileName),
|
|
26
|
+
);
|
|
27
|
+
const to: string = from.replace(props.top, props.to);
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
return ts.visitEachChild(
|
|
30
|
+
props.file,
|
|
31
|
+
(node) =>
|
|
32
|
+
transform_node({
|
|
33
|
+
top: props.top,
|
|
34
|
+
from,
|
|
35
|
+
to,
|
|
36
|
+
node,
|
|
37
|
+
}),
|
|
38
|
+
props.context,
|
|
39
|
+
);
|
|
40
|
+
};
|
|
30
41
|
|
|
31
|
-
const transform_node =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
const transform_node = (props: {
|
|
43
|
+
top: string;
|
|
44
|
+
from: string;
|
|
45
|
+
to: string;
|
|
46
|
+
node: ts.Node;
|
|
47
|
+
}) => {
|
|
48
|
+
if (
|
|
49
|
+
!ts.isImportDeclaration(props.node) ||
|
|
50
|
+
!ts.isStringLiteral(props.node.moduleSpecifier)
|
|
51
|
+
)
|
|
52
|
+
return props.node;
|
|
38
53
|
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
const text: string = props.node.moduleSpecifier.text;
|
|
55
|
+
if (text[0] !== ".") return props.node;
|
|
41
56
|
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
const location: string = path.resolve(props.from, text);
|
|
58
|
+
if (location.indexOf(props.top) === 0) return props.node;
|
|
44
59
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
const replaced: string = (() => {
|
|
61
|
+
const simple: string = path
|
|
62
|
+
.relative(props.to, location)
|
|
63
|
+
.split(path.sep)
|
|
64
|
+
.join("/");
|
|
65
|
+
return simple[0] === "." ? simple : `./${simple}`;
|
|
66
|
+
})();
|
|
52
67
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
return ts.factory.createImportDeclaration(
|
|
69
|
+
undefined,
|
|
70
|
+
props.node.importClause,
|
|
71
|
+
ts.factory.createStringLiteral(replaced),
|
|
72
|
+
props.node.assertClause,
|
|
73
|
+
);
|
|
74
|
+
};
|
|
60
75
|
}
|
|
61
76
|
|
|
62
77
|
const get_directory_path = (file: string): string => {
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import { StringUtil } from "./StringUtil";
|
|
2
|
-
|
|
3
|
-
export namespace NamingConvention {
|
|
4
|
-
const unsnake =
|
|
5
|
-
(props: {
|
|
6
|
-
plain: (str: string) => string;
|
|
7
|
-
snake: (str: string, index: number) => string;
|
|
8
|
-
}) =>
|
|
9
|
-
(str: string): string => {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
-
let prefix: string = "";
|
|
12
|
-
for (let i: number = 0; i < str.length; i++) {
|
|
13
|
-
if (str[i] === "_") prefix += "_";
|
|
14
|
-
else break;
|
|
15
|
-
}
|
|
16
|
-
if (prefix.length !== 0) str = str.substring(prefix.length);
|
|
17
|
-
|
|
18
|
-
const out = (s: string) => `${prefix}${s}`;
|
|
19
|
-
if (str.length === 0) return out("");
|
|
20
|
-
|
|
21
|
-
const items: string[] = str.split("_").filter((s) => s.length !== 0);
|
|
22
|
-
return items.length === 0
|
|
23
|
-
? out("")
|
|
24
|
-
: items.length === 1
|
|
25
|
-
? out(props.plain(items[0]!))
|
|
26
|
-
: out(items.map(props.snake).join(""));
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export function snake(str: string): string {
|
|
30
|
-
if (str.length === 0) return str;
|
|
31
|
-
|
|
32
|
-
// PREFIX
|
|
33
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
-
let prefix: string = "";
|
|
35
|
-
for (let i: number = 0; i < str.length; i++) {
|
|
36
|
-
if (str[i] === "_") prefix += "_";
|
|
37
|
-
else break;
|
|
38
|
-
}
|
|
39
|
-
if (prefix.length !== 0) str = str.substring(prefix.length);
|
|
40
|
-
|
|
41
|
-
const out = (s: string) => `${prefix}${s}`;
|
|
42
|
-
|
|
43
|
-
// SNAKE CASE
|
|
44
|
-
const items: string[] = str.split("_");
|
|
45
|
-
if (items.length > 1)
|
|
46
|
-
return out(items.map((s) => s.toLowerCase()).join("_"));
|
|
47
|
-
|
|
48
|
-
// CAMEL OR PASCAL CASE
|
|
49
|
-
const indexes: number[] = [];
|
|
50
|
-
for (let i: number = 0; i < str.length; i++) {
|
|
51
|
-
const code: number = str.charCodeAt(i);
|
|
52
|
-
if (65 <= code && code <= 90) indexes.push(i);
|
|
53
|
-
}
|
|
54
|
-
for (let i: number = indexes.length - 1; i > 0; --i) {
|
|
55
|
-
const now: number = indexes[i]!;
|
|
56
|
-
const prev: number = indexes[i - 1]!;
|
|
57
|
-
if (now - prev === 1) indexes.splice(i, 1);
|
|
58
|
-
}
|
|
59
|
-
if (indexes.length !== 0 && indexes[0] === 0) indexes.splice(0, 1);
|
|
60
|
-
if (indexes.length === 0) return str.toLowerCase();
|
|
61
|
-
|
|
62
|
-
let ret: string = "";
|
|
63
|
-
for (let i: number = 0; i < indexes.length; i++) {
|
|
64
|
-
const first: number = i === 0 ? 0 : indexes[i - 1]!;
|
|
65
|
-
const last: number = indexes[i]!;
|
|
66
|
-
|
|
67
|
-
ret += str.substring(first, last).toLowerCase();
|
|
68
|
-
ret += "_";
|
|
69
|
-
}
|
|
70
|
-
ret += str.substring(indexes[indexes.length - 1]!).toLowerCase();
|
|
71
|
-
return out(ret);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function camel(str: string) {
|
|
75
|
-
return unsnake({
|
|
76
|
-
plain: (str) =>
|
|
77
|
-
str.length
|
|
78
|
-
? str === str.toUpperCase()
|
|
79
|
-
? str.toLocaleLowerCase()
|
|
80
|
-
: `${str[0]!.toLowerCase()}${str.substring(1)}`
|
|
81
|
-
: str,
|
|
82
|
-
snake: (str, i) =>
|
|
83
|
-
i === 0 ? str.toLowerCase() : StringUtil.capitalize(str.toLowerCase()),
|
|
84
|
-
})(str);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function pascal(str: string) {
|
|
88
|
-
return unsnake({
|
|
89
|
-
plain: (str) =>
|
|
90
|
-
str.length ? `${str[0]!.toUpperCase()}${str.substring(1)}` : str,
|
|
91
|
-
snake: StringUtil.capitalize,
|
|
92
|
-
})(str);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
import { StringUtil } from "./StringUtil";
|
|
2
|
+
|
|
3
|
+
export namespace NamingConvention {
|
|
4
|
+
const unsnake =
|
|
5
|
+
(props: {
|
|
6
|
+
plain: (str: string) => string;
|
|
7
|
+
snake: (str: string, index: number) => string;
|
|
8
|
+
}) =>
|
|
9
|
+
(str: string): string => {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
let prefix: string = "";
|
|
12
|
+
for (let i: number = 0; i < str.length; i++) {
|
|
13
|
+
if (str[i] === "_") prefix += "_";
|
|
14
|
+
else break;
|
|
15
|
+
}
|
|
16
|
+
if (prefix.length !== 0) str = str.substring(prefix.length);
|
|
17
|
+
|
|
18
|
+
const out = (s: string) => `${prefix}${s}`;
|
|
19
|
+
if (str.length === 0) return out("");
|
|
20
|
+
|
|
21
|
+
const items: string[] = str.split("_").filter((s) => s.length !== 0);
|
|
22
|
+
return items.length === 0
|
|
23
|
+
? out("")
|
|
24
|
+
: items.length === 1
|
|
25
|
+
? out(props.plain(items[0]!))
|
|
26
|
+
: out(items.map(props.snake).join(""));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function snake(str: string): string {
|
|
30
|
+
if (str.length === 0) return str;
|
|
31
|
+
|
|
32
|
+
// PREFIX
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
34
|
+
let prefix: string = "";
|
|
35
|
+
for (let i: number = 0; i < str.length; i++) {
|
|
36
|
+
if (str[i] === "_") prefix += "_";
|
|
37
|
+
else break;
|
|
38
|
+
}
|
|
39
|
+
if (prefix.length !== 0) str = str.substring(prefix.length);
|
|
40
|
+
|
|
41
|
+
const out = (s: string) => `${prefix}${s}`;
|
|
42
|
+
|
|
43
|
+
// SNAKE CASE
|
|
44
|
+
const items: string[] = str.split("_");
|
|
45
|
+
if (items.length > 1)
|
|
46
|
+
return out(items.map((s) => s.toLowerCase()).join("_"));
|
|
47
|
+
|
|
48
|
+
// CAMEL OR PASCAL CASE
|
|
49
|
+
const indexes: number[] = [];
|
|
50
|
+
for (let i: number = 0; i < str.length; i++) {
|
|
51
|
+
const code: number = str.charCodeAt(i);
|
|
52
|
+
if (65 <= code && code <= 90) indexes.push(i);
|
|
53
|
+
}
|
|
54
|
+
for (let i: number = indexes.length - 1; i > 0; --i) {
|
|
55
|
+
const now: number = indexes[i]!;
|
|
56
|
+
const prev: number = indexes[i - 1]!;
|
|
57
|
+
if (now - prev === 1) indexes.splice(i, 1);
|
|
58
|
+
}
|
|
59
|
+
if (indexes.length !== 0 && indexes[0] === 0) indexes.splice(0, 1);
|
|
60
|
+
if (indexes.length === 0) return str.toLowerCase();
|
|
61
|
+
|
|
62
|
+
let ret: string = "";
|
|
63
|
+
for (let i: number = 0; i < indexes.length; i++) {
|
|
64
|
+
const first: number = i === 0 ? 0 : indexes[i - 1]!;
|
|
65
|
+
const last: number = indexes[i]!;
|
|
66
|
+
|
|
67
|
+
ret += str.substring(first, last).toLowerCase();
|
|
68
|
+
ret += "_";
|
|
69
|
+
}
|
|
70
|
+
ret += str.substring(indexes[indexes.length - 1]!).toLowerCase();
|
|
71
|
+
return out(ret);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function camel(str: string) {
|
|
75
|
+
return unsnake({
|
|
76
|
+
plain: (str) =>
|
|
77
|
+
str.length
|
|
78
|
+
? str === str.toUpperCase()
|
|
79
|
+
? str.toLocaleLowerCase()
|
|
80
|
+
: `${str[0]!.toLowerCase()}${str.substring(1)}`
|
|
81
|
+
: str,
|
|
82
|
+
snake: (str, i) =>
|
|
83
|
+
i === 0 ? str.toLowerCase() : StringUtil.capitalize(str.toLowerCase()),
|
|
84
|
+
})(str);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function pascal(str: string) {
|
|
88
|
+
return unsnake({
|
|
89
|
+
plain: (str) =>
|
|
90
|
+
str.length ? `${str[0]!.toUpperCase()}${str.substring(1)}` : str,
|
|
91
|
+
snake: StringUtil.capitalize,
|
|
92
|
+
})(str);
|
|
93
|
+
}
|
|
94
|
+
}
|
package/src/utils/StringUtil.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export namespace StringUtil {
|
|
2
|
-
export const capitalize = (str: string) =>
|
|
3
|
-
str.length ? str[0]!.toUpperCase() + str.slice(1).toLowerCase() : str;
|
|
4
|
-
|
|
5
|
-
export const escapeDuplicate = (props: {
|
|
6
|
-
keep: string[];
|
|
7
|
-
input: string;
|
|
8
|
-
escape?: (str: string) => string;
|
|
9
|
-
}): string =>
|
|
10
|
-
props.keep.includes(props.input)
|
|
11
|
-
? escapeDuplicate({
|
|
12
|
-
keep: props.keep,
|
|
13
|
-
input: (props.escape ?? ((str) => `_${str}`))(props.input),
|
|
14
|
-
})
|
|
15
|
-
: props.input;
|
|
16
|
-
}
|
|
1
|
+
export namespace StringUtil {
|
|
2
|
+
export const capitalize = (str: string) =>
|
|
3
|
+
str.length ? str[0]!.toUpperCase() + str.slice(1).toLowerCase() : str;
|
|
4
|
+
|
|
5
|
+
export const escapeDuplicate = (props: {
|
|
6
|
+
keep: string[];
|
|
7
|
+
input: string;
|
|
8
|
+
escape?: (str: string) => string;
|
|
9
|
+
}): string =>
|
|
10
|
+
props.keep.includes(props.input)
|
|
11
|
+
? escapeDuplicate({
|
|
12
|
+
keep: props.keep,
|
|
13
|
+
input: (props.escape ?? ((str) => `_${str}`))(props.input),
|
|
14
|
+
})
|
|
15
|
+
: props.input;
|
|
16
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"$httpFormDataReadArray.js","sourceRoot":"","sources":["../../src/internal/$httpFormDataReadArray.ts"],"names":[],"mappings":";;;AAAO,IAAM,sBAAsB,GAAG,UACpC,KAAY,EACZ,WAA6B,IAC1B,OAAA,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,EAApC,CAAoC,CAAC;AAH7B,QAAA,sBAAsB,0BAGO"}
|
|
File without changes
|