ts-gems 2.7.1 → 2.7.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/lib/keys.d.ts +43 -40
- package/lib/type-check.d.ts +4 -3
- package/package.json +4 -4
package/lib/keys.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
IfEquals, IfCompatible, IfUndefined,
|
|
3
|
+
IfJson, IfNull, IfFunction
|
|
4
|
+
} from './type-check';
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* KeyOf
|
|
@@ -17,31 +20,32 @@ export type ValuesOf<T> = T[keyof T];
|
|
|
17
20
|
* @desc Returns required keys of an object
|
|
18
21
|
*/
|
|
19
22
|
export type RequiredKeys<T> = _RequiredKeys<T>
|
|
20
|
-
export type _RequiredKeys<T> = {
|
|
21
|
-
[K in keyof T]-?: IfUndefined<T[K]> extends true
|
|
22
|
-
?
|
|
23
|
-
|
|
24
|
-
}
|
|
23
|
+
export type _RequiredKeys<T> = ValuesOf<{
|
|
24
|
+
[K in keyof T]-?: IfUndefined<T[K]> extends true ? never
|
|
25
|
+
: T extends { [K1 in K]: any } ? K
|
|
26
|
+
: never
|
|
27
|
+
}>;
|
|
25
28
|
|
|
26
29
|
/**
|
|
27
30
|
* OptionalKeys
|
|
28
31
|
* @desc Returns optional keys of an object
|
|
29
32
|
*/
|
|
30
33
|
export type OptionalKeys<T> = _OptionalKeys<T>
|
|
31
|
-
export type _OptionalKeys<T> = {
|
|
32
|
-
[K in keyof T]-?: IfUndefined<T[K]> extends true
|
|
33
|
-
? never
|
|
34
|
-
|
|
35
|
-
}
|
|
34
|
+
export type _OptionalKeys<T> = ValuesOf<{
|
|
35
|
+
[K in keyof T]-?: IfUndefined<T[K]> extends true ? never
|
|
36
|
+
: T extends { [K1 in K]: any } ? never
|
|
37
|
+
: K
|
|
38
|
+
}>;
|
|
36
39
|
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
42
|
* @desc Returns readonly keys of an object
|
|
40
43
|
*/
|
|
41
|
-
export type ReadonlyKeys<T> =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
export type ReadonlyKeys<T> = _ReadonlyKeys<T>
|
|
45
|
+
type _ReadonlyKeys<T, J = Required<T>> = ValuesOf<{
|
|
46
|
+
[K in keyof J]: K extends symbol ? never
|
|
47
|
+
: IfEquals<{ [Q in K]: J[K] }, { -readonly [Q in K]: J[K] }, never, K>
|
|
48
|
+
}>;
|
|
45
49
|
|
|
46
50
|
/**
|
|
47
51
|
* @desc Returns JSON friendly keys of an object
|
|
@@ -49,10 +53,8 @@ export type ReadonlyKeys<T> = {
|
|
|
49
53
|
export type JsonKeys<T> = _JsonKeys<T>;
|
|
50
54
|
type _JsonKeys<T, J = Required<T>> = ValuesOf<{
|
|
51
55
|
[K in keyof J]: K extends symbol ? never
|
|
52
|
-
:
|
|
53
|
-
?
|
|
54
|
-
: IfJson<J[K]> extends true
|
|
55
|
-
? K
|
|
56
|
+
: IfNull<J[K]> extends true ? K
|
|
57
|
+
: IfJson<Exclude<J[K], undefined>> extends true ? K
|
|
56
58
|
: never
|
|
57
59
|
|
|
58
60
|
}>;
|
|
@@ -60,51 +62,52 @@ type _JsonKeys<T, J = Required<T>> = ValuesOf<{
|
|
|
60
62
|
/**
|
|
61
63
|
* @desc Returns writable keys of an object
|
|
62
64
|
*/
|
|
63
|
-
export type WritableKeys<T> =
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
export type WritableKeys<T> = _WritableKeys<T>;
|
|
66
|
+
type _WritableKeys<T> = ValuesOf<{
|
|
67
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
68
|
+
: IfEquals<{ [Q in K]: T[K] }, { readonly [Q in K]: T[K] }, never, K>
|
|
69
|
+
}>;
|
|
66
70
|
|
|
67
71
|
|
|
68
72
|
/**
|
|
69
73
|
* @desc Returns writable json keys of an object
|
|
70
74
|
*/
|
|
71
|
-
export type WritableJsonKeys<T> = Extract<
|
|
72
|
-
[K in keyof T]-?: IfEquals<{ [Q in K]: T[K] }, { -readonly [Q in K]: T[K] }, K, never>
|
|
73
|
-
}[keyof T], JsonKeys<T>>;
|
|
75
|
+
export type WritableJsonKeys<T> = Extract<WritableKeys<T>, JsonKeys<T>>;
|
|
74
76
|
|
|
75
77
|
/**
|
|
76
78
|
* @desc Returns Function keys of an object
|
|
77
79
|
*/
|
|
78
|
-
export type FunctionKeys<T> =
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
: never : never : never;
|
|
80
|
+
export type FunctionKeys<T> = _FunctionKeys<T>;
|
|
81
|
+
type _FunctionKeys<T> = ValuesOf<{
|
|
82
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
83
|
+
: IfFunction<T[K]> extends true ? K : never;
|
|
83
84
|
}>;
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
87
|
* @desc Returns non function keys of an object
|
|
87
88
|
*/
|
|
88
|
-
export type NonFunctionKeys<T> =
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
: K : K : K;
|
|
89
|
+
export type NonFunctionKeys<T> = _NonFunctionKeys<T>;
|
|
90
|
+
type _NonFunctionKeys<T> = ValuesOf<{
|
|
91
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
92
|
+
: IfFunction<T[K]> extends true ? never : K;
|
|
93
93
|
}>;
|
|
94
94
|
|
|
95
95
|
|
|
96
|
-
|
|
97
96
|
/**
|
|
98
97
|
* @desc Returns keys that match given type
|
|
99
98
|
*/
|
|
100
|
-
export type KeysCompatible<T, U> =
|
|
101
|
-
|
|
99
|
+
export type KeysCompatible<T, U> = _KeysCompatible<T, U>;
|
|
100
|
+
type _KeysCompatible<T, U> = ValuesOf<{
|
|
101
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
102
|
+
: IfCompatible<T[K], U, K, never>;
|
|
102
103
|
}>;
|
|
103
104
|
|
|
104
105
|
/**
|
|
105
106
|
* @desc Returns keys that equals given type
|
|
106
107
|
*/
|
|
107
|
-
export type KeysEquals<T, U> =
|
|
108
|
-
|
|
108
|
+
export type KeysEquals<T, U> = _KeysEquals<T, U>;
|
|
109
|
+
type _KeysEquals<T, U> = ValuesOf<{
|
|
110
|
+
[K in keyof T]-?: K extends symbol ? never
|
|
111
|
+
: IfEquals<T[K], U, K, never>;
|
|
109
112
|
}>;
|
|
110
113
|
|
package/lib/type-check.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Primitive, Type} from './common';
|
|
1
|
+
import { Primitive, Type } from './common';
|
|
2
2
|
|
|
3
3
|
type NonObj = Primitive | Function;
|
|
4
4
|
|
|
@@ -113,8 +113,9 @@ export type IfFunction<T, Y = true, N = false> =
|
|
|
113
113
|
IfNever<T> extends true ? N
|
|
114
114
|
: IfUndefined<T> extends true ? N
|
|
115
115
|
: IfNull<T> extends true ? N
|
|
116
|
-
: T extends
|
|
117
|
-
:
|
|
116
|
+
: T extends Type ? N
|
|
117
|
+
: T extends Function ? Y
|
|
118
|
+
: N;
|
|
118
119
|
|
|
119
120
|
export type IfFunctionOrAny<T, Y = true, N = false> =
|
|
120
121
|
IfAny<T> extends true ? Y : IfFunction<T, Y, N>;
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"lodash",
|
|
13
13
|
"underscore"
|
|
14
14
|
],
|
|
15
|
-
"version": "2.7.
|
|
15
|
+
"version": "2.7.3",
|
|
16
16
|
"types": "lib/index.d.ts",
|
|
17
17
|
"main": "lib/index.js",
|
|
18
18
|
"module": "lib/index.js",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"lib/"
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@types/jest": "^29.5.
|
|
36
|
-
"eslint": "^8.
|
|
35
|
+
"@types/jest": "^29.5.11",
|
|
36
|
+
"eslint": "^8.55.0",
|
|
37
37
|
"jest": "^29.7.0",
|
|
38
38
|
"ts-jest": "^29.1.1",
|
|
39
|
-
"typescript": "^5.
|
|
39
|
+
"typescript": "^5.3.3"
|
|
40
40
|
}
|
|
41
41
|
}
|