ts-gems 1.1.2 → 1.4.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/lib/deep-modify.d.ts +6 -6
- package/lib/deep-pick.d.ts +24 -6
- package/lib/keys.ts +2 -3
- package/lib/type-check.d.ts +7 -8
- package/package.json +4 -3
package/lib/deep-modify.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ type _DeepPartial<T> =
|
|
|
17
17
|
: T extends WeakSet<infer U> ? WeakSet<DeepPartial<U>>
|
|
18
18
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPartial<T[K]> }
|
|
19
19
|
: T extends (infer U)[] ? DeepPartial<U>[]
|
|
20
|
-
: { [P in keyof T]?: DeepPartial<
|
|
20
|
+
: { [P in keyof T]?: DeepPartial<T[P]> };
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Combination of Partial and Writable but deeply
|
|
@@ -34,7 +34,7 @@ type _DeepBuildable<T> =
|
|
|
34
34
|
: T extends WeakSet<infer U> ? WeakSet<DeepBuildable<U>>
|
|
35
35
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepBuildable<T[K]> }
|
|
36
36
|
: T extends (infer U)[] ? DeepBuildable<U>[]
|
|
37
|
-
: { -readonly [P in keyof T]?: DeepBuildable<
|
|
37
|
+
: { -readonly [P in keyof T]?: DeepBuildable<T[P]> };
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Make all properties in T required deeply
|
|
@@ -51,7 +51,7 @@ type _DeepRequired<T> =
|
|
|
51
51
|
: T extends WeakSet<infer U> ? WeakSet<DeepRequired<U>>
|
|
52
52
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepRequired<T[K]> }
|
|
53
53
|
: T extends (infer U)[] ? DeepRequired<U>[]
|
|
54
|
-
: { [P in keyof T]-?: DeepRequired<
|
|
54
|
+
: { [P in keyof T]-?: DeepRequired<T[P]> };
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
/**
|
|
@@ -69,7 +69,7 @@ type _DeepReadonly<T> =
|
|
|
69
69
|
: T extends WeakSet<infer U> ? WeakSet<DeepReadonly<U>>
|
|
70
70
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepReadonly<T[K]> }
|
|
71
71
|
: T extends (infer U)[] ? DeepReadonly<U>[]
|
|
72
|
-
: { readonly [P in keyof T]: DeepReadonly<
|
|
72
|
+
: { readonly [P in keyof T]: DeepReadonly<T[P]> };
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* Make all properties in T writable deeply
|
|
@@ -86,7 +86,7 @@ type _DeepWritable<T> =
|
|
|
86
86
|
: T extends WeakSet<infer U> ? WeakSet<DeepWritable<U>>
|
|
87
87
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepWritable<T[K]> }
|
|
88
88
|
: T extends (infer U)[] ? DeepWritable<U>[]
|
|
89
|
-
: { -readonly [P in keyof T]: DeepWritable<
|
|
89
|
+
: { -readonly [P in keyof T]: DeepWritable<T[P]> };
|
|
90
90
|
|
|
91
91
|
/**
|
|
92
92
|
* Make all properties in T nullable deeply
|
|
@@ -103,4 +103,4 @@ type _DeepNullish<T> =
|
|
|
103
103
|
: T extends WeakSet<infer U> ? WeakSet<DeepNullish<U>>
|
|
104
104
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepNullish<T[K]> }
|
|
105
105
|
: T extends (infer U)[] ? DeepNullish<U>[] | null | undefined
|
|
106
|
-
: { [P in keyof T]: DeepNullish<T[P]
|
|
106
|
+
: { [P in keyof T]: DeepNullish<T[P]> | null | undefined };
|
package/lib/deep-pick.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ type _DeepPickOptional<T, K extends keyof T = OptionalKeys<T>> =
|
|
|
17
17
|
: T extends WeakSet<infer U> ? WeakSet<DeepPickOptional<U>>
|
|
18
18
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPickOptional<T[K]> }
|
|
19
19
|
: T extends (infer U)[] ? DeepPickOptional<U>[]
|
|
20
|
-
: { [P in K]
|
|
20
|
+
: { [P in K]?: DeepPickOptional<T[P]> };
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Pick all required properties in T deeply
|
|
@@ -34,7 +34,7 @@ type _DeepPickRequired<T, J extends keyof T = RequiredKeys<T>> =
|
|
|
34
34
|
: T extends WeakSet<infer U> ? WeakSet<DeepPickRequired<U>>
|
|
35
35
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPickRequired<T[K]> }
|
|
36
36
|
: T extends (infer U)[] ? DeepPickRequired<U>[]
|
|
37
|
-
: { [P in J]: DeepPickRequired<
|
|
37
|
+
: { [P in J]: DeepPickRequired<T[P]> };
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Pick all readonly properties in T deeply
|
|
@@ -51,7 +51,7 @@ type _DeepPickReadonly<T, J extends keyof T = ReadonlyKeys<T>> =
|
|
|
51
51
|
: T extends WeakSet<infer U> ? WeakSet<DeepPickReadonly<U>>
|
|
52
52
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPickReadonly<T[K]> }
|
|
53
53
|
: T extends (infer U)[] ? DeepPickReadonly<U>[]
|
|
54
|
-
: { [P in J]: DeepPickReadonly<
|
|
54
|
+
: { [P in J]: DeepPickReadonly<T[P]> };
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* Pick all writable properties in T deeply
|
|
@@ -68,13 +68,13 @@ type _DeepPickWritable<T, K extends keyof T = WritableKeys<T>> =
|
|
|
68
68
|
: T extends WeakSet<infer U> ? WeakSet<DeepPickWritable<U>>
|
|
69
69
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPickWritable<T[K]> }
|
|
70
70
|
: T extends (infer U)[] ? DeepPickWritable<U>[]
|
|
71
|
-
: { [P in K]: DeepPickWritable<
|
|
71
|
+
: { [P in K]: DeepPickWritable<T[P]> }
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Pick all JSON friendly properties in T deeply
|
|
75
75
|
*/
|
|
76
76
|
export type DeepPickJson<T> = _DeepPickJson<T>
|
|
77
|
-
type _DeepPickJson<T,
|
|
77
|
+
type _DeepPickJson<T, Keys extends keyof T = JsonKeys<T>> =
|
|
78
78
|
T extends Builtin ? T
|
|
79
79
|
: T extends Promise<infer U> ? Promise<DeepPickJson<U>>
|
|
80
80
|
: T extends Map<infer K, infer V> ? Map<K, DeepPickJson<V>>
|
|
@@ -85,4 +85,22 @@ type _DeepPickJson<T, K extends keyof T = JsonKeys<T>> =
|
|
|
85
85
|
: T extends WeakSet<infer U> ? WeakSet<DeepPickJson<U>>
|
|
86
86
|
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPickJson<T[K]> }
|
|
87
87
|
: T extends (infer U)[] ? DeepPickJson<U>[]
|
|
88
|
-
: { [P in
|
|
88
|
+
: { [P in Keys]: DeepPickJson<T[P]> };
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Pick all JSON friendly properties in T deeply
|
|
93
|
+
*/
|
|
94
|
+
export type DeepPickWritableJson<T> = _DeepPickWritableJson<T>
|
|
95
|
+
type _DeepPickWritableJson<T, Keys extends keyof T = Exclude<JsonKeys<T>, ReadonlyKeys<T>>> =
|
|
96
|
+
T extends Builtin ? T
|
|
97
|
+
: T extends Promise<infer U> ? Promise<DeepPickWritableJson<U>>
|
|
98
|
+
: T extends Map<infer K, infer V> ? Map<K, DeepPickWritableJson<V>>
|
|
99
|
+
: T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<K, DeepPickWritableJson<V>>
|
|
100
|
+
: T extends WeakMap<infer K, infer V> ? WeakMap<K, DeepPickWritableJson<V>>
|
|
101
|
+
: T extends Set<infer U> ? Set<DeepPickWritableJson<U>>
|
|
102
|
+
: T extends ReadonlySet<infer U> ? ReadonlySet<DeepPickWritableJson<U>>
|
|
103
|
+
: T extends WeakSet<infer U> ? WeakSet<DeepPickWritableJson<U>>
|
|
104
|
+
: IfTuple<T> extends true ? { [K in OptionalKeys<T>]?: DeepPickWritableJson<T[K]> }
|
|
105
|
+
: T extends (infer U)[] ? DeepPickWritableJson<U>[]
|
|
106
|
+
: { [P in Keys]: DeepPickWritableJson<T[P]> };
|
package/lib/keys.ts
CHANGED
|
@@ -51,9 +51,8 @@ export type NonFunctionKeys<T> = Exclude<keyof T, FunctionKeys<T>>;
|
|
|
51
51
|
*/
|
|
52
52
|
export type JsonKeys<T> = _JsonKeys<T>;
|
|
53
53
|
type _JsonKeys<T, J = Required<T>> = ValuesOf<{
|
|
54
|
-
[K in keyof J]:
|
|
55
|
-
|
|
56
|
-
: K extends symbol
|
|
54
|
+
[K in keyof J]: K extends symbol ? never
|
|
55
|
+
: IfUndefined<J[K]> extends true
|
|
57
56
|
? never
|
|
58
57
|
: IfJson<J[K]> extends true
|
|
59
58
|
? K
|
package/lib/type-check.d.ts
CHANGED
|
@@ -69,15 +69,14 @@ export type IfPrimitiveOrAny<T, Y = true, N = false> =
|
|
|
69
69
|
* Returns Y if typeof T is JSON like, N otherwise
|
|
70
70
|
*/
|
|
71
71
|
export type IfJson<T, Y = true, N = false> =
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
IfAny<T> extends true ? Y :
|
|
73
|
+
IfNull<T> extends true ? Y :
|
|
74
|
+
IfNever<T> extends true ? N :
|
|
75
|
+
T extends Function ? N :
|
|
76
|
+
T extends symbol ? N :
|
|
77
77
|
IfUndefined<T> extends true ? N :
|
|
78
|
-
T extends
|
|
79
|
-
|
|
80
|
-
: Y;
|
|
78
|
+
T extends (infer U)[] ? IfJson<U> extends true ? Y : N
|
|
79
|
+
: Y;
|
|
81
80
|
|
|
82
81
|
export type IfJsonOrAny<T, Y = true, N = false> =
|
|
83
82
|
IfAny<T> extends true ? Y : IfJson<T, Y, N>;
|
package/package.json
CHANGED
|
@@ -12,16 +12,17 @@
|
|
|
12
12
|
"lodash",
|
|
13
13
|
"underscore"
|
|
14
14
|
],
|
|
15
|
-
"version": "1.
|
|
15
|
+
"version": "1.4.0",
|
|
16
16
|
"types": "lib/index.d.ts",
|
|
17
17
|
"repository": "git@github.com:panates/ts-gems.git",
|
|
18
18
|
"author": "Eray Hanoglu <e.hanoglu@panates.com>",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"scripts": {
|
|
21
|
+
"compile": "tsc -b tsconfig.json",
|
|
22
|
+
"lint": "eslint --no-error-on-unmatched-pattern",
|
|
21
23
|
"test:common": "jest --clearCache && jest --config=./jest.config.js",
|
|
22
24
|
"test:strict-null": "jest --clearCache && jest --config=./jest.strict-null.config.js",
|
|
23
|
-
"test": "npm run test:common && npm run test:strict-null"
|
|
24
|
-
"release": "npm run test && npm publish"
|
|
25
|
+
"test": "npm run test:common && npm run test:strict-null"
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"LICENSE",
|