danholibraryjs 2.0.2 → 2.0.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/dist/Extensions/Object/extracts.extension.js +6 -2
- package/dist/Extensions/Object/properties.extension.js +1 -1
- package/dist/Extensions/String/case.extension.d.ts +1 -1
- package/dist/Extensions/String/case.extension.js +4 -1
- package/docs/Classes.md +467 -467
- package/docs/Extensions.md +197 -197
- package/docs/Interfaces.md +12 -12
- package/docs/Types.md +23 -23
- package/docs/Utils.md +75 -75
- package/package.json +1 -1
- package/src/Extensions/Object/extracts.extension.ts +6 -2
- package/src/Extensions/Object/properties.extension.ts +1 -1
- package/src/Extensions/String/case.extension.ts +13 -9
package/docs/Extensions.md
CHANGED
|
@@ -10,89 +10,89 @@ Extensions add new methods to native JavaScript types and interfaces.
|
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
interface Array<T> {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Pushes items to array and returns self with new items
|
|
15
|
+
* @param items Items to add to array
|
|
16
|
+
*/
|
|
17
|
+
add(...items: Array<T>): this;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Update an item in array
|
|
21
|
+
* @param old The old value, index, or finder function to locate item to update
|
|
22
|
+
* @param updated Updated value
|
|
23
|
+
*/
|
|
24
|
+
update(old: T | number | ((item: T, index: number, self: Array<T>) => boolean), updated: T): T;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Removes item from array and returns self without item
|
|
28
|
+
* @param item Item or index to remove
|
|
29
|
+
*/
|
|
30
|
+
remove(item: T | number): Array<T>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns a random element from array
|
|
34
|
+
*/
|
|
35
|
+
random(): T;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Shuffles array in random order
|
|
39
|
+
*/
|
|
40
|
+
shuffle(): Array<T>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the first `count` elements from the array
|
|
44
|
+
* @param count Number of elements to take
|
|
45
|
+
*/
|
|
46
|
+
take(count: number): Array<T>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns a new array with only unique elements
|
|
50
|
+
*/
|
|
51
|
+
unique(): Array<T>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Splits the array into chunks of a specified size or by a splitter function
|
|
55
|
+
* @param chunkSizeOrSplitter The size of each chunk or a function that determines where to split
|
|
56
|
+
*/
|
|
57
|
+
splitBy(chunkSizeOrSplitter: number | ((value: T, index: number, array: Array<T>) => boolean)): Array<Array<T>>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Groups elements based on a key selector function
|
|
61
|
+
* @param keySelector A function that selects a key for each element
|
|
62
|
+
*/
|
|
63
|
+
groupBy<K>(keySelector: (value: T, index: number, array: Array<T>) => K): Map<K, Array<T>>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* For every nth element in array, execute callback
|
|
67
|
+
* @param every Execute callback every nth element
|
|
68
|
+
* @param callback Function to execute
|
|
69
|
+
*/
|
|
70
|
+
nth<U>(every: number, callback: (collection: Array<T>, index: number, self: this) => U): Array<U>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Joins array elements with a separator, and a different separator before the last element
|
|
74
|
+
* @param separator Separator between elements (default: ',')
|
|
75
|
+
* @param endSeparator Separator before last element (default: '&')
|
|
76
|
+
*/
|
|
77
|
+
join(separator?: string, endSeparator?: string): string;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Orders array by comparators in ascending order
|
|
81
|
+
* @param comparators Comparison functions
|
|
82
|
+
*/
|
|
83
|
+
orderBy(...comparators: Array<(a: T, b: T) => number>): Array<T>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Orders array by comparators in descending order
|
|
87
|
+
* @param comparators Comparison functions
|
|
88
|
+
*/
|
|
89
|
+
orderByDescending(...comparators: Array<(a: T, b: T) => number>): Array<T>;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Sorts array by object properties
|
|
93
|
+
* @param properties Properties to sort by
|
|
94
|
+
*/
|
|
95
|
+
sortByProperty(...properties: Array<keyof T>): Array<T>;
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
@@ -100,11 +100,11 @@ interface Array<T> {
|
|
|
100
100
|
|
|
101
101
|
```ts
|
|
102
102
|
interface ArrayConstructor {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Forces an arrayable object into an array
|
|
105
|
+
* @param arrayable The value or array to normalize
|
|
106
|
+
*/
|
|
107
|
+
forceArray<T>(arrayable: T | Array<T>): Array<T>;
|
|
108
108
|
}
|
|
109
109
|
```
|
|
110
110
|
|
|
@@ -134,45 +134,45 @@ function forceFunction<T, TArgs extends any[] = any[]>(functionable: T | ((...ar
|
|
|
134
134
|
|
|
135
135
|
```ts
|
|
136
136
|
interface Map<K, V> {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Converts map into Array<[Key, Value]>
|
|
139
|
+
*/
|
|
140
|
+
array(): Array<[K, V]>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Maps values into new types
|
|
144
|
+
* @param callback Mapping function
|
|
145
|
+
*/
|
|
146
|
+
map<EK, EV>(callback: (value: V, key: K, index: number, self: this) => [EK, EV]): Map<EK, EV>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Filters map entries
|
|
150
|
+
* @param callback Filter function
|
|
151
|
+
*/
|
|
152
|
+
filter(callback: (value: V, key: K, index: number, self: this) => boolean): Map<K, V>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Returns array of keys
|
|
156
|
+
*/
|
|
157
|
+
keyArr(): Array<K>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Returns array of values
|
|
161
|
+
*/
|
|
162
|
+
valueArr(): Array<V>;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Finds first entry matching callback
|
|
166
|
+
* @param callback Find function
|
|
167
|
+
*/
|
|
168
|
+
find(callback: (value: V, key: K, index: number, self: this) => boolean): [K, V] | undefined;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Checks if map includes a value
|
|
172
|
+
* @param value Value to search for
|
|
173
|
+
* @param fromIndex Start looking from specific index
|
|
174
|
+
*/
|
|
175
|
+
includes(value: V, fromIndex?: number): boolean;
|
|
176
176
|
}
|
|
177
177
|
```
|
|
178
178
|
|
|
@@ -180,16 +180,16 @@ interface Map<K, V> {
|
|
|
180
180
|
|
|
181
181
|
```ts
|
|
182
182
|
interface Number {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
183
|
+
/**
|
|
184
|
+
* Formats number with thousand and decimal separators
|
|
185
|
+
* @param separators Custom separators for thousand and decimal (optional)
|
|
186
|
+
*/
|
|
187
|
+
toSeparationString(separators?: Partial<{ thousand: string; decimal: string }>): string;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Converts number to Roman numeral (1-3999)
|
|
191
|
+
*/
|
|
192
|
+
toRomanNumeral(): string;
|
|
193
193
|
}
|
|
194
194
|
```
|
|
195
195
|
|
|
@@ -199,53 +199,53 @@ interface Number {
|
|
|
199
199
|
|
|
200
200
|
```ts
|
|
201
201
|
interface ObjectConstructor {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
202
|
+
/**
|
|
203
|
+
* Destructures object into array of [property, value]
|
|
204
|
+
* @param from Object to destruct
|
|
205
|
+
*/
|
|
206
|
+
array<From extends {} = {}>(from: From): Array<[keyof From, ValueOf<From>]>;
|
|
207
|
+
/**
|
|
208
|
+
* Destructures object into array of property keys or values depending on selector
|
|
209
|
+
* @param from Object to destruct
|
|
210
|
+
* @param selector Selects whether to return keys or values
|
|
211
|
+
*/
|
|
212
|
+
array<From extends {} = {}>(from: From, selector: 'keys'): Array<keyof From>;
|
|
213
|
+
/**
|
|
214
|
+
* Destructures object into array of property keys or values depending on selector
|
|
215
|
+
* @param from Object to destruct
|
|
216
|
+
* @param selector Selects whether to return keys or values
|
|
217
|
+
*/
|
|
218
|
+
array<From extends {} = {}>(from: From, selector: 'values'): Array<ValueOf<From>>;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Returns array of object keys with proper typing
|
|
222
|
+
* @param from Object to get keys from
|
|
223
|
+
*/
|
|
224
|
+
keysOf<From = {}>(from: From): Array<keyof From>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Object with property filter methods by type
|
|
228
|
+
* Methods: getStrings, getNumbers, getBooleans, getUndefineds, getNulls,
|
|
229
|
+
* getObjects, getFunctions, getAnys, getDates, getRegExps,
|
|
230
|
+
* getPromises, getArrays, getMaps, getSets
|
|
231
|
+
* @example Object.properties.getStrings(obj) // Returns object with only string properties
|
|
232
|
+
*/
|
|
233
|
+
properties: {
|
|
234
|
+
getStrings<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
235
|
+
getNumbers<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
236
|
+
getBooleans<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
237
|
+
getUndefineds<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
238
|
+
getNulls<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
239
|
+
getObjects<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
240
|
+
getFunctions<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
241
|
+
getAnys<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
242
|
+
getDates<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
243
|
+
getRegExps<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
244
|
+
getPromises<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
245
|
+
getArrays<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
246
|
+
getMaps<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
247
|
+
getSets<Source extends {}, AllowFunctions extends boolean = false>(source: Source, withFunctions?: AllowFunctions): Partial<Source>;
|
|
248
|
+
};
|
|
249
249
|
}
|
|
250
250
|
```
|
|
251
251
|
|
|
@@ -298,19 +298,19 @@ function isNullOrUndefined(obj: any): obj is null | undefined;
|
|
|
298
298
|
|
|
299
299
|
```ts
|
|
300
300
|
interface String {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
301
|
+
/**
|
|
302
|
+
* Converts string from one case to another
|
|
303
|
+
* @param from Case to convert from ('camel' | 'pascal' | 'snake' | 'kebab' | 'lower' | 'upper')
|
|
304
|
+
* @param to Cases to convert to, can chain multiple conversions
|
|
305
|
+
*/
|
|
306
|
+
convertCase(from: Case, ...to: Array<Case>): string;
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Truncates string to specified length with optional ellipsis
|
|
310
|
+
* @param length Maximum length of string
|
|
311
|
+
* @param ellipsis String to append if truncated (default: '...')
|
|
312
|
+
*/
|
|
313
|
+
truncate(length: number, ellipsis?: string): string;
|
|
314
314
|
}
|
|
315
315
|
```
|
|
316
316
|
|
package/docs/Interfaces.md
CHANGED
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
* @borrows Arrayable
|
|
11
11
|
*/
|
|
12
12
|
interface ElementOptions<K extends keyof HTMLElementTagNameMap> {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
/**css classes to give the element*/
|
|
14
|
+
classes?: Array<string>;
|
|
15
|
+
/**attributes to give the element*/
|
|
16
|
+
attributes?: Array<[string, string]>;
|
|
17
|
+
/**Children of the element*/
|
|
18
|
+
children?: Arrayable<IElement>;
|
|
19
|
+
/**Events for the element to listen to
|
|
20
|
+
* @use HTMLEvent<Event, RetrunType>(name: Event, handler: (e: Event) => ReturnType)
|
|
21
|
+
*/
|
|
22
|
+
events?: Array<{ name: string, handler: (e: Event) => any }>
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Replacement tool for
|
|
@@ -28,7 +28,7 @@ interface ElementOptions<K extends keyof HTMLElementTagNameMap> {
|
|
|
28
28
|
* @borrows StringRegex
|
|
29
29
|
*/
|
|
30
30
|
interface IReplacement {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
replacer?: StringRegex,
|
|
32
|
+
replacement?: string
|
|
33
33
|
}
|
|
34
34
|
```
|
package/docs/Types.md
CHANGED
|
@@ -164,9 +164,9 @@ type BaseEvent<Keys extends string, Types extends Array<any>> = Record<Keys, Typ
|
|
|
164
164
|
* Event handler type
|
|
165
165
|
*/
|
|
166
166
|
type EventHandler<
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
167
|
+
Events extends BaseEvent<string, Array<any>> = BaseEvent<string, Array<any>>,
|
|
168
|
+
Event extends keyof Events = keyof Events,
|
|
169
|
+
ReturnType = any
|
|
170
170
|
> = (...args: Events[Event]) => ReturnType;
|
|
171
171
|
```
|
|
172
172
|
|
|
@@ -177,13 +177,13 @@ type EventHandler<
|
|
|
177
177
|
* Changes return type of a function
|
|
178
178
|
*/
|
|
179
179
|
type NewReturnType<Func extends (...args: any[]) => any, NewReturn> =
|
|
180
|
-
|
|
180
|
+
Func extends (...args: infer Args) => any ? (...args: Args) => NewReturn : never;
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
183
|
* Wraps function return type in Promise
|
|
184
184
|
*/
|
|
185
185
|
type PromisedReturn<Func extends (...args: any[]) => any> =
|
|
186
|
-
|
|
186
|
+
Func extends (...args: infer Args) => infer Return ? (...args: Args) => Promise<Return> : never;
|
|
187
187
|
|
|
188
188
|
/**
|
|
189
189
|
* Removes all function properties from type
|
|
@@ -198,7 +198,7 @@ type NoFunctions<T> = { [K in keyof T]: T[K] extends Function ? never : T[K] };
|
|
|
198
198
|
* Type's properties are all ReturnType
|
|
199
199
|
*/
|
|
200
200
|
type AllPropsAre<ReturnType> = {
|
|
201
|
-
|
|
201
|
+
[key: string]: ReturnType;
|
|
202
202
|
};
|
|
203
203
|
```
|
|
204
204
|
|
|
@@ -209,25 +209,25 @@ type AllPropsAre<ReturnType> = {
|
|
|
209
209
|
* Filters all properties from From that have the return type of Type
|
|
210
210
|
*/
|
|
211
211
|
type PropertiesWith<Type, From> = {
|
|
212
|
-
|
|
212
|
+
[Key in keyof From as From[Key] extends Type ? Key : never]: From[Key];
|
|
213
213
|
};
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
216
|
* Filters all properties from From that don't have the return type of Type
|
|
217
217
|
*/
|
|
218
218
|
type PropertiesWithout<Type, From> = {
|
|
219
|
-
|
|
219
|
+
[Key in keyof From as From[Key] extends Type ? never : Key]: From[Key];
|
|
220
220
|
};
|
|
221
221
|
|
|
222
222
|
/**
|
|
223
223
|
* Gets keys that appear in all types in the array
|
|
224
224
|
*/
|
|
225
225
|
type GetRepeatedKeys<Types extends Array<any>> =
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
226
|
+
Types extends [infer First, ...infer Rest]
|
|
227
|
+
? Rest extends Array<any>
|
|
228
|
+
? keyof First & GetRepeatedKeys<Rest>
|
|
229
|
+
: keyof First
|
|
230
|
+
: never;
|
|
231
231
|
|
|
232
232
|
/**
|
|
233
233
|
* Filters types that have specific properties
|
|
@@ -251,27 +251,27 @@ type Autocomplete<T> = T | (string & {});
|
|
|
251
251
|
* Converts Start types to Switch types in From type
|
|
252
252
|
*/
|
|
253
253
|
type TransformType<From, Start, Switch> = {
|
|
254
|
-
|
|
254
|
+
[Key in keyof From]: From[Key] extends Start ? Switch : From[Key];
|
|
255
255
|
};
|
|
256
256
|
|
|
257
257
|
/**
|
|
258
258
|
* Returns object with properties matching BaseType with types of NewType
|
|
259
259
|
*/
|
|
260
260
|
type TransformTypes<From, BaseType, NewType> = Record<keyof {
|
|
261
|
-
|
|
261
|
+
[Key in keyof From as From[Key] extends BaseType ? Key : never]: Key;
|
|
262
262
|
}, NewType>;
|
|
263
263
|
|
|
264
264
|
/**
|
|
265
265
|
* Converts object to JSON-serializable type (removes functions, Date -> string, etc.)
|
|
266
266
|
*/
|
|
267
267
|
type Json<T> = {
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
268
|
+
[K in keyof T]: T[K] extends Function
|
|
269
|
+
? never
|
|
270
|
+
: T[K] extends Date
|
|
271
|
+
? string
|
|
272
|
+
: T[K] extends object
|
|
273
|
+
? Json<T[K]>
|
|
274
|
+
: T[K];
|
|
275
275
|
};
|
|
276
276
|
```
|
|
277
277
|
|
|
@@ -282,5 +282,5 @@ type Json<T> = {
|
|
|
282
282
|
* Reducer function for Store state updates
|
|
283
283
|
*/
|
|
284
284
|
type Reducer<State, Types extends Record<string, any[]>, Action extends keyof Types> =
|
|
285
|
-
|
|
285
|
+
(state: State, ...args: Types[Action]) => State;
|
|
286
286
|
```
|