@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
|
@@ -1,121 +1,253 @@
|
|
|
1
1
|
import { PlainObject } from "../models.mjs";
|
|
2
2
|
|
|
3
|
-
//#region src/array/
|
|
4
|
-
|
|
3
|
+
//#region src/array/match.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Comparison of an array within another array
|
|
6
|
+
*/
|
|
7
|
+
type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
|
|
5
8
|
/**
|
|
6
9
|
* Does the needle array end the haystack array?
|
|
7
10
|
* @param haystack Haystack array
|
|
8
11
|
* @param needle Needle array
|
|
9
|
-
* @param
|
|
10
|
-
* @
|
|
12
|
+
* @param callback Callback to get an item's value for matching
|
|
13
|
+
* @returns `true` if the haystack ends with the needle, otherwise `false`
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* endsWithArray(
|
|
18
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
19
|
+
* [{id: 2}, {id: 3}],
|
|
20
|
+
* item => item.id,
|
|
21
|
+
* ); // => true
|
|
22
|
+
* ```
|
|
11
23
|
*/
|
|
12
|
-
declare function endsWithArray<Item
|
|
24
|
+
declare function endsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
13
25
|
/**
|
|
14
26
|
* Does the needle array end the haystack array?
|
|
27
|
+
*
|
|
15
28
|
* @param haystack Haystack array
|
|
16
29
|
* @param needle Needle array
|
|
17
|
-
* @param
|
|
18
|
-
* @
|
|
30
|
+
* @param key Key to get an item's value for matching
|
|
31
|
+
* @returns `true` if the haystack ends with the needle, otherwise `false`
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* endsWithArray(
|
|
36
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
37
|
+
* [{id: 2}, {id: 3}],
|
|
38
|
+
* 'id',
|
|
39
|
+
* ); // => true
|
|
40
|
+
* ```
|
|
19
41
|
*/
|
|
20
|
-
declare function endsWithArray<Item>(haystack: Item[], needle: Item[],
|
|
42
|
+
declare function endsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
21
43
|
/**
|
|
22
44
|
* Does the needle array end the haystack array?
|
|
45
|
+
*
|
|
23
46
|
* @param haystack Haystack array
|
|
24
47
|
* @param needle Needle array
|
|
25
|
-
* @
|
|
48
|
+
* @returns `true` if the haystack ends with the needle, otherwise `false`
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* endsWithArray([1, 2, 3], [2, 3]); // => true
|
|
53
|
+
* ```
|
|
26
54
|
*/
|
|
27
55
|
declare function endsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
28
56
|
/**
|
|
29
57
|
* Get the position of an array within another array
|
|
58
|
+
*
|
|
30
59
|
* @param haystack Haystack array
|
|
31
60
|
* @param needle Needle array
|
|
32
|
-
* @param
|
|
61
|
+
* @param callback Callback to get an item's value for matching
|
|
33
62
|
* @returns Position of the needle within the haystack
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* getArrayComparison(
|
|
67
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
68
|
+
* [{id: 2}, {id: 3}],
|
|
69
|
+
* item => item.id,
|
|
70
|
+
* ); // => 'end'
|
|
71
|
+
* ```
|
|
34
72
|
*/
|
|
35
|
-
declare function
|
|
73
|
+
declare function getArrayComparison<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayComparison;
|
|
36
74
|
/**
|
|
37
75
|
* Get the position of an array within another array
|
|
76
|
+
*
|
|
38
77
|
* @param haystack Haystack array
|
|
39
78
|
* @param needle Needle array
|
|
40
|
-
* @param
|
|
79
|
+
* @param key Key to get an item's value for matching
|
|
41
80
|
* @returns Position of the needle within the haystack
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* getArrayComparison(
|
|
85
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
86
|
+
* [{id: 2}, {id: 3}],
|
|
87
|
+
* 'id',
|
|
88
|
+
* ); // => 'end'
|
|
89
|
+
* ```
|
|
42
90
|
*/
|
|
43
|
-
declare function
|
|
91
|
+
declare function getArrayComparison<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayComparison;
|
|
44
92
|
/**
|
|
45
93
|
* Get the position of an array within another array
|
|
94
|
+
*
|
|
46
95
|
* @param haystack Haystack array
|
|
47
96
|
* @param needle Needle array
|
|
48
97
|
* @returns Position of the needle within the haystack
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* getArrayComparison([1, 2, 3], [2, 3]); // => 'end'
|
|
102
|
+
* ```
|
|
49
103
|
*/
|
|
50
|
-
declare function
|
|
104
|
+
declare function getArrayComparison<Item>(haystack: Item[], needle: Item[]): ArrayComparison;
|
|
51
105
|
/**
|
|
52
106
|
* Does the needle array exist within the haystack array?
|
|
107
|
+
*
|
|
53
108
|
* @param haystack Haystack array
|
|
54
109
|
* @param needle Needle array
|
|
55
|
-
* @param
|
|
56
|
-
* @
|
|
110
|
+
* @param callback Callback to get an item's value for matching
|
|
111
|
+
* @returns `true` if the haystack includes the needle, otherwise `false`
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* includesArray(
|
|
116
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
117
|
+
* [{id: 2}, {id: 3}],
|
|
118
|
+
* item => item.id,
|
|
119
|
+
* ); // => true
|
|
120
|
+
* ```
|
|
57
121
|
*/
|
|
58
|
-
declare function includesArray<Item
|
|
122
|
+
declare function includesArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
59
123
|
/**
|
|
60
124
|
* Does the needle array exist within the haystack array?
|
|
125
|
+
*
|
|
61
126
|
* @param haystack Haystack array
|
|
62
127
|
* @param needle Needle array
|
|
63
|
-
* @param
|
|
64
|
-
* @
|
|
128
|
+
* @param key Key to get an item's value for matching
|
|
129
|
+
* @returns `true` if the haystack includes the needle, otherwise `false`
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* includesArray(
|
|
134
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
135
|
+
* [{id: 2}, {id: 3}],
|
|
136
|
+
* 'id',
|
|
137
|
+
* ); // => true
|
|
138
|
+
* ```
|
|
65
139
|
*/
|
|
66
|
-
declare function includesArray<Item>(haystack: Item[], needle: Item[],
|
|
140
|
+
declare function includesArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
67
141
|
/**
|
|
68
142
|
* Does the needle array exist within the haystack array?
|
|
143
|
+
*
|
|
69
144
|
* @param haystack Haystack array
|
|
70
145
|
* @param needle Needle array
|
|
71
|
-
* @
|
|
146
|
+
* @returns `true` if the haystack includes the needle, otherwise `false`
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* includesArray([1, 2, 3], [2, 3]); // => true
|
|
151
|
+
* ```
|
|
72
152
|
*/
|
|
73
153
|
declare function includesArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
74
154
|
/**
|
|
75
155
|
* Get the index of an array within another array
|
|
156
|
+
*
|
|
76
157
|
* @param haystack Haystack array
|
|
77
158
|
* @param needle Needle array
|
|
78
|
-
* @param
|
|
79
|
-
* @
|
|
159
|
+
* @param callback Callback to get an item's value for matching
|
|
160
|
+
* @returns Index of the needle's start within the haystack, or `-1` if it is not found
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* indexOfArray(
|
|
165
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
166
|
+
* [{id: 2}, {id: 3}],
|
|
167
|
+
* item => item.id,
|
|
168
|
+
* ); // => 1
|
|
169
|
+
* ```
|
|
80
170
|
*/
|
|
81
|
-
declare function indexOfArray<Item
|
|
171
|
+
declare function indexOfArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): number;
|
|
82
172
|
/**
|
|
83
173
|
* Get the index of an array within another array
|
|
174
|
+
*
|
|
84
175
|
* @param haystack Haystack array
|
|
85
176
|
* @param needle Needle array
|
|
86
|
-
* @param
|
|
87
|
-
* @
|
|
177
|
+
* @param key Key to get an item's value for matching
|
|
178
|
+
* @returns Index of the needle's start within the haystack, or `-1` if it is not found
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* indexOfArray(
|
|
183
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
184
|
+
* [{id: 2}, {id: 3}],
|
|
185
|
+
* 'id',
|
|
186
|
+
* ); // => 1
|
|
187
|
+
* ```
|
|
88
188
|
*/
|
|
89
|
-
declare function indexOfArray<Item>(haystack: Item[], needle: Item[],
|
|
189
|
+
declare function indexOfArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): number;
|
|
90
190
|
/**
|
|
91
191
|
* Get the index of an array within another array
|
|
192
|
+
*
|
|
92
193
|
* @param haystack Haystack array
|
|
93
194
|
* @param needle Needle array
|
|
94
|
-
* @
|
|
195
|
+
* @returns Index of the needle's start within the haystack, or `-1` if it is not found
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* indexOfArray([1, 2, 3], [2, 3]); // => 1
|
|
200
|
+
* ```
|
|
95
201
|
*/
|
|
96
202
|
declare function indexOfArray<Item>(haystack: Item[], needle: Item[]): number;
|
|
97
203
|
/**
|
|
98
204
|
* Does the needle array start the haystack array?
|
|
205
|
+
*
|
|
99
206
|
* @param haystack Haystack array
|
|
100
207
|
* @param needle Needle array
|
|
101
|
-
* @param
|
|
102
|
-
* @
|
|
208
|
+
* @param callback Callback to get an item's value for matching
|
|
209
|
+
* @returns `true` if the haystack starts with the needle, otherwise `false`
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* startsWithArray(
|
|
214
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
215
|
+
* [{id: 1}, {id: 2}],
|
|
216
|
+
* item => item.id,
|
|
217
|
+
* ); // => true
|
|
218
|
+
* ```
|
|
103
219
|
*/
|
|
104
|
-
declare function startsWithArray<Item
|
|
220
|
+
declare function startsWithArray<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
|
|
105
221
|
/**
|
|
106
222
|
* Does the needle array start the haystack array?
|
|
223
|
+
*
|
|
107
224
|
* @param haystack Haystack array
|
|
108
225
|
* @param needle Needle array
|
|
109
|
-
* @param
|
|
110
|
-
* @
|
|
226
|
+
* @param key Key to get an item's value for matching
|
|
227
|
+
* @returns `true` if the haystack starts with the needle, otherwise `false`
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* startsWithArray(
|
|
232
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
233
|
+
* [{id: 1}, {id: 2}],
|
|
234
|
+
* 'id',
|
|
235
|
+
* ); // => true
|
|
236
|
+
* ```
|
|
111
237
|
*/
|
|
112
|
-
declare function startsWithArray<Item>(haystack: Item[], needle: Item[],
|
|
238
|
+
declare function startsWithArray<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
|
|
113
239
|
/**
|
|
114
240
|
* Does the needle array start the haystack array?
|
|
241
|
+
*
|
|
115
242
|
* @param haystack Haystack array
|
|
116
243
|
* @param needle Needle array
|
|
117
|
-
* @
|
|
244
|
+
* @returns `true` if the haystack starts with the needle, otherwise `false`
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* startsWithArray([1, 2, 3], [1, 2]); // => true
|
|
249
|
+
* ```
|
|
118
250
|
*/
|
|
119
251
|
declare function startsWithArray<Item>(haystack: Item[], needle: Item[]): boolean;
|
|
120
252
|
//#endregion
|
|
121
|
-
export {
|
|
253
|
+
export { ArrayComparison, endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { getArrayCallback } from "../internal/array/callbacks.mjs";
|
|
2
|
-
//#region src/array/
|
|
2
|
+
//#region src/array/match.ts
|
|
3
3
|
function endsWithArray(haystack, needle, key) {
|
|
4
4
|
return endings.has(getPosition(haystack, needle, key)[1]);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
6
|
+
function getArrayComparison(haystack, needle, key) {
|
|
7
7
|
return getPosition(haystack, needle, key)[1];
|
|
8
8
|
}
|
|
9
9
|
function getName(start, haystack, needle) {
|
|
10
|
-
if (start === 0) return haystack === needle ?
|
|
11
|
-
return start + needle === haystack ?
|
|
10
|
+
if (start === 0) return haystack === needle ? COMPARISON_SAME : COMPARISON_START;
|
|
11
|
+
return start + needle === haystack ? COMPARISON_END : COMPARISON_INSIDE;
|
|
12
12
|
}
|
|
13
13
|
function getPosition(haystack, needle, key) {
|
|
14
14
|
if (!Array.isArray(haystack) || !Array.isArray(needle)) return invalid;
|
|
@@ -43,16 +43,16 @@ function indexOfArray(haystack, needle, key) {
|
|
|
43
43
|
function startsWithArray(haystack, needle, key) {
|
|
44
44
|
return starts.has(getPosition(haystack, needle, key)[1]);
|
|
45
45
|
}
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const endings = new Set([
|
|
53
|
-
const invalid = [-1,
|
|
54
|
-
const outside = [-1,
|
|
55
|
-
const outsides = new Set([
|
|
56
|
-
const starts = new Set([
|
|
46
|
+
const COMPARISON_END = "end";
|
|
47
|
+
const COMPARISON_INSIDE = "inside";
|
|
48
|
+
const COMPARISON_INVALID = "invalid";
|
|
49
|
+
const COMPARISON_OUTSIDE = "outside";
|
|
50
|
+
const COMPARISON_SAME = "same";
|
|
51
|
+
const COMPARISON_START = "start";
|
|
52
|
+
const endings = new Set([COMPARISON_END, COMPARISON_SAME]);
|
|
53
|
+
const invalid = [-1, COMPARISON_INVALID];
|
|
54
|
+
const outside = [-1, COMPARISON_OUTSIDE];
|
|
55
|
+
const outsides = new Set([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
|
|
56
|
+
const starts = new Set([COMPARISON_START, COMPARISON_SAME]);
|
|
57
57
|
//#endregion
|
|
58
|
-
export { endsWithArray,
|
|
58
|
+
export { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
|
package/dist/array/move.d.mts
CHANGED
|
@@ -7,36 +7,66 @@ import { PlainObject } from "../models.mjs";
|
|
|
7
7
|
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
|
|
8
8
|
*
|
|
9
9
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
10
|
+
*
|
|
10
11
|
* @param array Array to move within
|
|
11
12
|
* @param from Item or items to move
|
|
12
13
|
* @param to Item or items to move to
|
|
13
|
-
* @param
|
|
14
|
+
* @param callback Callback to get an item's value for matching
|
|
14
15
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
20
|
+
*
|
|
21
|
+
* move(array, {id: 1}, {id: 3}, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
|
|
22
|
+
* move(array, [{id: 2}, {id: 3}], {id: 4}, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
|
|
23
|
+
* move(array, {id: 5}, {id: 1}, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
|
|
24
|
+
* ```
|
|
15
25
|
*/
|
|
16
|
-
declare function move<Item
|
|
26
|
+
declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[], callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
17
27
|
/**
|
|
18
28
|
* Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
|
|
19
29
|
*
|
|
20
30
|
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
|
|
21
31
|
*
|
|
22
32
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
33
|
+
*
|
|
23
34
|
* @param array Array to move within
|
|
24
35
|
* @param from Item or items to move
|
|
25
36
|
* @param to Item or items to move to
|
|
26
|
-
* @param
|
|
37
|
+
* @param key Key to get an item's value for matching
|
|
27
38
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
43
|
+
*
|
|
44
|
+
* move(array, {id: 1}, {id: 3}, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
|
|
45
|
+
* move(array, [{id: 2}, {id: 3}], {id: 4}, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
|
|
46
|
+
* move(array, {id: 5}, {id: 1}, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
|
|
47
|
+
* ```
|
|
28
48
|
*/
|
|
29
|
-
declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[],
|
|
49
|
+
declare function move<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], from: Item | Item[], to: Item | Item[], key: ItemKey): Item[];
|
|
30
50
|
/**
|
|
31
51
|
* Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
|
|
32
52
|
*
|
|
33
53
|
* When moving to the front of the array, the moved items will be placed __before__ the target item. When moving to the back of the array, the moved items will be placed __after__ the target item.
|
|
34
54
|
*
|
|
35
55
|
* If either of values are not present in the array, or if they overlap, the array will be returned unchanged
|
|
56
|
+
*
|
|
36
57
|
* @param array Array to move within
|
|
37
58
|
* @param from Item or items to move
|
|
38
59
|
* @param to Item or items to move to
|
|
39
60
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const array = [1, 2, 3, 4];
|
|
65
|
+
*
|
|
66
|
+
* move(array, 1, 3); // => [2, 3, 1, 4]
|
|
67
|
+
* move(array, [2, 3], 4); // => [1, 4, 2, 3]
|
|
68
|
+
* move(array, 5, 1); // => [1, 2, 3, 4] (unchanged)
|
|
69
|
+
* ```
|
|
40
70
|
*/
|
|
41
71
|
declare function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[]): Item[];
|
|
42
72
|
declare namespace move {
|
|
@@ -49,10 +79,20 @@ declare namespace move {
|
|
|
49
79
|
* If the from index is out of bounds, the array will be returned unchanged
|
|
50
80
|
*
|
|
51
81
|
* Available as `moveIndices` and `move.indices`
|
|
82
|
+
*
|
|
52
83
|
* @param array Array to move within
|
|
53
84
|
* @param from Index to move from
|
|
54
85
|
* @param to Index to move to
|
|
55
86
|
* @returns Original array with item moved _(or unchanged if unable to move)_
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const array = [1, 2, 3, 4];
|
|
91
|
+
*
|
|
92
|
+
* moveIndices(array, 0, 2); // => [2, 3, 1, 4]
|
|
93
|
+
* moveIndices(array, -1, 0); // => [4, 2, 3, 1]
|
|
94
|
+
* moveIndices(array, 5, 1); // => [4, 2, 3, 1] (unchanged)
|
|
95
|
+
* ```
|
|
56
96
|
*/
|
|
57
97
|
declare function moveIndices<Item>(array: Item[], from: number, to: number): Item[];
|
|
58
98
|
/**
|
|
@@ -61,36 +101,66 @@ declare function moveIndices<Item>(array: Item[], from: number, to: number): Ite
|
|
|
61
101
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
62
102
|
*
|
|
63
103
|
* Available as `moveToIndex` and `move.toIndex`
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
108
|
+
*
|
|
109
|
+
* moveToIndex(array, {id: 1}, 2, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
|
|
110
|
+
* moveToIndex(array, [{id: 2}, {id: 3}], 3, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
|
|
111
|
+
* moveToIndex(array, {id: 5}, 1, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
64
114
|
* @param array Array to move within
|
|
65
115
|
* @param value Item or items to move
|
|
66
116
|
* @param index Index to move to
|
|
67
|
-
* @param
|
|
117
|
+
* @param callback Callback to get an item's value for matching
|
|
68
118
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
69
119
|
*/
|
|
70
|
-
declare function moveToIndex<Item
|
|
120
|
+
declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
|
|
71
121
|
/**
|
|
72
122
|
* Move an item _(or array of items)_ to an index within an array
|
|
73
123
|
*
|
|
74
124
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
75
125
|
*
|
|
76
126
|
* Available as `moveToIndex` and `move.toIndex`
|
|
127
|
+
*
|
|
77
128
|
* @param array Array to move within
|
|
78
129
|
* @param value Item or items to move
|
|
79
130
|
* @param index Index to move to
|
|
80
|
-
* @param
|
|
131
|
+
* @param key Key to get an item's value for matching
|
|
81
132
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
|
|
137
|
+
*
|
|
138
|
+
* moveToIndex(array, {id: 1}, 2, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
|
|
139
|
+
* moveToIndex(array, [{id: 2}, {id: 3}], 3, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
|
|
140
|
+
* moveToIndex(array, {id: 5}, 1, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
|
|
141
|
+
* ```
|
|
82
142
|
*/
|
|
83
|
-
declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number,
|
|
143
|
+
declare function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], value: Item | Item[], index: number, key: ItemKey): Item[];
|
|
84
144
|
/**
|
|
85
145
|
* Move an item _(or array of items)_ to an index within an array
|
|
86
146
|
*
|
|
87
147
|
* If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
|
|
88
148
|
*
|
|
89
149
|
* Available as `moveToIndex` and `move.toIndex`
|
|
150
|
+
*
|
|
90
151
|
* @param array Array to move within
|
|
91
152
|
* @param value Item or items to move
|
|
92
153
|
* @param index Index to move to
|
|
93
154
|
* @returns Original array with items moved _(or unchanged if unable to move)_
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const array = [1, 2, 3, 4];
|
|
159
|
+
*
|
|
160
|
+
* moveToIndex(array, 1, 2); // => [2, 3, 1, 4]
|
|
161
|
+
* moveToIndex(array, [2, 3], 3); // => [1, 4, 2, 3]
|
|
162
|
+
* moveToIndex(array, 5, 1); // => [1, 2, 3, 4] (unchanged)
|
|
163
|
+
* ```
|
|
94
164
|
*/
|
|
95
165
|
declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number): Item[];
|
|
96
166
|
//#endregion
|
package/dist/array/move.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { indexOfArray } from "./
|
|
1
|
+
import { indexOfArray } from "./match.mjs";
|
|
2
2
|
import { arraysOverlap } from "../internal/array/overlap.mjs";
|
|
3
3
|
//#region src/array/move.ts
|
|
4
4
|
function move(array, from, to, key) {
|
|
@@ -31,10 +31,20 @@ move.toIndex = moveToIndex;
|
|
|
31
31
|
* If the from index is out of bounds, the array will be returned unchanged
|
|
32
32
|
*
|
|
33
33
|
* Available as `moveIndices` and `move.indices`
|
|
34
|
+
*
|
|
34
35
|
* @param array Array to move within
|
|
35
36
|
* @param from Index to move from
|
|
36
37
|
* @param to Index to move to
|
|
37
38
|
* @returns Original array with item moved _(or unchanged if unable to move)_
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const array = [1, 2, 3, 4];
|
|
43
|
+
*
|
|
44
|
+
* moveIndices(array, 0, 2); // => [2, 3, 1, 4]
|
|
45
|
+
* moveIndices(array, -1, 0); // => [4, 2, 3, 1]
|
|
46
|
+
* moveIndices(array, 5, 1); // => [4, 2, 3, 1] (unchanged)
|
|
47
|
+
* ```
|
|
38
48
|
*/
|
|
39
49
|
function moveIndices(array, from, to) {
|
|
40
50
|
if (!Array.isArray(array)) return [];
|
|
@@ -3,32 +3,67 @@ import { PlainObject } from "../models.mjs";
|
|
|
3
3
|
//#region src/array/partition.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Get a partitioned array of items
|
|
6
|
+
*
|
|
6
7
|
* @param array Array to search in
|
|
7
8
|
* @param callback Callback to get an item's value for matching
|
|
8
9
|
* @param value Value to match against
|
|
9
10
|
* @returns Partitioned array of items
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* partition(
|
|
15
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
16
|
+
* item => item.id,
|
|
17
|
+
* 2,
|
|
18
|
+
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
19
|
+
* ```
|
|
10
20
|
*/
|
|
11
21
|
declare function partition<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[][];
|
|
12
22
|
/**
|
|
13
23
|
* Get a partitioned array of items
|
|
24
|
+
*
|
|
14
25
|
* @param array Array to search in
|
|
15
26
|
* @param key Key to get an item's value for matching
|
|
16
27
|
* @param value Value to match against
|
|
17
28
|
* @returns Partitioned array of items
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* partition(
|
|
33
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
34
|
+
* 'id',
|
|
35
|
+
* 2,
|
|
36
|
+
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
37
|
+
* ```
|
|
18
38
|
*/
|
|
19
39
|
declare function partition<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[][];
|
|
20
40
|
/**
|
|
21
41
|
* Get a partitioned array of items
|
|
42
|
+
*
|
|
22
43
|
* @param array Array to search in
|
|
23
44
|
* @param filter Filter callback to match items
|
|
24
45
|
* @returns Partitioned array of items
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* partition(
|
|
50
|
+
* [{id: 1}, {id: 2}, {id: 3}],
|
|
51
|
+
* item => item.id === 2,
|
|
52
|
+
* ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
|
|
53
|
+
* ```
|
|
25
54
|
*/
|
|
26
55
|
declare function partition<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[][];
|
|
27
56
|
/**
|
|
28
57
|
* Get a partitioned array of items matching the given item
|
|
58
|
+
*
|
|
29
59
|
* @param array Array to search in
|
|
30
60
|
* @param item Item to match against
|
|
31
61
|
* @returns Partitioned array of items
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* partition([1, 2, 3, 4, 5], 3); // => [[3], [1, 2, 4, 5]]
|
|
66
|
+
* ```
|
|
32
67
|
*/
|
|
33
68
|
declare function partition<Item>(array: Item[], item: Item): Item[][];
|
|
34
69
|
//#endregion
|
package/dist/array/push.d.mts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
//#region src/array/push.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Push items into an array _(at the end)_
|
|
4
|
+
*
|
|
5
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
6
|
+
*
|
|
4
7
|
* @param array Original array
|
|
5
8
|
* @param pushed Pushed items
|
|
6
9
|
* @returns New length of the array
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* push([1, 2, 3], [4, 5]); // => 5 (new length); array becomes [1, 2, 3, 4, 5]
|
|
14
|
+
* ```
|
|
7
15
|
*/
|
|
8
16
|
declare function push<Item>(array: Item[], pushed: Item[]): number;
|
|
9
17
|
//#endregion
|
package/dist/array/push.mjs
CHANGED
|
@@ -2,9 +2,17 @@ import { INSERT_TYPE_PUSH, insertValues } from "../internal/array/insert.mjs";
|
|
|
2
2
|
//#region src/array/push.ts
|
|
3
3
|
/**
|
|
4
4
|
* Push items into an array _(at the end)_
|
|
5
|
+
*
|
|
6
|
+
* _(Uses chunking to avoid call stack size being exceeded)_
|
|
7
|
+
*
|
|
5
8
|
* @param array Original array
|
|
6
9
|
* @param pushed Pushed items
|
|
7
10
|
* @returns New length of the array
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* push([1, 2, 3], [4, 5]); // => 5 (new length); array becomes [1, 2, 3, 4, 5]
|
|
15
|
+
* ```
|
|
8
16
|
*/
|
|
9
17
|
function push(array, pushed) {
|
|
10
18
|
return insertValues(INSERT_TYPE_PUSH, array, pushed, array.length, 0);
|
package/dist/array/reverse.d.mts
CHANGED