@inzero/ts-ut 0.3.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 +25 -0
- package/dist/_internal.d.ts +9 -2
- 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/modifiers.d.ts +4 -4
- package/dist/dict/pick.d.ts +87 -1
- 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,30 @@
|
|
|
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
|
+
|
|
17
|
+
## [0.4.0] 2026-11-14
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- `MutableDeep`, `ReadonlyDeep`, `PartialDeep` and `RequiredDeep` now return prettified objects.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- Added `PickMutable`, `PickReadonly`, `PickOptional`, `PickRequired` and their deep versions.
|
|
26
|
+
- Added internal utils `IsOptionalKey` and `IsReadonlyKey`.
|
|
27
|
+
|
|
3
28
|
## [0.3.0] 2026-11-10
|
|
4
29
|
|
|
5
30
|
This update focuses on:
|
package/dist/_internal.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Mutable } from "./dict";
|
|
1
|
+
import type { DictKey, Mutable } from "./dict";
|
|
2
2
|
import type { List, ROList } from "./list";
|
|
3
3
|
import type { Decrement, Increment, ToNumber } from "./number";
|
|
4
|
-
import type { AreEqual, IsAny, IsNever, IsSubtype, IsUnknown } from "./other";
|
|
4
|
+
import type { AreEqual, AreNotEqual, IsAny, IsNever, IsSubtype, IsUnknown } from "./other";
|
|
5
5
|
import type { EnsurePrefix, Stringify } from "./string";
|
|
6
6
|
export type IsNegative<T extends string | number> = T extends T ? StartsWith<Stringify<T>, "-"> extends true ? true : false : never;
|
|
7
7
|
export type IsNumber<T extends string> = ToNumber<T> extends number ? true : false;
|
|
@@ -24,4 +24,11 @@ type _IsPrimitive<T> = T extends T ? AreEqual<T, [string]> | AreEqual<T, [number
|
|
|
24
24
|
type _Wrap<T> = (T extends T ? [T] : never) extends infer R ? IsSubtype<[true], R> | IsSubtype<[false], R> extends true ? [boolean] | Exclude<R, [boolean]> : R : never;
|
|
25
25
|
declare const __TS_UT: unique symbol;
|
|
26
26
|
export type TS_UT = typeof __TS_UT;
|
|
27
|
+
export type IsOptionalKey<T, K extends DictKey> = T extends T ? K extends keyof T ? {} extends Pick<T, K> ? true : false : never : never;
|
|
28
|
+
export type IsReadonlyKey<T, K extends DictKey> = T extends T ? K extends keyof T ? _IsReadonlyKey<T, K> : never : never;
|
|
29
|
+
type _IsReadonlyKey<T, K extends keyof T> = AreNotEqual<{
|
|
30
|
+
[P in K]: T[P];
|
|
31
|
+
}, {
|
|
32
|
+
-readonly [P in K]: T[P];
|
|
33
|
+
}>;
|
|
27
34
|
export {};
|
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/modifiers.d.ts
CHANGED
|
@@ -12,25 +12,25 @@ export type Mutable<T> = {
|
|
|
12
12
|
*/
|
|
13
13
|
export type RequiredDeep<T> = {
|
|
14
14
|
[P in keyof T]-?: RequiredDeep<T[P]>;
|
|
15
|
-
};
|
|
15
|
+
} & {};
|
|
16
16
|
/**
|
|
17
17
|
* Makes all properties of `T` optional (deep).
|
|
18
18
|
*/
|
|
19
19
|
export type PartialDeep<T> = {
|
|
20
20
|
[P in keyof T]?: PartialDeep<T[P]>;
|
|
21
|
-
};
|
|
21
|
+
} & {};
|
|
22
22
|
/**
|
|
23
23
|
* Makes all properties of `T` readonly (deep).
|
|
24
24
|
*/
|
|
25
25
|
export type ReadonlyDeep<T> = {
|
|
26
26
|
readonly [P in keyof T]: ReadonlyDeep<T[P]>;
|
|
27
|
-
};
|
|
27
|
+
} & {};
|
|
28
28
|
/**
|
|
29
29
|
* Makes all properties of `T` mutable (deep).
|
|
30
30
|
*/
|
|
31
31
|
export type MutableDeep<T> = {
|
|
32
32
|
-readonly [P in keyof T]: MutableDeep<T[P]>;
|
|
33
|
-
};
|
|
33
|
+
} & {};
|
|
34
34
|
/**
|
|
35
35
|
* Makes a property of `T` required.
|
|
36
36
|
*/
|
package/dist/dict/pick.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import type { IsOptionalKey, IsReadonlyKey } from "../_internal";
|
|
2
|
+
import type { HasType, Not } from "../other";
|
|
1
3
|
import type { Keys } from "./keyof";
|
|
2
|
-
import type { Known, SuggestKey } from "./utils";
|
|
4
|
+
import type { Dict, Known, SuggestKey } from "./utils";
|
|
3
5
|
/**
|
|
4
6
|
* A distributive/loose version of the built-in {@linkcode Pick}.
|
|
5
7
|
*
|
|
@@ -43,3 +45,87 @@ export type LooseOmit<T, K extends SuggestKey<Keys<Known<T>>>> = T extends T ? {
|
|
|
43
45
|
*
|
|
44
46
|
*/
|
|
45
47
|
export type StrictOmit<T, K extends Keys<T>> = LooseOmit<T, K>;
|
|
48
|
+
/**
|
|
49
|
+
* Pick optional properties of `T`.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* type R1 = PickOptional<{ a: 1, b: 2, c?: 4 }>; // { c?: 4 }
|
|
53
|
+
*/
|
|
54
|
+
export type PickOptional<T> = T extends T ? {
|
|
55
|
+
[P in keyof T as IsOptionalKey<T, P> extends true ? P : never]: T[P];
|
|
56
|
+
} & {} : never;
|
|
57
|
+
/**
|
|
58
|
+
* Recursively pick optional properties of `T`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* type Input = { a?: 1, b: { c?: 4, d: 5 } }
|
|
62
|
+
*
|
|
63
|
+
* type R1 = PickOptional<Input>; // { a?: 1 }
|
|
64
|
+
* type R2 = PickOptionalDeep<Input>; // { a?: 2, b: { c?: 4 } }
|
|
65
|
+
*/
|
|
66
|
+
export type PickOptionalDeep<T> = T extends T ? {
|
|
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
|
+
} & {} : never;
|
|
69
|
+
/**
|
|
70
|
+
* Pick required properties of `T`.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* type R1 = PickRequired<{ a: 1, b: 2, c?: 4 }>; // { a: 1, b: 2 }
|
|
74
|
+
*/
|
|
75
|
+
export type PickRequired<T> = T extends T ? {
|
|
76
|
+
[P in keyof T as IsOptionalKey<T, P> extends true ? never : P]: T[P];
|
|
77
|
+
} & {} : never;
|
|
78
|
+
/**
|
|
79
|
+
* Recursively pick required properties of `T`.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* type Input = { a?: 1, b: { c?: 4, d: 5 } }
|
|
83
|
+
*
|
|
84
|
+
* type R1 = PickRequired<Input>; // { b: { c?: 4, d: 5 } }
|
|
85
|
+
* type R2 = PickRequiredDeep<Input>; // { b: { d: 5 } }
|
|
86
|
+
*/
|
|
87
|
+
export type PickRequiredDeep<T> = T extends T ? {
|
|
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
|
+
} & {} : never;
|
|
90
|
+
/**
|
|
91
|
+
* Pick readonly properties of `T`.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* type R1 = PickReadonly<{ a: 1, readonly c: 4 }>; // { readonly c: 4 }
|
|
95
|
+
*/
|
|
96
|
+
export type PickReadonly<T> = T extends T ? {
|
|
97
|
+
[P in keyof T as IsReadonlyKey<T, P> extends true ? P : never]: T[P];
|
|
98
|
+
} & {} : never;
|
|
99
|
+
/**
|
|
100
|
+
* Recursively pick readonly properties of `T`.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* type Input = { readonly a: 1; b: { readonly c: 4, d: 5 }, e: 6 };
|
|
104
|
+
*
|
|
105
|
+
* type R1 = PickReadonly<Input>; // { readonly a: 1 }
|
|
106
|
+
* type R2 = PickReadonlyDeep<Input>; // { readonly a: 1, b: { readonly c: 4 } }
|
|
107
|
+
*/
|
|
108
|
+
export type PickReadonlyDeep<T> = T extends T ? {
|
|
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
|
+
} & {} : never;
|
|
111
|
+
/**
|
|
112
|
+
* Pick mutable properties of `T`.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* type R1 = PickMutable<{ a: 1, readonly c: 4 }>; // { a: 1 }
|
|
116
|
+
*/
|
|
117
|
+
export type PickMutable<T> = T extends T ? {
|
|
118
|
+
[P in keyof T as IsReadonlyKey<T, P> extends true ? never : P]: T[P];
|
|
119
|
+
} & {} : never;
|
|
120
|
+
/**
|
|
121
|
+
* Recursively pick mutable properties of `T`.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* type Input = { readonly a: 1; b: { readonly c: 4, d: 5 }, e: 6 };
|
|
125
|
+
*
|
|
126
|
+
* type R1 = PickMutable<Input>; // { b: { readonly c: 4, d: 5 }, e: 6 }
|
|
127
|
+
* type R2 = PickMutableDeep<Input>; // { b: { d: 5 }, e: 6 }
|
|
128
|
+
*/
|
|
129
|
+
export type PickMutableDeep<T> = T extends T ? {
|
|
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
|
+
} & {} : 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";
|