@tolki/arr 0.0.0-stage → 0.0.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/arr.d.ts ADDED
@@ -0,0 +1,1701 @@
1
+ import { SortDirection } from '@tolki/enum';
2
+ import { ArrayInnerValue, ArrayItems, ArrayResolvePath, ArrayResolvePathOrDefault, ArrayResolvePathOrNull, CaseValue, CollapsedObject, DotReach, EnsureArray, FlattenItemReach, MapArrayKey, NonNullableArray, NonObjectItems, ObjectFlatValue, ObjectValue, PathKey, PathKeys, PluckValue, SetObjectPath, Simplify, SortSpec, SpreadArgs, TruthyArray, UndotArrayKey, UndotResult } from '@tolki/types';
3
+ /**
4
+ * Mutation contract: pop, shift, splice and unshift mutate their first
5
+ * argument; every other function returns a new value. arr and obj agree
6
+ * on this — re-read Collection.php before "aligning" one to the other.
7
+ */
8
+ type WrapResult<TValue> = TValue extends unknown ? [TValue] : never;
9
+ type NonBooleanValue = string | number | bigint | symbol | object | null | undefined;
10
+ type AnyValueOr<TCallback> = TCallback | NonNullable<unknown> | null | undefined;
11
+ type CanonicalIndex<TSegment extends string> = TSegment extends `${infer TIndex extends number}` ? `${TIndex}` extends TSegment ? TSegment : never : never;
12
+ type ListIndex<TSegment extends string> = TSegment extends `-${string}` ? never : CanonicalIndex<TSegment>;
13
+ type PathHead<TPath extends string> = TPath extends `${infer THead}.${string}` ? THead : TPath;
14
+ type ArraySetPathTarget<TValue> = [TValue] extends [never] ? object : TValue extends readonly unknown[] ? object : TValue extends object ? TValue : object;
15
+ type ArraySetPathElement<TValue, TRest extends string, TSetValue> = [
16
+ Extract<TValue, ReadonlyMap<unknown, unknown>>
17
+ ] extends [never] ? SetObjectPath<ArraySetPathTarget<TValue>, TRest, TSetValue> : SetObjectPath<{
18
+ element: TValue;
19
+ }, `element.${TRest}`, TSetValue>["element"];
20
+ type ArraySetPathListElement<TValue> = [TValue] extends [readonly unknown[]] ? TValue[] : (TValue | unknown[])[];
21
+ type ArraySetPathResult<TValue, TPath extends string, TSetValue> = TPath extends `${infer THead}.${infer TRest}` ? [ListIndex<THead>] extends [never] ? TValue[] : [CanonicalIndex<PathHead<TRest>>] extends [never] ? [ArraySetPathElement<TValue, TRest, TSetValue>] extends [TValue] ? [TValue] extends [ArraySetPathElement<TValue, TRest, TSetValue>] ? TValue[] : (TValue | ArraySetPathElement<TValue, TRest, TSetValue>)[] : (TValue | ArraySetPathElement<TValue, TRest, TSetValue>)[] : ArraySetPathListElement<TValue> : TValue[];
22
+ type DotLeaf<T, D extends number = 5> = [D] extends [never] ? unknown : T extends readonly (infer E)[] ? DotLeaf<E, DotDepth[D]> | (0 extends T["length"] ? T : never) : T extends ReadonlyMap<unknown, infer V> ? DotLeaf<V, DotDepth[D]> | T : T extends NonObjectItems | Date | RegExp | Promise<unknown> ? T : T extends object ? [keyof T] extends [never] ? unknown : DotLeaf<ObjectValue<T>, DotDepth[D]> | (Record<never, never> extends T ? T : never) : T;
23
+ type DotDepth = [never, 0, 1, 2, 3, 4];
24
+ type CollapseRead<T> = T extends {
25
+ all: (...args: never[]) => infer R;
26
+ } ? R : T;
27
+ type CollapseNotPlain = readonly unknown[] | NonObjectItems | Date | RegExp | Promise<unknown>;
28
+ type CollapsePlain<T> = CollapseRead<T> extends infer U ? U extends CollapseNotPlain ? never : U extends object ? U : never : never;
29
+ type CollapseOther<T> = CollapseRead<T> extends infer U ? U extends CollapseNotPlain ? U : U extends object ? never : U : never;
30
+ type CollapseListItem<T> = CollapseRead<T> extends infer U ? U extends readonly (infer E)[] ? E : never : never;
31
+ type ArrCollapse<TItem> = ([CollapseOther<TItem>] extends [never] ? never : CollapseListItem<TItem>[]) | ([CollapsePlain<TItem>] extends [never] ? never : CollapsedObject<Record<number, TItem>>);
32
+ type PrependedItem<TValue, TPrependValue> = [TPrependValue] extends [TValue] ? TValue : TValue | TPrependValue;
33
+ type ListPrepend<TValue, TPrependValue, TPrependKey> = [
34
+ MapArrayKey<TPrependKey>
35
+ ] extends [0] ? PrependedItem<TValue, TPrependValue>[] : 0 extends MapArrayKey<TPrependKey> ? PrependedItem<TValue, TPrependValue>[] | Record<string | number, PrependedItem<TValue, TPrependValue>> : ListPrependRecord<TValue, TPrependValue, MapArrayKey<TPrependKey>>;
36
+ type ListPrependRecord<TValue, TPrependValue, TStoredKey> = [
37
+ Exclude<TStoredKey, number>
38
+ ] extends [never] ? Record<number, PrependedItem<TValue, TPrependValue>> : Simplify<Record<number, TValue | ([Extract<TStoredKey, number>] extends [never] ? never : TPrependValue)> & Record<Extract<Exclude<TStoredKey, number>, PropertyKey>, TPrependValue>>;
39
+ /**
40
+ * Determine whether the given value is array accessible.
41
+ *
42
+ * @example
43
+ *
44
+ * accessible([]); // true
45
+ * accessible([1, 2]); // true
46
+ * accessible({ a: 1, b: 2 }); // false
47
+ */
48
+ export declare function accessible<TValue>(value: TValue): value is TValue & unknown[];
49
+ /**
50
+ * Determine whether the given value is arrayable.
51
+ *
52
+ * @example
53
+ *
54
+ * arrayable([]); // true
55
+ * arrayable([1, 2]); // true
56
+ * arrayable({ a: 1, b: 2 }); // false
57
+ */
58
+ export declare function arrayable(value: unknown): value is unknown[];
59
+ /**
60
+ * Add an element to an array using "dot" notation if it doesn't exist.
61
+ *
62
+ * @param data - The array to add the element to.
63
+ * @param key - The key or dot-notated path where to add the value.
64
+ * @param value - The value to add.
65
+ * @returns A new array with the value added if the key didn't exist.
66
+ *
67
+ * @example
68
+ *
69
+ * add(['products', ['desk', [100]]], '1.1', 200); -> ['products', ['desk', [100, 200]]]
70
+ * add(['products', ['desk', [100]]], '2', ['chair', [150]]); -> ['products', ['desk', [100]], ['chair', [150]]]
71
+ */
72
+ export declare function add<TValue, TAddValue>(data: ArrayItems<TValue>, key: PathKey, value: TAddValue): (TValue | TAddValue)[];
73
+ /**
74
+ * Get an array item from an array using "dot" notation.
75
+ *
76
+ * @param data - The array to get the item from.
77
+ * @param key - The key or dot-notated path of the item to get.
78
+ * @param defaultValue - The default value if key is not found.
79
+ * @returns The array value.
80
+ * @throws InvalidArgumentException if the value is not an array.
81
+ *
82
+ * @example
83
+ *
84
+ * arrayItem([['a', 'b'], ['c', 'd']], 0); -> ['a', 'b']
85
+ * arrayItem([{items: ['x', 'y']}], '0.items'); -> ['x', 'y']
86
+ * arrayItem([{items: 'not array'}], '0.items'); -> throws InvalidArgumentException
87
+ */
88
+ export declare function arrayItem<TData extends readonly unknown[], TPath extends string | number>(data: TData, key: TPath): EnsureArray<ArrayResolvePath<TData, TPath>>;
89
+ export declare function arrayItem<TData extends readonly unknown[], TPath extends string | number, TDefault>(data: TData, key: TPath, defaultValue: TDefault | (() => TDefault) | null): EnsureArray<ArrayResolvePath<TData, TPath>>;
90
+ export declare function arrayItem<TDefault = null>(data: readonly unknown[] | null | undefined, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): unknown[];
91
+ /**
92
+ * Get a boolean item from an array using "dot" notation.
93
+ * Throws an error if the value is not a boolean.
94
+ *
95
+ * @param data - The array to get the item from.
96
+ * @param key - The key or dot-notated path of the item to get.
97
+ * @param defaultValue - The default value if key is not found.
98
+ * @returns The boolean value.
99
+ * @throws InvalidArgumentException if the value is not a boolean.
100
+ *
101
+ * @example
102
+ *
103
+ * boolean([true, false], 0); -> true
104
+ * boolean([{active: true}], '0.active'); -> true
105
+ * boolean([{active: 'yes'}], '0.active'); -> throws InvalidArgumentException
106
+ */
107
+ export declare function boolean<TValue, TDefault = null>(data: ArrayItems<TValue>, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): boolean;
108
+ export declare function boolean<TDefault = null>(data: readonly unknown[] | null | undefined, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): boolean;
109
+ /**
110
+ * Chunk the array into chunks of the given size.
111
+ *
112
+ * @see Collection::chunk — `packages/collection/stubs/Collection.php:1533`. Wraps `array_chunk`.
113
+ *
114
+ * @param data - The array to chunk
115
+ * @param size - The size of each chunk
116
+ * @param preserveKeys - Whether to key each chunk by its source index instead of reindexing it;
117
+ * defaults to false, since a JS array's own keys are already just its indices
118
+ * @returns Chunked array
119
+ */
120
+ export declare function chunk<TValue>(data: ArrayItems<TValue>, size: number, preserveKeys?: false | undefined): TValue[][];
121
+ export declare function chunk<TValue>(data: ArrayItems<TValue>, size: number, preserveKeys: true | undefined): Record<number, TValue>[];
122
+ export declare function chunk<TValue>(data: ArrayItems<TValue>, size: number, preserveKeys: boolean | undefined): TValue[][] | Record<number, TValue>[];
123
+ /**
124
+ * Chunk the array into chunks with a callback.
125
+ *
126
+ * @see Collection::chunkWhile — `packages/collection/stubs/Collection.php:1554`, which runs
127
+ * `LazyCollection::chunkWhile`. Chunks are reindexed, as `chunk` does.
128
+ *
129
+ * @param data - The array to chunk
130
+ * @param callback - Receives the value, its index and the chunk built so far; return true to keep appending
131
+ * @returns The chunked array
132
+ *
133
+ * @example
134
+ *
135
+ * chunkWhile(['A', 'A', 'B'], (value, index, chunk) => chunk.at(-1) === value); -> [['A', 'A'], ['B']]
136
+ */
137
+ export declare function chunkWhile<TValue>(data: ArrayItems<TValue>, callback: (value: TValue, index: number, chunk: TValue[]) => unknown): TValue[][];
138
+ /**
139
+ * Chunk the array into chunks by comparing adjacent values using the given key or callback.
140
+ *
141
+ * @see EnumeratesValues::chunkBy — `packages/collection/stubs/EnumeratesValues.php:939`.
142
+ * Adjacent values compare with PHP's `==`, so `1` and `"1"` share a chunk.
143
+ *
144
+ * @param data - The array to chunk
145
+ * @param key - A path into each item, or a callback receiving the value and its index
146
+ * @returns The chunked array
147
+ *
148
+ * @example
149
+ *
150
+ * chunkBy([1, 1, 2, 2, 1], (value) => value); -> [[1, 1], [2, 2], [1]]
151
+ * chunkBy([{ p: 'a' }, { p: 'a' }, { p: 'b' }], 'p'); -> [[{ p: 'a' }, { p: 'a' }], [{ p: 'b' }]]
152
+ */
153
+ export declare function chunkBy<TValue>(data: ArrayItems<TValue>, key: PathKey | ((value: TValue, index: number) => unknown)): TValue[][];
154
+ /**
155
+ * Collapse an array of arrays into a single array, or an array of objects into a single object.
156
+ *
157
+ * Once any item is a plain object, the result is `array_merge`'s: list values append under the next
158
+ * integer key, integer keys renumber and a later string key wins. A Collection-like item, a class
159
+ * instance with an `all()` method, unwraps through it; a plain object is data whatever members it has.
160
+ * Any other item that isn't a plain object or a list is skipped, as `Arr::collapse` skips a PHP
161
+ * object: a `Date`, a `Map` or a class instance.
162
+ *
163
+ * @param data - The array to collapse.
164
+ * @returns A new flattened array or merged object.
165
+ *
166
+ * @example
167
+ *
168
+ * collapse([[1], [2], [3], ['foo', 'bar']]); -> [1, 2, 3, 'foo', 'bar']
169
+ * collapse([{ a: 1, b: 2 }, { c: 3, d: 4 }]) -> { a: 1, b: 2, c: 3, d: 4 }
170
+ * collapse([[1, 2], { x: 1 }]) -> { 0: 1, 1: 2, x: 1 }
171
+ */
172
+ export declare function collapse<TValue>(data: TValue[][]): TValue[];
173
+ export declare function collapse<TValue extends ArrayItems<ArrayItems<unknown>>>(data: TValue): ArrayInnerValue<TValue[number]>[];
174
+ export declare function collapse<TItem extends object>(data: ArrayItems<TItem>): ArrCollapse<TItem>;
175
+ export declare function collapse<TValue extends ArrayItems<unknown>>(data: TValue): Record<string, unknown> | ArrayInnerValue<TValue[number]>[] | unknown[];
176
+ /**
177
+ * Combine an array of keys with an array of values into an object, like PHP's
178
+ * `array_combine()` / `Collection::combine()` (`Collection.php:936`).
179
+ *
180
+ * Each key is cast with `toPhpKeyString()`, matching `array_combine`'s key rules, so the
181
+ * result's key type is always `string` rather than `PropertyKey`. `values` is read by
182
+ * `arrayableValues`, so a keyed or Collection-like operand contributes its values in order.
183
+ *
184
+ * @see Collection::combine — `packages/collection/stubs/Collection.php:936`. Wraps `array_combine`.
185
+ *
186
+ * @param keys - The keys.
187
+ * @param values - The values, matched to `keys` by position.
188
+ * @returns A new object mapping each key to its corresponding value.
189
+ * @throws Error if `keys` and `values` do not have the same length.
190
+ */
191
+ export declare function combine<TKey, TValue>(keys: ArrayItems<TKey>, values: ArrayItems<TValue> | Record<PropertyKey, TValue>): Record<string, TValue>;
192
+ /**
193
+ * Cross join the given arrays, returning all possible permutations.
194
+ * Each argument is one dimension. The rows are array-shaped so keyed dimensions
195
+ * fall through to `objCrossJoin`, which walks them like PHP's `foreach`.
196
+ *
197
+ * @param arrays - The arrays to cross join.
198
+ * @return A new array with all combinations of the input arrays.
199
+ *
200
+ * @example
201
+ *
202
+ * crossJoin([1], ["a"]); -> [[1, 'a']]
203
+ * crossJoin([1, 2], ["x", "y"]); -> [[1, 'x'], [1, 'y'], [2, 'x'], [2, 'y']]
204
+ */
205
+ export declare function crossJoin(): unknown[][];
206
+ export declare function crossJoin<A>(a: readonly A[]): [A][];
207
+ export declare function crossJoin<A, B>(a: readonly A[], b: readonly B[]): [A, B][];
208
+ export declare function crossJoin<A, B, C>(a: readonly A[], b: readonly B[], c: readonly C[]): [A, B, C][];
209
+ export declare function crossJoin<A, B, C, D>(a: readonly A[], b: readonly B[], c: readonly C[], d: readonly D[]): [A, B, C, D][];
210
+ export declare function crossJoin<A, B, C, D, E>(a: readonly A[], b: readonly B[], c: readonly C[], d: readonly D[], e: readonly E[]): [A, B, C, D, E][];
211
+ export declare function crossJoin<A, B, C, D, E, F>(a: readonly A[], b: readonly B[], c: readonly C[], d: readonly D[], e: readonly E[], f: readonly F[]): [A, B, C, D, E, F][];
212
+ export declare function crossJoin(...arrays: readonly (readonly unknown[])[]): unknown[][];
213
+ /**
214
+ * Divide an array into two arrays. One with keys and the other with values.
215
+ *
216
+ * @param array - The array to divide.
217
+ * @return A tuple with an array of keys and an array of values.
218
+ *
219
+ * @example
220
+ *
221
+ * divide(["Desk", 100, true]); -> [[0, 1, 2], ['Desk', 100, true]]
222
+ */
223
+ export declare function divide(array: readonly []): [number[], unknown[]];
224
+ export declare function divide<TValue>(array: readonly TValue[]): [number[], TValue[]];
225
+ /**
226
+ * Flatten a multi-dimensional array with "dot" notation.
227
+ *
228
+ * @param data - The array or to flatten.
229
+ * @param prepend - An optional string to prepend to each key.
230
+ * @param depth - Maximum depth to flatten. Defaults to Infinity.
231
+ * @returns A new object with dot-notated keys.
232
+ *
233
+ * @example
234
+ *
235
+ * dot(['a', ['b', 'c']]); -> { '0': 'a', '1.0': 'b', '1.1': 'c' }
236
+ */
237
+ export declare function dot<TValue>(data: readonly TValue[], prepend?: string): Record<string, DotLeaf<TValue>>;
238
+ export declare function dot<TValue>(data: readonly TValue[], prepend: string, depth?: number): Record<string, DotReach<TValue>>;
239
+ export declare function dot<TValue>(data: readonly unknown[] | null | undefined, prepend?: string, depth?: number): Record<string, TValue>;
240
+ /**
241
+ * Convert a flatten "dot" notation object into an expanded array.
242
+ *
243
+ * Only accepts numeric-first dotted keys — use `Obj.undot` for anything else.
244
+ *
245
+ * @param map - The flat object with numeric-first dot-notated keys.
246
+ * @returns A new multi-dimensional array.
247
+ * @throws TypeError if any key segment isn't a canonical decimal integer within
248
+ * MAX_UNDOT_INDEX, or the resulting containers would exceed that budget.
249
+ *
250
+ * @example
251
+ *
252
+ * undot({ '0': 'a', '1.0': 'b', '1.1': 'c' }); -> ['a', ['b', 'c']]
253
+ */
254
+ export declare function undot<TValue, TKey extends UndotArrayKey = number>(map: Record<TKey, TValue>): UndotResult<TKey, TValue>;
255
+ /**
256
+ * Union multiple arrays, mirroring PHP's `+` operator: a KEY union, not a
257
+ * value union, folded left-to-right — the first array to occupy an index
258
+ * keeps it. Not `array_merge`/`Collection::merge`, which concatenates.
259
+ *
260
+ * @see Collection::union — `packages/collection/stubs/Collection.php:947`.
261
+ * Uses PHP's `+` operator (key union: left keys win), not `array_merge`.
262
+ *
263
+ * A `null`/`undefined` operand contributes nothing, matching the
264
+ * `(array) null` cast `getArrayableItems` performs before the `+`. The rows are
265
+ * array-shaped so keyed operands fall through to `objUnion`; at runtime such an
266
+ * operand still joins by key — each integer key fills that index if it is free,
267
+ * an index no operand fills holds `undefined`, and a string key, which a list
268
+ * can't hold, is dropped.
269
+ *
270
+ * @param arrays - The arrays to union.
271
+ * @returns A new array combining each array's indices, left-most wins.
272
+ */
273
+ export declare function union(): unknown[];
274
+ export declare function union<A>(a: readonly A[]): A[];
275
+ export declare function union<A, B>(a: readonly A[], b: readonly B[]): (A | B)[];
276
+ export declare function union<A, B, C>(a: readonly A[], b: readonly B[], c: readonly C[]): (A | B | C)[];
277
+ export declare function union<A, B, C, D>(a: readonly A[], b: readonly B[], c: readonly C[], d: readonly D[]): (A | B | C | D)[];
278
+ export declare function union<A, B, C, D, E>(a: readonly A[], b: readonly B[], c: readonly C[], d: readonly D[], e: readonly E[]): (A | B | C | D | E)[];
279
+ export declare function union<A, B, C, D, E, F>(a: readonly A[], b: readonly B[], c: readonly C[], d: readonly D[], e: readonly E[], f: readonly F[]): (A | B | C | D | E | F)[];
280
+ export declare function union(...arrays: (readonly unknown[] | null | undefined)[]): unknown[];
281
+ /**
282
+ * Prepend one or more items to the beginning of the array, mutating it in
283
+ * place, like PHP's array_unshift.
284
+ * Undefined items are skipped.
285
+ *
286
+ * @see Collection::unshift — `packages/collection/stubs/Collection.php:1096`.
287
+ * Wraps `array_unshift`; mutates.
288
+ *
289
+ * @param data - The array to prepend items to. Mutated in place.
290
+ * @param items - The items to prepend.
291
+ * @returns The same array reference, mutated.
292
+ */
293
+ export declare function unshift<TValue>(data: TValue[]): TValue[];
294
+ export declare function unshift<TValue, A>(data: TValue[], a: A): (TValue | A)[];
295
+ export declare function unshift<TValue, A, B>(data: TValue[], a: A, b: B): (TValue | A | B)[];
296
+ export declare function unshift<TValue, A, B, C>(data: TValue[], a: A, b: B, c: C): (TValue | A | B | C)[];
297
+ export declare function unshift<TValue, A, B, C, D>(data: TValue[], a: A, b: B, c: C, d: D): (TValue | A | B | C | D)[];
298
+ export declare function unshift<TValue>(data: TValue[], ...items: unknown[]): unknown[];
299
+ /**
300
+ * Get all of the given array except for a specified array of keys.
301
+ *
302
+ * @param data - The array to remove items from.
303
+ * @param keys - The keys of the items to remove.
304
+ * @returns A new array with the specified items removed.
305
+ *
306
+ * @example
307
+ *
308
+ * except(["a", "b", "c"], 1); -> ['a', 'c']
309
+ * except(["a", "b", "c"], [0, 2]); -> ['b']
310
+ */
311
+ export declare function except<TValue>(data: readonly TValue[], keys: PathKeys): TValue[];
312
+ /**
313
+ * Get all of the given array except for a specified array of values.
314
+ *
315
+ * @param data - The array to filter.
316
+ * @param values - The value(s) to exclude from the array.
317
+ * @param strict - Whether to use strict comparison (default: false).
318
+ * @returns A new array with the specified values removed.
319
+ *
320
+ * @example
321
+ *
322
+ * exceptValues(['foo', 'bar', 'baz', 'qux'], ['foo', 'baz']); -> [1 => 'bar', 3 => 'qux']
323
+ * exceptValues([1, 2, 3, 4, 5], [3, 4]); -> [0 => 1, 1 => 2, 4 => 5]
324
+ * exceptValues([1, '1', 2, '2', 3], [1, 2, 3], true); -> [1 => '1', 3 => '2']
325
+ */
326
+ export declare function exceptValues<TValue>(data: readonly TValue[], values: TValue | readonly TValue[], strict?: boolean): TValue[];
327
+ /**
328
+ * Determine if the given key exists in the provided data structure.
329
+ *
330
+ * @param data - array to check
331
+ * @param key - key to check for
332
+ * @returns True if the key exists, false otherwise.
333
+ *
334
+ * @example
335
+ *
336
+ * exists([1, 2, 3], 0); -> true
337
+ * exists([1, 2, 3], 3); -> false
338
+ * exists([1, 2, 3], '01'); -> false
339
+ */
340
+ export declare function exists<TValue>(data: readonly TValue[], key: PathKey): boolean;
341
+ /**
342
+ * Return the first element in an iterable passing a given truth test.
343
+ * A Map, a plain object or a collection is read by its keys, as Laravel reads an array.
344
+ *
345
+ * @param data - The array, iterable, Map, plain object or collection to search through.
346
+ * @param callback - Optional truth test, given each value and its key or position.
347
+ * @param defaultValue - Value, or a callback returning it, to use when no element passes.
348
+ * @returns The first element passing the test, otherwise the default (null when none is given).
349
+ *
350
+ * @example
351
+ *
352
+ * first([1, 2, 3]); -> 1
353
+ * first([]); -> null
354
+ * first([], null, 'default'); -> 'default'
355
+ * first([1, 2, 3], x => x > 1); -> 2
356
+ * first([1, 2, 3], x => x > 5, 'none'); -> 'none'
357
+ * first(new Map([['a', 1], ['b', 2]])); -> 1
358
+ */
359
+ export declare function first<TValue, TKey, TFirstDefault = null>(data: ReadonlyMap<TKey, TValue>, callback?: ((value: TValue, key: MapArrayKey<TKey>) => unknown) | null, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
360
+ export declare function first<TValue, TFirstDefault = null>(data: {
361
+ all(): Readonly<Record<string, TValue>>;
362
+ }, callback?: ((value: TValue, key: string | number) => unknown) | null, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
363
+ export declare function first<TValue, TFirstDefault = null>(data: TValue[], callback: (value: TValue, key: number) => unknown, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
364
+ export declare function first<TValue, TFirstDefault = null>(data: TValue[], callback?: null | undefined, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
365
+ export declare function first<TValue, TFirstDefault = null>(data: Iterable<TValue>, callback: (value: TValue, key: number) => unknown, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
366
+ export declare function first<TValue, TFirstDefault = null>(data: Iterable<TValue>, callback?: null | undefined, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
367
+ export declare function first<TValue, TFirstDefault = null>(data: Iterable<TValue>, callback?: ((value: TValue, key: number) => unknown) | null, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
368
+ export declare function first<TValue, TFirstDefault = null>(data: readonly unknown[] | null | undefined, callback?: ((value: TValue, key: number) => unknown) | null, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
369
+ /**
370
+ * Return the last element in an iterable passing a given truth test.
371
+ * A Map, a plain object or a collection is read by its keys, as Laravel reads an array.
372
+ *
373
+ * @param data - The array, iterable, Map, plain object or collection to search through.
374
+ * @param callback - Optional truth test, given each value and its key or position.
375
+ * @param defaultValue - Value, or a callback returning it, to use when no element passes.
376
+ * @returns The last element passing the test, otherwise the default (null when none is given).
377
+ *
378
+ * @example
379
+ *
380
+ * last([1, 2, 3]); -> 3
381
+ * last([]); -> null
382
+ * last([], null, 'default'); -> 'default'
383
+ * last([1, 2, 3], x => x < 3); -> 2
384
+ * last([1, 2, 3], x => x > 5, 'none'); -> 'none'
385
+ * last(new Map([['a', 1], ['b', 2]])); -> 2
386
+ */
387
+ export declare function last<TValue, TKey, TFirstDefault = null>(data: ReadonlyMap<TKey, TValue>, callback?: ((value: TValue, key: MapArrayKey<TKey>) => unknown) | null, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
388
+ export declare function last<TValue, TFirstDefault = null>(data: {
389
+ all(): Readonly<Record<string, TValue>>;
390
+ }, callback?: ((value: TValue, key: string | number) => unknown) | null, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
391
+ export declare function last<TValue, TFirstDefault = null>(data: TValue[], callback: (value: TValue, key: number) => unknown, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
392
+ export declare function last<TValue, TFirstDefault = null>(data: TValue[], callback?: null | undefined, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
393
+ export declare function last<TValue, TFirstDefault = null>(data: Iterable<TValue>, callback: (value: TValue, key: number) => unknown, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
394
+ export declare function last<TValue, TFirstDefault = null>(data: Iterable<TValue>, callback?: null | undefined, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
395
+ export declare function last<TValue, TFirstDefault = null>(data: Iterable<TValue>, callback?: ((value: TValue, key: number) => unknown) | null, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
396
+ export declare function last<TValue, TFirstDefault = null>(data: readonly unknown[] | null | undefined, callback?: ((value: TValue, key: number) => unknown) | null, defaultValue?: TFirstDefault | (() => TFirstDefault)): TValue | TFirstDefault | null;
397
+ /**
398
+ * Take the first or last `limit` items from an array.
399
+ *
400
+ * Positive limit => first `limit` items.
401
+ * Negative limit => last `abs(limit)` items.
402
+ * Oversized | zero => returns entire or empty array accordingly.
403
+ *
404
+ * @param data The array to take items from.
405
+ * @param limit The number of items to take. Positive for first N, negative for last N.
406
+ * @returns A new array containing the taken items.
407
+ *
408
+ * @example
409
+ *
410
+ * take([1, 2, 3, 4, 5], 2); -> [1, 2]
411
+ * take([1, 2, 3, 4, 5], -2); -> [4, 5]
412
+ * take([1, 2, 3], 5); -> [1, 2, 3]
413
+ */
414
+ export declare function take<TValue>(data: readonly TValue[] | null | undefined, limit: number): TValue[];
415
+ /**
416
+ * Flatten a multi-dimensional array into a single level.
417
+ *
418
+ * Only arrays and plain objects are flattened, along with the items of a Collection-like item (a class instance
419
+ * with an `all()` method); any other object, a `Date`, `Map` or class instance included, is kept as a value.
420
+ * A plain object is data whatever members it has, so its `all` member is one of its values.
421
+ * TypeScript cannot tell a class instance from a plain object, so a class instance item is typed as walked while the
422
+ * runtime keeps it whole.
423
+ *
424
+ * @param data The array to flatten.
425
+ * @param depth Maximum depth to flatten. Use Infinity for full flattening.
426
+ * @returns A new flattened array.
427
+ *
428
+ * @example
429
+ *
430
+ * flatten([1, [2, [3, 4]], 5]); -> [1, 2, 3, 4, 5]
431
+ * flatten([1, [2, [3, 4]], 5], 1); -> [1, 2, [3, 4], 5]
432
+ */
433
+ export declare function flatten<TValue>(data: ArrayItems<TValue>): ObjectFlatValue<TValue>[];
434
+ export declare function flatten<TValue>(data: ArrayItems<TValue>, depth?: number): FlattenItemReach<TValue>[];
435
+ export declare function flatten(data: readonly unknown[] | null | undefined, depth?: number): unknown[];
436
+ /**
437
+ * Flip the indices and values of an array.
438
+ *
439
+ * @param data - The array of items to flip
440
+ * @return - the data items flipped
441
+ *
442
+ * @example
443
+ * flip(['a', 'b', 'c']); -> {a: 0, b: 1, c: 2}
444
+ * flip(['a', 1, null, false, true, 1.5, [], {}]); -> {a: 0, 1: 1}
445
+ */
446
+ export declare function flip<TValue>(data: ArrayItems<TValue>): Record<string, number>;
447
+ export declare function flip(data: readonly unknown[] | null | undefined): Record<string, number>;
448
+ /**
449
+ * Get a float item from an array using "dot" notation.
450
+ * Throws an error if the value is not a number.
451
+ *
452
+ * Known divergence: PHP's `is_float()` rejects a whole-number int (`Arr::float`
453
+ * throws on `1`, see docs/php-parity/Arr/float.json, "Arr::float
454
+ * rejects a whole-number int"). JS has one number type, so `isNumber` accepts
455
+ * it — narrowing to reject whole numbers would also reject `1.0`.
456
+ *
457
+ * @param data - The array to get the item from.
458
+ * @param key - The key or dot-notated path of the item to get.
459
+ * @param defaultValue - The default value if key is not found.
460
+ * @returns The float value.
461
+ * @throws InvalidArgumentException if the value is not a number.
462
+ *
463
+ * @example
464
+ *
465
+ * float([1.5, 2.3], 1); -> 2.3
466
+ * float([{price: 19.99}], '0.price'); -> 19.99
467
+ * float([{price: 'free'}], '0.price'); -> throws InvalidArgumentException
468
+ */
469
+ export declare function float<TValue, TDefault = null>(data: ArrayItems<TValue>, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): number;
470
+ export declare function float<TDefault = null>(data: readonly unknown[] | null | undefined, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): number;
471
+ /**
472
+ * Remove one or many array items from a given array using dot notation.
473
+ *
474
+ * @param data - The array to remove items from.
475
+ * @param keys - The keys of the items to remove.
476
+ * @returns A new array with the specified items removed.
477
+ *
478
+ * @example
479
+ *
480
+ * forget(['products', ['desk', [100]]], null); -> ['products', ['desk', [100]]]
481
+ * forget(['products', ['desk', [100]]], '1'); -> ['products']
482
+ * forget(['products', ['desk', [100]]], 1); -> ['products']
483
+ * forget(['products', ['desk', [100]]], '1.1'); -> ['products', ['desk']]
484
+ * forget(['products', ['desk', [100]]], 2); -> ['products', ['desk', [100]]]
485
+ */
486
+ export declare function forget<TValue>(data: ArrayItems<TValue>, keys: PathKeys): TValue[];
487
+ /**
488
+ * Get the underlying array or object of items from the given argument.
489
+ * The rows are array- and iterable-shaped so a plain object falls through to
490
+ * `objFrom`, which is the backing that keeps its keys.
491
+ *
492
+ * @param items The array, Map, or iterable to extract from.
493
+ * @returns The underlying array or object.
494
+ *
495
+ * @example
496
+ *
497
+ * from([1, 2, 3]); -> [1, 2, 3]
498
+ * from(new Map([['foo', 'bar']])); -> { foo: 'bar' }
499
+ * from(new Set([1, 2])); -> [1, 2]
500
+ *
501
+ * @throws InvalidArgumentException if items is a scalar value.
502
+ * @throws Error if items is a WeakMap, whose values JavaScript cannot enumerate.
503
+ */
504
+ export declare function from<TValue>(items: ArrayItems<TValue>): TValue[];
505
+ export declare function from<TValue, TKey extends PropertyKey = PropertyKey>(items: Map<PropertyKey, TValue>): Record<TKey, TValue>;
506
+ export declare function from(items: number | string | boolean | symbol | null | undefined): never;
507
+ export declare function from<TValue>(items: Iterable<TValue>): TValue[];
508
+ export declare function from(items: readonly unknown[] | Iterable<unknown>): unknown[];
509
+ /**
510
+ * Get an item from an array using "dot" notation.
511
+ *
512
+ * A path walks into lists, plain objects and Maps, as Laravel walks nested arrays.
513
+ *
514
+ * @param array - The array to get the item from.
515
+ * @param key - The key or dot-notated path of the item to get.
516
+ * @param defaultValue - The default value if key is not found
517
+ * @returns The value or the default
518
+ *
519
+ * @example
520
+ *
521
+ * get(['foo', 'bar', 'baz'], 1); -> 'bar'
522
+ * get(['foo', 'bar', 'baz'], null); -> ['foo', 'bar', 'baz']
523
+ * get(['foo', 'bar', 'baz'], 9, 'default'); -> 'default'
524
+ */
525
+ export declare function get<TValue>(array: TValue[], key: null | undefined): TValue[];
526
+ export declare function get<TData extends readonly unknown[], TPath extends string | number, TDefault>(array: TData, key: TPath, defaultValue: TDefault | (() => TDefault)): ArrayResolvePathOrDefault<TData, TPath, TDefault>;
527
+ export declare function get<TValue, TDefault>(array: TValue[], key: PathKey, defaultValue: TDefault | (() => TDefault)): TValue | TDefault;
528
+ export declare function get<TData extends readonly unknown[], TPath extends string | number>(array: TData, key: TPath): ArrayResolvePathOrNull<TData, TPath>;
529
+ export declare function get<TValue>(array: TValue[], key: PathKey): TValue | null;
530
+ export declare function get<TValue, TDefault = unknown>(array: readonly unknown[] | null | undefined, key: PathKey | null | undefined, defaultValue?: TDefault | (() => TDefault) | null): TValue | TValue[] | TDefault | null;
531
+ /**
532
+ * Check if an item or items exist in an array using "dot" notation.
533
+ *
534
+ * @param data - The array to check.
535
+ * @param keys - The key or dot-notated path of the item to check.
536
+ * @returns True if the item or items exist, false otherwise.
537
+ *
538
+ * @example
539
+ *
540
+ * has(['foo', 'bar', ['baz', 'qux']], 1); -> true
541
+ * has(['foo', 'bar'], 5); -> false
542
+ * has(['foo', 'bar', ['baz', 'qux']], ['0', '2.1']); -> true
543
+ * has(['foo', 'bar', ['baz', 'qux']], ['0', '2.2']); -> false
544
+ */
545
+ export declare function has<TValue>(data: ArrayItems<TValue>, keys: PathKeys): boolean;
546
+ export declare function has(data: readonly unknown[] | null | undefined, keys: PathKeys): boolean;
547
+ /**
548
+ * Determine if all keys exist in an array using "dot" notation.
549
+ *
550
+ * @param data - The array to check.
551
+ * @param keys - The key or dot-notated path of the item to check.
552
+ * @returns True if all keys exist, false otherwise.
553
+ *
554
+ * @example
555
+ *
556
+ * hasAll(['foo', 'bar', ['baz', 'qux']], ['0', '2.1']); -> true
557
+ * hasAll(['foo', 'bar', ['baz', 'qux']], ['0', '2.2']); -> false
558
+ */
559
+ export declare function hasAll<TValue>(data: ArrayItems<TValue>, keys: PathKeys): boolean;
560
+ export declare function hasAll(data: readonly unknown[] | null | undefined, keys: PathKeys): boolean;
561
+ /**
562
+ * Determine if any of the keys exist in an array using "dot" notation.
563
+ *
564
+ * @param data - The array to check.
565
+ * @param keys - The key or dot-notated path of the item to check.
566
+ * @returns True if any key exists, false otherwise.
567
+ *
568
+ * @example
569
+ *
570
+ * hasAny(['foo', 'bar', ['baz', 'qux']], ['0', '2.2']); -> true
571
+ * hasAny(['foo', 'bar', ['baz', 'qux']], ['3', '4']); -> false
572
+ */
573
+ export declare function hasAny<TValue>(data: ArrayItems<TValue>, keys: PathKeys): boolean;
574
+ export declare function hasAny(data: readonly unknown[] | null | undefined, keys: PathKeys): boolean;
575
+ /**
576
+ * Determine if all items pass the given truth test.
577
+ *
578
+ * Accepts arrays as well as any other iterable such as a generator or a Set,
579
+ * in which case the zero based position of the item is passed as the key.
580
+ *
581
+ * @param data - The array or iterable to iterate over.
582
+ * @param callback - The function to call for each item.
583
+ * @returns True if all items pass the test, false otherwise.
584
+ *
585
+ * @example
586
+ *
587
+ * every([2, 4, 6], n => n % 2 === 0); -> true
588
+ * every([1, 2, 3], n => n % 2 === 0); -> false
589
+ * every(new Set([2, 4]), n => n % 2 === 0); -> true
590
+ */
591
+ export declare function every<TValue>(data: TValue[], callback: (value: TValue, key: number) => unknown): boolean;
592
+ export declare function every<TValue>(data: Iterable<TValue>, callback: (value: TValue, key: number) => unknown): boolean;
593
+ export declare function every<TValue>(data: readonly unknown[] | null | undefined, callback: (value: TValue, key: number) => unknown): boolean;
594
+ /**
595
+ * Determine if some items pass the given truth test.
596
+ *
597
+ * Accepts arrays as well as any other iterable such as a generator or a Set,
598
+ * in which case the zero based position of the item is passed as the key.
599
+ *
600
+ * @param data - The array or iterable to iterate over.
601
+ * @param callback - The function to call for each item.
602
+ * @returns True if any item passes the test, false otherwise.
603
+ *
604
+ * @example
605
+ *
606
+ * some([1, 2, 3], n => n % 2 === 0); -> true
607
+ * some([1, 3, 5], n => n % 2 === 0); -> false
608
+ * some(new Set([1, 2]), n => n % 2 === 0); -> true
609
+ */
610
+ export declare function some<TValue>(data: TValue[], callback: (value: TValue, key: number) => unknown): boolean;
611
+ export declare function some<TValue>(data: Iterable<TValue>, callback: (value: TValue, key: number) => unknown): boolean;
612
+ export declare function some<TValue>(data: readonly unknown[] | null | undefined, callback: (value: TValue, key: number) => unknown): boolean;
613
+ /**
614
+ * Get an integer item from an array using "dot" notation.
615
+ *
616
+ * @param data - The array to get the item from.
617
+ * @param key - The key or dot-notated path of the item to get.
618
+ * @param defaultValue - The default value if key is not found
619
+ *
620
+ * @returns The integer value.
621
+ *
622
+ * @throws InvalidArgumentException if the value is not an integer.
623
+ *
624
+ * @example
625
+ *
626
+ * integer([10, 20, 30], 1); -> 20
627
+ * integer([10, 20, 30], 5, 100); -> 100
628
+ * integer(["house"], 0); -> throws InvalidArgumentException
629
+ */
630
+ export declare function integer<TValue, TDefault = null>(data: ArrayItems<TValue>, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): number;
631
+ export declare function integer<TDefault = null>(data: readonly unknown[] | null | undefined, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): number;
632
+ /**
633
+ * Join all items using a string. The final items can use a separate glue string.
634
+ *
635
+ * @param data - The array to join.
636
+ * @param glue - The string to join all but the last item.
637
+ * @param finalGlue - The string to join the last item.
638
+ * @returns The items joined, each cast as PHP's (string) cast casts it: "Array" for an array, "1" for true.
639
+ * @throws Error `Object of class X could not be converted to string` for an object without its own toString.
640
+ *
641
+ * @example
642
+ *
643
+ * join(['a', 'b', 'c'], ', ') => 'a, b, c'
644
+ * join(['a', 'b', 'c'], ', ', ' and ') => 'a, b and c'
645
+ */
646
+ export declare function join<TValue>(data: ArrayItems<TValue>, glue: string, finalGlue?: string): string;
647
+ export declare function join(data: readonly unknown[] | null | undefined, glue: string, finalGlue?: string): string;
648
+ /**
649
+ * Key an associative array by a field or using a callback.
650
+ * Each resolved key is stored the way PHP stores an array key: `null` as `""`, a boolean as `0`/`1`,
651
+ * and a float truncated toward zero.
652
+ *
653
+ * @param data - The array to key.
654
+ * @param keyBy - The field name to key by, or a callback function that receives each item and its index.
655
+ * @returns A new object keyed by the specified field or callback result.
656
+ *
657
+ * @example
658
+ *
659
+ * keyBy([{id: 1, name: 'John'}, {id: 2, name: 'Jane'}], 'id'); -> {1: {id: 1, name: 'John'}, 2: {id: 2, name: 'Jane'}}
660
+ * keyBy([{name: 'John'}, {name: 'Jane'}], (item) => item.name); -> {John: {name: 'John'}, Jane: {name: 'Jane'}}
661
+ * keyBy([{name: 'John'}], (item, index) => `k${index}`); -> {k0: {name: 'John'}}
662
+ */
663
+ export declare function keyBy<TValue extends object, R extends string | number | null | undefined>(data: ArrayItems<TValue>, keyBy: (item: TValue, key: number) => R): Record<MapArrayKey<R>, TValue>;
664
+ export declare function keyBy<TValue extends object, R extends string | number | null | undefined = never, P extends string = never>(data: ArrayItems<TValue>, keyBy: P | ((item: TValue, key: number) => R)): Record<MapArrayKey<R | PluckValue<TValue, P>>, TValue>;
665
+ export declare function keyBy<TValue extends object>(data: readonly unknown[] | null | undefined, keyBy: string | ((item: TValue, key: number) => string | number | null | undefined)): Record<string, unknown>;
666
+ /**
667
+ * Prepend the key names of an associative array.
668
+ * Note: This is designed for object-like operations, adapted for arrays with string indices.
669
+ *
670
+ * @param data - The array to process.
671
+ * @param prependWith - The string to prepend to each key.
672
+ * @returns A new array with transformed string-based indices.
673
+ *
674
+ * @example
675
+ *
676
+ * prependKeysWith(['a', 'b', 'c'], 'item_'); -> Creates array with keys: item_0, item_1, item_2
677
+ */
678
+ export declare function prependKeysWith<TValue>(data: ArrayItems<TValue>, prependWith: string): Record<string, TValue>;
679
+ export declare function prependKeysWith(data: readonly unknown[] | null | undefined, prependWith: string): Record<string, unknown>;
680
+ /**
681
+ * Get a subset of the items from the given array.
682
+ *
683
+ * Mirrors PHP's `(array) $keys` cast in `Arr::only` (Arr.php:754): `null` becomes
684
+ * no keys, a bare index becomes a single-index selection.
685
+ *
686
+ * Items keep the array's order, not the order of `keys`, as with `array_intersect_key`.
687
+ *
688
+ * @param data - The array to get items from.
689
+ * @param keys - The index, indices, or null to select.
690
+ * @returns A new array with only the specified indices.
691
+ *
692
+ * @example
693
+ *
694
+ * only(['a', 'b', 'c', 'd'], [0, 2]); -> ['a', 'c']
695
+ * only(['a', 'b', 'c', 'd'], [3, 1]); -> ['b', 'd']
696
+ */
697
+ export declare function only<TValue>(data: ArrayItems<TValue>, keys: number | number[] | null): TValue[];
698
+ export declare function only(data: readonly unknown[] | null | undefined, keys: number | number[] | null): unknown[];
699
+ /**
700
+ * Get a subset of the items from the given array by value.
701
+ *
702
+ * @param data - The array to filter.
703
+ * @param values - The value(s) to include in the result.
704
+ * @param strict - Whether to use strict comparison (default: false).
705
+ * @returns A new array containing only the specified values.
706
+ *
707
+ * @example
708
+ *
709
+ * onlyValues(['foo', 'bar', 'baz', 'qux'], ['foo', 'baz']); -> [0 => 'foo', 2 => 'baz']
710
+ * onlyValues([1, 2, 3, 4, 5], [3, 4]); -> [2 => 3, 3 => 4]
711
+ * onlyValues([1, '1', 2, '2', 3], [1, 2, 3], true); -> [0 => 1, 2 => 2, 4 => 3]
712
+ */
713
+ export declare function onlyValues<TValue>(data: readonly TValue[], values: TValue | readonly TValue[], strict?: boolean): TValue[];
714
+ /**
715
+ * Select an array of values from each item in the array.
716
+ *
717
+ * @param data - The array to select from.
718
+ * @param keys - The key or keys to select from each item.
719
+ * @returns A new array with selected key/value pairs from each item.
720
+ *
721
+ * @example
722
+ *
723
+ * select([{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}], 'a'); -> [{a: 1}, {a: 4}]
724
+ * select([{a: 1, b: 2}, {a: 3, b: 4}], ['a', 'b']); -> [{a: 1, b: 2}, {a: 3, b: 4}]
725
+ */
726
+ export declare function select<TValue extends object, const TKeys extends readonly (keyof TValue & string)[]>(data: ArrayItems<TValue>, keys: TKeys): Pick<TValue, TKeys[number]>[];
727
+ export declare function select<TValue extends object, const TKey extends keyof TValue & string>(data: ArrayItems<TValue>, keys: TKey): Pick<TValue, TKey>[];
728
+ export declare function select(data: readonly unknown[] | null | undefined, keys: PathKeys): Record<string, unknown>[];
729
+ /**
730
+ * Pluck an array of values from an array.
731
+ *
732
+ * @param data - The array to pluck from.
733
+ * @param value - The key path to pluck (a dot-notated string, an array of
734
+ * segments, or a path containing a `*` wildcard segment), a callback, or
735
+ * `null`/`undefined` to keep each whole item.
736
+ * @param key - Optional key path to use as keys in result, or callback function.
737
+ * @returns A new array of plucked values, or a record keyed by the
738
+ * resolved `key` values when a key is given.
739
+ *
740
+ * @example
741
+ *
742
+ * pluck([{name: 'John', age: 30}, {name: 'Jane', age: 25}], 'name'); -> ['John', 'Jane']
743
+ * pluck([{user: {name: 'John'}}, {user: {name: 'Jane'}}], 'user.name'); -> ['John', 'Jane']
744
+ * pluck([{id: 1, name: 'John'}, {id: 2, name: 'Jane'}], 'name', 'id'); -> {1: 'John', 2: 'Jane'}
745
+ * pluck([{developer: {name: 'Taylor'}}], ['developer', 'name']); -> ['Taylor']
746
+ * pluck([{users: [{first: 'taylor'}, {first: 'dayle'}]}], 'users.*.first'); -> [['taylor', 'dayle']]
747
+ * pluck([{name: 'John'}, {name: 'Jane'}], 'missing'); -> [null, null]
748
+ * pluck([{name: 'John'}, {name: 'Jane'}], null); -> [{name: 'John'}, {name: 'Jane'}]
749
+ */
750
+ export declare function pluck<TValue extends object, const TPath extends string>(data: ArrayItems<TValue>, value: TPath, key: string | readonly string[] | ((item: TValue) => unknown)): Record<string | number, PluckValue<TValue, TPath>>;
751
+ export declare function pluck<TValue extends object, const TPath extends string>(data: ArrayItems<TValue>, value: TPath, key?: null | undefined): PluckValue<TValue, TPath>[];
752
+ export declare function pluck<TValue extends object, TResult>(data: ArrayItems<TValue>, value: (item: TValue) => TResult, key: string | readonly string[] | ((item: TValue) => unknown)): Record<string | number, TResult>;
753
+ export declare function pluck<TValue extends object, TResult>(data: ArrayItems<TValue>, value: (item: TValue) => TResult, key?: null | undefined): TResult[];
754
+ export declare function pluck<TValue extends object>(data: ArrayItems<TValue>, value: null | undefined, key: string | readonly string[] | ((item: TValue) => unknown)): Record<string | number, TValue>;
755
+ export declare function pluck<TValue extends object>(data: ArrayItems<TValue>, value: null | undefined, key?: null | undefined): TValue[];
756
+ export declare function pluck<TValue extends object>(data: ArrayItems<TValue>, value: string | readonly string[] | ((item: TValue) => unknown), key: string | readonly string[] | ((item: TValue) => unknown)): Record<string | number, unknown>;
757
+ export declare function pluck<TValue extends object>(data: ArrayItems<TValue>, value: string | readonly string[] | ((item: TValue) => unknown), key?: null | undefined): unknown[];
758
+ export declare function pluck<TValue extends object>(data: readonly unknown[] | null | undefined, value: string | readonly string[] | ((item: TValue) => unknown) | null | undefined, key?: string | readonly string[] | ((item: TValue) => unknown) | null): unknown[] | Record<string | number, unknown>;
759
+ /**
760
+ * Get and remove the last N items from the array, mutating it in place,
761
+ * like PHP's array_pop.
762
+ *
763
+ * @see Collection::pop — `packages/collection/stubs/Collection.php:1030`.
764
+ * Mirrors `array_pop`, called `$count` times from the end; mutates.
765
+ *
766
+ * @param data - The array to pop items from. Mutated in place.
767
+ * @param count - The number of items to pop. Defaults to 1; a fraction is dropped, and NAN pops every item.
768
+ * @returns The popped item when count is 1, an array of popped items
769
+ * (reverse order) otherwise, or null if the array had nothing to pop.
770
+ * @throws Error for a fraction between 1 and 2 that the items do not cap, as PHP's range() throws its ValueError.
771
+ */
772
+ export declare function pop<TValue>(data: TValue[]): TValue | null;
773
+ export declare function pop<TValue>(data: TValue[], count: number): TValue[];
774
+ export declare function pop<TValue>(data: TValue[] | null | undefined, count?: number): TValue | TValue[] | null;
775
+ /**
776
+ * Run a map over each of the items in the array.
777
+ *
778
+ * @param data - The array to map over.
779
+ * @param callback - The function to call for each item (value, index) => newValue.
780
+ * @returns A new array with transformed values.
781
+ *
782
+ * @example
783
+ *
784
+ * map([1, 2, 3], (value) => value * 2); -> [2, 4, 6]
785
+ * map(['a', 'b'], (value, index) => `${index}:${value}`); -> ['0:a', '1:b']
786
+ */
787
+ export declare function map<TValue, TMapReturn>(data: ArrayItems<TValue>, callback: (value: TValue, index: number) => TMapReturn): TMapReturn[];
788
+ export declare function map<TValue, TMapReturn>(data: readonly unknown[] | null | undefined, callback: (value: TValue, index: number) => TMapReturn): TMapReturn[];
789
+ /**
790
+ * Run an associative map over each of the items.
791
+ * The callback should return an object with key/value pairs.
792
+ *
793
+ * @param data - The array to map.
794
+ * @param callback - Function that returns an object with key/value pairs.
795
+ * @returns A new object with all mapped key/value pairs.
796
+ *
797
+ * @example
798
+ *
799
+ * mapWithKeys([{id: 1, name: 'John'}], (item) => ({[item.name]: item.id})); -> {John: 1}
800
+ * mapWithKeys(['a', 'b'], (value, index) => ({[value]: index})); -> {a: 0, b: 1}
801
+ */
802
+ export declare function mapWithKeys<TValue, TMapWithKeysValue, TKey extends number = number, TMapWithKeysKey extends string = string>(data: ArrayItems<TValue>, callback: (value: TValue, index: TKey) => Record<TMapWithKeysKey, TMapWithKeysValue>): Record<TMapWithKeysKey, TMapWithKeysValue>;
803
+ export declare function mapWithKeys<TValue, TMapWithKeysValue, TKey extends number = number, TMapWithKeysKey extends string = string>(data: readonly unknown[] | null | undefined, callback: (value: TValue, index: TKey) => Record<TMapWithKeysKey, TMapWithKeysValue>): Record<TMapWithKeysKey, TMapWithKeysValue>;
804
+ /**
805
+ * Run a map over each row, spreading a list row's items (or a plain object's or a Map's values), then the index.
806
+ *
807
+ * @param data - The array to map over.
808
+ * @param callback - The function to call with spread arguments from each chunk.
809
+ * @returns A new array with mapped values.
810
+ *
811
+ * @example
812
+ *
813
+ * mapSpread([[1, 2], [3, 4]], (a, b) => a + b); -> [3, 7]
814
+ * mapSpread([['John', 25], ['Jane', 30]], (name, age) => `${name} is ${age}`); -> ['John is 25', 'Jane is 30']
815
+ */
816
+ export declare function mapSpread<T1, TMapReturn>(data: ArrayItems<readonly [T1]>, callback: (arg1: T1, index: number) => TMapReturn): TMapReturn[];
817
+ export declare function mapSpread<T1, T2, TMapReturn>(data: ArrayItems<readonly [T1, T2]>, callback: (arg1: T1, arg2: T2, index: number) => TMapReturn): TMapReturn[];
818
+ export declare function mapSpread<T1, T2, T3, TMapReturn>(data: ArrayItems<readonly [T1, T2, T3]>, callback: (arg1: T1, arg2: T2, arg3: T3, index: number) => TMapReturn): TMapReturn[];
819
+ export declare function mapSpread<T1, T2, T3, T4, TMapReturn>(data: ArrayItems<readonly [T1, T2, T3, T4]>, callback: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, index: number) => TMapReturn): TMapReturn[];
820
+ export declare function mapSpread<T1, T2, T3, T4, T5, TMapReturn>(data: ArrayItems<readonly [T1, T2, T3, T4, T5]>, callback: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, index: number) => TMapReturn): TMapReturn[];
821
+ export declare function mapSpread<TRow extends readonly unknown[], TMapReturn>(data: ArrayItems<TRow>, callback: (...args: SpreadArgs<TRow, number>) => TMapReturn): TMapReturn[];
822
+ export declare function mapSpread<TMapReturn>(data: readonly unknown[] | null | undefined, callback: (...args: unknown[]) => TMapReturn): TMapReturn[];
823
+ /**
824
+ * Push an item onto the beginning of an array.
825
+ *
826
+ * @param data - The array to prepend to.
827
+ * @param value - The value to prepend.
828
+ * @param key - The key, cast as PHP casts an array key (null or undefined becomes ""); omit it to unshift, as
829
+ * `Arr::prepend` does with two arguments. `[$key => $value] + $list` stays a list only for key 0, which replaces the
830
+ * first item; any other key makes the result an object, as PHP's array is then keyed.
831
+ * @returns A new array with the value prepended, or the object PHP's keyed array becomes.
832
+ *
833
+ * @example
834
+ *
835
+ * prepend(['b', 'c'], 'a'); -> ['a', 'b', 'c']
836
+ * prepend([1, 2, 3], 0); -> [0, 1, 2, 3]
837
+ * prepend(['b', 'c'], 'a', 0); -> ['a', 'c']
838
+ * prepend(['b', 'c'], 'a', 'k'); -> { k: 'a', 0: 'b', 1: 'c' }
839
+ */
840
+ export declare function prepend<TValue, TPrependValue>(data: ArrayItems<TValue>, value: TPrependValue): PrependedItem<TValue, TPrependValue>[];
841
+ export declare function prepend<TValue, TPrependValue, TPrependKey extends PropertyKey | null | undefined>(data: ArrayItems<TValue>, value: TPrependValue, key: TPrependKey): ListPrepend<TValue, TPrependValue, TPrependKey>;
842
+ export declare function prepend<TValue>(data: null | undefined, value: TValue): TValue[];
843
+ export declare function prepend(data: readonly unknown[] | null | undefined, value: unknown): unknown[];
844
+ export declare function prepend(data: readonly unknown[] | null | undefined, value: unknown, key: PropertyKey | null | undefined): unknown[] | Record<string | number, unknown>;
845
+ /**
846
+ * Get a value from the array, and remove it.
847
+ *
848
+ * @param data - The array to pull the item from.
849
+ * @param key - The key or dot-notated path of the item to pull.
850
+ * @param defaultValue - The default value if key is not found.
851
+ * @returns An object containing the pulled value (or default) and the updated array.
852
+ *
853
+ * @example
854
+ *
855
+ * pull(['a', 'b', 'c'], 1); -> { value: 'b', data: ['a', 'c'] }
856
+ * pull(['a', ['b', 'c']], '1.0'); -> { value: 'b', data: ['a', ['c']] }
857
+ * pull(['a', 'b', 'c'], 5, 'x'); -> { value: 'x', data: ['a', 'b', 'c'] }
858
+ * pull(['a', ['b', 'c']], '1.2', 'x'); -> { value: 'x', data: ['a', ['b', 'c']] }
859
+ */
860
+ export declare function pull<TValue>(data: ArrayItems<TValue>, key: PathKey): {
861
+ value: TValue | null;
862
+ data: TValue[];
863
+ };
864
+ export declare function pull<TValue, TDefault>(data: ArrayItems<TValue>, key: PathKey, defaultValue: TDefault | (() => TDefault)): {
865
+ value: TValue | TDefault;
866
+ data: TValue[];
867
+ };
868
+ export declare function pull<TValue, TDefault = null>(data: readonly unknown[] | null | undefined, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): {
869
+ value: TValue | TDefault | null;
870
+ data: TValue[];
871
+ };
872
+ /**
873
+ * Convert the array into a query string.
874
+ *
875
+ * @param data - The array or object to convert to a query string.
876
+ * @returns A URL-encoded query string.
877
+ *
878
+ * @example
879
+ *
880
+ * query({name: 'John', age: 30}); -> 'name=John&age=30'
881
+ * query(['a', 'b', 'c']); -> '0=a&1=b&2=c'
882
+ * query({tags: ['php', 'js']}); -> 'tags[0]=php&tags[1]=js'
883
+ * query({user: {name: 'John', age: 30}}); -> 'user%5Bname%5D=John&user%5Bage%5D=30'
884
+ * query({foo: 'bar', bar: true}); -> 'foo=bar&bar=1' (booleans cast like PHP's http_build_query)
885
+ * query({foo: 'bar', bar: false}); -> 'foo=bar&bar=0'
886
+ */
887
+ export declare function query<TValue>(data: ArrayItems<TValue>): string;
888
+ export declare function query(data: readonly unknown[] | null | undefined): string;
889
+ /**
890
+ * Get one or a specified number of random values from an array.
891
+ *
892
+ * The picked items come back in the array's own order, as `Randomizer::pickArrayKeys` returns them.
893
+ *
894
+ * @param data - The array to get random values from. Non-array-like input is treated as absent, not as an empty array.
895
+ * @param number - The number of items to return, a fraction truncated. If null, returns a single item.
896
+ * @param preserveKeys - Whether to preserve the original keys when returning multiple items.
897
+ * @returns A single random item, an array of random items, an empty array when zero or fewer items are requested, or null when no count is given and the input isn't array-like.
898
+ * @throws InvalidArgumentException if more items are requested than are available, including requesting a single
899
+ * item (or any positive count) from an empty array.
900
+ * @throws TypeError for a NAN count or a string that is not numeric, which PHP's Randomizer rejects too.
901
+ * @throws Error for a count between 0 and 1, which truncates to no item, as PHP's Randomizer rejects it.
902
+ *
903
+ * @example
904
+ *
905
+ * random([1, 2, 3]); -> 2 (single random item)
906
+ * random([1, 2, 3], 2); -> [1, 3] (two random items, in the array's order)
907
+ * random(['a', 'b', 'c'], 2, true); -> {1: 'b', 2: 'c'} (with original keys)
908
+ * random([], 0); -> [] (explicitly requesting zero items)
909
+ * random([]); -> throws InvalidArgumentException (no items available)
910
+ * random([1, 2], 5); -> throws InvalidArgumentException
911
+ */
912
+ export declare function random<TValue>(data: ArrayItems<TValue>): TValue | null;
913
+ export declare function random<TValue>(data: ArrayItems<TValue>, number: number, preserveKeys: true): Record<number, TValue>;
914
+ export declare function random<TValue>(data: ArrayItems<TValue>, number: number, preserveKeys?: false): TValue[];
915
+ export declare function random<TValue>(data: readonly unknown[] | null | undefined, number?: number | string | null, preserveKeys?: boolean): TValue | TValue[] | Record<number, TValue> | null;
916
+ /**
917
+ * Get and remove the first N items from the array, mutating it in place,
918
+ * like PHP's array_shift.
919
+ *
920
+ * Guard order matters: a negative count throws, a count of zero returns an
921
+ * empty array, and an empty array returns null for a count of 1 and an empty
922
+ * array for any other; then items shift.
923
+ *
924
+ * @see Collection::shift — `packages/collection/stubs/Collection.php:1281`.
925
+ * Mirrors `array_shift`-style removal from the front, driven by `$count`; mutates.
926
+ *
927
+ * @param data - The array to shift items from. Mutated in place.
928
+ * @param count - The number of items to shift. Defaults to 1; a fraction is dropped, and NAN shifts every item.
929
+ * @returns The shifted item when count is 1, or null if there was none; an array of the shifted items otherwise.
930
+ * @throws InvalidArgumentException if count is negative.
931
+ * @throws Error for a fraction below 2 that the items do not cap, as PHP's range() throws its ValueError.
932
+ */
933
+ export declare function shift<TValue>(data: TValue[]): TValue | null;
934
+ export declare function shift<TValue>(data: TValue[], count: number): TValue[];
935
+ export declare function shift<TValue>(data: TValue[] | null | undefined, count?: number): TValue | TValue[] | null;
936
+ /**
937
+ * Set an array item to a given value using "dot" notation.
938
+ *
939
+ * If no key is given to the method, the entire array will be replaced.
940
+ *
941
+ * @param array - The array to set the item in.
942
+ * @param key - The key or dot-notated path of the item to set.
943
+ * @param value - The value to set.
944
+ * @returns - A new array with the item set, or the value itself when key is null/undefined.
945
+ *
946
+ * @example
947
+ * set(['a', 'b', 'c'], 1, 'x'); -> ['a', 'x', 'c']
948
+ * set(['a', ['b', 'c']], '1.0', 'x'); -> ['a', ['x', 'c']]
949
+ * set(['a', 'b'], null, ['x', 'y']); -> ['x', 'y']
950
+ */
951
+ export declare function set<TSetValue>(array: readonly unknown[] | null | undefined, key: null | undefined, value: TSetValue): TSetValue;
952
+ export declare function set<TValue, TSetValue, const TPath extends `${string}.${string}`>(array: ArrayItems<TValue>, key: TPath, value: TSetValue): ArraySetPathResult<TValue, TPath, TSetValue>;
953
+ export declare function set<TValue>(array: ArrayItems<TValue>, key: string | number, value: NoInfer<TValue>): TValue[];
954
+ export declare function set<TValue, TSetValue>(array: ArrayItems<TValue>, key: string | number, value: TSetValue): (TValue | TSetValue)[];
955
+ export declare function set<TValue, TSetValue>(array: ArrayItems<TValue>, key: PathKey, value: TSetValue): (TValue | TSetValue)[] | NoInfer<TSetValue>;
956
+ export declare function set<TValue>(array: readonly unknown[] | null | undefined, key: string | number, value: unknown): TValue[];
957
+ export declare function set<TValue, TSetValue>(array: readonly unknown[] | null | undefined, key: PathKey, value: TSetValue): TValue[] | NoInfer<TSetValue>;
958
+ /**
959
+ * Push an item into an array using "dot" notation.
960
+ *
961
+ * Unlike PHP, the whole array is returned rather than `Arr::set`'s innermost container,
962
+ * and an out-of-range index is clamped to an append instead of a gapped integer key.
963
+ *
964
+ * @param data - The array to push items into.
965
+ * @param key - The key or dot-notated path of the array to push into. If null, push into root.
966
+ * @param values - The values to push.
967
+ * @returns The array with the values pushed into the array, object or Map at the key.
968
+ * @throws InvalidArgumentException if the value at the key is not an array, object or Map.
969
+ */
970
+ export declare function push<TValue>(data: ArrayItems<TValue>, key: PathKey, ...values: TValue[]): TValue[];
971
+ export declare function push<TValue>(data: readonly unknown[] | null | undefined, key: PathKey, ...values: TValue[]): TValue[];
972
+ /**
973
+ * Shuffle the given array and return the result.
974
+ *
975
+ * @param data - The array to shuffle.
976
+ * @returns A new shuffled array.
977
+ *
978
+ * @example
979
+ *
980
+ * shuffle([1, 2, 3, 4, 5]); -> [3, 1, 5, 2, 4] (random order)
981
+ * shuffle(['a', 'b', 'c']); -> ['c', 'a', 'b'] (random order)
982
+ */
983
+ export declare function shuffle<TValue>(data: ArrayItems<TValue>): TValue[];
984
+ export declare function shuffle(data: readonly unknown[] | null | undefined): unknown[];
985
+ /**
986
+ * Skip items in the array until the given condition is met.
987
+ *
988
+ * A value is compared with PHP's `===`; a callback gets each value and index, and PHP truthiness judges its answer.
989
+ *
990
+ * @param data - The array to skip items of.
991
+ * @param value - The value to skip until, or a callback answering whether an item meets the condition.
992
+ * @returns A new array of the items from the first that meets the condition on.
993
+ *
994
+ * @example
995
+ *
996
+ * skipUntil([1, 2, 3, 4], 3); -> [3, 4]
997
+ * skipUntil([1, 2, 3, 4], (value) => value >= 3); -> [3, 4]
998
+ * skipUntil([1, 2, 3, 4], 5); -> []
999
+ */
1000
+ export declare function skipUntil<TValue>(data: ArrayItems<TValue>, value: NoInfer<TValue> | ((value: TValue, index: number) => unknown)): TValue[];
1001
+ export declare function skipUntil(data: readonly unknown[] | null | undefined, value: AnyValueOr<(value: unknown, index: number) => unknown>): unknown[];
1002
+ /**
1003
+ * Skip items in the array while the given condition is met.
1004
+ *
1005
+ * A value is compared with PHP's `===`; a callback gets each value and index, and PHP truthiness judges its answer.
1006
+ *
1007
+ * @param data - The array to skip items of.
1008
+ * @param value - The value to skip while items equal it, or a callback answering whether an item meets the condition.
1009
+ * @returns A new array of the items from the first that fails the condition on.
1010
+ *
1011
+ * @example
1012
+ *
1013
+ * skipWhile([1, 1, 2, 1], 1); -> [2, 1]
1014
+ * skipWhile([1, 2, 3, 4], (value) => value < 3); -> [3, 4]
1015
+ * skipWhile([1, 2, 3, 4], 5); -> [1, 2, 3, 4]
1016
+ */
1017
+ export declare function skipWhile<TValue>(data: ArrayItems<TValue>, value: NoInfer<TValue> | ((value: TValue, index: number) => unknown)): TValue[];
1018
+ export declare function skipWhile(data: readonly unknown[] | null | undefined, value: AnyValueOr<(value: unknown, index: number) => unknown>): unknown[];
1019
+ /**
1020
+ * Slice the underlying array items, like PHP's `array_slice()`. A READ operation that
1021
+ * extracts a subset without mutating; use `splice()` for a WRITE that removes items.
1022
+ *
1023
+ * @see Collection::slice — `packages/collection/stubs/Collection.php:1382`. Wraps `array_slice`, preserveKeys: true.
1024
+ *
1025
+ * @param data - The array to slice
1026
+ * @param offset - The starting index
1027
+ * @param length - The number of items to include (negative means stop that many from the end)
1028
+ * @returns Sliced array (subset of the original)
1029
+ */
1030
+ export declare function slice<TValue>(data: ArrayItems<TValue>, offset: number, length?: number | null): TValue[];
1031
+ export declare function slice<TValue>(data: readonly unknown[] | null | undefined, offset: number, length?: number | null): TValue[];
1032
+ /**
1033
+ * Get the first item in the array, but only if exactly one item exists. Otherwise, throw an exception.
1034
+ *
1035
+ * @param data - The array to check.
1036
+ * @param callback - Optional callback to filter items.
1037
+ * @returns The single item in the array.
1038
+ * @throws ItemNotFoundException if no item matches, MultipleItemsFoundException if several do.
1039
+ *
1040
+ * @example
1041
+ *
1042
+ * sole([42]); -> 42
1043
+ * sole([1, 2, 3], (value) => value > 2); -> 3
1044
+ * sole([]); -> throws ItemNotFoundException
1045
+ * sole([1, 2]); -> throws MultipleItemsFoundException: 2 items were found.
1046
+ * sole([1, 2, 3], (value) => value > 1); -> throws MultipleItemsFoundException: 2 items were found.
1047
+ */
1048
+ export declare function sole<TValue>(data: ArrayItems<TValue>, callback: (value: TValue, index: number) => unknown): TValue;
1049
+ export declare function sole<TValue>(data: ArrayItems<TValue>, callback?: undefined): TValue;
1050
+ export declare function sole<TValue>(data: readonly unknown[] | null | undefined, callback?: (value: TValue, index: number) => unknown): TValue;
1051
+ /**
1052
+ * Sort the array using the given callback, "dot" notation, or an array of
1053
+ * sort descriptors for multi-key sorting.
1054
+ *
1055
+ * @param data - The array to sort.
1056
+ * @param callback - The sorting callback, field name, an array of sort descriptors, or null for natural sorting.
1057
+ * @returns A new sorted array.
1058
+ *
1059
+ * @example
1060
+ *
1061
+ * sort([3, 1, 4, 1, 5]); -> [1, 1, 3, 4, 5]
1062
+ * sort(['banana', 'apple', 'cherry']); -> ['apple', 'banana', 'cherry']
1063
+ * sort([{name: 'John', age: 25}, {name: 'Jane', age: 30}], 'age'); -> sorted by age
1064
+ * sort([{name: 'John', age: 25}, {name: 'Jane', age: 30}], (item) => item.name); -> sorted by name
1065
+ * sort([{name: 'John', age: 25}, {name: 'John', age: 30}], ['name', ['age', false]]); -> sorted by name asc, then age desc
1066
+ */
1067
+ export declare function sort<TValue>(data: ArrayItems<TValue>, callback: readonly SortSpec<TValue>[]): TValue[];
1068
+ export declare function sort<TValue>(data: ArrayItems<TValue>, callback: ((value: TValue, key: number) => unknown) | string | readonly SortSpec<TValue>[] | null): TValue[];
1069
+ export declare function sort<TValue>(data: ArrayItems<TValue>): TValue[];
1070
+ export declare function sort<TValue>(data: readonly unknown[] | null | undefined, callback?: ((value: TValue, key: number) => unknown) | string | readonly SortSpec<TValue>[] | null): TValue[];
1071
+ /**
1072
+ * Sort the array in descending order using the given callback, "dot"
1073
+ * notation, or an array of sort descriptors for multi-key sorting.
1074
+ *
1075
+ * @param data - The array to sort.
1076
+ * @param callback - The sorting callback, field name, an array of sort descriptors, or null for natural sorting.
1077
+ * @returns A new sorted array in descending order.
1078
+ *
1079
+ * @example
1080
+ *
1081
+ * sortDesc([3, 1, 4, 1, 5]); -> [5, 4, 3, 1, 1]
1082
+ * sortDesc(['banana', 'apple', 'cherry']); -> ['cherry', 'banana', 'apple']
1083
+ * sortDesc([{name: 'John', age: 25}, {name: 'Jane', age: 30}], 'age'); -> sorted by age desc
1084
+ * sortDesc([{name: 'John', age: 25}, {name: 'Jane', age: 30}], (item) => item.name); -> sorted by name desc
1085
+ * sortDesc([{name: 'John', age: 25}, {name: 'John', age: 30}], ['name', ['age', false]]); -> each descriptor's comparison is reversed
1086
+ */
1087
+ export declare function sortDesc<TValue>(data: ArrayItems<TValue>, callback: readonly SortSpec<TValue>[]): TValue[];
1088
+ export declare function sortDesc<TValue>(data: ArrayItems<TValue>, callback: ((value: TValue, key: number) => unknown) | string | readonly SortSpec<TValue>[] | null): TValue[];
1089
+ export declare function sortDesc<TValue>(data: ArrayItems<TValue>): TValue[];
1090
+ export declare function sortDesc<TValue>(data: readonly unknown[] | null | undefined, callback?: ((value: TValue, key: number) => unknown) | string | readonly SortSpec<TValue>[] | null): TValue[];
1091
+ /**
1092
+ * Recursively sort an array by keys and values.
1093
+ * Only arrays and plain objects are sorted; any other object (a class instance, Date or Map) is kept as it is.
1094
+ *
1095
+ * @param data - The array to sort recursively.
1096
+ * @param options - Sort options (currently unused, for PHP compatibility).
1097
+ * @param descending - Whether to sort in descending order.
1098
+ * @returns A new recursively sorted array.
1099
+ *
1100
+ * @example
1101
+ *
1102
+ * sortRecursive({ b: [3, 1, 2], a: { d: 2, c: 1 } }); -> { a: { c: 1, d: 2 }, b: [1, 2, 3] }
1103
+ * sortRecursive([{ name: 'john', age: 30 }, { name: 'jane', age: 25 }]); -> sorted objects with sorted keys
1104
+ */
1105
+ export declare function sortRecursive<TValue>(data: ArrayItems<TValue>, descending?: CaseValue<typeof SortDirection> | boolean): TValue[];
1106
+ export declare function sortRecursive<TValue>(data: readonly unknown[] | null | undefined, descending?: CaseValue<typeof SortDirection> | boolean): TValue[] | Record<string, unknown>;
1107
+ /**
1108
+ * Recursively sort an array by keys and values in descending order.
1109
+ *
1110
+ * @param data - The array to sort recursively in descending order.
1111
+ * @param options - Sort options (currently unused, for PHP compatibility).
1112
+ * @returns A new recursively sorted array in descending order.
1113
+ *
1114
+ * @example
1115
+ *
1116
+ * sortRecursiveDesc({ a: [1, 2, 3], b: { c: 1, d: 2 } }); -> { b: { d: 2, c: 1 }, a: [3, 2, 1] }
1117
+ */
1118
+ export declare function sortRecursiveDesc<TValue>(data: ArrayItems<TValue>): TValue[];
1119
+ export declare function sortRecursiveDesc<TValue>(data: readonly unknown[] | null | undefined): TValue[] | Record<string, unknown>;
1120
+ /**
1121
+ * Splice a portion of the underlying array, mutating it in place, like PHP's
1122
+ * `array_splice()`. Returns what was removed; use `slice()` for a non-mutating read.
1123
+ * Replacement arrays are flattened into the result.
1124
+ *
1125
+ * @see Collection::splice — `packages/collection/stubs/Collection.php:1768`. Wraps `array_splice`; mutates.
1126
+ *
1127
+ * @param data - The array to splice. Mutated in place.
1128
+ * @param offset - The starting index; a fraction is dropped, as array_splice()'s int parameter drops it
1129
+ * @param length - The number of items to remove, a fraction dropped. Null or none removes everything from offset on.
1130
+ * @param replacement - The replacement items (arrays will be flattened)
1131
+ * @returns The removed elements.
1132
+ * @throws TypeError when the offset or the length is NAN, infinite or outside PHP's int range, which array_splice()
1133
+ * refuses.
1134
+ */
1135
+ export declare function splice<TValue, TReplacements>(data: TValue[], offset: number, length?: number | null, ...replacement: TReplacements[]): TValue[];
1136
+ /**
1137
+ * Take items in the array until the given condition is met.
1138
+ *
1139
+ * A value is compared with PHP's `===`; a callback gets each value and index, and PHP truthiness judges its answer.
1140
+ *
1141
+ * @param data - The array to take items from.
1142
+ * @param value - The value to take until, or a callback answering whether an item meets the condition.
1143
+ * @returns A new array of the items before the first that meets the condition.
1144
+ *
1145
+ * @example
1146
+ *
1147
+ * takeUntil([1, 2, 3, 4], 3); -> [1, 2]
1148
+ * takeUntil([1, 2, 3, 4], (value) => value >= 3); -> [1, 2]
1149
+ * takeUntil([1, 2, 3, 4], 99); -> [1, 2, 3, 4]
1150
+ */
1151
+ export declare function takeUntil<TValue>(data: ArrayItems<TValue>, value: NoInfer<TValue> | ((value: TValue, index: number) => unknown)): TValue[];
1152
+ export declare function takeUntil(data: readonly unknown[] | null | undefined, value: AnyValueOr<(value: unknown, index: number) => unknown>): unknown[];
1153
+ /**
1154
+ * Take items in the array while the given condition is met.
1155
+ *
1156
+ * A value is compared with PHP's `===`; a callback gets each value and index, and PHP truthiness judges its answer.
1157
+ *
1158
+ * @param data - The array to take items from.
1159
+ * @param value - The value to take while items equal it, or a callback answering whether an item meets the condition.
1160
+ * @returns A new array of the items before the first that fails the condition.
1161
+ *
1162
+ * @example
1163
+ *
1164
+ * takeWhile([1, 1, 2, 2, 3, 3], 1); -> [1, 1]
1165
+ * takeWhile([1, 2, 3, 4], (value) => value < 3); -> [1, 2]
1166
+ * takeWhile([1, 2, 3, 4], 2); -> []
1167
+ */
1168
+ export declare function takeWhile<TValue>(data: ArrayItems<TValue>, value: NoInfer<TValue> | ((value: TValue, index: number) => unknown)): TValue[];
1169
+ export declare function takeWhile(data: readonly unknown[] | null | undefined, value: AnyValueOr<(value: unknown, index: number) => unknown>): unknown[];
1170
+ /**
1171
+ * Get a string item from an array using "dot" notation.
1172
+ * Throws an error if the value is not a string.
1173
+ *
1174
+ * @param data - The array to get the item from.
1175
+ * @param key - The key or dot-notated path of the item to get.
1176
+ * @param defaultValue - The default value if key is not found.
1177
+ * @returns The string value.
1178
+ * @throws InvalidArgumentException if the value is not a string.
1179
+ *
1180
+ * @example
1181
+ *
1182
+ * string(['hello', 'world'], 0); -> 'hello'
1183
+ * string([{name: 'John'}], '0.name'); -> 'John'
1184
+ * string([{name: 123}], '0.name'); -> throws InvalidArgumentException
1185
+ */
1186
+ export declare function string<TValue, TDefault = null>(data: ArrayItems<TValue>, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): string;
1187
+ export declare function string<TDefault = null>(data: readonly unknown[] | null | undefined, key: PathKey, defaultValue?: TDefault | (() => TDefault) | null): string;
1188
+ /**
1189
+ * Conditionally compile CSS classes from an array into a CSS class list.
1190
+ *
1191
+ * @param data - The array to convert to CSS classes.
1192
+ * @returns A string of CSS classes separated by spaces.
1193
+ *
1194
+ * @example
1195
+ *
1196
+ * toCssClasses(['font-bold', 'mt-4']); -> 'font-bold mt-4'
1197
+ * toCssClasses(Object.assign(['font-bold', 'mt-4'], { 'ml-2': true, 'mr-2': false })); -> 'font-bold mt-4 ml-2'
1198
+ * toCssClasses(Object.assign([], { 'font-bold': true, 'text-red': false })); -> 'font-bold'
1199
+ */
1200
+ export declare function toCssClasses<TValue>(data: ArrayItems<TValue>): string;
1201
+ export declare function toCssClasses(data: readonly unknown[] | null | undefined): string;
1202
+ /**
1203
+ * Conditionally compile CSS styles from an array into a CSS style list.
1204
+ *
1205
+ * @param data - The array to convert to CSS styles.
1206
+ * @returns A string of CSS styles separated by spaces, each ending with semicolon.
1207
+ *
1208
+ * @example
1209
+ *
1210
+ * toCssStyles(['font-weight: bold', 'margin-top: 4px']); -> 'font-weight: bold; margin-top: 4px;'
1211
+ * toCssStyles(Object.assign(['font-weight: bold'], { 'margin-left: 2px': true, 'margin-right: 2px': false }));
1212
+ * -> 'font-weight: bold; margin-left: 2px;'
1213
+ */
1214
+ export declare function toCssStyles<TValue>(data: ArrayItems<TValue>): string;
1215
+ export declare function toCssStyles(data: readonly unknown[] | null | undefined): string;
1216
+ /**
1217
+ * Filter the array using the given callback.
1218
+ *
1219
+ * @param data - The array to filter.
1220
+ * @param callback - The function to call for each item (value, index) => boolean.
1221
+ * @returns A new filtered array.
1222
+ *
1223
+ * @example
1224
+ *
1225
+ * where([1, 2, 3, 4], (value) => value > 2); -> [3, 4]
1226
+ * where(['a', 'b', null, 'c'], (value) => value !== null); -> ['a', 'b', 'c']
1227
+ */
1228
+ export declare function where<TValue>(data: ArrayItems<TValue>, callback: (value: TValue, index: number) => unknown): TValue[];
1229
+ export declare function where<TValue>(data: readonly unknown[] | null | undefined, callback: (value: TValue, index: number) => unknown): TValue[];
1230
+ /**
1231
+ * Filter the array using the negation of the given callback.
1232
+ *
1233
+ * @param data - The array to filter.
1234
+ * @param callback - The function to call for each item (value, index) => boolean.
1235
+ * @returns A new filtered array with items that fail the test.
1236
+ *
1237
+ * @example
1238
+ *
1239
+ * reject([1, 2, 3, 4], (value) => value > 2); -> [1, 2]
1240
+ * reject(['a', 'b', null, 'c'], (value) => value === null); -> ['a', 'b', 'c']
1241
+ */
1242
+ export declare function reject<TValue>(data: ArrayItems<TValue>, callback: (value: TValue, index: number) => unknown): TValue[];
1243
+ export declare function reject<TValue>(data: readonly unknown[] | null | undefined, callback: (value: TValue, index: number) => unknown): TValue[];
1244
+ /**
1245
+ * Replace the data items with the given replacer items.
1246
+ *
1247
+ * The replacer is read the way `getArrayableItems()` reads it (a scalar as `[scalar]`), and each of
1248
+ * its integer keys replaces or adds that index, an index none fills holding `undefined`. A string key,
1249
+ * which a list can't hold, is dropped, as `union` drops one.
1250
+ *
1251
+ * @see Collection::replace — `packages/collection/stubs/Collection.php:1183`.
1252
+ * Wraps `array_replace`.
1253
+ *
1254
+ * @param data - The array to replace items in.
1255
+ * @param replacerData - The list, object or Collection-like operand holding the items to replace.
1256
+ * @returns A new array with the replaced items.
1257
+ *
1258
+ * @example
1259
+ *
1260
+ * replace(['a', 'b', 'c'], ['d', 'e']); -> ['d', 'e', 'c']
1261
+ * replace(['a', 'b', 'c'], { 1: 'd', 2: 'e', 3: 'f' }); -> ['a', 'd', 'e', 'f']
1262
+ */
1263
+ export declare function replace<TValue>(data: ArrayItems<TValue>, replacerData: null | undefined): TValue[];
1264
+ export declare function replace<TValue>(data: ArrayItems<TValue>, replacerData: ArrayItems<TValue>): TValue[];
1265
+ export declare function replace<TValue, TReplace>(data: ArrayItems<TValue>, replacerData: TReplace[]): (TValue | TReplace)[];
1266
+ export declare function replace<TValue, TReplace = TValue>(data: ArrayItems<TValue>, replacerData: Record<number, TReplace>): (TValue | TReplace | undefined)[];
1267
+ export declare function replace<TValue, TReplace = TValue>(data: readonly unknown[] | null | undefined, replacerData: ArrayItems<TReplace> | Record<number, TReplace> | unknown): (TValue | TReplace | undefined)[];
1268
+ /**
1269
+ * Recursively replace the data items with the given items.
1270
+ *
1271
+ * The replacer is read the way `getArrayableItems()` reads it (a scalar as `[scalar]`), and only its
1272
+ * integer keys apply: a string key, which a list can't hold, is dropped, as `union` drops one. Each index
1273
+ * merges the way `@tolki/obj`'s `replaceRecursive` merges a key: two arrays or plain objects merge,
1274
+ * and anything else, a `Date` or class instance included, is replaced whole.
1275
+ *
1276
+ * @see Collection::replaceRecursive — `packages/collection/stubs/Collection.php:1194`. Wraps `array_replace_recursive`.
1277
+ *
1278
+ * @param data - The original array to replace items in.
1279
+ * @param replacerData - The list, object or Collection-like operand holding the items to replace.
1280
+ * @returns A new array with the replaced items.
1281
+ */
1282
+ export declare function replaceRecursive<TValue>(data: ArrayItems<TValue>, replacerData: null | undefined): TValue[];
1283
+ export declare function replaceRecursive<TValue>(data: ArrayItems<TValue>, replacerData: ArrayItems<TValue>): (TValue | undefined)[];
1284
+ export declare function replaceRecursive<TValue, TReplace>(data: ArrayItems<TValue>, replacerData: TReplace[]): (TValue | TReplace | undefined)[];
1285
+ export declare function replaceRecursive<TValue, TReplace = TValue>(data: ArrayItems<TValue>, replacerData: Record<number, TReplace>): (TValue | TReplace | undefined)[];
1286
+ export declare function replaceRecursive<TValue, TReplace = TValue>(data: readonly unknown[] | null | undefined, replacerData: ArrayItems<TReplace> | Record<number, TReplace> | unknown): (TValue | TReplace | undefined)[];
1287
+ /**
1288
+ * Reverse the order of the array and return the result.
1289
+ *
1290
+ * @see Collection::reverse — `packages/collection/stubs/Collection.php:1204`.
1291
+ * Wraps `array_reverse($items, true)` — preserves keys.
1292
+ *
1293
+ * @param data - The array to reverse.
1294
+ * @returns A new array with the items in reverse order.
1295
+ *
1296
+ * @example
1297
+ *
1298
+ * reverse([1, 2, 3]); -> [3, 2, 1]
1299
+ * reverse(['a', 'b', 'c']); -> ['c', 'b', 'a']
1300
+ */
1301
+ export declare function reverse<TValue>(data: ArrayItems<TValue>): TValue[];
1302
+ export declare function reverse(data: readonly unknown[] | null | undefined): unknown[];
1303
+ /**
1304
+ * Pad array to the specified length with a value.
1305
+ *
1306
+ * If size is positive, pads on the right (append).
1307
+ * If size is negative, pads on the left (prepend).
1308
+ *
1309
+ * @see Collection::pad — `packages/collection/stubs/Collection.php:1917`.
1310
+ * Wraps `array_pad`.
1311
+ *
1312
+ * @param data - The array to pad.
1313
+ * @param size - The desired length of the array (negative means pad left); a fraction is dropped.
1314
+ * @param value - The value to pad with.
1315
+ * @returns A new padded array.
1316
+ * @throws TypeError when the size is NAN, infinite or outside PHP's int range, as array_pad() refuses it.
1317
+ * @throws Error when the size is past PHP's maximum array size, as array_pad()'s ValueError.
1318
+ *
1319
+ * @example
1320
+ *
1321
+ * pad([1, 2, 3], 5, 0); -> [1, 2, 3, 0, 0]
1322
+ * pad([1, 2, 3], -5, 0); -> [0, 0, 1, 2, 3]
1323
+ */
1324
+ export declare function pad<TPadValue, TValue>(data: ArrayItems<TValue>, size: number, value: TPadValue): (TValue | TPadValue)[];
1325
+ /**
1326
+ * Partition the array into two arrays using the given callback.
1327
+ *
1328
+ * @param data - The array to partition.
1329
+ * @param callback - The function to call for each item (value, index) => boolean.
1330
+ * @returns A tuple containing [passed, failed] arrays.
1331
+ *
1332
+ * @example
1333
+ *
1334
+ * partition([1, 2, 3, 4], (value) => value > 2); -> [[3, 4], [1, 2]]
1335
+ * partition(['a', 'b', null, 'c'], (value) => value !== null); -> [['a', 'b', 'c'], [null]]
1336
+ */
1337
+ export declare function partition<TValue>(data: ArrayItems<TValue>, callback: (value: TValue, index: number) => unknown): [TValue[], TValue[]];
1338
+ export declare function partition<TValue>(data: readonly unknown[] | null | undefined, callback: (value: TValue, index: number) => unknown): [TValue[], TValue[]];
1339
+ /**
1340
+ * Filter items where the value is not null.
1341
+ *
1342
+ * @param data - The array to filter.
1343
+ * @returns A new array with null values removed.
1344
+ *
1345
+ * @example
1346
+ *
1347
+ * whereNotNull([1, null, 2, undefined, 3]); -> [1, 2, undefined, 3]
1348
+ * whereNotNull(['a', null, 'b', null]); -> ['a', 'b']
1349
+ */
1350
+ export declare function whereNotNull<TData extends readonly unknown[]>(data: TData): NonNullableArray<TData>;
1351
+ export declare function whereNotNull(data: readonly unknown[] | null | undefined): unknown[];
1352
+ /**
1353
+ * Check if an array contains a given value, a matching item, or a matching key path.
1354
+ *
1355
+ * A third argument that is a boolean or absent is this port's `strict` flag, so PHP's
1356
+ * key/value form `contains($key, $flag)` is written with an explicit operator here.
1357
+ * Otherwise a third argument is the key/value form's value, and a fourth makes the
1358
+ * third the operator. A null or undefined key compares the item itself, and a callable
1359
+ * key is the predicate, as `operatorForWhere` treats one.
1360
+ *
1361
+ * The key/value row therefore declares `NonBooleanValue`, and four third-argument shapes
1362
+ * pay for it — each rejected, each written as `contains(data, key, "=", value)` instead:
1363
+ * an `unknown` value; a union holding `boolean` (`string | boolean`, `null | boolean`);
1364
+ * an unconstrained type parameter, which could be instantiated with `boolean`; and a type
1365
+ * parameter whose constraint holds `boolean`. A plain `boolean` is NOT among them: it
1366
+ * matches the earlier `strict` row, which is what the runtime does with it.
1367
+ *
1368
+ * @see Collection::contains — `packages/collection/stubs/Collection.php:196`.
1369
+ * Value/callback/key-operator-value search; has no `Arr.php` counterpart at all.
1370
+ *
1371
+ * @param data - The array to search in.
1372
+ * @param value - The value to search for, or the key path when a third argument follows.
1373
+ * @param key - The dot path read from each item, a predicate, or null for the item itself.
1374
+ * @param operator - One of PHP's `where()` operators when a fourth argument follows; any
1375
+ * other value shares the `=` arm, as PHP's `switch` default does.
1376
+ * @param strict - Whether to use strict comparison.
1377
+ * @returns True if the value is found, false otherwise.
1378
+ *
1379
+ * @example
1380
+ *
1381
+ * contains([1, 2, 3], 2); -> true
1382
+ * contains(['a', 'b', 'c'], 'd'); -> false
1383
+ * contains([1, '1'], '1', true); -> true
1384
+ * contains([{ age: 30 }], 'age', 30); -> true (key/value)
1385
+ * contains([{ age: 30 }], 'age', '>', 25); -> true (key/operator/value)
1386
+ * contains([{ on: true }], 'on', '=', true); -> true (a boolean value needs the operator)
1387
+ */
1388
+ export declare function contains<TValue>(data: ArrayItems<TValue>, value: (value: TValue, key: number) => unknown, strict?: boolean): boolean;
1389
+ export declare function contains<TValue>(data: ArrayItems<TValue>, value: TValue, strict?: boolean): boolean;
1390
+ export declare function contains<TValue>(data: readonly unknown[] | null | undefined, value: TValue | ((value: TValue, key: number) => unknown), strict?: boolean): boolean;
1391
+ export declare function contains<TValue>(data: readonly unknown[] | null | undefined, key: PathKey | ((value: TValue, key: number) => unknown), operator: unknown, value: unknown): boolean;
1392
+ export declare function contains<TValue>(data: readonly unknown[] | null | undefined, key: PathKey | ((value: TValue, key: number) => unknown), value: NonBooleanValue): boolean;
1393
+ /**
1394
+ * Check if an array contains a given value, using strict comparison.
1395
+ *
1396
+ * With a second argument, each item's `key` path is compared with it the way PHP's
1397
+ * `===` compares — so an array or plain object matches by value, in order. Without one,
1398
+ * this is `contains(data, key, true)`: `in_array($key, $items, true)` for a value, and
1399
+ * `array_any($items, $key)` for a callback, so a match holding null counts.
1400
+ *
1401
+ * @see Collection::containsStrict — `packages/collection/stubs/Collection.php:216`.
1402
+ *
1403
+ * @param data - The array to search in.
1404
+ * @param key - The value to search for, or the path to compare when `value` is given.
1405
+ * @param value - The value the path must strictly equal.
1406
+ * @returns True if the item is found, false otherwise.
1407
+ *
1408
+ * @example
1409
+ *
1410
+ * containsStrict([1, 3, 5, '02'], '02'); -> true
1411
+ * containsStrict([1, 3, 5, '02'], 2); -> false
1412
+ * containsStrict([{ tags: ['a', 'b'] }], 'tags', ['a', 'b']); -> true
1413
+ * containsStrict([1, null, 2], (value) => value === null); -> true
1414
+ */
1415
+ export declare function containsStrict<TValue>(data: ArrayItems<TValue>, key: TValue | ((value: TValue, index: number) => unknown)): boolean;
1416
+ export declare function containsStrict(data: readonly unknown[] | null | undefined, key: unknown, value?: unknown): boolean;
1417
+ /**
1418
+ * Filter the array using a callback function.
1419
+ *
1420
+ * @see Collection::filter — `packages/collection/stubs/Collection.php:425`.
1421
+ * With a callback, delegates to `Arr::where()`; without one, wraps `array_filter`.
1422
+ *
1423
+ * @param data - The array to filter.
1424
+ * @param callback - Optional callback function to filter items.
1425
+ * @returns A new filtered array.
1426
+ *
1427
+ * @example
1428
+ *
1429
+ * filter([1, 2, 3, 4], (x) => x > 2); -> [3, 4]
1430
+ * filter([1, null, 2, undefined, 3]); -> [1, 2, 3]
1431
+ * filter(["0", "", 0, "x"]); -> ["x"]
1432
+ * filter(["00", "0.0"]); -> ["00", "0.0"]
1433
+ */
1434
+ export declare function filter<TData extends readonly unknown[]>(data: TData): TruthyArray<TData>;
1435
+ export declare function filter<TValue>(data: ArrayItems<TValue>, callback: (value: TValue, index: number) => unknown): TValue[];
1436
+ export declare function filter<TValue>(data: readonly unknown[] | null | undefined, callback?: (value: TValue, index: number) => unknown): TValue[];
1437
+ /**
1438
+ * If the given value is not an array and not null, wrap it in one.
1439
+ *
1440
+ * @param value - The value to wrap.
1441
+ * @returns An array containing the value, or an empty array if null.
1442
+ *
1443
+ * @example
1444
+ *
1445
+ * wrap('hello'); -> ['hello']
1446
+ * wrap(['hello']); -> ['hello']
1447
+ * wrap(null); -> []
1448
+ * wrap(undefined); -> [undefined]
1449
+ */
1450
+ export declare function wrap(value: null): [];
1451
+ export declare function wrap<TValue>(value: TValue[]): TValue[];
1452
+ export declare function wrap<TValue>(value: readonly TValue[]): readonly TValue[];
1453
+ export declare function wrap<TValue>(value: TValue): WrapResult<TValue>;
1454
+ /**
1455
+ * Get all keys from an array.
1456
+ *
1457
+ * @see Collection::keys — `packages/collection/stubs/Collection.php:793`.
1458
+ * Wraps `array_keys`.
1459
+ *
1460
+ * @param data - The array to get keys from.
1461
+ * @returns An array of all keys.
1462
+ *
1463
+ * @example
1464
+ *
1465
+ * keys(['name', 'age', 'city']); -> [0, 1, 2]
1466
+ * keys([]); -> []
1467
+ */
1468
+ export declare function keys<TValue>(data: ArrayItems<TValue>): number[];
1469
+ export declare function keys(data: readonly unknown[] | null | undefined): number[];
1470
+ /**
1471
+ * Get all values from an array.
1472
+ *
1473
+ * @see Collection::values — `packages/collection/stubs/Collection.php:1883`.
1474
+ * Wraps `array_values`.
1475
+ *
1476
+ * @param data - The array to get values from.
1477
+ * @returns An array of all values.
1478
+ *
1479
+ * @example
1480
+ *
1481
+ * values(['name', 'age', 'city']); -> ['name', 'age', 'city']
1482
+ * values([]); -> []
1483
+ */
1484
+ export declare function values<TValue>(data: ArrayItems<TValue>): TValue[];
1485
+ export declare function values(data: readonly unknown[] | null | undefined): unknown[];
1486
+ /**
1487
+ * Get the items that are not present in the given array.
1488
+ *
1489
+ * Compares scalars the way PHP's `(string) $a === (string) $b` does (see
1490
+ * `phpValueMatch`); `other` is normalized by `arrayableValues`.
1491
+ *
1492
+ * @see Collection::diff — `packages/collection/stubs/Collection.php:277`. Wraps `array_diff`.
1493
+ *
1494
+ * @param data - The original array.
1495
+ * @param other - The items to compare against (array, object, scalar or nullish).
1496
+ * @returns A new array containing items from data that are not in other.
1497
+ */
1498
+ export declare function diff<TValue>(data: ArrayItems<TValue>, other: ArrayItems<TValue>): TValue[];
1499
+ export declare function diff<TValue>(data: readonly unknown[] | null | undefined, other: ArrayItems<TValue> | unknown): TValue[];
1500
+ /**
1501
+ * Get the items whose index and value are not both present in the given other array.
1502
+ *
1503
+ * This is `array_diff_assoc` — unlike `diff`, matching by index+value, not by value
1504
+ * alone. `other` is normalized by `arrayableItems`, so each index is looked up among
1505
+ * its keys: a keyed operand matches by key, never by position, and a nullish one is empty.
1506
+ *
1507
+ * @see Collection::diffAssoc — `packages/collection/stubs/Collection.php:300`. Wraps `array_diff_assoc`.
1508
+ *
1509
+ * @param data - The original array
1510
+ * @param other - The array to diff against
1511
+ * @returns A new array containing items whose index+value pair is not in other
1512
+ */
1513
+ export declare function diffAssoc<TValue>(data: ArrayItems<TValue>, other: ArrayItems<TValue>): TValue[];
1514
+ export declare function diffAssoc(data: readonly unknown[] | null | undefined, other: unknown): unknown[];
1515
+ /**
1516
+ * Get the items whose index is not present in the given other data.
1517
+ *
1518
+ * This is `array_diff_key` — values are ignored entirely; only the index decides.
1519
+ * `other` is normalized by `arrayableItems`, so a keyed operand matches by key.
1520
+ * PHP keeps each survivor's original index; a JavaScript list cannot hold the gap,
1521
+ * so the survivors are reindexed, as every other list-returning helper here does.
1522
+ *
1523
+ * @see Collection::diffKeys — `packages/collection/stubs/Collection.php:323`. Wraps `array_diff_key`.
1524
+ *
1525
+ * @param data - The original array
1526
+ * @param other - The data to diff against
1527
+ * @returns A new array holding the items whose index is not in other
1528
+ *
1529
+ * @example
1530
+ *
1531
+ * diffKeys([1, 2, 3], [9, 9]); -> [3]
1532
+ * diffKeys([1, 2], { a: 1, 1: 5 }); -> [1]
1533
+ */
1534
+ export declare function diffKeys<TValue>(data: ArrayItems<TValue>, other: unknown): TValue[];
1535
+ export declare function diffKeys(data: readonly unknown[] | null | undefined, other: unknown): unknown[];
1536
+ /**
1537
+ * Get the items whose value is not present in the given other data, comparing with a callback.
1538
+ *
1539
+ * This is `array_udiff` — the callback replaces the default `(string)` cast comparison,
1540
+ * and reports whether two values are equal. `other` is normalized by `arrayableValues`.
1541
+ *
1542
+ * @see Collection::diffUsing — `packages/collection/stubs/Collection.php:289`. Wraps `array_udiff`.
1543
+ *
1544
+ * @param data - The original array
1545
+ * @param other - The data to diff against
1546
+ * @param callable - Function that reports whether two values are equal
1547
+ * @returns A new array holding the items no value of other is equal to
1548
+ *
1549
+ * @example
1550
+ *
1551
+ * const strcasecmp = (a: unknown, b: unknown) => String(a).toLowerCase() === String(b).toLowerCase();
1552
+ * diffUsing(['green', 'brown', 'blue'], ['GREEN', 'yellow'], strcasecmp); -> ['brown', 'blue']
1553
+ */
1554
+ export declare function diffUsing<TValue, TOther>(data: ArrayItems<TValue>, other: ArrayItems<TOther>, callable: (a: TValue, b: TOther) => boolean): TValue[];
1555
+ export declare function diffUsing<TValue, TOther>(data: readonly unknown[] | null | undefined, other: unknown, callable: (a: TValue, b: TOther) => boolean): TValue[];
1556
+ /**
1557
+ * Get the items whose index and value are not both present in the given other data,
1558
+ * comparing indexes with a callback.
1559
+ *
1560
+ * This is `array_diff_uassoc` — the callback reports whether two keys match, and the
1561
+ * values of a matching pair are compared with PHP's `(string)` cast rule. `other` is
1562
+ * normalized by `arrayableItems`, and the survivors are reindexed.
1563
+ *
1564
+ * @see Collection::diffAssocUsing — `packages/collection/stubs/Collection.php:312`.
1565
+ * Wraps `array_diff_uassoc`.
1566
+ *
1567
+ * @param data - The original array
1568
+ * @param other - The data to diff against
1569
+ * @param callback - Function that reports whether two keys match
1570
+ * @returns A new array holding the items no matching key/value pair of other covers
1571
+ *
1572
+ * @example
1573
+ *
1574
+ * const same = (a: unknown, b: unknown) => String(a) === String(b);
1575
+ * diffAssocUsing([1, 2, 3], [1, 9, 3], same); -> [2]
1576
+ */
1577
+ export declare function diffAssocUsing<TValue>(data: ArrayItems<TValue>, other: unknown, callback: (keyA: number, keyB: string | number) => boolean): TValue[];
1578
+ export declare function diffAssocUsing(data: readonly unknown[] | null | undefined, other: unknown, callback: (keyA: number, keyB: string | number) => boolean): unknown[];
1579
+ /**
1580
+ * Get the items whose index is not present in the given other data, comparing indexes
1581
+ * with a callback.
1582
+ *
1583
+ * This is `array_diff_ukey` — values are ignored entirely. `other` is normalized by
1584
+ * `arrayableItems`, and the survivors are reindexed.
1585
+ *
1586
+ * @see Collection::diffKeysUsing — `packages/collection/stubs/Collection.php:335`.
1587
+ * Wraps `array_diff_ukey`.
1588
+ *
1589
+ * @param data - The original array
1590
+ * @param other - The data to diff against
1591
+ * @param callback - Function that reports whether two keys match
1592
+ * @returns A new array holding the items whose index no key of other matches
1593
+ *
1594
+ * @example
1595
+ *
1596
+ * const same = (a: unknown, b: unknown) => String(a) === String(b);
1597
+ * diffKeysUsing([1, 2], { a: 1, 1: 5 }, same); -> [1]
1598
+ */
1599
+ export declare function diffKeysUsing<TValue>(data: ArrayItems<TValue>, other: unknown, callback: (keyA: number, keyB: string | number) => boolean): TValue[];
1600
+ export declare function diffKeysUsing(data: readonly unknown[] | null | undefined, other: unknown, callback: (keyA: number, keyB: string | number) => boolean): unknown[];
1601
+ /**
1602
+ * Intersect the data array with the given other array.
1603
+ *
1604
+ * Compares scalars the way PHP's `(string) $a === (string) $b` does (see
1605
+ * `phpValueMatch`); `other` is normalized by `arrayableValues`. `callable`, when
1606
+ * given, replaces the default comparator.
1607
+ *
1608
+ * @see Collection::intersect — `packages/collection/stubs/Collection.php:663`. Wraps `array_intersect`.
1609
+ *
1610
+ * @param data - The original array
1611
+ * @param other - The items to intersect with (array, object, scalar or nullish)
1612
+ * @param callable - Optional function to compare values
1613
+ * @returns A new array containing items present in both arrays
1614
+ */
1615
+ export declare function intersect<TValue, TOther>(data: ArrayItems<TValue>, other: ArrayItems<TOther>, callable: (a: TValue, b: TOther) => boolean): TValue[];
1616
+ export declare function intersect<TValue>(data: ArrayItems<TValue>, other: ArrayItems<TValue>, callable?: null): TValue[];
1617
+ export declare function intersect<TValue, TOther>(data: readonly unknown[] | null | undefined, other: unknown, callable?: ((a: TValue, b: TOther) => boolean) | null): TValue[];
1618
+ /**
1619
+ * Intersect the array with the given items, comparing values with a callback.
1620
+ *
1621
+ * This is `array_uintersect`. It is `intersect`'s third parameter under its own name,
1622
+ * so the two share one algorithm; the callback reports whether two values are equal.
1623
+ *
1624
+ * @see Collection::intersectUsing — `packages/collection/stubs/Collection.php:675`.
1625
+ * Wraps `array_uintersect`.
1626
+ *
1627
+ * @param data - The original array
1628
+ * @param other - The items to intersect with
1629
+ * @param callable - Function that reports whether two values are equal
1630
+ * @returns A new array holding the items some value of other is equal to
1631
+ *
1632
+ * @example
1633
+ *
1634
+ * const strcasecmp = (a: unknown, b: unknown) => String(a).toLowerCase() === String(b).toLowerCase();
1635
+ * intersectUsing(['green', 'brown', 'blue'], ['GREEN', 'yellow'], strcasecmp); -> ['green']
1636
+ */
1637
+ export declare function intersectUsing<TValue, TOther>(data: ArrayItems<TValue>, other: ArrayItems<TOther>, callable: (a: TValue, b: TOther) => boolean): TValue[];
1638
+ export declare function intersectUsing<TValue, TOther>(data: readonly unknown[] | null | undefined, other: unknown, callable: (a: TValue, b: TOther) => boolean): TValue[];
1639
+ /**
1640
+ * Intersect the array with the given items with additional index check.
1641
+ * Returns items where both the index AND value match.
1642
+ *
1643
+ * `other` is normalized by `arrayableItems`, so each index is looked up among its keys:
1644
+ * a keyed operand matches by key, never by position.
1645
+ *
1646
+ * @see Collection::intersectAssoc — `packages/collection/stubs/Collection.php:686`.
1647
+ * Wraps `array_intersect_assoc`.
1648
+ *
1649
+ * @param data - The original array
1650
+ * @param other - The array to intersect with
1651
+ * @returns A new array containing items where both index and value match
1652
+ *
1653
+ * @example
1654
+ *
1655
+ * intersectAssoc([1, 2, 3], [2, 3, 4]); -> []
1656
+ * intersectAssoc(['a', 'b', 'c'], ['a', 'b', 'd']); -> ['a', 'b']
1657
+ * intersectAssoc([1, 2, 3, 4], [5, 2, 3]); -> [2, 3]
1658
+ */
1659
+ export declare function intersectAssoc<TValue>(data: ArrayItems<TValue>, other: ArrayItems<TValue>): TValue[];
1660
+ export declare function intersectAssoc(data: readonly unknown[] | null | undefined, other: unknown): unknown[];
1661
+ /**
1662
+ * Intersect the array with the given items with additional index check, using the callback.
1663
+ * The callback is used to compare indices, while values are compared by PHP's `(string)` cast rule.
1664
+ *
1665
+ * `other` is normalized by `arrayableItems`, so the callback receives each of its real keys: an
1666
+ * index for a list, or the key PHP would store (a number for a canonical integer) for a keyed operand.
1667
+ *
1668
+ * @see Collection::intersectAssocUsing — `packages/collection/stubs/Collection.php:698`.
1669
+ * Wraps `array_intersect_uassoc`.
1670
+ *
1671
+ * @param data - The original array
1672
+ * @param other - The array to intersect with
1673
+ * @param callback - The callback function to compare indices (returns true if indices match)
1674
+ * @returns A new array containing items where both index (via callback) and value match
1675
+ *
1676
+ * @example
1677
+ *
1678
+ * Example: treat all indices as equal (not very useful, but demonstrates the concept)
1679
+ * const alwaysEqual = (a: number, b: number) => true;
1680
+ * intersectAssocUsing([1, 2, 3], [1, 2, 3], alwaysEqual); -> [1, 2, 3]
1681
+ */
1682
+ export declare function intersectAssocUsing<TValue>(data: ArrayItems<TValue>, other: ArrayItems<TValue>, callback: (keyA: number, keyB: number) => boolean): TValue[];
1683
+ export declare function intersectAssocUsing<TValue>(data: readonly unknown[] | null | undefined, other: ArrayItems<unknown> | string | number | boolean | null | undefined, callback: (keyA: number, keyB: number) => boolean): TValue[];
1684
+ export declare function intersectAssocUsing<TValue>(data: readonly unknown[] | null | undefined, other: unknown, callback: (keyA: number, keyB: number | string) => boolean): TValue[];
1685
+ /**
1686
+ * Intersect the array with the given items by key.
1687
+ *
1688
+ * `other` is normalized by `arrayableItems`, so an index survives only when it is one of
1689
+ * `other`'s keys: a keyed operand matches by key, never by position.
1690
+ *
1691
+ * @see Collection::intersectByKeys — `packages/collection/stubs/Collection.php:709`.
1692
+ * Wraps `array_intersect_key`.
1693
+ *
1694
+ * @param data - The original array
1695
+ * @param other - The array to intersect with
1696
+ * @returns A new array containing items with keys present in both arrays
1697
+ */
1698
+ export declare function intersectByKeys<TValue>(data: ArrayItems<TValue>, other: ArrayItems<unknown>): TValue[];
1699
+ export declare function intersectByKeys<TValue>(data: readonly unknown[] | null | undefined, other: ArrayItems<TValue> | unknown): TValue[];
1700
+ export {};
1701
+ //# sourceMappingURL=arr.d.ts.map