@inzero/ts-ut 0.4.0 → 0.5.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.
- package/CHANGELOG.md +14 -0
- package/dist/dict/extract.d.ts +31 -2
- package/dist/dict/index.d.ts +9 -9
- package/dist/dict/keyof.d.ts +1 -1
- package/dist/dict/pick.d.ts +16 -16
- package/dist/dict/utils.d.ts +7 -0
- package/dist/func/index.d.ts +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/list/index.d.ts +1 -1
- package/dist/number/index.d.ts +2 -2
- package/dist/other/index.d.ts +2 -2
- package/dist/other/validation.d.ts +1 -1
- package/dist/string/index.d.ts +5 -5
- package/dist/tuple/index.d.ts +2 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.5.0] 2026-11-15
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Added dict utils: `ExtractFromValues`, `ExcludeFromValues` and `PrettifyKeyof`.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Improve some utility implementations without changing their behavior.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- Add distribution in dict pick utils: `PickMutable`, `PickMutableDeep`, ...
|
|
16
|
+
|
|
3
17
|
## [0.4.0] 2026-11-14
|
|
4
18
|
|
|
5
19
|
### Changed
|
package/dist/dict/extract.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AreEqual, HasType } from "../other";
|
|
1
|
+
import type { AreEqual, HasType, IsNever } from "../other";
|
|
2
|
+
import type { SuggestKey } from "./utils";
|
|
2
3
|
import type { Keys, Values } from "./keyof";
|
|
3
|
-
import type { Dict } from "./utils";
|
|
4
|
+
import type { Dict, Known } from "./utils";
|
|
4
5
|
/**
|
|
5
6
|
* Extracts union members whose specified properties contain at least one of the specified value types.
|
|
6
7
|
*
|
|
@@ -25,3 +26,31 @@ export type ExtractByValue<T, M extends Partial<Dict<Keys<T>>>> = T extends T ?
|
|
|
25
26
|
export type ExtractByExactValue<T, M extends Partial<Dict<Keys<T>>>> = T extends T ? Values<{
|
|
26
27
|
[P in keyof M]: P extends keyof T ? AreEqual<T[P], M[P]> : false;
|
|
27
28
|
}> extends true ? T : never : never;
|
|
29
|
+
/**
|
|
30
|
+
* Extracts types assignable to `U` from values of `T`.
|
|
31
|
+
*
|
|
32
|
+
* By default, extraction is applied to all properties. If K is specified,
|
|
33
|
+
* extraction is limited to those keys, leaving the remaining properties unchanged.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* type T = { a: string | number, b: string | number };
|
|
37
|
+
*
|
|
38
|
+
* type R1 = ExtractFromValues<T, string>; // { a: string, b: string };
|
|
39
|
+
*/
|
|
40
|
+
export type ExtractFromValues<T, U, K extends SuggestKey<Keys<Known<T>>> = never> = {
|
|
41
|
+
[P in keyof T]: Extract<T[P], U> extends infer R ? IsNever<K> extends true ? R : P extends K ? R : T[P] : never;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Excludes types assignable to `U` from values of `T`.
|
|
45
|
+
*
|
|
46
|
+
* By default, exclusion is applied to all properties. If K is specified,
|
|
47
|
+
* exclusion is limited to those keys, leaving the remaining properties unchanged.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* type T = { a: string | undefined, b: string | undefined };
|
|
51
|
+
*
|
|
52
|
+
* type R1 = ExcludeFromValues<T, string>; // { a: string, b: string };
|
|
53
|
+
*/
|
|
54
|
+
export type ExcludeFromValues<T, U, K extends SuggestKey<Keys<Known<T>>> = never> = {
|
|
55
|
+
[P in keyof T]: Exclude<T[P], U> extends infer R ? IsNever<K> extends true ? R : P extends K ? R : T[P] : never;
|
|
56
|
+
};
|
package/dist/dict/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
1
|
+
export * from "./extract";
|
|
2
|
+
export * from "./get";
|
|
3
|
+
export * from "./keyof";
|
|
4
|
+
export * from "./merge";
|
|
5
|
+
export * from "./modifiers";
|
|
6
|
+
export * from "./pick";
|
|
7
|
+
export * from "./prefix";
|
|
8
|
+
export * from "./rename";
|
|
9
|
+
export * from "./utils";
|
package/dist/dict/keyof.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type Values<T> = T extends T ? T[keyof T] : never;
|
|
|
28
28
|
*
|
|
29
29
|
* type R1 = Entries<Config>; // ["foo" | "bar", string | number] | ["c", 4]
|
|
30
30
|
*/
|
|
31
|
-
export type Entries<T> = T extends T ? [
|
|
31
|
+
export type Entries<T> = T extends T ? [keyof T, T[keyof T]] : never;
|
|
32
32
|
/**
|
|
33
33
|
* A deep version of {@linkcode Keys}.
|
|
34
34
|
*
|
package/dist/dict/pick.d.ts
CHANGED
|
@@ -51,9 +51,9 @@ export type StrictOmit<T, K extends Keys<T>> = LooseOmit<T, K>;
|
|
|
51
51
|
* @example
|
|
52
52
|
* type R1 = PickOptional<{ a: 1, b: 2, c?: 4 }>; // { c?: 4 }
|
|
53
53
|
*/
|
|
54
|
-
export type PickOptional<T> = {
|
|
54
|
+
export type PickOptional<T> = T extends T ? {
|
|
55
55
|
[P in keyof T as IsOptionalKey<T, P> extends true ? P : never]: T[P];
|
|
56
|
-
};
|
|
56
|
+
} & {} : never;
|
|
57
57
|
/**
|
|
58
58
|
* Recursively pick optional properties of `T`.
|
|
59
59
|
*
|
|
@@ -63,18 +63,18 @@ export type PickOptional<T> = {
|
|
|
63
63
|
* type R1 = PickOptional<Input>; // { a?: 1 }
|
|
64
64
|
* type R2 = PickOptionalDeep<Input>; // { a?: 2, b: { c?: 4 } }
|
|
65
65
|
*/
|
|
66
|
-
export type PickOptionalDeep<T> = {
|
|
66
|
+
export type PickOptionalDeep<T> = T extends T ? {
|
|
67
67
|
[P in keyof T as IsOptionalKey<T, P> | HasType<T[P], Dict> extends false ? never : P]: T[P] extends infer TP ? (TP extends Dict ? PickOptionalDeep<TP> : TP) : never;
|
|
68
|
-
} & {};
|
|
68
|
+
} & {} : never;
|
|
69
69
|
/**
|
|
70
70
|
* Pick required properties of `T`.
|
|
71
71
|
*
|
|
72
72
|
* @example
|
|
73
73
|
* type R1 = PickRequired<{ a: 1, b: 2, c?: 4 }>; // { a: 1, b: 2 }
|
|
74
74
|
*/
|
|
75
|
-
export type PickRequired<T> = {
|
|
75
|
+
export type PickRequired<T> = T extends T ? {
|
|
76
76
|
[P in keyof T as IsOptionalKey<T, P> extends true ? never : P]: T[P];
|
|
77
|
-
};
|
|
77
|
+
} & {} : never;
|
|
78
78
|
/**
|
|
79
79
|
* Recursively pick required properties of `T`.
|
|
80
80
|
*
|
|
@@ -84,18 +84,18 @@ export type PickRequired<T> = {
|
|
|
84
84
|
* type R1 = PickRequired<Input>; // { b: { c?: 4, d: 5 } }
|
|
85
85
|
* type R2 = PickRequiredDeep<Input>; // { b: { d: 5 } }
|
|
86
86
|
*/
|
|
87
|
-
export type PickRequiredDeep<T> = {
|
|
87
|
+
export type PickRequiredDeep<T> = T extends T ? {
|
|
88
88
|
[P in keyof T as Not<IsOptionalKey<T, P>> | HasType<T[P], Dict> extends false ? never : P]: T[P] extends infer TP ? (TP extends Dict ? PickRequiredDeep<TP> : TP) : never;
|
|
89
|
-
} & {};
|
|
89
|
+
} & {} : never;
|
|
90
90
|
/**
|
|
91
91
|
* Pick readonly properties of `T`.
|
|
92
92
|
*
|
|
93
93
|
* @example
|
|
94
94
|
* type R1 = PickReadonly<{ a: 1, readonly c: 4 }>; // { readonly c: 4 }
|
|
95
95
|
*/
|
|
96
|
-
export type PickReadonly<T> = {
|
|
96
|
+
export type PickReadonly<T> = T extends T ? {
|
|
97
97
|
[P in keyof T as IsReadonlyKey<T, P> extends true ? P : never]: T[P];
|
|
98
|
-
};
|
|
98
|
+
} & {} : never;
|
|
99
99
|
/**
|
|
100
100
|
* Recursively pick readonly properties of `T`.
|
|
101
101
|
*
|
|
@@ -105,18 +105,18 @@ export type PickReadonly<T> = {
|
|
|
105
105
|
* type R1 = PickReadonly<Input>; // { readonly a: 1 }
|
|
106
106
|
* type R2 = PickReadonlyDeep<Input>; // { readonly a: 1, b: { readonly c: 4 } }
|
|
107
107
|
*/
|
|
108
|
-
export type PickReadonlyDeep<T> = {
|
|
108
|
+
export type PickReadonlyDeep<T> = T extends T ? {
|
|
109
109
|
[P in keyof T as IsReadonlyKey<T, P> | HasType<T[P], Dict> extends false ? never : P]: T[P] extends infer TP ? (TP extends Dict ? PickReadonlyDeep<TP> : TP) : never;
|
|
110
|
-
} & {};
|
|
110
|
+
} & {} : never;
|
|
111
111
|
/**
|
|
112
112
|
* Pick mutable properties of `T`.
|
|
113
113
|
*
|
|
114
114
|
* @example
|
|
115
115
|
* type R1 = PickMutable<{ a: 1, readonly c: 4 }>; // { a: 1 }
|
|
116
116
|
*/
|
|
117
|
-
export type PickMutable<T> = {
|
|
117
|
+
export type PickMutable<T> = T extends T ? {
|
|
118
118
|
[P in keyof T as IsReadonlyKey<T, P> extends true ? never : P]: T[P];
|
|
119
|
-
};
|
|
119
|
+
} & {} : never;
|
|
120
120
|
/**
|
|
121
121
|
* Recursively pick mutable properties of `T`.
|
|
122
122
|
*
|
|
@@ -126,6 +126,6 @@ export type PickMutable<T> = {
|
|
|
126
126
|
* type R1 = PickMutable<Input>; // { b: { readonly c: 4, d: 5 }, e: 6 }
|
|
127
127
|
* type R2 = PickMutableDeep<Input>; // { b: { d: 5 }, e: 6 }
|
|
128
128
|
*/
|
|
129
|
-
export type PickMutableDeep<T> = {
|
|
129
|
+
export type PickMutableDeep<T> = T extends T ? {
|
|
130
130
|
[P in keyof T as Not<IsReadonlyKey<T, P>> | HasType<T[P], Dict> extends false ? never : P]: T[P] extends infer TP ? (TP extends Dict ? PickMutableDeep<TP> : TP) : never;
|
|
131
|
-
} & {};
|
|
131
|
+
} & {} : never;
|
package/dist/dict/utils.d.ts
CHANGED
|
@@ -37,3 +37,10 @@ export type Prettify<T> = {
|
|
|
37
37
|
export type PrettifyDeep<T> = {
|
|
38
38
|
[P in keyof T]: T[P] extends infer V ? (V extends Dict ? PrettifyDeep<V> : V) : never;
|
|
39
39
|
} & {};
|
|
40
|
+
/**
|
|
41
|
+
* @example
|
|
42
|
+
* type MyDict = { a: 1, b: 2 };
|
|
43
|
+
* type MyDictKeys = keyof MyDict; // type: keyof MyDict
|
|
44
|
+
* type Pretty = PrettifyKeyof<keyof MyDict>; // type: "a" | "b"
|
|
45
|
+
*/
|
|
46
|
+
export type PrettifyKeyof<T> = (T extends T ? [T] : never)[number];
|
package/dist/func/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./utils";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from "./dict";
|
|
2
|
+
export * from "./func";
|
|
3
|
+
export * from "./list";
|
|
4
|
+
export * from "./number";
|
|
5
|
+
export * from "./other";
|
|
6
|
+
export * from "./string";
|
|
7
|
+
export * from "./tuple";
|
package/dist/list/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./utils";
|
package/dist/number/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./increment";
|
|
2
|
+
export * from "./utils";
|
package/dist/other/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./utils";
|
|
2
|
+
export * from "./validation";
|
|
@@ -41,7 +41,7 @@ export type IsNotSubtype<T, U> = Not<IsSubtype<T, U>>;
|
|
|
41
41
|
* type R1 = HasType<"foo" | "bar", "foo">; // true
|
|
42
42
|
* type R2 = HasType<"foo" | "bar", "baz">; // false
|
|
43
43
|
*/
|
|
44
|
-
export type HasType<U, T> = (U extends T ? true : false) extends infer R ?
|
|
44
|
+
export type HasType<U, T> = (U extends T ? true : false) extends infer R ? [R] extends [false] ? false : true : never;
|
|
45
45
|
/**
|
|
46
46
|
* A negated version of {@linkcode HasType}.
|
|
47
47
|
*/
|
package/dist/string/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./extract";
|
|
2
|
+
export * from "./firstChar";
|
|
3
|
+
export * from "./prefix";
|
|
4
|
+
export * from "./split";
|
|
5
|
+
export * from "./utils";
|
package/dist/tuple/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./push";
|
|
2
|
+
export * from "./utils";
|