@oscarpalmer/atoms 0.193.0 → 0.194.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.
Files changed (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
package/src/array/move.ts DELETED
@@ -1,315 +0,0 @@
1
- import {arraysOverlap} from '../internal/array/overlap';
2
- import type {PlainObject} from '../models';
3
- import {indexOfArray} from './match';
4
-
5
- // #region Functions
6
-
7
- /**
8
- * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
9
- *
10
- * 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
11
- *
12
- * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
13
- *
14
- * @param array Array to move within
15
- * @param from Item or items to move
16
- * @param to Item or items to move to
17
- * @param callback Callback to get an item's value for matching
18
- * @returns Original array with items moved _(or unchanged if unable to move)_
19
- *
20
- * @example
21
- * ```typescript
22
- * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
23
- *
24
- * move(array, {id: 1}, {id: 3}, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
25
- * move(array, [{id: 2}, {id: 3}], {id: 4}, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
26
- * move(array, {id: 5}, {id: 1}, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
27
- * ```
28
- */
29
- export function move<Item>(
30
- array: Item[],
31
- from: Item | Item[],
32
- to: Item | Item[],
33
- callback: (item: Item, index: number, array: Item[]) => unknown,
34
- ): Item[];
35
-
36
- /**
37
- * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
38
- *
39
- * 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
40
- *
41
- * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
42
- *
43
- * @param array Array to move within
44
- * @param from Item or items to move
45
- * @param to Item or items to move to
46
- * @param key Key to get an item's value for matching
47
- * @returns Original array with items moved _(or unchanged if unable to move)_
48
- *
49
- * @example
50
- * ```typescript
51
- * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
52
- *
53
- * move(array, {id: 1}, {id: 3}, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
54
- * move(array, [{id: 2}, {id: 3}], {id: 4}, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
55
- * move(array, {id: 5}, {id: 1}, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
56
- * ```
57
- */
58
- export function move<Item extends PlainObject, ItemKey extends keyof Item>(
59
- array: Item[],
60
- from: Item | Item[],
61
- to: Item | Item[],
62
- key: ItemKey,
63
- ): Item[];
64
-
65
- /**
66
- * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
67
- *
68
- * 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
69
- *
70
- * If either of values are not present in the array, or if they overlap, the array will be returned unchanged
71
- *
72
- * @param array Array to move within
73
- * @param from Item or items to move
74
- * @param to Item or items to move to
75
- * @returns Original array with items moved _(or unchanged if unable to move)_
76
- *
77
- * @example
78
- * ```typescript
79
- * const array = [1, 2, 3, 4];
80
- *
81
- * move(array, 1, 3); // => [2, 3, 1, 4]
82
- * move(array, [2, 3], 4); // => [1, 4, 2, 3]
83
- * move(array, 5, 1); // => [1, 2, 3, 4] (unchanged)
84
- * ```
85
- */
86
- export function move<Item>(array: Item[], from: Item | Item[], to: Item | Item[]): Item[];
87
-
88
- export function move(array: unknown[], from: unknown, to: unknown, key?: unknown): unknown[] {
89
- if (!Array.isArray(array)) {
90
- return [];
91
- }
92
-
93
- const firstArray = Array.isArray(from) ? from : [from];
94
- const secondArray = Array.isArray(to) ? to : [to];
95
-
96
- if (firstArray.length === 0 || secondArray.length === 0) {
97
- return array;
98
- }
99
-
100
- const firstPosition = indexOfArray(array, firstArray, key as never);
101
- const secondPosition = indexOfArray(array, secondArray, key as never);
102
-
103
- if (firstPosition === -1 || secondPosition === -1 || firstPosition === secondPosition) {
104
- return array;
105
- }
106
-
107
- const {overlap} = arraysOverlap(
108
- {
109
- array: firstArray,
110
- index: firstPosition,
111
- },
112
- {
113
- array: secondArray,
114
- index: secondPosition,
115
- },
116
- );
117
-
118
- if (overlap) {
119
- // The arrays overlap, so we can't swap them without losing data
120
-
121
- return array;
122
- }
123
-
124
- array.splice(firstPosition, firstArray.length);
125
-
126
- const next =
127
- secondPosition < firstPosition
128
- ? secondPosition
129
- : secondPosition + secondArray.length - firstArray.length;
130
-
131
- if (next >= array.length) {
132
- array.push(...firstArray);
133
- } else {
134
- array.splice(next, 0, ...firstArray);
135
- }
136
-
137
- return array;
138
- }
139
-
140
- move.indices = moveIndices;
141
- move.toIndex = moveToIndex;
142
-
143
- /**
144
- * Move an item from one index to another within an array
145
- *
146
- * If the from index is out of bounds, the array will be returned unchanged
147
- *
148
- * _Available as `moveIndices` and `move.indices`_
149
- *
150
- * @param array Array to move within
151
- * @param from Index to move from
152
- * @param to Index to move to
153
- * @returns Original array with item moved _(or unchanged if unable to move)_
154
- *
155
- * @example
156
- * ```typescript
157
- * const array = [1, 2, 3, 4];
158
- *
159
- * moveIndices(array, 0, 2); // => [2, 3, 1, 4]
160
- * moveIndices(array, -1, 0); // => [4, 2, 3, 1]
161
- * moveIndices(array, 5, 1); // => [4, 2, 3, 1] (unchanged)
162
- * ```
163
- */
164
- export function moveIndices<Item>(array: Item[], from: number, to: number): Item[] {
165
- if (!Array.isArray(array)) {
166
- return [];
167
- }
168
-
169
- const {length} = array;
170
-
171
- if (length === 0 || typeof from !== 'number' || typeof to !== 'number') {
172
- return array;
173
- }
174
-
175
- const fromIndex = from < 0 ? length + from : from;
176
- const toIndex = to < 0 ? length + to : to;
177
-
178
- if (fromIndex === toIndex || fromIndex >= length || toIndex >= length) {
179
- return array;
180
- }
181
-
182
- const spliced = array.splice(fromIndex, 1);
183
-
184
- if (toIndex >= array.length) {
185
- array.push(...spliced);
186
- } else {
187
- array.splice(toIndex, 0, ...spliced);
188
- }
189
-
190
- return array;
191
- }
192
-
193
- /**
194
- * Move an item _(or array of items)_ to an index within an array
195
- *
196
- * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
197
- *
198
- * _Available as `moveToIndex` and `move.toIndex`_
199
- *
200
- * @example
201
- * ```typescript
202
- * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
203
- *
204
- * moveToIndex(array, {id: 1}, 2, item => item.id); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
205
- * moveToIndex(array, [{id: 2}, {id: 3}], 3, item => item.id); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
206
- * moveToIndex(array, {id: 5}, 1, item => item.id); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
207
- * ```
208
- *
209
- * @param array Array to move within
210
- * @param value Item or items to move
211
- * @param index Index to move to
212
- * @param callback Callback to get an item's value for matching
213
- * @returns Original array with items moved _(or unchanged if unable to move)_
214
- */
215
- export function moveToIndex<Item>(
216
- array: Item[],
217
- value: Item | Item[],
218
- index: number,
219
- callback: (item: Item, index: number, array: Item[]) => unknown,
220
- ): Item[];
221
-
222
- /**
223
- * Move an item _(or array of items)_ to an index within an array
224
- *
225
- * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
226
- *
227
- * _Available as `moveToIndex` and `move.toIndex`_
228
- *
229
- * @param array Array to move within
230
- * @param value Item or items to move
231
- * @param index Index to move to
232
- * @param key Key to get an item's value for matching
233
- * @returns Original array with items moved _(or unchanged if unable to move)_
234
- *
235
- * @example
236
- * ```typescript
237
- * const array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}];
238
- *
239
- * moveToIndex(array, {id: 1}, 2, 'id'); // => [{id: 2}, {id: 3}, {id: 1}, {id: 4}]
240
- * moveToIndex(array, [{id: 2}, {id: 3}], 3, 'id'); // => [{id: 1}, {id: 4}, {id: 2}, {id: 3}]
241
- * moveToIndex(array, {id: 5}, 1, 'id'); // => [{id: 1}, {id: 2}, {id: 3}, {id: 4}] (unchanged)
242
- * ```
243
- */
244
- export function moveToIndex<Item extends PlainObject, ItemKey extends keyof Item>(
245
- array: Item[],
246
- value: Item | Item[],
247
- index: number,
248
- key: ItemKey,
249
- ): Item[];
250
-
251
- /**
252
- * Move an item _(or array of items)_ to an index within an array
253
- *
254
- * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
255
- *
256
- * _Available as `moveToIndex` and `move.toIndex`_
257
- *
258
- * @param array Array to move within
259
- * @param value Item or items to move
260
- * @param index Index to move to
261
- * @returns Original array with items moved _(or unchanged if unable to move)_
262
- *
263
- * @example
264
- * ```typescript
265
- * const array = [1, 2, 3, 4];
266
- *
267
- * moveToIndex(array, 1, 2); // => [2, 3, 1, 4]
268
- * moveToIndex(array, [2, 3], 3); // => [1, 4, 2, 3]
269
- * moveToIndex(array, 5, 1); // => [1, 2, 3, 4] (unchanged)
270
- * ```
271
- */
272
- export function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number): Item[];
273
-
274
- export function moveToIndex(
275
- array: unknown[],
276
- value: unknown,
277
- index: number,
278
- key?: unknown,
279
- ): unknown[] {
280
- if (!Array.isArray(array)) {
281
- return [];
282
- }
283
-
284
- const {length} = array;
285
-
286
- if (length === 0 || typeof index !== 'number') {
287
- return array;
288
- }
289
-
290
- const next = index < 0 ? length + index : index;
291
-
292
- if (next >= length) {
293
- return array;
294
- }
295
-
296
- const values = Array.isArray(value) ? value : [value];
297
-
298
- const position = indexOfArray(array, values, key as never);
299
-
300
- if (position === -1 || position === next) {
301
- return array;
302
- }
303
-
304
- array.splice(position, values.length);
305
-
306
- if (next >= array.length) {
307
- array.push(...values);
308
- } else {
309
- array.splice(next, 0, ...values);
310
- }
311
-
312
- return array;
313
- }
314
-
315
- // #endregion
@@ -1,91 +0,0 @@
1
- import {FIND_VALUES_ALL, findValues} from '../internal/array/find';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Get a partitioned array of items
8
- *
9
- * @param array Array to search in
10
- * @param callback Callback to get an item's value for matching
11
- * @param value Value to match against
12
- * @returns Partitioned array of items
13
- *
14
- * @example
15
- * ```typescript
16
- * partition(
17
- * [{id: 1}, {id: 2}, {id: 3}],
18
- * item => item.id,
19
- * 2,
20
- * ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
21
- * ```
22
- */
23
- export function partition<
24
- Item,
25
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
26
- >(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[][];
27
-
28
- /**
29
- * Get a partitioned array of items
30
- *
31
- * @param array Array to search in
32
- * @param key Key to get an item's value for matching
33
- * @param value Value to match against
34
- * @returns Partitioned array of items
35
- *
36
- * @example
37
- * ```typescript
38
- * partition(
39
- * [{id: 1}, {id: 2}, {id: 3}],
40
- * 'id',
41
- * 2,
42
- * ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
43
- * ```
44
- */
45
- export function partition<Item extends PlainObject, ItemKey extends keyof Item>(
46
- array: Item[],
47
- key: ItemKey,
48
- value: Item[ItemKey],
49
- ): Item[][];
50
-
51
- /**
52
- * Get a partitioned array of items
53
- *
54
- * @param array Array to search in
55
- * @param filter Filter callback to match items
56
- * @returns Partitioned array of items
57
- *
58
- * @example
59
- * ```typescript
60
- * partition(
61
- * [{id: 1}, {id: 2}, {id: 3}],
62
- * item => item.id === 2,
63
- * ); // => [[{id: 2}], [{id: 1}, {id: 3}]]
64
- * ```
65
- */
66
- export function partition<Item>(
67
- array: Item[],
68
- filter: (item: Item, index: number, array: Item[]) => boolean,
69
- ): Item[][];
70
-
71
- /**
72
- * Get a partitioned array of items matching the given item
73
- *
74
- * @param array Array to search in
75
- * @param item Item to match against
76
- * @returns Partitioned array of items
77
- *
78
- * @example
79
- * ```typescript
80
- * partition([1, 2, 3, 4, 5], 3); // => [[3], [1, 2, 4, 5]]
81
- * ```
82
- */
83
- export function partition<Item>(array: Item[], item: Item): Item[][];
84
-
85
- export function partition(array: unknown[], ...parameters: unknown[]): unknown[][] {
86
- const {matched, notMatched} = findValues(FIND_VALUES_ALL, array, parameters);
87
-
88
- return [matched, notMatched];
89
- }
90
-
91
- // #endregion
package/src/array/push.ts DELETED
@@ -1,23 +0,0 @@
1
- import {INSERT_TYPE_PUSH, insertValues} from '../internal/array/insert';
2
-
3
- // #region Functions
4
-
5
- /**
6
- * Push items into an array _(at the end)_
7
- *
8
- * _(Uses chunking to avoid call stack size being exceeded)_
9
- *
10
- * @param array Original array
11
- * @param pushed Pushed items
12
- * @returns New length of the array
13
- *
14
- * @example
15
- * ```typescript
16
- * push([1, 2, 3], [4, 5]); // => 5 (new length); array becomes [1, 2, 3, 4, 5]
17
- * ```
18
- */
19
- export function push<Item>(array: Item[], pushed: Item[]): number {
20
- return insertValues(INSERT_TYPE_PUSH, array, pushed, array.length, 0) as number;
21
- }
22
-
23
- // #endregion
@@ -1,33 +0,0 @@
1
- // #region Functions
2
-
3
- /**
4
- * Reverse the order of items in an array
5
- *
6
- * @param array Array to reverse
7
- * @returns Reversed array
8
- */
9
- export function reverse<Item>(array: Item[]): Item[] {
10
- if (!Array.isArray(array)) {
11
- return [];
12
- }
13
-
14
- const {length} = array;
15
-
16
- if (length < 2) {
17
- return array;
18
- }
19
-
20
- const half = Math.floor(length / 2);
21
-
22
- for (let firstIndex = 0; firstIndex < half; firstIndex += 1) {
23
- const temporaryItem = array[firstIndex];
24
- const secondIndex = length - 1 - firstIndex;
25
-
26
- array[firstIndex] = array[secondIndex];
27
- array[secondIndex] = temporaryItem;
28
- }
29
-
30
- return array;
31
- }
32
-
33
- // #endregion Functions