ts-type 3.0.2 → 3.0.3
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/CHANGELOG.md +15 -0
- package/lib/helper/conditional.d.ts +34 -0
- package/lib/helper/conditional.js +10 -0
- package/lib/helper/conditional.js.map +1 -0
- package/lib/helper/deep-map.d.ts +56 -0
- package/lib/helper/deep-map.js +10 -0
- package/lib/helper/deep-map.js.map +1 -0
- package/lib/helper/string/operations.d.ts +123 -0
- package/lib/helper/string/operations.js +10 -0
- package/lib/helper/string/operations.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.3](https://github.com/bluelovers/ws-ts-type/compare/ts-type@3.0.2...ts-type@3.0.3) (2026-03-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### ✨ Features
|
|
11
|
+
|
|
12
|
+
* **ts-type:** 新增輔助類型工具 ([7a670c2](https://github.com/bluelovers/ws-ts-type/commit/7a670c236c77f8a6694299e80d5f742f13a1661f))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### 🛠 Build System
|
|
16
|
+
|
|
17
|
+
* **release:** publish ([d12a117](https://github.com/bluelovers/ws-ts-type/commit/d12a117d467df70f1f78f028a1371cee57124ca6))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
6
21
|
## [3.0.2](https://github.com/bluelovers/ws-ts-type/compare/ts-type@3.0.1...ts-type@3.0.2) (2026-03-07)
|
|
7
22
|
|
|
8
23
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 條件類型工具
|
|
3
|
+
* Conditional Type Utilities
|
|
4
|
+
*
|
|
5
|
+
* 提供基於條件的類型選擇工具
|
|
6
|
+
* Provides conditional-based type selection utilities
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 條件類型:根據條件 C 選擇 T 或 U
|
|
10
|
+
* Conditional type: select T or U based on condition C
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* type IsString<T> = T extends string ? true : false;
|
|
14
|
+
* type Result = ITSIf<IsString<T>, 'is string', 'not string'>;
|
|
15
|
+
*/
|
|
16
|
+
export type ITSHelperIf<C extends boolean, T, U> = C extends true ? T : U;
|
|
17
|
+
/**
|
|
18
|
+
* 條件類型:根據類型匹配選擇 T 或 U
|
|
19
|
+
* Conditional type: select T or U based on type match
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* type Result = ITSIfExtends<string, 'text', 'other'>; // 'text'
|
|
23
|
+
* type Result2 = ITSIfExtends<number, 'text', 'other'>; // 'other'
|
|
24
|
+
*/
|
|
25
|
+
export type ITSHelperIfExtends<T, U, IfTrue, IfFalse> = T extends U ? IfTrue : IfFalse;
|
|
26
|
+
/**
|
|
27
|
+
* 條件類型:根據類型相等選擇 T 或 U
|
|
28
|
+
* Conditional type: select T or U based on type equality
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* type Result = ITSIfEquals<string, string, 'same', 'different'>; // 'same'
|
|
32
|
+
* type Result2 = ITSIfEquals<string, number, 'same', 'different'>; // 'different'
|
|
33
|
+
*/
|
|
34
|
+
export type ITSHelperIfEquals<T, U, IfTrue, IfFalse> = T extends U ? U extends T ? IfTrue : IfFalse : IfFalse;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional.js","sourceRoot":"","sources":["conditional.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 條件類型工具\n * Conditional Type Utilities\n * \n * 提供基於條件的類型選擇工具\n * Provides conditional-based type selection utilities\n */\n\n/**\n * 條件類型:根據條件 C 選擇 T 或 U\n * Conditional type: select T or U based on condition C\n * \n * @example\n * type IsString<T> = T extends string ? true : false;\n * type Result = ITSIf<IsString<T>, 'is string', 'not string'>;\n */\nexport type ITSHelperIf<C extends boolean, T, U> = C extends true ? T : U;\n\n/**\n * 條件類型:根據類型匹配選擇 T 或 U\n * Conditional type: select T or U based on type match\n * \n * @example\n * type Result = ITSIfExtends<string, 'text', 'other'>; // 'text'\n * type Result2 = ITSIfExtends<number, 'text', 'other'>; // 'other'\n */\nexport type ITSHelperIfExtends<T, U, IfTrue, IfFalse> = T extends U ? IfTrue : IfFalse;\n\n/**\n * 條件類型:根據類型相等選擇 T 或 U\n * Conditional type: select T or U based on type equality\n * \n * @example\n * type Result = ITSIfEquals<string, string, 'same', 'different'>; // 'same'\n * type Result2 = ITSIfEquals<string, number, 'same', 'different'>; // 'different'\n */\nexport type ITSHelperIfEquals<T, U, IfTrue, IfFalse> = T extends U \n ? U extends T \n ? IfTrue \n : IfFalse \n : IfFalse;\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 深層映射工具
|
|
3
|
+
* Deep Mapping Utilities
|
|
4
|
+
*
|
|
5
|
+
* 提供對物件進行深層類型轉換的工具
|
|
6
|
+
* Provides utilities for deep type transformation of objects
|
|
7
|
+
*/
|
|
8
|
+
import { ITSArrayListMaybeReadonly } from '../type/base';
|
|
9
|
+
/**
|
|
10
|
+
* 深層映射:對物件的所有屬性應用轉換 - 無法實現
|
|
11
|
+
* Deep mapping: apply transformation to all properties of an object
|
|
12
|
+
*
|
|
13
|
+
* TypeScript 無法在類型層級將函數作為泛型參數傳遞
|
|
14
|
+
* TypeScript cannot pass functions as generic parameters at type level
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* interface User { name: string; profile: { age: number; } }
|
|
18
|
+
* type ReadonlyUser = ITSDeepMap<User, readonly>;
|
|
19
|
+
* // { readonly name: string; readonly profile: { readonly age: number; } }
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* 深層映射:對物件的所有屬性應用轉換(包含陣列)- 無法實現
|
|
23
|
+
* Deep mapping: apply transformation to all properties of an object (including arrays)
|
|
24
|
+
*
|
|
25
|
+
* TypeScript 無法在類型層級將函數作為泛型參數傳遞
|
|
26
|
+
* TypeScript cannot pass functions as generic parameters at type level
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* interface Data { items: string[]; nested: { values: number[]; } }
|
|
30
|
+
* type ReadonlyData = ITSDeepMapWithArrays<Data, readonly>;
|
|
31
|
+
* // { readonly items: readonly string[]; readonly nested: { readonly values: readonly number[]; } }
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* 深層部分映射:對物件的所有屬性應用 Partial
|
|
35
|
+
* Deep partial mapping: apply Partial to all properties of an object
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* interface User { name: string; profile: { age: number; } }
|
|
39
|
+
* type PartialUser = ITSDeepPartial<User>;
|
|
40
|
+
* // { name?: string; profile?: { age?: number; } }
|
|
41
|
+
*/
|
|
42
|
+
export type ITSDeepPartial<T> = T extends object ? T extends ITSArrayListMaybeReadonly<any> ? T : {
|
|
43
|
+
[K in keyof T]?: ITSDeepPartial<T[K]>;
|
|
44
|
+
} : T;
|
|
45
|
+
/**
|
|
46
|
+
* 深層必填映射:對物件的所有屬性應用 Required
|
|
47
|
+
* Deep required mapping: apply Required to all properties of an object
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* interface User { name?: string; profile?: { age?: number; } }
|
|
51
|
+
* type RequiredUser = ITSDeepRequired<User>;
|
|
52
|
+
* // { name: string; profile: { age: number; } }
|
|
53
|
+
*/
|
|
54
|
+
export type ITSDeepRequired<T> = T extends object ? T extends ITSArrayListMaybeReadonly<any> ? T : {
|
|
55
|
+
[K in keyof T]-?: ITSDeepRequired<T[K]>;
|
|
56
|
+
} : T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-map.js","sourceRoot":"","sources":["deep-map.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 深層映射工具\n * Deep Mapping Utilities\n * \n * 提供對物件進行深層類型轉換的工具\n * Provides utilities for deep type transformation of objects\n */\n\nimport { ITSArrayListMaybeReadonly } from '../type/base';\n\n/**\n * 深層映射:對物件的所有屬性應用轉換 - 無法實現\n * Deep mapping: apply transformation to all properties of an object\n * \n * TypeScript 無法在類型層級將函數作為泛型參數傳遞\n * TypeScript cannot pass functions as generic parameters at type level\n * \n * @example\n * interface User { name: string; profile: { age: number; } }\n * type ReadonlyUser = ITSDeepMap<User, readonly>;\n * // { readonly name: string; readonly profile: { readonly age: number; } }\n */\n// export type ITSDeepMap<T, F> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSDeepMap<T, F> = T extends object \n// \t? T extends ITSArrayListMaybeReadonly<any>\n// \t\t? T\n// \t\t: {\n// \t\t\t[K in keyof T]: ITSDeepMap<T[K], F>;\n// \t\t }\n// \t: T;\n\n/**\n * 深層映射:對物件的所有屬性應用轉換(包含陣列)- 無法實現\n * Deep mapping: apply transformation to all properties of an object (including arrays)\n * \n * TypeScript 無法在類型層級將函數作為泛型參數傳遞\n * TypeScript cannot pass functions as generic parameters at type level\n * \n * @example\n * interface Data { items: string[]; nested: { values: number[]; } }\n * type ReadonlyData = ITSDeepMapWithArrays<Data, readonly>;\n * // { readonly items: readonly string[]; readonly nested: { readonly values: readonly number[]; } }\n */\n// export type ITSDeepMapWithArrays<T, F> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSDeepMapWithArrays<T, F extends (x: any) => any> = T extends object \n// \t? T extends ITSArrayListMaybeReadonly<any>\n// \t\t? F<T>\n// \t\t: {\n// \t\t\t[K in keyof T]: ITSDeepMapWithArrays<T[K], F>;\n// \t\t }\n// \t: T;\n\n/**\n * 深層部分映射:對物件的所有屬性應用 Partial\n * Deep partial mapping: apply Partial to all properties of an object\n * \n * @example\n * interface User { name: string; profile: { age: number; } }\n * type PartialUser = ITSDeepPartial<User>;\n * // { name?: string; profile?: { age?: number; } }\n */\nexport type ITSDeepPartial<T> = T extends object \n ? T extends ITSArrayListMaybeReadonly<any>\n ? T\n : {\n [K in keyof T]?: ITSDeepPartial<T[K]>;\n }\n : T;\n\n/**\n * 深層必填映射:對物件的所有屬性應用 Required\n * Deep required mapping: apply Required to all properties of an object\n * \n * @example\n * interface User { name?: string; profile?: { age?: number; } }\n * type RequiredUser = ITSDeepRequired<User>;\n * // { name: string; profile: { age: number; } }\n */\nexport type ITSDeepRequired<T> = T extends object \n ? T extends ITSArrayListMaybeReadonly<any>\n ? T\n : {\n [K in keyof T]-?: ITSDeepRequired<T[K]>;\n }\n : T;\n"]}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 字串操作工具
|
|
3
|
+
* String Operation Utilities
|
|
4
|
+
*
|
|
5
|
+
* 提供字串相關的類型操作工具
|
|
6
|
+
* Provides string-related type manipulation utilities
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 字串首字母大寫
|
|
10
|
+
* Capitalize first letter of string
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* type Result = ITSCapitalize<'hello'>; // 'Hello'
|
|
14
|
+
* type Result2 = ITSCapitalize<'world'>; // 'World'
|
|
15
|
+
*/
|
|
16
|
+
export type ITSCapitalize<S extends string> = S extends `${infer First}${infer Rest}` ? `${Uppercase<First>}${Rest}` : S;
|
|
17
|
+
/**
|
|
18
|
+
* 字串首字母小寫
|
|
19
|
+
* Uncapitalize first letter of string
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* type Result = ITSUncapitalize<'Hello'>; // 'hello'
|
|
23
|
+
* type Result2 = ITSUncapitalize<'World'>; // 'world'
|
|
24
|
+
*/
|
|
25
|
+
export type ITSUncapitalize<S extends string> = S extends `${infer First}${infer Rest}` ? `${Lowercase<First>}${Rest}` : S;
|
|
26
|
+
/**
|
|
27
|
+
* 字串轉為大寫
|
|
28
|
+
* Convert string to uppercase
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* type Result = ITSToUpperCase<'hello'>; // 'HELLO'
|
|
32
|
+
* type Result2 = ITSToUpperCase<'World'>; // 'WORLD'
|
|
33
|
+
*/
|
|
34
|
+
export type ITSToUpperCase<S extends string> = Uppercase<S>;
|
|
35
|
+
/**
|
|
36
|
+
* 字串轉為小寫
|
|
37
|
+
* Convert string to lowercase
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* type Result = ITSToLowerCase<'HELLO'>; // 'hello'
|
|
41
|
+
* type Result2 = ITSToLowerCase<'World'>; // 'world'
|
|
42
|
+
*/
|
|
43
|
+
export type ITSToLowerCase<S extends string> = Lowercase<S>;
|
|
44
|
+
/**
|
|
45
|
+
* TODO: 字串重複指定次數 - 無法實現
|
|
46
|
+
* Repeat string specified number of times
|
|
47
|
+
*
|
|
48
|
+
* TypeScript 無法在類型層級進行遞迴數學運算
|
|
49
|
+
* TypeScript cannot perform recursive mathematical operations at type level
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* type Result = ITSRepeat<'abc', 3>; // 'abcabcabc'
|
|
53
|
+
* type Result2 = ITSRepeat<'x', 5>; // 'xxxxx'
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* TODO: 字串長度 - 無法實現
|
|
57
|
+
* Get string length
|
|
58
|
+
*
|
|
59
|
+
* TypeScript 無法在類型層級計算字串長度
|
|
60
|
+
* TypeScript cannot calculate string length at type level
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* type Result = ITSStringLength<'hello'>; // 5
|
|
64
|
+
* type Result2 = ITSStringLength<''>; // 0
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* TODO: 字串分割 - 無法實現
|
|
68
|
+
* Split string by separator
|
|
69
|
+
*
|
|
70
|
+
* TypeScript 無法在類型層級進行字串分割操作
|
|
71
|
+
* TypeScript cannot perform string splitting operations at type level
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* type Result = ITSSplit<'a,b,c', ','>; // ['a', 'b', 'c']
|
|
75
|
+
* type Result2 = ITSSplit<'hello world', ' '>; // ['hello', 'world']
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* TODO: 字串連接 - 無法實現
|
|
79
|
+
* Join string array with separator
|
|
80
|
+
*
|
|
81
|
+
* TypeScript 無法在類型層級進行陣列連接操作
|
|
82
|
+
* TypeScript cannot perform array joining operations at type level
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* type Result = ITSJoin<['a', 'b', 'c'], ','>; // 'a,b,c'
|
|
86
|
+
* type Result2 = ITSJoin<['hello', 'world'], ' '>; // 'hello world'
|
|
87
|
+
*/
|
|
88
|
+
/**
|
|
89
|
+
* 字串替換
|
|
90
|
+
* Replace substring in string
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* type Result = ITSReplace<'hello world', 'world', 'typescript'>; // 'hello typescript'
|
|
94
|
+
* type Result2 = ITSReplace<'abc123', '123', '456'>; // 'abc456'
|
|
95
|
+
*/
|
|
96
|
+
export type ITSReplace<S extends string, Search extends string, Replace extends string> = S extends `${infer Prefix}${Search}${infer Suffix}` ? `${Prefix}${Replace}${Suffix}` : S;
|
|
97
|
+
/**
|
|
98
|
+
* 字串是否包含子字串
|
|
99
|
+
* Check if string contains substring
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* type Result = ITSIncludes<'hello world', 'world'>; // true
|
|
103
|
+
* type Result2 = ITSIncludes<'hello world', 'typescript'>; // false
|
|
104
|
+
*/
|
|
105
|
+
export type ITSIncludes<S extends string, Search extends string> = S extends `${string}${Search}${string}` ? true : false;
|
|
106
|
+
/**
|
|
107
|
+
* 字串是否以指定前綴開始
|
|
108
|
+
* Check if string starts with prefix
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* type Result = ITSStartsWith<'hello world', 'hello'>; // true
|
|
112
|
+
* type Result2 = ITSStartsWith<'hello world', 'world'>; // false
|
|
113
|
+
*/
|
|
114
|
+
export type ITSStartsWith<S extends string, Prefix extends string> = S extends `${Prefix}${string}` ? true : false;
|
|
115
|
+
/**
|
|
116
|
+
* 字串是否以指定後綴結束
|
|
117
|
+
* Check if string ends with suffix
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* type Result = ITSEndsWith<'hello world', 'world'>; // true
|
|
121
|
+
* type Result2 = ITSEndsWith<'hello world', 'hello'>; // false
|
|
122
|
+
*/
|
|
123
|
+
export type ITSEndsWith<S extends string, Suffix extends string> = S extends `${string}${Suffix}` ? true : false;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["operations.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串操作工具\n * String Operation Utilities\n * \n * 提供字串相關的類型操作工具\n * Provides string-related type manipulation utilities\n */\n\n/**\n * 字串首字母大寫\n * Capitalize first letter of string\n * \n * @example\n * type Result = ITSCapitalize<'hello'>; // 'Hello'\n * type Result2 = ITSCapitalize<'world'>; // 'World'\n */\nexport type ITSCapitalize<S extends string> = S extends `${infer First}${infer Rest}` \n ? `${Uppercase<First>}${Rest}` \n : S;\n\n/**\n * 字串首字母小寫\n * Uncapitalize first letter of string\n * \n * @example\n * type Result = ITSUncapitalize<'Hello'>; // 'hello'\n * type Result2 = ITSUncapitalize<'World'>; // 'world'\n */\nexport type ITSUncapitalize<S extends string> = S extends `${infer First}${infer Rest}` \n ? `${Lowercase<First>}${Rest}` \n : S;\n\n/**\n * 字串轉為大寫\n * Convert string to uppercase\n * \n * @example\n * type Result = ITSToUpperCase<'hello'>; // 'HELLO'\n * type Result2 = ITSToUpperCase<'World'>; // 'WORLD'\n */\nexport type ITSToUpperCase<S extends string> = Uppercase<S>;\n\n/**\n * 字串轉為小寫\n * Convert string to lowercase\n * \n * @example\n * type Result = ITSToLowerCase<'HELLO'>; // 'hello'\n * type Result2 = ITSToLowerCase<'World'>; // 'world'\n */\nexport type ITSToLowerCase<S extends string> = Lowercase<S>;\n\n/**\n * TODO: 字串重複指定次數 - 無法實現\n * Repeat string specified number of times\n * \n * TypeScript 無法在類型層級進行遞迴數學運算\n * TypeScript cannot perform recursive mathematical operations at type level\n * \n * @example\n * type Result = ITSRepeat<'abc', 3>; // 'abcabcabc'\n * type Result2 = ITSRepeat<'x', 5>; // 'xxxxx'\n */\n// export type ITSRepeat<S extends string, N extends number> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSRepeat<S extends string, N extends number> = \n// \tN extends 0 \n// \t\t? '' \n// \t\t: N extends infer Count \n// \t\t\t? Count extends number \n// \t\t\t\t? `${S}${ITSRepeat<S, Count extends 0 ? never : Count - 1>}`\n// \t\t\t\t: never \n// \t\t\t: never;\n\n/**\n * TODO: 字串長度 - 無法實現\n * Get string length\n * \n * TypeScript 無法在類型層級計算字串長度\n * TypeScript cannot calculate string length at type level\n * \n * @example\n * type Result = ITSStringLength<'hello'>; // 5\n * type Result2 = ITSStringLength<''>; // 0\n */\n// export type ITSStringLength<S extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSStringLength<S extends string, Counter extends any[] = []> = \n// \tS extends `${string}${infer Rest}` \n// \t\t? ITSStringLength<Rest, [...Counter, any]>\n// \t\t: Counter['length'];\n\n/**\n * TODO: 字串分割 - 無法實現\n * Split string by separator\n * \n * TypeScript 無法在類型層級進行字串分割操作\n * TypeScript cannot perform string splitting operations at type level\n * \n * @example\n * type Result = ITSSplit<'a,b,c', ','>; // ['a', 'b', 'c']\n * type Result2 = ITSSplit<'hello world', ' '>; // ['hello', 'world']\n */\n// export type ITSSplit<S extends string, Separator extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSSplit<S extends string, Separator extends string> = \n// \tS extends `${infer First}${Separator}${infer Rest}`\n// \t\t? [First, ...ITSSplit<Rest, Separator>]\n// \t\t: [S];\n\n/**\n * TODO: 字串連接 - 無法實現\n * Join string array with separator\n * \n * TypeScript 無法在類型層級進行陣列連接操作\n * TypeScript cannot perform array joining operations at type level\n * \n * @example\n * type Result = ITSJoin<['a', 'b', 'c'], ','>; // 'a,b,c'\n * type Result2 = ITSJoin<['hello', 'world'], ' '>; // 'hello world'\n */\n// export type ITSJoin<T extends string[], Separator extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSJoin<T extends string[], Separator extends string> = \n// \tT extends [infer First, ...infer Rest]\n// \t\t? First extends string\n// \t\t\t? Rest extends string[]\n// \t\t\t\t? Rest['length'] extends 0\n// \t\t\t\t\t? First\n// \t\t\t\t\t: `${First}${Separator}${ITSJoin<Rest, Separator>}`\n// \t\t\t\t: never\n// \t\t\t: never\n// \t\t: '';\n\n/**\n * 字串替換\n * Replace substring in string\n * \n * @example\n * type Result = ITSReplace<'hello world', 'world', 'typescript'>; // 'hello typescript'\n * type Result2 = ITSReplace<'abc123', '123', '456'>; // 'abc456'\n */\nexport type ITSReplace<S extends string, Search extends string, Replace extends string> = \n S extends `${infer Prefix}${Search}${infer Suffix}`\n ? `${Prefix}${Replace}${Suffix}`\n : S;\n\n/**\n * 字串是否包含子字串\n * Check if string contains substring\n * \n * @example\n * type Result = ITSIncludes<'hello world', 'world'>; // true\n * type Result2 = ITSIncludes<'hello world', 'typescript'>; // false\n */\nexport type ITSIncludes<S extends string, Search extends string> = \n S extends `${string}${Search}${string}` ? true : false;\n\n/**\n * 字串是否以指定前綴開始\n * Check if string starts with prefix\n * \n * @example\n * type Result = ITSStartsWith<'hello world', 'hello'>; // true\n * type Result2 = ITSStartsWith<'hello world', 'world'>; // false\n */\nexport type ITSStartsWith<S extends string, Prefix extends string> = \n S extends `${Prefix}${string}` ? true : false;\n\n/**\n * 字串是否以指定後綴結束\n * Check if string ends with suffix\n * \n * @example\n * type Result = ITSEndsWith<'hello world', 'world'>; // true\n * type Result2 = ITSEndsWith<'hello world', 'hello'>; // false\n */\nexport type ITSEndsWith<S extends string, Suffix extends string> = \n S extends `${string}${Suffix}` ? true : false;\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from './generic';
|
|
2
2
|
export * from './helper';
|
|
3
3
|
export * from './helper/array/readonly';
|
|
4
|
+
export * from './helper/conditional';
|
|
5
|
+
export * from './helper/deep-map';
|
|
4
6
|
export * from './helper/filter';
|
|
5
7
|
export * from './helper/infer';
|
|
6
8
|
export * from './helper/intersection';
|
|
@@ -19,6 +21,7 @@ export * from './helper/record/pick-type';
|
|
|
19
21
|
export * from './helper/string';
|
|
20
22
|
export * from './helper/string/infer';
|
|
21
23
|
export * from './helper/string/literal-string';
|
|
24
|
+
export * from './helper/string/operations';
|
|
22
25
|
export * from './helper/tuple';
|
|
23
26
|
export * from './helper/typeof';
|
|
24
27
|
export * from './internal/filter';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-type",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "TypeScript 類型工具庫:提供豐富的類型操作工具和重新導出的內建類型 / TypeScript type utility library: provides rich type manipulation utilities and re-exported built-in types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
".d.ts",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"peerDependencies": {
|
|
98
98
|
"ts-toolbelt": "^9.6.0"
|
|
99
99
|
},
|
|
100
|
-
"gitHead": "
|
|
100
|
+
"gitHead": "4ef633a04245358fed59633c9d9ceff0607d30d3"
|
|
101
101
|
}
|