@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.
Files changed (156) hide show
  1. package/dist/array/difference.d.mts +29 -0
  2. package/dist/array/exists.d.mts +35 -0
  3. package/dist/array/filter.d.mts +72 -2
  4. package/dist/array/find.d.mts +70 -0
  5. package/dist/array/first.d.mts +77 -2
  6. package/dist/array/flatten.d.mts +6 -0
  7. package/dist/array/flatten.mjs +6 -0
  8. package/dist/array/from.d.mts +36 -0
  9. package/dist/array/get.d.mts +21 -13
  10. package/dist/array/group-by.d.mts +142 -0
  11. package/dist/array/index.d.mts +2 -2
  12. package/dist/array/index.mjs +2 -2
  13. package/dist/array/insert.d.mts +16 -0
  14. package/dist/array/intersection.d.mts +29 -0
  15. package/dist/array/last.d.mts +75 -2
  16. package/dist/array/{position.d.mts → match.d.mts} +168 -36
  17. package/dist/array/{position.mjs → match.mjs} +16 -16
  18. package/dist/array/move.d.mts +78 -8
  19. package/dist/array/move.mjs +11 -1
  20. package/dist/array/partition.d.mts +35 -0
  21. package/dist/array/push.d.mts +8 -0
  22. package/dist/array/push.mjs +8 -0
  23. package/dist/array/reverse.d.mts +1 -0
  24. package/dist/array/reverse.mjs +1 -0
  25. package/dist/array/select.d.mts +94 -8
  26. package/dist/array/single.d.mts +29 -0
  27. package/dist/array/slice.d.mts +106 -16
  28. package/dist/array/sort.d.mts +30 -4
  29. package/dist/array/sort.mjs +1 -1
  30. package/dist/array/splice.d.mts +48 -0
  31. package/dist/array/splice.mjs +2 -1
  32. package/dist/array/swap.d.mts +113 -8
  33. package/dist/array/swap.mjs +2 -1
  34. package/dist/array/to-map.d.mts +124 -0
  35. package/dist/array/to-record.d.mts +124 -0
  36. package/dist/array/to-set.d.mts +24 -0
  37. package/dist/array/toggle.d.mts +38 -3
  38. package/dist/array/union.d.mts +29 -0
  39. package/dist/array/unique.d.mts +24 -0
  40. package/dist/array/update.d.mts +38 -3
  41. package/dist/beacon.d.mts +12 -0
  42. package/dist/beacon.mjs +9 -0
  43. package/dist/color/instance.d.mts +8 -0
  44. package/dist/color/instance.mjs +3 -0
  45. package/dist/color/models.d.mts +30 -0
  46. package/dist/function/assert.d.mts +29 -8
  47. package/dist/function/assert.mjs +29 -8
  48. package/dist/function/memoize.d.mts +3 -0
  49. package/dist/function/memoize.mjs +3 -0
  50. package/dist/function/retry.d.mts +3 -0
  51. package/dist/function/retry.mjs +3 -0
  52. package/dist/function/work.mjs +1 -1
  53. package/dist/index.d.mts +2158 -288
  54. package/dist/index.mjs +294 -181
  55. package/dist/internal/array/chunk.d.mts +6 -0
  56. package/dist/internal/array/chunk.mjs +6 -0
  57. package/dist/internal/array/compact.d.mts +12 -0
  58. package/dist/internal/array/index-of.d.mts +70 -0
  59. package/dist/internal/math/aggregate.d.mts +29 -0
  60. package/dist/internal/value/compare.d.mts +2 -1
  61. package/dist/internal/value/equal.d.mts +5 -0
  62. package/dist/internal/value/get.d.mts +27 -5
  63. package/dist/internal/value/has.d.mts +7 -7
  64. package/dist/internal/value/has.mjs +1 -1
  65. package/dist/internal/value/misc.d.mts +2 -2
  66. package/dist/internal/value/misc.mjs +10 -4
  67. package/dist/logger.d.mts +11 -0
  68. package/dist/logger.mjs +11 -0
  69. package/dist/models.d.mts +14 -1
  70. package/dist/promise/helpers.mjs +1 -1
  71. package/dist/promise/index.d.mts +0 -6
  72. package/dist/promise/models.d.mts +36 -0
  73. package/dist/promise/models.mjs +6 -0
  74. package/dist/queue.d.mts +13 -1
  75. package/dist/queue.mjs +9 -0
  76. package/dist/result/index.d.mts +0 -8
  77. package/dist/result/index.mjs +0 -8
  78. package/dist/result/match.d.mts +4 -4
  79. package/dist/result/work/flow.d.mts +12 -36
  80. package/dist/result/work/pipe.d.mts +11 -33
  81. package/dist/sized/set.d.mts +3 -2
  82. package/dist/sized/set.mjs +3 -2
  83. package/dist/value/collection.d.mts +1 -1
  84. package/dist/value/handle.mjs +1 -1
  85. package/dist/value/merge.d.mts +28 -25
  86. package/dist/value/merge.mjs +29 -18
  87. package/dist/value/shake.d.mts +3 -0
  88. package/dist/value/smush.d.mts +3 -0
  89. package/dist/value/transform.d.mts +10 -1
  90. package/dist/value/unsmush.d.mts +2 -3
  91. package/package.json +5 -5
  92. package/src/array/difference.ts +33 -0
  93. package/src/array/exists.ts +35 -0
  94. package/src/array/filter.ts +72 -2
  95. package/src/array/find.ts +70 -0
  96. package/src/array/first.ts +77 -3
  97. package/src/array/flatten.ts +6 -0
  98. package/src/array/from.ts +40 -0
  99. package/src/array/get.ts +21 -15
  100. package/src/array/group-by.ts +142 -0
  101. package/src/array/index.ts +1 -1
  102. package/src/array/insert.ts +16 -2
  103. package/src/array/intersection.ts +33 -0
  104. package/src/array/last.ts +75 -2
  105. package/src/array/{position.ts → match.ts} +197 -65
  106. package/src/array/move.ts +87 -13
  107. package/src/array/partition.ts +35 -0
  108. package/src/array/push.ts +8 -2
  109. package/src/array/reverse.ts +5 -0
  110. package/src/array/select.ts +96 -13
  111. package/src/array/single.ts +29 -0
  112. package/src/array/slice.ts +114 -24
  113. package/src/array/sort.ts +30 -4
  114. package/src/array/splice.ts +52 -4
  115. package/src/array/swap.ts +122 -13
  116. package/src/array/to-map.ts +124 -0
  117. package/src/array/to-record.ts +124 -0
  118. package/src/array/to-set.ts +24 -0
  119. package/src/array/toggle.ts +42 -3
  120. package/src/array/union.ts +33 -0
  121. package/src/array/unique.ts +24 -0
  122. package/src/array/update.ts +38 -3
  123. package/src/beacon.ts +12 -0
  124. package/src/color/index.ts +0 -3
  125. package/src/color/instance.ts +9 -1
  126. package/src/color/models.ts +30 -0
  127. package/src/function/assert.ts +66 -7
  128. package/src/function/memoize.ts +3 -0
  129. package/src/function/once.ts +5 -1
  130. package/src/function/retry.ts +3 -0
  131. package/src/internal/array/chunk.ts +6 -0
  132. package/src/internal/array/compact.ts +12 -0
  133. package/src/internal/array/index-of.ts +70 -0
  134. package/src/internal/math/aggregate.ts +29 -0
  135. package/src/internal/string.ts +0 -2
  136. package/src/internal/value/compare.ts +2 -1
  137. package/src/internal/value/equal.ts +5 -0
  138. package/src/internal/value/get.ts +27 -5
  139. package/src/internal/value/has.ts +10 -10
  140. package/src/internal/value/misc.ts +24 -13
  141. package/src/logger.ts +11 -0
  142. package/src/models.ts +18 -0
  143. package/src/promise/index.ts +0 -6
  144. package/src/promise/models.ts +36 -0
  145. package/src/queue.ts +13 -1
  146. package/src/result/index.ts +0 -8
  147. package/src/result/match.ts +4 -4
  148. package/src/result/work/flow.ts +12 -36
  149. package/src/result/work/pipe.ts +11 -33
  150. package/src/sized/set.ts +4 -3
  151. package/src/value/collection.ts +1 -1
  152. package/src/value/merge.ts +88 -66
  153. package/src/value/shake.ts +3 -0
  154. package/src/value/smush.ts +3 -0
  155. package/src/value/transform.ts +10 -1
  156. package/src/value/unsmush.ts +2 -8
@@ -1,121 +1,253 @@
1
1
  import { PlainObject } from "../models.mjs";
2
2
 
3
- //#region src/array/position.d.ts
4
- type ArrayPosition = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
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 key Key to get an item's value for matching
10
- * @return `true` if the haystack ends with the needle, otherwise `false`
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 extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
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 callback Callback to get an item's value for matching
18
- * @return `true` if the haystack ends with the needle, otherwise `false`
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[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
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
- * @return `true` if the haystack ends with the needle, otherwise `false`
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 key Key to get an item's value for matching
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 getArrayPosition<Item extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): ArrayPosition;
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 callback Callback to get an item's value for matching
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 getArrayPosition<Item>(haystack: Item[], needle: Item[], callback: (item: Item, index: number, array: Item[]) => unknown): ArrayPosition;
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 getArrayPosition<Item>(haystack: Item[], needle: Item[]): ArrayPosition;
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 key Key to get an item's value for matching
56
- * @return `true` if the haystack includes the needle, otherwise `false`
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 extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
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 callback Callback to get an item's value for matching
64
- * @return `true` if the haystack includes the needle, otherwise `false`
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[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
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
- * @return `true` if the haystack includes the needle, otherwise `false`
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 key Key to get an item's value for matching
79
- * @return Index of the needle's start within the haystack, or `-1` if it is not found
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 extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): number;
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 callback Callback to get an item's value for matching
87
- * @return Index of the needle's start within the haystack, or `-1` if it is not found
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[], callback: (item: Item, index: number, array: Item[]) => unknown): number;
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
- * @return Index of the needle's start within the haystack, or `-1` if it is not found
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 key Key to get an item's value for matching
102
- * @return `true` if the haystack starts with the needle, otherwise `false`
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 extends PlainObject>(haystack: Item[], needle: Item[], key: keyof Item): boolean;
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 callback Callback to get an item's value for matching
110
- * @return `true` if the haystack starts with the needle, otherwise `false`
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[], callback: (item: Item, index: number, array: Item[]) => unknown): boolean;
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
- * @return `true` if the haystack starts with the needle, otherwise `false`
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 { ArrayPosition, endsWithArray, getArrayPosition, includesArray, indexOfArray, startsWithArray };
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/position.ts
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 getArrayPosition(haystack, needle, key) {
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 ? POSITION_SAME : POSITION_START;
11
- return start + needle === haystack ? POSITION_END : POSITION_INSIDE;
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 POSITION_END = "end";
47
- const POSITION_INSIDE = "inside";
48
- const POSITION_INVALID = "invalid";
49
- const POSITION_OUTSIDE = "outside";
50
- const POSITION_SAME = "same";
51
- const POSITION_START = "start";
52
- const endings = new Set([POSITION_END, POSITION_SAME]);
53
- const invalid = [-1, POSITION_INVALID];
54
- const outside = [-1, POSITION_OUTSIDE];
55
- const outsides = new Set([POSITION_INVALID, POSITION_OUTSIDE]);
56
- const starts = new Set([POSITION_START, POSITION_SAME]);
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, getArrayPosition, includesArray, indexOfArray, startsWithArray };
58
+ export { endsWithArray, getArrayComparison, includesArray, indexOfArray, startsWithArray };
@@ -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 key Key to get an item's value for matching
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 extends PlainObject, ItemKey extends keyof Item>(array: Item[], from: Item | Item[], to: Item | Item[], key: ItemKey): 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 callback Callback to get an item's value for matching
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[], callback: (item: Item, index: number, array: Item[]) => unknown): 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 key Key to get an item's value for matching
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 extends PlainObject, ItemKey extends keyof Item>(array: Item[], value: Item | Item[], index: number, key: ItemKey): 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 callback Callback to get an item's value for matching
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, callback: (item: Item, index: number, array: Item[]) => unknown): Item[];
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
@@ -1,4 +1,4 @@
1
- import { indexOfArray } from "./position.mjs";
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
@@ -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
@@ -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);
@@ -1,6 +1,7 @@
1
1
  //#region src/array/reverse.d.ts
2
2
  /**
3
3
  * Reverse the order of items in an array
4
+ *
4
5
  * @param array Array to reverse
5
6
  * @returns Reversed array
6
7
  */
@@ -1,6 +1,7 @@
1
1
  //#region src/array/reverse.ts
2
2
  /**
3
3
  * Reverse the order of items in an array
4
+ *
4
5
  * @param array Array to reverse
5
6
  * @returns Reversed array
6
7
  */