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.
@@ -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
- IfNever<T> extends true ? N
46
- : T extends null ? Y
47
- : T extends undefined ? Y : N;
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
- IfEquals<T, [any]> extends true
55
- ? T extends [any]
56
- ? number extends T['length'] ? N : Y
57
- : N : N;
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
- IfAny<T> extends true ? Y : IfTuple<T, Y, N>;
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
- IfNever<T> extends true ? N :
66
- IfNull<T> extends true ? Y :
67
- IfUndefined<T> extends true ? Y :
68
- IfClass<T> extends true ? N :
69
- IfFunction<T> extends true ? N :
70
- T extends Primitive ? Y :
71
- N;
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
- IfAny<T> extends true ? Y : IfPrimitive<T, Y, N>;
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
- IfNever<T> extends true ? N
87
- : T extends object
88
- ? T extends NonObj | any[]
89
- ? N
90
- : Y
91
- : N;
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
- IfAny<T> extends true ? Y : IfObject<T, Y, N>;
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
- IfNever<T> extends true ? N
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
- IfAny<T> extends true ? Y : IfFunction<T, Y, N>;
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
- IfNever<T> extends true ? N
113
- : IfUndefined<T> extends true ? N
114
- : T extends Type ? Y : N;
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
- IfAny<T> extends true ? Y : IfClass<T, Y, N>;
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
- IfObject<T1> | IfObject<T2> extends true
125
- ? ((<G>() => G extends EqualsWrapped<T1> ? 1 : 2) extends (<G>() => G extends EqualsWrapped<T2> ? 1 : 2) ? Y : N)
126
- : ((<G>() => G extends T1 ? 1 : 2) extends (<G>() => G extends T2 ? 1 : 2) ? Y : N);
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
- ? { [P in keyof R]: R[P] }
130
- : never;
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
- IfUndefined<T1> extends true ? IfEquals<T1, T2, Y, N> : IfUndefined<T2> extends true ? N
137
- : IfNever<T1> extends true ? IfEquals<T1, T2, Y, N> : IfNever<T2> extends true ? N
138
- : IfNull<T1> extends true ? IfEquals<T1, T2, Y, N> : IfNull<T2> extends true ? N
139
- : IfUnknown<T1> extends true ? Y : IfUnknown<T2> extends true ? Y
140
- : IfAny<T1> extends true ? Y : IfAny<T2> extends true ? Y
141
- : IfEmptyObject<T1> extends true ? IfObject<T2, Y, N>
142
- : IfEmptyObject<T2> extends true ? IfObject<T1, Y, N>
143
- : IfFunction<T1> extends true ? IfCompatibleFunction<T1, T2, Y, N>
144
- : IfObject<T1> extends true ? [T1] extends [T2] ? Y : N
145
- : [T1] extends [T2] ? Y
146
- : IfPrimitive<T2> extends true ? [T2] extends [T1] ? Y
147
- : N : N;
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
- IfFunction<T1> extends false ? N
151
- : IfFunction<T2> extends false ? N
152
- : T1 extends T2
153
- ? Y
154
- : N;
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: "byob" }): ReadableStreamBYOBReader;
16
+ getReader(options: { mode: 'byob' }): ReadableStreamBYOBReader;
17
17
 
18
18
  getReader(): ReadableStreamDefaultReader<R>;
19
19
 
20
- getReader(options?: ReadableStreamGetReaderOptions): ReadableStreamReader<R>;
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 = Primitive | Function | String | Number | Date | Error | RegExp |
58
- Buffer | ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray |
59
- Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array |
60
- URL | ReadableStream | WritableStream;
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<Args extends any[] = any[], Instance = {}, Static = {}> =
75
- (new(...args: Args) => Instance) & Static;
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<T extends { [P in K & any]: any },
113
- K extends keyof T | number> = T[K];
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.3.0",
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
- "test:common": "jest --clearCache && jest --config=./jest.config.js",
26
- "test:nostrict": "jest --clearCache && jest --config=./jest.nostrict.config.js",
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": "^9.0.0",
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