typia 5.2.0-dev.20231007 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/lib/CamelCase.d.ts +10 -0
  2. package/lib/PascalCase.d.ts +10 -0
  3. package/lib/Primitive.d.ts +1 -1
  4. package/lib/Resolved.d.ts +1 -1
  5. package/lib/SnakeCase.d.ts +10 -0
  6. package/package.json +1 -1
  7. package/src/CamelCase.ts +116 -116
  8. package/src/PascalCase.ts +116 -106
  9. package/src/Primitive.ts +135 -135
  10. package/src/Resolved.ts +116 -116
  11. package/src/SnakeCase.ts +156 -156
  12. package/src/functional/$convention.ts +40 -40
  13. package/src/functional/Namespace.ts +164 -164
  14. package/src/module.ts +662 -662
  15. package/src/notations.ts +855 -855
  16. package/src/programmers/helpers/NotationJoiner.ts +146 -146
  17. package/src/programmers/misc/MiscCloneProgrammer.ts +790 -790
  18. package/src/programmers/misc/MiscPruneProgrammer.ts +552 -552
  19. package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +72 -72
  20. package/src/programmers/notations/NotationGeneralProgrammer.ts +720 -720
  21. package/src/programmers/notations/NotationIsGeneralProgrammer.ts +79 -79
  22. package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +88 -88
  23. package/src/transformers/CallExpressionTransformer.ts +380 -380
  24. package/src/transformers/features/json/JsonAssertParseTransformer.ts +10 -10
  25. package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
  26. package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +12 -12
  27. package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
  28. package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
  29. package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +12 -12
  30. package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
  31. package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +12 -12
  32. package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
  33. package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
  34. package/src/transformers/features/json/JsonIsStringifyTransformer.ts +10 -10
  35. package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
  36. package/src/transformers/features/json/JsonValidateParseTransformer.ts +10 -10
  37. package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
  38. package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +10 -10
  39. package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +10 -10
  40. package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
  41. package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +12 -12
  42. package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +12 -12
  43. package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
  44. package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
  45. package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
  46. package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
  47. package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +12 -12
  48. package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +12 -12
  49. package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
  50. package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
  51. package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
  52. package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +10 -10
  53. package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +10 -10
  54. package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +15 -15
  55. package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +15 -15
  56. package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +15 -15
  57. package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +15 -15
  58. package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +17 -17
  59. package/src/transformers/features/notations/NotationGeneralTransformer.ts +11 -11
  60. package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +15 -15
  61. package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +17 -17
  62. package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +12 -12
  63. package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +12 -12
  64. package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +9 -9
  65. package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +9 -9
  66. package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +12 -12
  67. package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +12 -12
  68. package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +12 -12
  69. package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +12 -12
  70. package/src/utils/NamingConvention.ts +91 -91
  71. package/src/utils/StringUtil.ts +4 -4
package/src/SnakeCase.ts CHANGED
@@ -1,156 +1,156 @@
1
- /**
2
- * Snake case type.
3
- *
4
- * `SnakeCase` type is a type that all keys of an object are converted to snake case.
5
- *
6
- * It also erase every method properties like {@link Resolved} type.
7
- *
8
- * @template T Target type to be snake cased
9
- * @author Jeongho Nam - https://github.com/samchon
10
- */
11
- export type SnakeCase<T> = Equal<T, SnakageMain<T>> extends true
12
- ? T
13
- : SnakageMain<T>;
14
-
15
- /* -----------------------------------------------------------
16
- OBJECT CONVERSION
17
- ----------------------------------------------------------- */
18
- type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
19
-
20
- type SnakageMain<T> = T extends [never]
21
- ? never // special trick for (jsonable | null) type
22
- : T extends { valueOf(): boolean | bigint | number | string }
23
- ? ValueOf<T>
24
- : T extends Function
25
- ? never
26
- : T extends object
27
- ? SnakageObject<T>
28
- : T;
29
-
30
- type SnakageObject<T extends object> = T extends Array<infer U>
31
- ? IsTuple<T> extends true
32
- ? SnakageTuple<T>
33
- : SnakageMain<U>[]
34
- : T extends Set<infer U>
35
- ? Set<SnakageMain<U>>
36
- : T extends Map<infer K, infer V>
37
- ? Map<SnakageMain<K>, SnakageMain<V>>
38
- : T extends WeakSet<any> | WeakMap<any, any>
39
- ? never
40
- : T extends
41
- | Date
42
- | Uint8Array
43
- | Uint8ClampedArray
44
- | Uint16Array
45
- | Uint32Array
46
- | BigUint64Array
47
- | Int8Array
48
- | Int16Array
49
- | Int32Array
50
- | BigInt64Array
51
- | Float32Array
52
- | Float64Array
53
- | ArrayBuffer
54
- | SharedArrayBuffer
55
- | DataView
56
- ? T
57
- : {
58
- [Key in keyof T as SnakageString<Key & string>]: SnakageMain<T[Key]>;
59
- };
60
-
61
- /* -----------------------------------------------------------
62
- SPECIAL CASES
63
- ----------------------------------------------------------- */
64
- type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
65
- never,
66
- ]
67
- ? false
68
- : T extends readonly any[]
69
- ? number extends T["length"]
70
- ? false
71
- : true
72
- : false;
73
- type SnakageTuple<T extends readonly any[]> = T extends []
74
- ? []
75
- : T extends [infer F]
76
- ? [SnakageMain<F>]
77
- : T extends [infer F, ...infer Rest extends readonly any[]]
78
- ? [SnakageMain<F>, ...SnakageTuple<Rest>]
79
- : T extends [(infer F)?]
80
- ? [SnakageMain<F>?]
81
- : T extends [(infer F)?, ...infer Rest extends readonly any[]]
82
- ? [SnakageMain<F>?, ...SnakageTuple<Rest>]
83
- : [];
84
-
85
- type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true
86
- ? boolean
87
- : IsValueOf<Instance, Number> extends true
88
- ? number
89
- : IsValueOf<Instance, String> extends true
90
- ? string
91
- : Instance;
92
-
93
- type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
94
- ? Object extends IValueOf<infer Primitive>
95
- ? Instance extends Primitive
96
- ? false
97
- : true // not Primitive, but Object
98
- : false // cannot be
99
- : false;
100
-
101
- interface IValueOf<T> {
102
- valueOf(): T;
103
- }
104
-
105
- /* -----------------------------------------------------------
106
- STRING CONVERTER
107
- ----------------------------------------------------------- */
108
- type SnakageString<Key extends string> = Key extends `${infer _}`
109
- ? SnakageStringRepeatedly<Key, "">
110
- : Key;
111
- type SnakageStringRepeatedly<
112
- S extends string,
113
- Previous extends string,
114
- > = S extends `${infer First}${infer Second}${infer Rest}`
115
- ? `${Underscore<Previous, First>}${Lowercase<First>}${Underscore<
116
- First,
117
- Second
118
- >}${Lowercase<Second>}${SnakageStringRepeatedly<Rest, Second>}`
119
- : S extends `${infer First}`
120
- ? `${Underscore<Previous, First>}${Lowercase<First>}`
121
- : "";
122
- type Underscore<First extends string, Second extends string> = First extends
123
- | UpperAlphabetic
124
- | ""
125
- | "_"
126
- ? ""
127
- : Second extends UpperAlphabetic
128
- ? "_"
129
- : "";
130
- type UpperAlphabetic =
131
- | "A"
132
- | "B"
133
- | "C"
134
- | "D"
135
- | "E"
136
- | "F"
137
- | "G"
138
- | "H"
139
- | "I"
140
- | "J"
141
- | "K"
142
- | "L"
143
- | "M"
144
- | "N"
145
- | "O"
146
- | "P"
147
- | "Q"
148
- | "R"
149
- | "S"
150
- | "T"
151
- | "U"
152
- | "V"
153
- | "W"
154
- | "X"
155
- | "Y"
156
- | "Z";
1
+ /**
2
+ * Snake case type.
3
+ *
4
+ * `SnakeCase` type is a type that all keys of an object are converted to snake case.
5
+ *
6
+ * It also erase every method properties like {@link Resolved} type.
7
+ *
8
+ * @template T Target type to be snake cased
9
+ * @author Jeongho Nam - https://github.com/samchon
10
+ */
11
+ export type SnakeCase<T> = Equal<T, SnakageMain<T>> extends true
12
+ ? T
13
+ : SnakageMain<T>;
14
+
15
+ /* -----------------------------------------------------------
16
+ OBJECT CONVERSION
17
+ ----------------------------------------------------------- */
18
+ type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
19
+
20
+ type SnakageMain<T> = T extends [never]
21
+ ? never // special trick for (jsonable | null) type
22
+ : T extends { valueOf(): boolean | bigint | number | string }
23
+ ? ValueOf<T>
24
+ : T extends Function
25
+ ? never
26
+ : T extends object
27
+ ? SnakageObject<T>
28
+ : T;
29
+
30
+ type SnakageObject<T extends object> = T extends Array<infer U>
31
+ ? IsTuple<T> extends true
32
+ ? SnakageTuple<T>
33
+ : SnakageMain<U>[]
34
+ : T extends Set<infer U>
35
+ ? Set<SnakageMain<U>>
36
+ : T extends Map<infer K, infer V>
37
+ ? Map<SnakageMain<K>, SnakageMain<V>>
38
+ : T extends WeakSet<any> | WeakMap<any, any>
39
+ ? never
40
+ : T extends
41
+ | Date
42
+ | Uint8Array
43
+ | Uint8ClampedArray
44
+ | Uint16Array
45
+ | Uint32Array
46
+ | BigUint64Array
47
+ | Int8Array
48
+ | Int16Array
49
+ | Int32Array
50
+ | BigInt64Array
51
+ | Float32Array
52
+ | Float64Array
53
+ | ArrayBuffer
54
+ | SharedArrayBuffer
55
+ | DataView
56
+ ? T
57
+ : {
58
+ [Key in keyof T as SnakageString<Key & string>]: SnakageMain<T[Key]>;
59
+ };
60
+
61
+ /* -----------------------------------------------------------
62
+ SPECIAL CASES
63
+ ----------------------------------------------------------- */
64
+ type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
65
+ never,
66
+ ]
67
+ ? false
68
+ : T extends readonly any[]
69
+ ? number extends T["length"]
70
+ ? false
71
+ : true
72
+ : false;
73
+ type SnakageTuple<T extends readonly any[]> = T extends []
74
+ ? []
75
+ : T extends [infer F]
76
+ ? [SnakageMain<F>]
77
+ : T extends [infer F, ...infer Rest extends readonly any[]]
78
+ ? [SnakageMain<F>, ...SnakageTuple<Rest>]
79
+ : T extends [(infer F)?]
80
+ ? [SnakageMain<F>?]
81
+ : T extends [(infer F)?, ...infer Rest extends readonly any[]]
82
+ ? [SnakageMain<F>?, ...SnakageTuple<Rest>]
83
+ : [];
84
+
85
+ type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true
86
+ ? boolean
87
+ : IsValueOf<Instance, Number> extends true
88
+ ? number
89
+ : IsValueOf<Instance, String> extends true
90
+ ? string
91
+ : Instance;
92
+
93
+ type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
94
+ ? Object extends IValueOf<infer Primitive>
95
+ ? Instance extends Primitive
96
+ ? false
97
+ : true // not Primitive, but Object
98
+ : false // cannot be
99
+ : false;
100
+
101
+ interface IValueOf<T> {
102
+ valueOf(): T;
103
+ }
104
+
105
+ /* -----------------------------------------------------------
106
+ STRING CONVERTER
107
+ ----------------------------------------------------------- */
108
+ type SnakageString<Key extends string> = Key extends `${infer _}`
109
+ ? SnakageStringRepeatedly<Key, "">
110
+ : Key;
111
+ type SnakageStringRepeatedly<
112
+ S extends string,
113
+ Previous extends string,
114
+ > = S extends `${infer First}${infer Second}${infer Rest}`
115
+ ? `${Underscore<Previous, First>}${Lowercase<First>}${Underscore<
116
+ First,
117
+ Second
118
+ >}${Lowercase<Second>}${SnakageStringRepeatedly<Rest, Second>}`
119
+ : S extends `${infer First}`
120
+ ? `${Underscore<Previous, First>}${Lowercase<First>}`
121
+ : "";
122
+ type Underscore<First extends string, Second extends string> = First extends
123
+ | UpperAlphabetic
124
+ | ""
125
+ | "_"
126
+ ? ""
127
+ : Second extends UpperAlphabetic
128
+ ? "_"
129
+ : "";
130
+ type UpperAlphabetic =
131
+ | "A"
132
+ | "B"
133
+ | "C"
134
+ | "D"
135
+ | "E"
136
+ | "F"
137
+ | "G"
138
+ | "H"
139
+ | "I"
140
+ | "J"
141
+ | "K"
142
+ | "L"
143
+ | "M"
144
+ | "N"
145
+ | "O"
146
+ | "P"
147
+ | "Q"
148
+ | "R"
149
+ | "S"
150
+ | "T"
151
+ | "U"
152
+ | "V"
153
+ | "W"
154
+ | "X"
155
+ | "Y"
156
+ | "Z";
@@ -1,40 +1,40 @@
1
- export const $convention = (rename: (str: string) => string) => {
2
- const main = (input: any): any => {
3
- if (typeof input === "object")
4
- if (input === null) return null;
5
- else if (Array.isArray(input)) return input.map(main);
6
- else if (
7
- input instanceof Boolean ||
8
- input instanceof BigInt ||
9
- input instanceof Number ||
10
- input instanceof String
11
- )
12
- return input.valueOf();
13
- else if (input instanceof Date) return new Date(input);
14
- else if (
15
- input instanceof Uint8Array ||
16
- input instanceof Uint8ClampedArray ||
17
- input instanceof Uint16Array ||
18
- input instanceof Uint32Array ||
19
- input instanceof BigUint64Array ||
20
- input instanceof Int8Array ||
21
- input instanceof Int16Array ||
22
- input instanceof Int32Array ||
23
- input instanceof BigInt64Array ||
24
- input instanceof Float32Array ||
25
- input instanceof Float64Array ||
26
- input instanceof DataView
27
- )
28
- return input;
29
- else return object(input);
30
- return input;
31
- };
32
- const object = (input: Record<string, any>) =>
33
- Object.fromEntries(
34
- Object.entries(input).map(([key, value]) => [
35
- rename(key),
36
- main(value),
37
- ]),
38
- );
39
- return main;
40
- };
1
+ export const $convention = (rename: (str: string) => string) => {
2
+ const main = (input: any): any => {
3
+ if (typeof input === "object")
4
+ if (input === null) return null;
5
+ else if (Array.isArray(input)) return input.map(main);
6
+ else if (
7
+ input instanceof Boolean ||
8
+ input instanceof BigInt ||
9
+ input instanceof Number ||
10
+ input instanceof String
11
+ )
12
+ return input.valueOf();
13
+ else if (input instanceof Date) return new Date(input);
14
+ else if (
15
+ input instanceof Uint8Array ||
16
+ input instanceof Uint8ClampedArray ||
17
+ input instanceof Uint16Array ||
18
+ input instanceof Uint32Array ||
19
+ input instanceof BigUint64Array ||
20
+ input instanceof Int8Array ||
21
+ input instanceof Int16Array ||
22
+ input instanceof Int32Array ||
23
+ input instanceof BigInt64Array ||
24
+ input instanceof Float32Array ||
25
+ input instanceof Float64Array ||
26
+ input instanceof DataView
27
+ )
28
+ return input;
29
+ else return object(input);
30
+ return input;
31
+ };
32
+ const object = (input: Record<string, any>) =>
33
+ Object.fromEntries(
34
+ Object.entries(input).map(([key, value]) => [
35
+ rename(key),
36
+ main(value),
37
+ ]),
38
+ );
39
+ return main;
40
+ };