@oscarpalmer/atoms 0.184.2 → 0.186.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/dist/array/difference.d.mts +29 -0
- package/dist/array/exists.d.mts +35 -0
- package/dist/array/filter.d.mts +72 -2
- package/dist/array/find.d.mts +70 -0
- package/dist/array/first.d.mts +77 -2
- package/dist/array/flatten.d.mts +6 -0
- package/dist/array/flatten.mjs +6 -0
- package/dist/array/from.d.mts +36 -0
- package/dist/array/get.d.mts +21 -13
- package/dist/array/group-by.d.mts +142 -0
- package/dist/array/index.d.mts +2 -2
- package/dist/array/index.mjs +2 -2
- package/dist/array/insert.d.mts +16 -0
- package/dist/array/intersection.d.mts +29 -0
- package/dist/array/last.d.mts +75 -2
- package/dist/array/{position.d.mts → match.d.mts} +168 -36
- package/dist/array/{position.mjs → match.mjs} +16 -16
- package/dist/array/move.d.mts +78 -8
- package/dist/array/move.mjs +11 -1
- package/dist/array/partition.d.mts +35 -0
- package/dist/array/push.d.mts +8 -0
- package/dist/array/push.mjs +8 -0
- package/dist/array/reverse.d.mts +1 -0
- package/dist/array/reverse.mjs +1 -0
- package/dist/array/select.d.mts +94 -8
- package/dist/array/single.d.mts +29 -0
- package/dist/array/slice.d.mts +106 -16
- package/dist/array/sort.d.mts +30 -4
- package/dist/array/sort.mjs +1 -1
- package/dist/array/splice.d.mts +48 -0
- package/dist/array/splice.mjs +2 -1
- package/dist/array/swap.d.mts +113 -8
- package/dist/array/swap.mjs +2 -1
- package/dist/array/to-map.d.mts +124 -0
- package/dist/array/to-record.d.mts +124 -0
- package/dist/array/to-set.d.mts +24 -0
- package/dist/array/toggle.d.mts +38 -3
- package/dist/array/union.d.mts +29 -0
- package/dist/array/unique.d.mts +24 -0
- package/dist/array/update.d.mts +38 -3
- package/dist/beacon.d.mts +12 -0
- package/dist/beacon.mjs +9 -0
- package/dist/color/instance.d.mts +8 -0
- package/dist/color/instance.mjs +3 -0
- package/dist/color/models.d.mts +30 -0
- package/dist/function/assert.d.mts +29 -8
- package/dist/function/assert.mjs +29 -8
- package/dist/function/memoize.d.mts +3 -0
- package/dist/function/memoize.mjs +3 -0
- package/dist/function/retry.d.mts +3 -0
- package/dist/function/retry.mjs +3 -0
- package/dist/function/work.mjs +1 -1
- package/dist/index.d.mts +2158 -288
- package/dist/index.mjs +294 -181
- package/dist/internal/array/chunk.d.mts +6 -0
- package/dist/internal/array/chunk.mjs +6 -0
- package/dist/internal/array/compact.d.mts +12 -0
- package/dist/internal/array/index-of.d.mts +70 -0
- package/dist/internal/math/aggregate.d.mts +29 -0
- package/dist/internal/value/compare.d.mts +2 -1
- package/dist/internal/value/equal.d.mts +5 -0
- package/dist/internal/value/get.d.mts +27 -5
- package/dist/internal/value/has.d.mts +7 -7
- package/dist/internal/value/has.mjs +1 -1
- package/dist/internal/value/misc.d.mts +2 -2
- package/dist/internal/value/misc.mjs +10 -4
- package/dist/logger.d.mts +11 -0
- package/dist/logger.mjs +11 -0
- package/dist/models.d.mts +14 -1
- package/dist/promise/helpers.mjs +1 -1
- package/dist/promise/index.d.mts +0 -6
- package/dist/promise/models.d.mts +36 -0
- package/dist/promise/models.mjs +6 -0
- package/dist/queue.d.mts +13 -1
- package/dist/queue.mjs +9 -0
- package/dist/result/index.d.mts +0 -8
- package/dist/result/index.mjs +0 -8
- package/dist/result/match.d.mts +4 -4
- package/dist/result/work/flow.d.mts +12 -36
- package/dist/result/work/pipe.d.mts +11 -33
- package/dist/sized/set.d.mts +3 -2
- package/dist/sized/set.mjs +3 -2
- package/dist/value/collection.d.mts +1 -1
- package/dist/value/handle.mjs +1 -1
- package/dist/value/merge.d.mts +28 -25
- package/dist/value/merge.mjs +29 -18
- package/dist/value/shake.d.mts +3 -0
- package/dist/value/smush.d.mts +3 -0
- package/dist/value/transform.d.mts +10 -1
- package/dist/value/unsmush.d.mts +2 -3
- package/package.json +5 -5
- package/src/array/difference.ts +33 -0
- package/src/array/exists.ts +35 -0
- package/src/array/filter.ts +72 -2
- package/src/array/find.ts +70 -0
- package/src/array/first.ts +77 -3
- package/src/array/flatten.ts +6 -0
- package/src/array/from.ts +40 -0
- package/src/array/get.ts +21 -15
- package/src/array/group-by.ts +142 -0
- package/src/array/index.ts +1 -1
- package/src/array/insert.ts +16 -2
- package/src/array/intersection.ts +33 -0
- package/src/array/last.ts +75 -2
- package/src/array/{position.ts → match.ts} +197 -65
- package/src/array/move.ts +87 -13
- package/src/array/partition.ts +35 -0
- package/src/array/push.ts +8 -2
- package/src/array/reverse.ts +5 -0
- package/src/array/select.ts +96 -13
- package/src/array/single.ts +29 -0
- package/src/array/slice.ts +114 -24
- package/src/array/sort.ts +30 -4
- package/src/array/splice.ts +52 -4
- package/src/array/swap.ts +122 -13
- package/src/array/to-map.ts +124 -0
- package/src/array/to-record.ts +124 -0
- package/src/array/to-set.ts +24 -0
- package/src/array/toggle.ts +42 -3
- package/src/array/union.ts +33 -0
- package/src/array/unique.ts +24 -0
- package/src/array/update.ts +38 -3
- package/src/beacon.ts +12 -0
- package/src/color/index.ts +0 -3
- package/src/color/instance.ts +9 -1
- package/src/color/models.ts +30 -0
- package/src/function/assert.ts +66 -7
- package/src/function/memoize.ts +3 -0
- package/src/function/once.ts +5 -1
- package/src/function/retry.ts +3 -0
- package/src/internal/array/chunk.ts +6 -0
- package/src/internal/array/compact.ts +12 -0
- package/src/internal/array/index-of.ts +70 -0
- package/src/internal/math/aggregate.ts +29 -0
- package/src/internal/string.ts +0 -2
- package/src/internal/value/compare.ts +2 -1
- package/src/internal/value/equal.ts +5 -0
- package/src/internal/value/get.ts +27 -5
- package/src/internal/value/has.ts +10 -10
- package/src/internal/value/misc.ts +24 -13
- package/src/logger.ts +11 -0
- package/src/models.ts +18 -0
- package/src/promise/index.ts +0 -6
- package/src/promise/models.ts +36 -0
- package/src/queue.ts +13 -1
- package/src/result/index.ts +0 -8
- package/src/result/match.ts +4 -4
- package/src/result/work/flow.ts +12 -36
- package/src/result/work/pipe.ts +11 -33
- package/src/sized/set.ts +4 -3
- package/src/value/collection.ts +1 -1
- package/src/value/merge.ts +88 -66
- package/src/value/shake.ts +3 -0
- package/src/value/smush.ts +3 -0
- package/src/value/transform.ts +10 -1
- package/src/value/unsmush.ts +2 -8
package/dist/array/select.d.mts
CHANGED
|
@@ -3,46 +3,100 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/select.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Get a filtered and mapped array of items
|
|
6
|
+
*
|
|
6
7
|
* @param array Array to search in
|
|
7
8
|
* @param filterCallback Callback to get an item's value for matching
|
|
8
9
|
* @param filterValue Value to match against
|
|
9
10
|
* @param mapCallback Callback to map the matched items
|
|
10
11
|
* @returns Filtered and mapped array of items
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* select(
|
|
16
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
17
|
+
* item => item.id,
|
|
18
|
+
* 2,
|
|
19
|
+
* item => item.name,
|
|
20
|
+
* ); // => ['Bob']
|
|
21
|
+
* ```
|
|
11
22
|
*/
|
|
12
23
|
declare function select<Item, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, mapCallback: MapCallback): Array<ReturnType<MapCallback>>;
|
|
13
24
|
/**
|
|
14
25
|
* Get a filtered and mapped array of items
|
|
26
|
+
*
|
|
15
27
|
* @param array Array to search in
|
|
16
28
|
* @param filterCallback Callback to get an item's value for matching
|
|
17
29
|
* @param filterValue Value to match against
|
|
18
30
|
* @param mapKey Key to get an item's value for mapping
|
|
19
31
|
* @returns Filtered and mapped array of items
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* select(
|
|
36
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
37
|
+
* item => item.id,
|
|
38
|
+
* 2,
|
|
39
|
+
* 'name',
|
|
40
|
+
* ); // => ['Bob']
|
|
41
|
+
* ```
|
|
20
42
|
*/
|
|
21
43
|
declare function select<Item extends PlainObject, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, MapKey extends keyof Item>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, mapKey: MapKey): Array<Item[MapKey]>;
|
|
22
44
|
/**
|
|
23
45
|
* Get a filtered and mapped array of items
|
|
46
|
+
*
|
|
24
47
|
* @param array Array to search in
|
|
25
48
|
* @param filterKey Key to get an item's value for matching
|
|
26
49
|
* @param filterValue Value to match against
|
|
27
50
|
* @param mapCallback Callback to map the matched items
|
|
28
51
|
* @returns Filtered and mapped array of items
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* select(
|
|
56
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
57
|
+
* 'id',
|
|
58
|
+
* 2,
|
|
59
|
+
* item => item.name,
|
|
60
|
+
* ); // => ['Bob']
|
|
61
|
+
* ```
|
|
29
62
|
*/
|
|
30
63
|
declare function select<Item extends PlainObject, ItemKey extends keyof Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filterKey: ItemKey, filterValue: Item[ItemKey], mapCallback: MapCallback): Array<ReturnType<MapCallback>>;
|
|
31
64
|
/**
|
|
32
65
|
* Get a filtered and mapped array of items
|
|
66
|
+
*
|
|
33
67
|
* @param array Array to search in
|
|
34
68
|
* @param filterKey Key to get an item's value for matching
|
|
35
69
|
* @param filterValue Value to match against
|
|
36
70
|
* @param mapKey Key to get an item's value for mapping
|
|
37
71
|
* @returns Filtered and mapped array of items
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* select(
|
|
76
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
77
|
+
* 'id',
|
|
78
|
+
* 2,
|
|
79
|
+
* 'name',
|
|
80
|
+
* ); // => ['Bob']
|
|
81
|
+
* ```
|
|
38
82
|
*/
|
|
39
83
|
declare function select<Item extends PlainObject, ItemKey extends keyof Item, MapKey extends keyof Item>(array: Item[], filterKey: ItemKey, filterValue: Item[ItemKey], mapKey: MapKey): Array<Item[MapKey]>;
|
|
40
84
|
/**
|
|
41
85
|
* Get a filtered and mapped array of items
|
|
86
|
+
*
|
|
42
87
|
* @param array Array to search in
|
|
43
88
|
* @param filterCallback Filter callback to match items
|
|
44
89
|
* @param mapCallback Callback to map the matched items
|
|
45
90
|
* @returns Filtered and mapped array of items
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* select(
|
|
95
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
96
|
+
* item => item.id === 2,
|
|
97
|
+
* item => item.name,
|
|
98
|
+
* ); // => ['Bob']
|
|
99
|
+
* ```
|
|
46
100
|
*/
|
|
47
101
|
declare function select<Item, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, mapCallback: MapCallback): Array<ReturnType<MapCallback>>;
|
|
48
102
|
/**
|
|
@@ -51,39 +105,71 @@ declare function select<Item, FilterCallback extends (item: Item, index: number,
|
|
|
51
105
|
* @param filterCallback Filter callback to match items
|
|
52
106
|
* @param mapKey Key to get an item's value for mapping
|
|
53
107
|
* @returns Filtered and mapped array of items
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* select(
|
|
112
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
113
|
+
* item => item.id,
|
|
114
|
+
* 2,
|
|
115
|
+
* 'name'
|
|
116
|
+
* ); // => ['Bob']
|
|
117
|
+
* ```
|
|
54
118
|
*/
|
|
55
119
|
declare function select<Item extends PlainObject, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, MapKey extends keyof Item>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, mapKey: MapKey): Array<Item[MapKey]>;
|
|
56
120
|
/**
|
|
57
121
|
* Get a filtered and mapped array of items
|
|
122
|
+
*
|
|
58
123
|
* @param array Array to search in
|
|
59
124
|
* @param filter Filter callback to match items
|
|
60
125
|
* @param map Callback to map the matched items
|
|
61
126
|
* @returns Filtered and mapped array of items
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* select(
|
|
131
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
132
|
+
* item => item.id === 2,
|
|
133
|
+
* item => item.name,
|
|
134
|
+
* ); // => ['Bob']
|
|
135
|
+
* ```
|
|
62
136
|
*/
|
|
63
137
|
declare function select<Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, map: MapCallback): Array<ReturnType<MapCallback>>;
|
|
64
138
|
/**
|
|
65
139
|
* Get a filtered and mapped array of items
|
|
140
|
+
*
|
|
66
141
|
* @param array Array to search in
|
|
67
142
|
* @param filter Filter callback to match items
|
|
68
143
|
* @param map Key to get an item's value for mapping
|
|
69
144
|
* @returns Filtered and mapped array of items
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* select(
|
|
149
|
+
* [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
|
|
150
|
+
* item => item.id === 2,
|
|
151
|
+
* 'name'
|
|
152
|
+
* ); // => ['Bob']
|
|
153
|
+
* ```
|
|
70
154
|
*/
|
|
71
155
|
declare function select<Item extends PlainObject, MapKey extends keyof Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, map: MapKey): Array<Item[MapKey]>;
|
|
72
156
|
/**
|
|
73
157
|
* Get a filtered and mapped array of items
|
|
158
|
+
*
|
|
74
159
|
* @param array Array to search in
|
|
75
160
|
* @param item Item to match against
|
|
76
161
|
* @param map Callback to map the matched items
|
|
77
162
|
* @returns Filtered and mapped array of items
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* select(
|
|
167
|
+
* [1, 2, 3, 2, 1],
|
|
168
|
+
* 3,
|
|
169
|
+
* value => value ** 2,
|
|
170
|
+
* ); // => [9]
|
|
171
|
+
* ```
|
|
78
172
|
*/
|
|
79
173
|
declare function select<Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], item: Item, map: MapCallback): Array<ReturnType<MapCallback>>;
|
|
80
|
-
/**
|
|
81
|
-
* Get a filtered and mapped array of items
|
|
82
|
-
* @param array Array to search in
|
|
83
|
-
* @param item Item to match against
|
|
84
|
-
* @param map Key to get an item's value for mapping
|
|
85
|
-
* @returns Filtered and mapped array of items
|
|
86
|
-
*/
|
|
87
|
-
declare function select<Item extends PlainObject, MapKey extends keyof Item>(array: Item[], item: Item, map: MapKey): Array<Item[MapKey]>;
|
|
88
174
|
//#endregion
|
|
89
175
|
export { select };
|
package/dist/array/single.d.mts
CHANGED
|
@@ -5,29 +5,58 @@ import { PlainObject } from "../models.mjs";
|
|
|
5
5
|
* Get the _only_ item matching the given value
|
|
6
6
|
*
|
|
7
7
|
* Throws an error if multiple items match the value
|
|
8
|
+
*
|
|
8
9
|
* @param array Array to search in
|
|
9
10
|
* @param callback Callback to get an item's value for matching
|
|
10
11
|
* @param value Value to match against
|
|
11
12
|
* @returns Only item that matches the value, or `undefined` if no match is found
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* single(
|
|
17
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
18
|
+
* item => item.id,
|
|
19
|
+
* 2
|
|
20
|
+
* ); // => {id: 2}
|
|
21
|
+
* ```
|
|
12
22
|
*/
|
|
13
23
|
declare function single<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
|
|
14
24
|
/**
|
|
15
25
|
* Get the _only_ item matching the given value by key
|
|
16
26
|
*
|
|
17
27
|
* Throws an error if multiple items match the value
|
|
28
|
+
*
|
|
18
29
|
* @param array Array to search in
|
|
19
30
|
* @param key Key to get an item's value for matching
|
|
20
31
|
* @param value Value to match against
|
|
21
32
|
* @returns Only item that matches the value, or `undefined` if no match is found
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* single(
|
|
37
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
38
|
+
* 'id',
|
|
39
|
+
* 2
|
|
40
|
+
* ); // => {id: 2}
|
|
41
|
+
* ```
|
|
22
42
|
*/
|
|
23
43
|
declare function single<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
|
|
24
44
|
/**
|
|
25
45
|
* Get the _only_ item matching the filter
|
|
26
46
|
*
|
|
27
47
|
* Throws an error if multiple items match the filter
|
|
48
|
+
*
|
|
28
49
|
* @param array Array to search in
|
|
29
50
|
* @param filter Filter callback to match items
|
|
30
51
|
* @returns Only item that matches the filter, or `undefined` if no match is found
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* single(
|
|
56
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
57
|
+
* item => item.id === 2
|
|
58
|
+
* ); // => {id: 2}
|
|
59
|
+
* ```
|
|
31
60
|
*/
|
|
32
61
|
declare function single<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
|
|
33
62
|
//#endregion
|
package/dist/array/slice.d.mts
CHANGED
|
@@ -3,83 +3,173 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/slice.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Drop items from the start of an array until they match a value
|
|
6
|
+
*
|
|
6
7
|
* @param array Original array
|
|
7
|
-
* @param
|
|
8
|
+
* @param callback Callback to get an item's value for matching
|
|
8
9
|
* @param value Value to match against
|
|
9
10
|
* @returns New array with items dropped
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* drop(
|
|
15
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
16
|
+
* item => item.id,
|
|
17
|
+
* 2,
|
|
18
|
+
* ); // => [{id: 2}, {id: 3}]
|
|
19
|
+
* ```
|
|
10
20
|
*/
|
|
11
|
-
declare function drop<Item extends
|
|
21
|
+
declare function drop<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
12
22
|
/**
|
|
13
23
|
* Drop items from the start of an array until they match a value
|
|
24
|
+
*
|
|
14
25
|
* @param array Original array
|
|
15
|
-
* @param
|
|
26
|
+
* @param key Key to get an item's value for matching
|
|
16
27
|
* @param value Value to match against
|
|
17
|
-
* @
|
|
28
|
+
* @returns New array with items dropped
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* drop(
|
|
33
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
34
|
+
* 'id',
|
|
35
|
+
* 2,
|
|
36
|
+
* ); // => [{id: 2}, {id: 3}]
|
|
37
|
+
* ```
|
|
18
38
|
*/
|
|
19
|
-
declare function drop<Item
|
|
39
|
+
declare function drop<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
20
40
|
/**
|
|
21
41
|
* Drop items from the start of an array while they match a filter
|
|
42
|
+
*
|
|
22
43
|
* @param array Original array
|
|
23
44
|
* @param callback Filter callback to match items
|
|
24
|
-
* @
|
|
45
|
+
* @returns New array with items dropped
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* drop(
|
|
50
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
51
|
+
* item => item.id === 2,
|
|
52
|
+
* ); // => [{id: 2}, {id: 3}]
|
|
53
|
+
* ```
|
|
25
54
|
*/
|
|
26
55
|
declare function drop<Item extends PlainObject>(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
27
56
|
/**
|
|
28
57
|
* Drop a specified number of items, from the start if `>= 0`, or from the end if `< 0`
|
|
58
|
+
*
|
|
29
59
|
* @param array Original array
|
|
30
60
|
* @param count Number of items to drop
|
|
31
61
|
* @returns New array with items dropped
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* drop([1, 2, 3, 4, 5], 2); // => [3, 4, 5]
|
|
66
|
+
* drop([1, 2, 3, 4, 5], -2); // => [1, 2, 3]
|
|
67
|
+
* ```
|
|
32
68
|
*/
|
|
33
69
|
declare function drop(array: unknown[], count: number): unknown[];
|
|
34
70
|
/**
|
|
35
71
|
* Slice an array, returning a new array with a specified range of items
|
|
72
|
+
*
|
|
36
73
|
* @param array Original array
|
|
37
74
|
* @param start Start index _(inclusive)_
|
|
38
75
|
* @param end End index _(exclusive)_
|
|
39
|
-
* @
|
|
76
|
+
* @returns New array with sliced items
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* slice([1, 2, 3, 4, 5], 1, 4); // => [2, 3, 4]
|
|
81
|
+
* ```
|
|
40
82
|
*/
|
|
41
83
|
declare function slice<Item>(array: Item[], start: number, end: number): Item[];
|
|
42
84
|
/**
|
|
43
|
-
* Slice an array, returning a new array with a specified number of items
|
|
85
|
+
* Slice an array, returning a new array with a specified number of items _(from the start)_
|
|
86
|
+
*
|
|
44
87
|
* @param array Original array
|
|
45
|
-
* @param count Maximum
|
|
46
|
-
* @
|
|
88
|
+
* @param count Maximum size of the new array
|
|
89
|
+
* @returns New array with sliced items
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* slice([1, 2, 3, 4, 5], 3); // => [1, 2, 3]
|
|
94
|
+
* ```
|
|
47
95
|
*/
|
|
48
96
|
declare function slice<Item>(array: Item[], count: number): Item[];
|
|
49
97
|
/**
|
|
50
98
|
* Slice an array
|
|
99
|
+
*
|
|
51
100
|
* @param array Array to slice
|
|
52
101
|
* @returns Sliced array
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* slice([1, 2, 3]); // => [1, 2, 3]
|
|
106
|
+
* ```
|
|
53
107
|
*/
|
|
54
108
|
declare function slice<Item>(array: Item[]): Item[];
|
|
55
109
|
/**
|
|
56
110
|
* Take items from the start of an array until they match a value
|
|
111
|
+
*
|
|
57
112
|
* @param array Original array
|
|
58
|
-
* @param
|
|
113
|
+
* @param callback Callback to get an item's value for matching
|
|
59
114
|
* @param value Value to match against
|
|
60
115
|
* @returns New array with taken items
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* take(
|
|
120
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
121
|
+
* item => item.id,
|
|
122
|
+
* 2,
|
|
123
|
+
* ); // => [{id: 1}]
|
|
124
|
+
* ```
|
|
61
125
|
*/
|
|
62
|
-
declare function take<Item extends
|
|
126
|
+
declare function take<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
|
|
63
127
|
/**
|
|
64
128
|
* Take items from the start of an array until they match a value
|
|
129
|
+
*
|
|
65
130
|
* @param array Original array
|
|
66
|
-
* @param
|
|
131
|
+
* @param key Key to get an item's value for matching
|
|
67
132
|
* @param value Value to match against
|
|
68
|
-
* @
|
|
133
|
+
* @returns New array with taken items
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* take(
|
|
138
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
139
|
+
* 'id',
|
|
140
|
+
* 2,
|
|
141
|
+
* ); // => [{id: 1}]
|
|
142
|
+
* ```
|
|
69
143
|
*/
|
|
70
|
-
declare function take<Item
|
|
144
|
+
declare function take<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
|
|
71
145
|
/**
|
|
72
146
|
* Take items from the start of an array while they match a filter
|
|
147
|
+
*
|
|
73
148
|
* @param array Original array
|
|
74
149
|
* @param callback Filter callback to match items
|
|
75
|
-
* @
|
|
150
|
+
* @returns New array with taken items
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* take(
|
|
155
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
156
|
+
* item => item.id === 2,
|
|
157
|
+
* ); // => [{id: 1}]
|
|
158
|
+
* ```
|
|
76
159
|
*/
|
|
77
160
|
declare function take<Item extends PlainObject>(array: Item[], callback: (item: Item, index: number, array: Item[]) => boolean): Item[];
|
|
78
161
|
/**
|
|
79
162
|
* Take a specified number of items, from the start if `>= 0`, or from the end if `< 0`
|
|
163
|
+
*
|
|
80
164
|
* @param array Original array
|
|
81
165
|
* @param count Number of items to take
|
|
82
166
|
* @returns New array with taken items
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* take([1, 2, 3, 4, 5], 2); // => [1, 2]
|
|
171
|
+
* take([1, 2, 3, 4, 5], -2); // => [4, 5]
|
|
172
|
+
* ```
|
|
83
173
|
*/
|
|
84
174
|
declare function take(array: unknown[], count: number): unknown[];
|
|
85
175
|
//#endregion
|
package/dist/array/sort.d.mts
CHANGED
|
@@ -65,9 +65,15 @@ type ComparisonSorter<Item> = (first: Item, second: Item) => number;
|
|
|
65
65
|
* Direction to sort by
|
|
66
66
|
*/
|
|
67
67
|
type SortDirection = 'ascending' | 'descending';
|
|
68
|
+
/**
|
|
69
|
+
* Sorter for an array with predefined sorters
|
|
70
|
+
*
|
|
71
|
+
* Can be used to sort an array, get the predicted index for an item, and check if an array is sorted
|
|
72
|
+
*/
|
|
68
73
|
type Sorter<Item> = {
|
|
69
74
|
/**
|
|
70
75
|
* Sort an array of items
|
|
76
|
+
*
|
|
71
77
|
* @param array Array to sort
|
|
72
78
|
* @returns Sorted array
|
|
73
79
|
*/
|
|
@@ -76,6 +82,7 @@ type Sorter<Item> = {
|
|
|
76
82
|
* Get the index for an item _(to be inserted into an array of items)_
|
|
77
83
|
*
|
|
78
84
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
85
|
+
*
|
|
79
86
|
* @param array Array to get the index from
|
|
80
87
|
* @param item Item to get the index for
|
|
81
88
|
* @returns Index for item
|
|
@@ -83,6 +90,7 @@ type Sorter<Item> = {
|
|
|
83
90
|
index(array: Item[], item: Item): number;
|
|
84
91
|
/**
|
|
85
92
|
* Is the array sorted?
|
|
93
|
+
*
|
|
86
94
|
* @param array Array to check
|
|
87
95
|
* @returns `true` if sorted, otherwise `false`
|
|
88
96
|
*/
|
|
@@ -93,7 +101,8 @@ type Sorter<Item> = {
|
|
|
93
101
|
*
|
|
94
102
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
95
103
|
*
|
|
96
|
-
* Available as `getSortedIndex` and `sort.
|
|
104
|
+
* Available as `getSortedIndex` and `sort.getIndex`
|
|
105
|
+
*
|
|
97
106
|
* @param array Array to get the index from
|
|
98
107
|
* @param item Item to get the index for
|
|
99
108
|
* @param sorters Sorters to use to determine sorting
|
|
@@ -106,7 +115,8 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, sorters: Array<
|
|
|
106
115
|
*
|
|
107
116
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
108
117
|
*
|
|
109
|
-
* Available as `getSortedIndex` and `sort.
|
|
118
|
+
* Available as `getSortedIndex` and `sort.getIndex`
|
|
119
|
+
*
|
|
110
120
|
* @param array Array to get the index from
|
|
111
121
|
* @param item Item to get the index for
|
|
112
122
|
* @param sorter Sorter to use to determine sorting
|
|
@@ -119,7 +129,8 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, sorter: ArraySo
|
|
|
119
129
|
*
|
|
120
130
|
* _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
|
|
121
131
|
*
|
|
122
|
-
* Available as `getSortedIndex` and `sort.
|
|
132
|
+
* Available as `getSortedIndex` and `sort.getIndex`
|
|
133
|
+
*
|
|
123
134
|
* @param array Array to get the index from
|
|
124
135
|
* @param item Item to get the index for
|
|
125
136
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
@@ -130,6 +141,7 @@ declare function getSortedIndex<Item>(array: Item[], item: Item, descending?: bo
|
|
|
130
141
|
* Initialize a sort handler with sorters _(and an optional default direction)_
|
|
131
142
|
*
|
|
132
143
|
* Available as `initializeSorter` and `sort.initialize`
|
|
144
|
+
*
|
|
133
145
|
* @param sorters Sorters to use for sorting
|
|
134
146
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
135
147
|
* @returns Sort handler
|
|
@@ -139,6 +151,7 @@ declare function initializeSorter<Item>(sorters: Array<ArraySorter<Item>>, desce
|
|
|
139
151
|
* Initialize a sort handler with a sorter _(and an optional default direction)_
|
|
140
152
|
*
|
|
141
153
|
* Available as `initializeSorter` and `sort.initialize`
|
|
154
|
+
*
|
|
142
155
|
* @param sorter Sorter to use for sorting
|
|
143
156
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
144
157
|
* @returns Sort handler
|
|
@@ -148,12 +161,14 @@ declare function initializeSorter<Item>(sorter: ArraySorter<Item>, descending?:
|
|
|
148
161
|
* Initialize a sort handler _(with an optional default direction)_
|
|
149
162
|
*
|
|
150
163
|
* Available as `initializeSorter` and `sort.initialize`
|
|
164
|
+
*
|
|
151
165
|
* @param descending Sort in descending order? _(defaults to `false`)_
|
|
152
166
|
* @returns Sort handler
|
|
153
167
|
*/
|
|
154
168
|
declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
|
|
155
169
|
/**
|
|
156
170
|
* Is the array sorted according to the sorters _(and the optional default direction)_?
|
|
171
|
+
*
|
|
157
172
|
* @param array Array to check
|
|
158
173
|
* @param sorters Sorters to determine sorting
|
|
159
174
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -162,6 +177,7 @@ declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
|
|
|
162
177
|
declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter<Item>>, descending?: boolean): boolean;
|
|
163
178
|
/**
|
|
164
179
|
* Is the array sorted according to the sorter _(and the optional default direction)_?
|
|
180
|
+
*
|
|
165
181
|
* @param array Array to check
|
|
166
182
|
* @param sorter Sorter to determine sorting
|
|
167
183
|
* @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
@@ -172,6 +188,7 @@ declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descen
|
|
|
172
188
|
* Is the array sorted?
|
|
173
189
|
*
|
|
174
190
|
* Available as `isSorted` and `sort.is`
|
|
191
|
+
*
|
|
175
192
|
* @param array Array to check
|
|
176
193
|
* @param descending Sorted in descending order? _(defaults to `false`)_
|
|
177
194
|
* @returns `true` if sorted, otherwise `false`
|
|
@@ -179,10 +196,19 @@ declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descen
|
|
|
179
196
|
declare function isSorted<Item>(array: Item[], descending?: boolean): boolean;
|
|
180
197
|
/**
|
|
181
198
|
* Sort an array of items using a comparison callback
|
|
199
|
+
*
|
|
182
200
|
* @param array Array to sort
|
|
183
201
|
* @param comparator Comparator to use for sorting
|
|
184
202
|
* @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
|
|
185
203
|
* @returns Sorted array
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* sort(
|
|
208
|
+
* [{id: 3}, {id: 1}, {id: 2}],
|
|
209
|
+
* (first, second) => first.id - second.id,
|
|
210
|
+
* ); // => [{id: 1}, {id: 2}, {id: 3}]
|
|
211
|
+
* ```
|
|
186
212
|
*/
|
|
187
213
|
declare function sort<Item>(array: Item[], comparator: (first: Item, second: Item) => number, descending?: boolean): Item[];
|
|
188
214
|
/**
|
|
@@ -209,7 +235,7 @@ declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending
|
|
|
209
235
|
*/
|
|
210
236
|
declare function sort<Item>(array: Item[], descending?: boolean): Item[];
|
|
211
237
|
declare namespace sort {
|
|
212
|
-
var
|
|
238
|
+
var getIndex: typeof getSortedIndex;
|
|
213
239
|
var initialize: typeof initializeSorter;
|
|
214
240
|
var is: typeof isSorted;
|
|
215
241
|
}
|
package/dist/array/sort.mjs
CHANGED
|
@@ -124,7 +124,7 @@ function sortArray(array, sorters) {
|
|
|
124
124
|
const { length } = sorters;
|
|
125
125
|
return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
|
|
126
126
|
}
|
|
127
|
-
sort.
|
|
127
|
+
sort.getIndex = getSortedIndex;
|
|
128
128
|
sort.initialize = initializeSorter;
|
|
129
129
|
sort.is = isSorted;
|
|
130
130
|
const SORT_PEEK_PERCENTAGE = 10;
|
package/dist/array/splice.d.mts
CHANGED
|
@@ -1,34 +1,82 @@
|
|
|
1
1
|
//#region src/array/splice.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Adds items into an array at a specific index and removes a specific amount of items
|
|
4
|
+
*
|
|
5
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
6
|
+
*
|
|
4
7
|
* @param array Original array
|
|
5
8
|
* @param start Index to start splicing from
|
|
6
9
|
* @param amount Number of items to remove
|
|
7
10
|
* @param added Added items
|
|
8
11
|
* @returns Removed items
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* splice(
|
|
16
|
+
* [1, 2, 3, 4, 5],
|
|
17
|
+
* 2,
|
|
18
|
+
* 2,
|
|
19
|
+
* [6, 7]
|
|
20
|
+
* ); // => [3, 4], array becomes [1, 2, 6, 7, 5]
|
|
21
|
+
* ```
|
|
9
22
|
*/
|
|
10
23
|
declare function splice<Item>(array: Item[], start: number, amount: number, added: Item[]): Item[];
|
|
11
24
|
/**
|
|
12
25
|
* Adds items into an array at a specific index
|
|
26
|
+
*
|
|
27
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
28
|
+
*
|
|
13
29
|
* @param array Original array
|
|
14
30
|
* @param start Index to start splicing from
|
|
15
31
|
* @param added Added items
|
|
16
32
|
* @returns Removed items
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* splice(
|
|
37
|
+
* [1, 2, 3, 4, 5],
|
|
38
|
+
* 2,
|
|
39
|
+
* [6, 7]
|
|
40
|
+
* ); // => [], array becomes [1, 2, 6, 7, 3, 4, 5]
|
|
41
|
+
* ```
|
|
17
42
|
*/
|
|
18
43
|
declare function splice<Item>(array: Item[], start: number, added: Item[]): Item[];
|
|
19
44
|
/**
|
|
20
45
|
* Removes and returns _(up to)_ a specific amount of items from an array, starting from a specific index
|
|
46
|
+
*
|
|
47
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
48
|
+
*
|
|
21
49
|
* @param array Original array
|
|
22
50
|
* @param start Index to start splicing from
|
|
23
51
|
* @param amount Number of items to remove
|
|
24
52
|
* @returns Removed items
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* splice(
|
|
57
|
+
* [1, 2, 3, 4, 5],
|
|
58
|
+
* 2,
|
|
59
|
+
* 2,
|
|
60
|
+
* ); // => [3, 4], array becomes [1, 2, 5]
|
|
61
|
+
* ```
|
|
25
62
|
*/
|
|
26
63
|
declare function splice<Item>(array: Item[], start: number, amount: number): Item[];
|
|
27
64
|
/**
|
|
28
65
|
* Removes and returns all items from an array starting from a specific index
|
|
66
|
+
*
|
|
67
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
68
|
+
*
|
|
29
69
|
* @param array Original array
|
|
30
70
|
* @param start Index to start splicing from
|
|
31
71
|
* @returns Removed items
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* splice(
|
|
76
|
+
* [1, 2, 3, 4, 5],
|
|
77
|
+
* 2,
|
|
78
|
+
* ); // => [3, 4, 5], array becomes [1, 2]
|
|
79
|
+
* ```
|
|
32
80
|
*/
|
|
33
81
|
declare function splice<Item>(array: Item[], start: number): Item[];
|
|
34
82
|
//#endregion
|
package/dist/array/splice.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { INSERT_TYPE_SPLICE, insertValues } from "../internal/array/insert.mjs";
|
|
2
2
|
//#region src/array/splice.ts
|
|
3
3
|
function splice(array, start, deleteCountOrItems, items) {
|
|
4
|
-
|
|
4
|
+
const deleteCountIsNumber = typeof deleteCountOrItems === "number";
|
|
5
|
+
return insertValues(INSERT_TYPE_SPLICE, array, deleteCountIsNumber ? items : deleteCountOrItems, start, deleteCountIsNumber ? deleteCountOrItems : 0);
|
|
5
6
|
}
|
|
6
7
|
//#endregion
|
|
7
8
|
export { splice };
|