@oscarpalmer/atoms 0.77.0 → 0.77.2
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/js/array/chunk.cjs +1 -1
- package/dist/js/array/chunk.js +1 -1
- package/dist/js/value/equal.cjs +4 -1
- package/dist/js/value/equal.js +4 -1
- package/package.json +1 -1
- package/src/js/array/chunk.ts +1 -1
- package/src/js/array/count.ts +6 -6
- package/src/js/array/exists.ts +6 -6
- package/src/js/array/filter.ts +6 -6
- package/src/js/array/find.ts +6 -6
- package/src/js/array/group-by.ts +67 -55
- package/src/js/array/index-of.ts +6 -6
- package/src/js/array/sort.ts +20 -0
- package/src/js/array/to-map.ts +55 -47
- package/src/js/array/to-record.ts +61 -57
- package/src/js/array/unique.ts +6 -6
- package/src/js/internal/value/handle.ts +5 -5
- package/src/js/value/clone.ts +3 -1
- package/src/js/value/equal.ts +4 -1
- package/src/js/value/get.ts +9 -9
- package/src/js/value/set.ts +10 -11
- package/types/array/count.d.cts +34 -2
- package/types/array/count.d.ts +3 -3
- package/types/array/exists.d.cts +34 -2
- package/types/array/exists.d.ts +3 -3
- package/types/array/filter.d.cts +34 -2
- package/types/array/filter.d.ts +3 -3
- package/types/array/find.d.cts +34 -2
- package/types/array/find.d.ts +3 -3
- package/types/array/group-by.d.cts +44 -12
- package/types/array/group-by.d.ts +14 -14
- package/types/array/index-of.d.cts +34 -2
- package/types/array/index-of.d.ts +3 -3
- package/types/array/index.d.cts +88 -46
- package/types/array/sort.d.cts +42 -0
- package/types/array/sort.d.ts +11 -1
- package/types/array/to-map.d.cts +42 -10
- package/types/array/to-map.d.ts +13 -13
- package/types/array/to-record.d.cts +44 -12
- package/types/array/to-record.d.ts +13 -13
- package/types/array/unique.d.cts +34 -2
- package/types/array/unique.d.ts +3 -3
- package/types/index.d.cts +1034 -317
- package/types/internal/value/handle.d.cts +27 -2
- package/types/internal/value/handle.d.ts +2 -2
- package/types/models.d.cts +467 -210
- package/types/value/clone.d.cts +1 -1
- package/types/value/clone.d.ts +1 -1
- package/types/value/get.d.cts +470 -211
- package/types/value/get.d.ts +3 -3
- package/types/value/index.d.cts +515 -224
- package/types/value/set.d.cts +357 -170
- package/types/value/set.d.ts +3 -3
- package/types/value/smush.d.cts +463 -209
package/types/array/index.d.cts
CHANGED
|
@@ -1,8 +1,40 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
Represents an object with `unknown` value. You probably want this instead of `{}`.
|
|
5
|
+
|
|
6
|
+
Use case: You have an object whose keys and values are unknown to you.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {UnknownRecord} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
function toJson(object: UnknownRecord) {
|
|
13
|
+
return JSON.stringify(object);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
toJson({hello: 'world'});
|
|
17
|
+
//=> '{"hello":"world"}'
|
|
18
|
+
|
|
19
|
+
function isObject(value: unknown): value is UnknownRecord {
|
|
20
|
+
return typeof value === 'object' && value !== null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
isObject({hello: 'world'});
|
|
24
|
+
//=> true
|
|
25
|
+
|
|
26
|
+
isObject('hello');
|
|
27
|
+
//=> false
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
@category Type
|
|
31
|
+
@category Object
|
|
32
|
+
*/
|
|
33
|
+
export type UnknownRecord = Record<PropertyKey, unknown>;
|
|
3
34
|
export type KeyedValue<Item, Key extends keyof Item> = Item[Key] extends PropertyKey ? Item[Key] : never;
|
|
4
35
|
export type NestedArrayType<Value> = Value extends Array<infer NestedValue> ? NestedArrayType<NestedValue> : Value;
|
|
5
36
|
export type Key = number | string;
|
|
37
|
+
export type PlainObject = UnknownRecord;
|
|
6
38
|
/**
|
|
7
39
|
* Chunk an array _(into smaller arrays of a specified size)_
|
|
8
40
|
*/
|
|
@@ -26,11 +58,11 @@ export declare function count<Item>(array: Item[], matches: (item: Item, index:
|
|
|
26
58
|
/**
|
|
27
59
|
* Get the number of items _(count)_ that match the given value
|
|
28
60
|
*/
|
|
29
|
-
export declare function count<Item,
|
|
61
|
+
export declare function count<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
30
62
|
/**
|
|
31
63
|
* Get the number of items _(count)_ that match the given value
|
|
32
64
|
*/
|
|
33
|
-
export declare function count<Item,
|
|
65
|
+
export declare function count<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
|
|
34
66
|
/**
|
|
35
67
|
* Does the value exist in array?
|
|
36
68
|
*/
|
|
@@ -43,12 +75,12 @@ export declare function exists<Item>(array: Item[], matches: (item: Item, index:
|
|
|
43
75
|
* - Does the value exist in array?
|
|
44
76
|
* - Use `key` to find a comparison value to match with `value`
|
|
45
77
|
*/
|
|
46
|
-
export declare function exists<Item,
|
|
78
|
+
export declare function exists<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): boolean;
|
|
47
79
|
/**
|
|
48
80
|
* - Does the value exist in array?
|
|
49
81
|
* - Use `key` to find a comparison value to match with `value`
|
|
50
82
|
*/
|
|
51
|
-
export declare function exists<Item,
|
|
83
|
+
export declare function exists<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): boolean;
|
|
52
84
|
/**
|
|
53
85
|
* Get a filtered array of items matching `value`
|
|
54
86
|
*/
|
|
@@ -61,12 +93,12 @@ export declare function filter<Item>(array: Item[], matches: (item: Item, index:
|
|
|
61
93
|
* - Get a filtered array of items
|
|
62
94
|
* - Use `key` to find a comparison value to match with `value`
|
|
63
95
|
*/
|
|
64
|
-
export declare function filter<Item,
|
|
96
|
+
export declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
65
97
|
/**
|
|
66
98
|
* - Get a filtered array of items
|
|
67
99
|
* - Use `key` to find a comparison value to match with `value`
|
|
68
100
|
*/
|
|
69
|
-
export declare function filter<Item,
|
|
101
|
+
export declare function filter<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): Item[];
|
|
70
102
|
/**
|
|
71
103
|
* Get the first item matching `value` _(or `undefined` if no match is found)_
|
|
72
104
|
*/
|
|
@@ -79,60 +111,60 @@ export declare function find<Item>(array: Item[], matches: (item: Item, index: n
|
|
|
79
111
|
* - Get the first matching item _(or `undefined` if no match is found)_
|
|
80
112
|
* - Use `key` to find a comparison value to match with `value`
|
|
81
113
|
*/
|
|
82
|
-
export declare function find<Item,
|
|
114
|
+
export declare function find<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
83
115
|
/**
|
|
84
116
|
* - Get the first matching item _(or `undefined` if no match is found)_
|
|
85
117
|
* - Use `key` to find a comparison value to match with `value`
|
|
86
118
|
*/
|
|
87
|
-
export declare function find<Item,
|
|
119
|
+
export declare function find<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): Item | undefined;
|
|
88
120
|
/**
|
|
89
121
|
* Create a record from an array of items using a specific key
|
|
90
122
|
*/
|
|
91
|
-
export declare function groupBy<Item,
|
|
123
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Record<KeyedValue<Item, ItemKey>, Item>;
|
|
92
124
|
/**
|
|
93
125
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
94
126
|
*/
|
|
95
|
-
export declare function groupBy<Item,
|
|
127
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Record<KeyedValue<Item, ItemKey>, Item[]>;
|
|
96
128
|
/**
|
|
97
129
|
* Create a record from an array of items using a specific key
|
|
98
130
|
*/
|
|
99
|
-
export declare function groupBy<Item,
|
|
131
|
+
export declare function groupBy<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey): Record<ReturnType<ItemKey>, Item>;
|
|
100
132
|
/**
|
|
101
133
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
102
134
|
*/
|
|
103
|
-
export declare function groupBy<Item,
|
|
135
|
+
export declare function groupBy<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, arrays: true): Record<ReturnType<ItemKey>, Item[]>;
|
|
104
136
|
/**
|
|
105
137
|
* Create a record from an array of items using a specific key and value
|
|
106
138
|
*/
|
|
107
|
-
export declare function groupBy<Item,
|
|
139
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
108
140
|
/**
|
|
109
141
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
110
142
|
*/
|
|
111
|
-
export declare function groupBy<Item,
|
|
143
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
112
144
|
/**
|
|
113
145
|
* Create a record from an array of items using a specific key and value
|
|
114
146
|
*/
|
|
115
|
-
export declare function groupBy<Item,
|
|
147
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
|
|
116
148
|
/**
|
|
117
149
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
118
150
|
*/
|
|
119
|
-
export declare function groupBy<Item,
|
|
151
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
120
152
|
/**
|
|
121
153
|
* Create a record from an array of items using a specific key and value
|
|
122
154
|
*/
|
|
123
|
-
export declare function groupBy<Item,
|
|
155
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
124
156
|
/**
|
|
125
157
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
126
158
|
*/
|
|
127
|
-
export declare function groupBy<Item,
|
|
159
|
+
export declare function groupBy<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
128
160
|
/**
|
|
129
161
|
* Create a record from an array of items using a specific key and value
|
|
130
162
|
*/
|
|
131
|
-
export declare function groupBy<Item,
|
|
163
|
+
export declare function groupBy<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>, ReturnType<ItemValue>>;
|
|
132
164
|
/**
|
|
133
165
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
134
166
|
*/
|
|
135
|
-
export declare function groupBy<Item,
|
|
167
|
+
export declare function groupBy<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
136
168
|
/**
|
|
137
169
|
* Get the index for the first item matching `value` _(or `-1` if no match is found)_
|
|
138
170
|
*/
|
|
@@ -145,12 +177,12 @@ export declare function indexOf<Item>(array: Item[], matches: (item: Item, index
|
|
|
145
177
|
* - Get the index for the first matching item _(or `-1` if no match is found)_
|
|
146
178
|
* - Use `key` to find a comparison value to match with `value`
|
|
147
179
|
*/
|
|
148
|
-
export declare function indexOf<Item,
|
|
180
|
+
export declare function indexOf<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): number;
|
|
149
181
|
/**
|
|
150
182
|
* - Get the index for the first matching item _(or `-1` if no match is found)_
|
|
151
183
|
* - Use `key` to find a comparison value to match with `value`
|
|
152
184
|
*/
|
|
153
|
-
export declare function indexOf<Item,
|
|
185
|
+
export declare function indexOf<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, value: ReturnType<ItemKey>): number;
|
|
154
186
|
export type SortKey<Item> = {
|
|
155
187
|
direction: "asc" | "desc";
|
|
156
188
|
value: Key | ((item: Item) => Key);
|
|
@@ -178,11 +210,21 @@ export declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
|
178
210
|
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
179
211
|
*/
|
|
180
212
|
export declare function sort<Item>(array: Item[], key: Key | SortKey<Item> | ((item: Item) => Key), descending?: boolean): Item[];
|
|
213
|
+
/**
|
|
214
|
+
* - Sort an array of items, using a `key` to sort by a specific value
|
|
215
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
216
|
+
*/
|
|
217
|
+
export declare function sort<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey | Key | SortKey<Item> | ((item: Item) => Key), descending?: boolean): Item[];
|
|
181
218
|
/**
|
|
182
219
|
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
183
220
|
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
184
221
|
*/
|
|
185
222
|
export declare function sort<Item>(array: Item[], keys: Array<Key | SortKey<Item> | ((item: Item) => Key)>, descending?: boolean): Item[];
|
|
223
|
+
/**
|
|
224
|
+
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
225
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
226
|
+
*/
|
|
227
|
+
export declare function sort<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], keys: Array<ItemKey | Key | SortKey<Item> | ((item: Item) => Key)>, descending?: boolean): Item[];
|
|
186
228
|
/**
|
|
187
229
|
* Removes and returns all items from an array starting from a specific index
|
|
188
230
|
*/
|
|
@@ -208,43 +250,43 @@ export declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
208
250
|
/**
|
|
209
251
|
* Create a map from an array of items using a specific key
|
|
210
252
|
*/
|
|
211
|
-
export declare function toMap<Item,
|
|
253
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<KeyedValue<Item, ItemKey>, Item>;
|
|
212
254
|
/**
|
|
213
255
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
214
256
|
*/
|
|
215
|
-
export declare function toMap<Item,
|
|
257
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<KeyedValue<Item, ItemKey>, Item[]>;
|
|
216
258
|
/**
|
|
217
259
|
* Create a map from an array of items using a specific key
|
|
218
260
|
*/
|
|
219
|
-
export declare function toMap<Item,
|
|
261
|
+
export declare function toMap<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey): Map<ReturnType<ItemKey>, Item>;
|
|
220
262
|
/**
|
|
221
263
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
222
264
|
*/
|
|
223
|
-
export declare function toMap<Item,
|
|
265
|
+
export declare function toMap<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, arrays: true): Map<ReturnType<ItemKey>, Item[]>;
|
|
224
266
|
/**
|
|
225
267
|
* Create a map from an array of items using a specific key and value
|
|
226
268
|
*/
|
|
227
|
-
export declare function toMap<Item,
|
|
269
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
228
270
|
/**
|
|
229
271
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
230
272
|
*/
|
|
231
|
-
export declare function toMap<Item,
|
|
273
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
232
274
|
/**
|
|
233
275
|
* Create a map from an array of items using a specific key and value
|
|
234
276
|
*/
|
|
235
|
-
export declare function toMap<Item,
|
|
277
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
|
|
236
278
|
/**
|
|
237
279
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
238
280
|
*/
|
|
239
|
-
export declare function toMap<Item,
|
|
281
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
240
282
|
/**
|
|
241
283
|
* Create a map from an array of items using a specific key and value
|
|
242
284
|
*/
|
|
243
|
-
export declare function toMap<Item,
|
|
285
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
244
286
|
/**
|
|
245
287
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
246
288
|
*/
|
|
247
|
-
export declare function toMap<Item,
|
|
289
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
248
290
|
/**
|
|
249
291
|
* Create a map from an array of items using a specific key and value
|
|
250
292
|
*/
|
|
@@ -260,51 +302,51 @@ export declare function toRecord<Item>(array: Item[]): Record<number, Item>;
|
|
|
260
302
|
/**
|
|
261
303
|
* Create a record from an array of items using a specific key
|
|
262
304
|
*/
|
|
263
|
-
export declare function toRecord<Item,
|
|
305
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Record<KeyedValue<Item, ItemKey>, Item>;
|
|
264
306
|
/**
|
|
265
307
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
266
308
|
*/
|
|
267
|
-
export declare function toRecord<Item,
|
|
309
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Record<KeyedValue<Item, ItemKey>, Item[]>;
|
|
268
310
|
/**
|
|
269
311
|
* Create a record from an array of items using a specific key
|
|
270
312
|
*/
|
|
271
|
-
export declare function toRecord<Item,
|
|
313
|
+
export declare function toRecord<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey): Record<ReturnType<ItemKey>, Item>;
|
|
272
314
|
/**
|
|
273
315
|
* Create a record from an array of items using a specific key, and grouping them into arrays
|
|
274
316
|
*/
|
|
275
|
-
export declare function toRecord<Item,
|
|
317
|
+
export declare function toRecord<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, arrays: true): Record<ReturnType<ItemKey>, Item[]>;
|
|
276
318
|
/**
|
|
277
319
|
* Create a record from an array of items using a specific key and value
|
|
278
320
|
*/
|
|
279
|
-
export declare function toRecord<Item,
|
|
321
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
280
322
|
/**
|
|
281
323
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
282
324
|
*/
|
|
283
|
-
export declare function toRecord<Item,
|
|
325
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
284
326
|
/**
|
|
285
327
|
* Create a record from an array of items using a specific key and value
|
|
286
328
|
*/
|
|
287
|
-
export declare function toRecord<Item,
|
|
329
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Record<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
|
|
288
330
|
/**
|
|
289
331
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
290
332
|
*/
|
|
291
|
-
export declare function toRecord<Item,
|
|
333
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
292
334
|
/**
|
|
293
335
|
* Create a record from an array of items using a specific key and value
|
|
294
336
|
*/
|
|
295
|
-
export declare function toRecord<Item,
|
|
337
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
296
338
|
/**
|
|
297
339
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
298
340
|
*/
|
|
299
|
-
export declare function toRecord<Item,
|
|
341
|
+
export declare function toRecord<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
300
342
|
/**
|
|
301
343
|
* Create a record from an array of items using a specific key and value
|
|
302
344
|
*/
|
|
303
|
-
export declare function toRecord<Item,
|
|
345
|
+
export declare function toRecord<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Record<ReturnType<ItemKey>, ReturnType<ItemValue>>;
|
|
304
346
|
/**
|
|
305
347
|
* Create a record from an array of items using a specific key and value, and grouping them into arrays
|
|
306
348
|
*/
|
|
307
|
-
export declare function toRecord<Item,
|
|
349
|
+
export declare function toRecord<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Record<ReturnType<ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
308
350
|
/**
|
|
309
351
|
* Get an array of unique items
|
|
310
352
|
*/
|
|
@@ -313,12 +355,12 @@ export declare function unique<Item>(array: Item[]): Item[];
|
|
|
313
355
|
* - Get an array of unique items
|
|
314
356
|
* - Use `key` to find a comparison value for an item
|
|
315
357
|
*/
|
|
316
|
-
export declare function unique<Item,
|
|
358
|
+
export declare function unique<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Item[];
|
|
317
359
|
/**
|
|
318
360
|
* - Get an array of unique items
|
|
319
361
|
* - Use `key` to find a comparison value for an item
|
|
320
362
|
*/
|
|
321
|
-
export declare function unique<Item,
|
|
363
|
+
export declare function unique<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey): Item[];
|
|
322
364
|
/**
|
|
323
365
|
* Flatten an array _(using native `flat` and maximum depth)_
|
|
324
366
|
*/
|
package/types/array/sort.d.cts
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
Represents an object with `unknown` value. You probably want this instead of `{}`.
|
|
5
|
+
|
|
6
|
+
Use case: You have an object whose keys and values are unknown to you.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {UnknownRecord} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
function toJson(object: UnknownRecord) {
|
|
13
|
+
return JSON.stringify(object);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
toJson({hello: 'world'});
|
|
17
|
+
//=> '{"hello":"world"}'
|
|
18
|
+
|
|
19
|
+
function isObject(value: unknown): value is UnknownRecord {
|
|
20
|
+
return typeof value === 'object' && value !== null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
isObject({hello: 'world'});
|
|
24
|
+
//=> true
|
|
25
|
+
|
|
26
|
+
isObject('hello');
|
|
27
|
+
//=> false
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
@category Type
|
|
31
|
+
@category Object
|
|
32
|
+
*/
|
|
33
|
+
export type UnknownRecord = Record<PropertyKey, unknown>;
|
|
3
34
|
export type Key = number | string;
|
|
35
|
+
export type PlainObject = UnknownRecord;
|
|
4
36
|
export type SortKey<Item> = {
|
|
5
37
|
direction: "asc" | "desc";
|
|
6
38
|
value: Key | ((item: Item) => Key);
|
|
@@ -14,10 +46,20 @@ export declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
|
14
46
|
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
15
47
|
*/
|
|
16
48
|
export declare function sort<Item>(array: Item[], key: Key | SortKey<Item> | ((item: Item) => Key), descending?: boolean): Item[];
|
|
49
|
+
/**
|
|
50
|
+
* - Sort an array of items, using a `key` to sort by a specific value
|
|
51
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
52
|
+
*/
|
|
53
|
+
export declare function sort<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey | Key | SortKey<Item> | ((item: Item) => Key), descending?: boolean): Item[];
|
|
17
54
|
/**
|
|
18
55
|
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
19
56
|
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
20
57
|
*/
|
|
21
58
|
export declare function sort<Item>(array: Item[], keys: Array<Key | SortKey<Item> | ((item: Item) => Key)>, descending?: boolean): Item[];
|
|
59
|
+
/**
|
|
60
|
+
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
61
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
62
|
+
*/
|
|
63
|
+
export declare function sort<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], keys: Array<ItemKey | Key | SortKey<Item> | ((item: Item) => Key)>, descending?: boolean): Item[];
|
|
22
64
|
|
|
23
65
|
export {};
|
package/types/array/sort.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SortKey } from '~/array/models';
|
|
2
|
-
import type { Key } from '~/models';
|
|
2
|
+
import type { Key, PlainObject } from '~/models';
|
|
3
3
|
/**
|
|
4
4
|
* Sort an array of items _(defaults to ascending)_
|
|
5
5
|
*/
|
|
@@ -9,8 +9,18 @@ export declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
|
9
9
|
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
10
10
|
*/
|
|
11
11
|
export declare function sort<Item>(array: Item[], key: Key | SortKey<Item> | ((item: Item) => Key), descending?: boolean): Item[];
|
|
12
|
+
/**
|
|
13
|
+
* - Sort an array of items, using a `key` to sort by a specific value
|
|
14
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using a `SortKey`
|
|
15
|
+
*/
|
|
16
|
+
export declare function sort<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey | Key | SortKey<Item> | ((item: Item) => Key), descending?: boolean): Item[];
|
|
12
17
|
/**
|
|
13
18
|
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
14
19
|
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
15
20
|
*/
|
|
16
21
|
export declare function sort<Item>(array: Item[], keys: Array<Key | SortKey<Item> | ((item: Item) => Key)>, descending?: boolean): Item[];
|
|
22
|
+
/**
|
|
23
|
+
* - Sort an array of items, using multiple `keys` to sort by specific values
|
|
24
|
+
* - Defaults to ascending, but can be changed by setting `descending` to `true`, or using `SortKey`
|
|
25
|
+
*/
|
|
26
|
+
export declare function sort<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], keys: Array<ItemKey | Key | SortKey<Item> | ((item: Item) => Key)>, descending?: boolean): Item[];
|
package/types/array/to-map.d.cts
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v9.5.1
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
Represents an object with `unknown` value. You probably want this instead of `{}`.
|
|
5
|
+
|
|
6
|
+
Use case: You have an object whose keys and values are unknown to you.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {UnknownRecord} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
function toJson(object: UnknownRecord) {
|
|
13
|
+
return JSON.stringify(object);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
toJson({hello: 'world'});
|
|
17
|
+
//=> '{"hello":"world"}'
|
|
18
|
+
|
|
19
|
+
function isObject(value: unknown): value is UnknownRecord {
|
|
20
|
+
return typeof value === 'object' && value !== null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
isObject({hello: 'world'});
|
|
24
|
+
//=> true
|
|
25
|
+
|
|
26
|
+
isObject('hello');
|
|
27
|
+
//=> false
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
@category Type
|
|
31
|
+
@category Object
|
|
32
|
+
*/
|
|
33
|
+
export type UnknownRecord = Record<PropertyKey, unknown>;
|
|
3
34
|
export type KeyedValue<Item, Key extends keyof Item> = Item[Key] extends PropertyKey ? Item[Key] : never;
|
|
4
35
|
export type Key = number | string;
|
|
36
|
+
export type PlainObject = UnknownRecord;
|
|
5
37
|
/**
|
|
6
38
|
* Create a map from an array of items _(using their indices as keys)_
|
|
7
39
|
*/
|
|
@@ -9,43 +41,43 @@ export declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
9
41
|
/**
|
|
10
42
|
* Create a map from an array of items using a specific key
|
|
11
43
|
*/
|
|
12
|
-
export declare function toMap<Item,
|
|
44
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<KeyedValue<Item, ItemKey>, Item>;
|
|
13
45
|
/**
|
|
14
46
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
15
47
|
*/
|
|
16
|
-
export declare function toMap<Item,
|
|
48
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<KeyedValue<Item, ItemKey>, Item[]>;
|
|
17
49
|
/**
|
|
18
50
|
* Create a map from an array of items using a specific key
|
|
19
51
|
*/
|
|
20
|
-
export declare function toMap<Item,
|
|
52
|
+
export declare function toMap<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey): Map<ReturnType<ItemKey>, Item>;
|
|
21
53
|
/**
|
|
22
54
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
23
55
|
*/
|
|
24
|
-
export declare function toMap<Item,
|
|
56
|
+
export declare function toMap<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, arrays: true): Map<ReturnType<ItemKey>, Item[]>;
|
|
25
57
|
/**
|
|
26
58
|
* Create a map from an array of items using a specific key and value
|
|
27
59
|
*/
|
|
28
|
-
export declare function toMap<Item,
|
|
60
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
29
61
|
/**
|
|
30
62
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
31
63
|
*/
|
|
32
|
-
export declare function toMap<Item,
|
|
64
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
33
65
|
/**
|
|
34
66
|
* Create a map from an array of items using a specific key and value
|
|
35
67
|
*/
|
|
36
|
-
export declare function toMap<Item,
|
|
68
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
|
|
37
69
|
/**
|
|
38
70
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
39
71
|
*/
|
|
40
|
-
export declare function toMap<Item,
|
|
72
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
41
73
|
/**
|
|
42
74
|
* Create a map from an array of items using a specific key and value
|
|
43
75
|
*/
|
|
44
|
-
export declare function toMap<Item,
|
|
76
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
45
77
|
/**
|
|
46
78
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
47
79
|
*/
|
|
48
|
-
export declare function toMap<Item,
|
|
80
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
49
81
|
/**
|
|
50
82
|
* Create a map from an array of items using a specific key and value
|
|
51
83
|
*/
|
package/types/array/to-map.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { KeyedValue,
|
|
1
|
+
import type { Key, KeyedValue, PlainObject } from '~/models';
|
|
2
2
|
/**
|
|
3
3
|
* Create a map from an array of items _(using their indices as keys)_
|
|
4
4
|
*/
|
|
@@ -6,48 +6,48 @@ export declare function toMap<Item>(array: Item[]): Map<number, Item>;
|
|
|
6
6
|
/**
|
|
7
7
|
* Create a map from an array of items using a specific key
|
|
8
8
|
*/
|
|
9
|
-
export declare function toMap<Item,
|
|
9
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Map<KeyedValue<Item, ItemKey>, Item>;
|
|
10
10
|
/**
|
|
11
11
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
12
12
|
*/
|
|
13
|
-
export declare function toMap<Item,
|
|
13
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, arrays: true): Map<KeyedValue<Item, ItemKey>, Item[]>;
|
|
14
14
|
/**
|
|
15
15
|
* Create a map from an array of items using a specific key
|
|
16
16
|
*/
|
|
17
|
-
export declare function toMap<Item,
|
|
17
|
+
export declare function toMap<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey): Map<ReturnType<ItemKey>, Item>;
|
|
18
18
|
/**
|
|
19
19
|
* Create a map from an array of items using a specific key, and grouping them into arrays
|
|
20
20
|
*/
|
|
21
|
-
export declare function toMap<Item,
|
|
21
|
+
export declare function toMap<Item, ItemKey extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], key: ItemKey, arrays: true): Map<ReturnType<ItemKey>, Item[]>;
|
|
22
22
|
/**
|
|
23
23
|
* Create a map from an array of items using a specific key and value
|
|
24
24
|
*/
|
|
25
|
-
export declare function toMap<Item,
|
|
25
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<KeyedValue<Item, ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
26
26
|
/**
|
|
27
27
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
28
28
|
*/
|
|
29
|
-
export declare function toMap<Item,
|
|
29
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<KeyedValue<Item, ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
30
30
|
/**
|
|
31
31
|
* Create a map from an array of items using a specific key and value
|
|
32
32
|
*/
|
|
33
|
-
export declare function toMap<Item,
|
|
33
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue): Map<KeyedValue<Item, ItemKey>, ReturnType<ItemValue>>;
|
|
34
34
|
/**
|
|
35
35
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
36
36
|
*/
|
|
37
|
-
export declare function toMap<Item,
|
|
37
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<KeyedValue<Item, ItemKey>, Array<ReturnType<ItemValue>>>;
|
|
38
38
|
/**
|
|
39
39
|
* Create a map from an array of items using a specific key and value
|
|
40
40
|
*/
|
|
41
|
-
export declare function toMap<Item,
|
|
41
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Map<ReturnType<ItemKey>, KeyedValue<Item, ItemValue>>;
|
|
42
42
|
/**
|
|
43
43
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
44
44
|
*/
|
|
45
|
-
export declare function toMap<Item,
|
|
45
|
+
export declare function toMap<Item extends PlainObject, ItemKey extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue, arrays: true): Map<ReturnType<ItemKey>, Array<KeyedValue<Item, ItemValue>>>;
|
|
46
46
|
/**
|
|
47
47
|
* Create a map from an array of items using a specific key and value
|
|
48
48
|
*/
|
|
49
|
-
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) =>
|
|
49
|
+
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value): Map<ReturnType<Key>, ReturnType<Value>>;
|
|
50
50
|
/**
|
|
51
51
|
* Create a map from an array of items using a specific key and value, and grouping them into arrays
|
|
52
52
|
*/
|
|
53
|
-
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) =>
|
|
53
|
+
export declare function toMap<Item, Key extends (item: Item, index: number, array: Item[]) => Key, Value extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: Key, value: Value, arrays: true): Map<ReturnType<Key>, Array<ReturnType<Value>>>;
|