ts-gems 3.3.0 → 3.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/combine.d.ts +4 -4
- package/lib/dto.d.ts +11 -7
- package/lib/helpers.d.ts +25 -16
- package/lib/index.cjs +16 -0
- package/lib/index.d.ts +61 -15
- package/lib/index.mjs +16 -0
- package/lib/logical.d.ts +26 -14
- package/lib/mutable.d.ts +23 -18
- package/lib/nullish.d.ts +18 -15
- package/lib/omit-never.d.ts +17 -13
- package/lib/omit.d.ts +30 -20
- package/lib/opaque.ts +1 -1
- package/lib/partial.d.ts +19 -17
- package/lib/pick.d.ts +45 -46
- package/lib/readonly.d.ts +87 -83
- package/lib/required.d.ts +89 -83
- package/lib/type-check.d.ts +110 -70
- package/lib/types.d.ts +38 -19
- package/package.json +15 -6
- package/lib/index.js +0 -0
package/lib/type-check.d.ts
CHANGED
|
@@ -5,150 +5,190 @@ type NonObj = Primitive | Function;
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns Y if typeof T is "any", N otherwise
|
|
7
7
|
*/
|
|
8
|
-
export type IfAny<T, Y = true, N = false> =
|
|
9
|
-
0 extends 1 & T ? Y : N;
|
|
8
|
+
export type IfAny<T, Y = true, N = false> = 0 extends 1 & T ? Y : N;
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Returns "Y" if "T" is "never", "N" otherwise
|
|
13
12
|
*/
|
|
14
|
-
export type IfNever<T, Y = true, N = false> =
|
|
15
|
-
[T] extends [never] ? Y : N;
|
|
13
|
+
export type IfNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* Returns Y if T is undefined, N otherwise
|
|
19
17
|
*/
|
|
20
|
-
export type IfUndefined<T, Y = true, N = false> =
|
|
21
|
-
IfEquals<T, undefined, Y, N>;
|
|
18
|
+
export type IfUndefined<T, Y = true, N = false> = IfEquals<T, undefined, Y, N>;
|
|
22
19
|
|
|
23
20
|
/**
|
|
24
21
|
* Returns "Y" if "T" is "never", "N" otherwise
|
|
25
22
|
*/
|
|
26
|
-
export type IfSymbol<T, Y = true, N = false> =
|
|
27
|
-
IfEquals<T, symbol, Y, N>;
|
|
23
|
+
export type IfSymbol<T, Y = true, N = false> = IfEquals<T, symbol, Y, N>;
|
|
28
24
|
|
|
29
25
|
/**
|
|
30
26
|
* Returns Y if typeof T is "unknown", N otherwise
|
|
31
27
|
*/
|
|
32
|
-
export type IfUnknown<T, Y = true, N = false> =
|
|
33
|
-
IfEquals<T, unknown, Y, N>;
|
|
28
|
+
export type IfUnknown<T, Y = true, N = false> = IfEquals<T, unknown, Y, N>;
|
|
34
29
|
|
|
35
30
|
/**
|
|
36
31
|
* Returns Y if typeof T is null, N otherwise
|
|
37
32
|
*/
|
|
38
|
-
export type IfNull<T, Y = true, N = false> =
|
|
39
|
-
IfEquals<T, null, Y, N>;
|
|
33
|
+
export type IfNull<T, Y = true, N = false> = IfEquals<T, null, Y, N>;
|
|
40
34
|
|
|
41
35
|
/**
|
|
42
36
|
* Returns Y if typeof T is null, N otherwise
|
|
43
37
|
*/
|
|
44
38
|
export type IfNullish<T, Y = true, N = false> =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
IfNever<T> extends true
|
|
40
|
+
? N
|
|
41
|
+
: T extends null
|
|
42
|
+
? Y
|
|
43
|
+
: T extends undefined
|
|
44
|
+
? Y
|
|
45
|
+
: N;
|
|
49
46
|
|
|
50
47
|
/**
|
|
51
48
|
* Returns Y if typeof T is a tuple, N otherwise
|
|
52
49
|
*/
|
|
53
50
|
export type IfTuple<T, Y = true, N = false> =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
IfEquals<T, [any]> extends true
|
|
52
|
+
? T extends [any]
|
|
53
|
+
? number extends T['length']
|
|
54
|
+
? N
|
|
55
|
+
: Y
|
|
56
|
+
: N
|
|
57
|
+
: N;
|
|
58
58
|
export type IfTupleOrAny<T, Y = true, N = false> =
|
|
59
|
-
|
|
59
|
+
IfAny<T> extends true ? Y : IfTuple<T, Y, N>;
|
|
60
60
|
|
|
61
61
|
/**
|
|
62
62
|
* Returns Y if typeof T is "Primitive", N otherwise
|
|
63
63
|
*/
|
|
64
64
|
export type IfPrimitive<T, Y = true, N = false> =
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
IfNever<T> extends true
|
|
66
|
+
? N
|
|
67
|
+
: IfNull<T> extends true
|
|
68
|
+
? Y
|
|
69
|
+
: IfUndefined<T> extends true
|
|
70
|
+
? Y
|
|
71
|
+
: IfClass<T> extends true
|
|
72
|
+
? N
|
|
73
|
+
: IfFunction<T> extends true
|
|
74
|
+
? N
|
|
75
|
+
: T extends Primitive
|
|
76
|
+
? Y
|
|
77
|
+
: N;
|
|
72
78
|
|
|
73
79
|
export type IfPrimitiveOrAny<T, Y = true, N = false> =
|
|
74
|
-
|
|
80
|
+
IfAny<T> extends true ? Y : IfPrimitive<T, Y, N>;
|
|
75
81
|
|
|
76
82
|
/**
|
|
77
83
|
* Returns Y if typeof T is an empty object, N otherwise
|
|
78
84
|
*/
|
|
79
|
-
export type IfEmptyObject<T, Y = true, N = false> =
|
|
80
|
-
IfEquals<T, {}, Y, N>;
|
|
85
|
+
export type IfEmptyObject<T, Y = true, N = false> = IfEquals<T, {}, Y, N>;
|
|
81
86
|
|
|
82
87
|
/**
|
|
83
88
|
* Returns Y if typeof T is an object, N otherwise
|
|
84
89
|
*/
|
|
85
90
|
export type IfObject<T, Y = true, N = false> =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
IfNever<T> extends true
|
|
92
|
+
? N
|
|
93
|
+
: T extends object
|
|
94
|
+
? T extends NonObj | any[]
|
|
95
|
+
? N
|
|
96
|
+
: Y
|
|
97
|
+
: N;
|
|
92
98
|
|
|
93
99
|
export type IfObjectOrAny<T, Y = true, N = false> =
|
|
94
|
-
|
|
100
|
+
IfAny<T> extends true ? Y : IfObject<T, Y, N>;
|
|
95
101
|
|
|
96
102
|
/**
|
|
97
103
|
* Returns Y if typeof T is an empty object, N otherwise
|
|
98
104
|
*/
|
|
99
105
|
export type IfFunction<T, Y = true, N = false> =
|
|
100
|
-
|
|
101
|
-
: T extends Type ? N
|
|
102
|
-
: T extends Function ? Y
|
|
103
|
-
: N;
|
|
106
|
+
IfNever<T> extends true ? N : T extends Type ? N : T extends Function ? Y : N;
|
|
104
107
|
|
|
105
108
|
export type IfFunctionOrAny<T, Y = true, N = false> =
|
|
106
|
-
|
|
109
|
+
IfAny<T> extends true ? Y : IfFunction<T, Y, N>;
|
|
107
110
|
|
|
108
111
|
/**
|
|
109
112
|
* Returns Y if typeof T is a constructor type, N otherwise
|
|
110
113
|
*/
|
|
111
114
|
export type IfClass<T, Y = true, N = false> =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
IfNever<T> extends true
|
|
116
|
+
? N
|
|
117
|
+
: IfUndefined<T> extends true
|
|
118
|
+
? N
|
|
119
|
+
: T extends Type
|
|
120
|
+
? Y
|
|
121
|
+
: N;
|
|
115
122
|
|
|
116
123
|
export type IfClassOrAny<T, Y = true, N = false> =
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
IfAny<T> extends true ? Y : IfClass<T, Y, N>;
|
|
119
125
|
|
|
120
126
|
/**
|
|
121
127
|
* Returns "Y" if "T1" is exactly same with "T2", "N" otherwise
|
|
122
128
|
*/
|
|
123
129
|
export type IfEquals<T1, T2, Y = true, N = false> =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
| IfObject<T1>
|
|
131
|
+
| IfObject<T2> extends true
|
|
132
|
+
? (<G>() => G extends EqualsWrapped<T1> ? 1 : 2) extends <
|
|
133
|
+
G,
|
|
134
|
+
>() => G extends EqualsWrapped<T2> ? 1 : 2
|
|
135
|
+
? Y
|
|
136
|
+
: N
|
|
137
|
+
: (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2
|
|
138
|
+
? Y
|
|
139
|
+
: N;
|
|
127
140
|
|
|
128
141
|
type EqualsWrapped<T> = T extends infer R & {}
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
? { [P in keyof R]: R[P] }
|
|
143
|
+
: never;
|
|
131
144
|
|
|
132
145
|
/**
|
|
133
146
|
* Returns "Y" if type "T" matches "U", "N" otherwise
|
|
134
147
|
*/
|
|
135
148
|
export type IfCompatible<T1, T2, Y = true, N = false> =
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
IfUndefined<T1> extends true
|
|
150
|
+
? IfEquals<T1, T2, Y, N>
|
|
151
|
+
: IfUndefined<T2> extends true
|
|
152
|
+
? N
|
|
153
|
+
: IfNever<T1> extends true
|
|
154
|
+
? IfEquals<T1, T2, Y, N>
|
|
155
|
+
: IfNever<T2> extends true
|
|
156
|
+
? N
|
|
157
|
+
: IfNull<T1> extends true
|
|
158
|
+
? IfEquals<T1, T2, Y, N>
|
|
159
|
+
: IfNull<T2> extends true
|
|
160
|
+
? N
|
|
161
|
+
: IfUnknown<T1> extends true
|
|
162
|
+
? Y
|
|
163
|
+
: IfUnknown<T2> extends true
|
|
164
|
+
? Y
|
|
165
|
+
: IfAny<T1> extends true
|
|
166
|
+
? Y
|
|
167
|
+
: IfAny<T2> extends true
|
|
168
|
+
? Y
|
|
169
|
+
: IfEmptyObject<T1> extends true
|
|
170
|
+
? IfObject<T2, Y, N>
|
|
171
|
+
: IfEmptyObject<T2> extends true
|
|
172
|
+
? IfObject<T1, Y, N>
|
|
173
|
+
: IfFunction<T1> extends true
|
|
174
|
+
? IfCompatibleFunction<T1, T2, Y, N>
|
|
175
|
+
: IfObject<T1> extends true
|
|
176
|
+
? [T1] extends [T2]
|
|
177
|
+
? Y
|
|
178
|
+
: N
|
|
179
|
+
: [T1] extends [T2]
|
|
180
|
+
? Y
|
|
181
|
+
: IfPrimitive<T2> extends true
|
|
182
|
+
? [T2] extends [T1]
|
|
183
|
+
? Y
|
|
184
|
+
: N
|
|
185
|
+
: N;
|
|
148
186
|
|
|
149
187
|
type IfCompatibleFunction<T1, T2, Y = true, N = false> =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
188
|
+
IfFunction<T1> extends false
|
|
189
|
+
? N
|
|
190
|
+
: IfFunction<T2> extends false
|
|
191
|
+
? N
|
|
192
|
+
: T1 extends T2
|
|
193
|
+
? Y
|
|
194
|
+
: N;
|
package/lib/types.d.ts
CHANGED
|
@@ -13,11 +13,13 @@ declare global {
|
|
|
13
13
|
|
|
14
14
|
cancel(reason?: any): Promise<void>;
|
|
15
15
|
|
|
16
|
-
getReader(options: { mode:
|
|
16
|
+
getReader(options: { mode: 'byob' }): ReadableStreamBYOBReader;
|
|
17
17
|
|
|
18
18
|
getReader(): ReadableStreamDefaultReader<R>;
|
|
19
19
|
|
|
20
|
-
getReader(
|
|
20
|
+
getReader(
|
|
21
|
+
options?: ReadableStreamGetReaderOptions,
|
|
22
|
+
): ReadableStreamReader<R>;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export interface WritableStream<W = any> {
|
|
@@ -35,7 +37,6 @@ declare global {
|
|
|
35
37
|
*/
|
|
36
38
|
type BasicPrimitive = number | string | boolean;
|
|
37
39
|
|
|
38
|
-
|
|
39
40
|
/**
|
|
40
41
|
* Primitive
|
|
41
42
|
* @desc Type representing [`Primitive`](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) types
|
|
@@ -47,33 +48,52 @@ export type Primitive = BasicPrimitive | null | bigint | symbol | undefined;
|
|
|
47
48
|
* JsonTypes
|
|
48
49
|
* @desc Type representing JSON types in TypeScript
|
|
49
50
|
*/
|
|
50
|
-
type JsonType = BasicPrimitive | null | object | (BasicPrimitive | object)[]
|
|
51
|
-
|
|
51
|
+
type JsonType = BasicPrimitive | null | object | (BasicPrimitive | object)[];
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
54
|
* Builtin
|
|
55
55
|
* @desc Type representing Builtin types in JavaScript
|
|
56
56
|
*/
|
|
57
|
-
export type Builtin =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
export type Builtin =
|
|
58
|
+
| Primitive
|
|
59
|
+
| Function
|
|
60
|
+
| String
|
|
61
|
+
| Number
|
|
62
|
+
| Date
|
|
63
|
+
| Error
|
|
64
|
+
| RegExp
|
|
65
|
+
| Buffer
|
|
66
|
+
| ArrayBuffer
|
|
67
|
+
| Int8Array
|
|
68
|
+
| Uint8Array
|
|
69
|
+
| Uint8ClampedArray
|
|
70
|
+
| Int16Array
|
|
71
|
+
| Uint16Array
|
|
72
|
+
| Int32Array
|
|
73
|
+
| Uint32Array
|
|
74
|
+
| Float32Array
|
|
75
|
+
| Float64Array
|
|
76
|
+
| URL
|
|
77
|
+
| ReadableStream
|
|
78
|
+
| WritableStream;
|
|
61
79
|
|
|
62
80
|
/**
|
|
63
81
|
* Type
|
|
64
82
|
* @desc Represents constructor of type T
|
|
65
83
|
*/
|
|
66
84
|
export interface Type<T = any> {
|
|
67
|
-
new(...args: any[]): T;
|
|
85
|
+
new (...args: any[]): T;
|
|
68
86
|
}
|
|
69
87
|
|
|
70
88
|
/**
|
|
71
89
|
* Class
|
|
72
90
|
* @desc Represents Class constructor of type T
|
|
73
91
|
*/
|
|
74
|
-
export type Class<
|
|
75
|
-
|
|
76
|
-
|
|
92
|
+
export type Class<
|
|
93
|
+
Args extends any[] = any[],
|
|
94
|
+
Instance = {},
|
|
95
|
+
Static = {},
|
|
96
|
+
> = (new (...args: Args) => Instance) & Static;
|
|
77
97
|
|
|
78
98
|
/**
|
|
79
99
|
* Maybe
|
|
@@ -87,18 +107,15 @@ export type Maybe<T> = T | undefined;
|
|
|
87
107
|
*/
|
|
88
108
|
export type Nullish<T = null> = T | undefined | null;
|
|
89
109
|
|
|
90
|
-
|
|
91
110
|
export type Awaited<T> = T extends PromiseLike<infer U> ? U : T;
|
|
92
111
|
|
|
93
|
-
|
|
94
112
|
export type Thunk<T> = T | (() => T);
|
|
95
|
-
export type ThunkAsync<T> = Thunk<T> | (() => Promise<T>)
|
|
113
|
+
export type ThunkAsync<T> = Thunk<T> | (() => Promise<T>);
|
|
96
114
|
export type TypeThunk<T = any> = Thunk<Type<T>>;
|
|
97
115
|
export type TypeThunkAsync<T = any> = ThunkAsync<Type<T>>;
|
|
98
116
|
|
|
99
117
|
export type MaybePromise<T> = T | Promise<T>;
|
|
100
118
|
|
|
101
|
-
|
|
102
119
|
/**
|
|
103
120
|
* PropertyType
|
|
104
121
|
* @desc Returns the type of property at a given key `K`
|
|
@@ -109,5 +126,7 @@ export type PropertyType<T, K extends keyof T> = T[K];
|
|
|
109
126
|
* $ElementType
|
|
110
127
|
* @desc Returns the type of elements inside of array, tuple or object of type `T`, that matches the given index type `K`
|
|
111
128
|
*/
|
|
112
|
-
export type ElementType<
|
|
113
|
-
|
|
129
|
+
export type ElementType<
|
|
130
|
+
T extends { [P in K & any]: any },
|
|
131
|
+
K extends keyof T | number,
|
|
132
|
+
> = T[K];
|
package/package.json
CHANGED
|
@@ -12,18 +12,20 @@
|
|
|
12
12
|
"lodash",
|
|
13
13
|
"underscore"
|
|
14
14
|
],
|
|
15
|
-
"version": "3.
|
|
15
|
+
"version": "3.4.0",
|
|
16
|
+
"type": "module",
|
|
17
|
+
"module": "lib/index.mjs",
|
|
18
|
+
"main": "lib/index.cjs",
|
|
16
19
|
"types": "lib/index.d.ts",
|
|
17
|
-
"main": "lib/index.js",
|
|
18
|
-
"module": "lib/index.js",
|
|
19
20
|
"repository": "git@github.com:panates/ts-gems.git",
|
|
20
21
|
"author": "Eray Hanoglu <e.hanoglu@panates.com>",
|
|
21
22
|
"license": "MIT",
|
|
22
23
|
"scripts": {
|
|
23
24
|
"compile": "tsc -b tsconfig.json",
|
|
24
25
|
"lint": "eslint --no-error-on-unmatched-pattern",
|
|
25
|
-
"
|
|
26
|
-
"test:
|
|
26
|
+
"format": "prettier . --write --log-level=warn",
|
|
27
|
+
"test:common": "jest --clearCache && jest --config=./jest.config.mjs",
|
|
28
|
+
"test:nostrict": "jest --clearCache && jest --config=./jest.nostrict.config.mjs",
|
|
27
29
|
"test": "npm run test:common && npm run test:nostrict"
|
|
28
30
|
},
|
|
29
31
|
"files": [
|
|
@@ -33,8 +35,15 @@
|
|
|
33
35
|
],
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"@types/jest": "^29.5.12",
|
|
36
|
-
"eslint": "^
|
|
38
|
+
"eslint": "^8.57.0",
|
|
39
|
+
"eslint-config-prettier": "^9.1.0",
|
|
40
|
+
"eslint-plugin-import": "^2.29.1",
|
|
41
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
42
|
+
"eslint-plugin-security": "^3.0.0",
|
|
43
|
+
"eslint-plugin-simple-import-sort": "^12.1.0",
|
|
44
|
+
"eslint-plugin-unused-imports": "^3.1.0",
|
|
37
45
|
"jest": "^29.7.0",
|
|
46
|
+
"prettier": "^3.2.5",
|
|
38
47
|
"ts-jest": "^29.1.2",
|
|
39
48
|
"typescript": "^5.4.5"
|
|
40
49
|
}
|
package/lib/index.js
DELETED
|
File without changes
|