@tolki/obj 0.0.0-stage → 1.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/LICENSE +21 -0
- package/README.md +2386 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +96 -0
- package/dist/obj.d.ts +2201 -0
- package/dist/obj.d.ts.map +1 -0
- package/dist/obj.js +1406 -0
- package/package.json +61 -3
package/dist/obj.d.ts
ADDED
|
@@ -0,0 +1,2201 @@
|
|
|
1
|
+
import { SortDirection } from '@tolki/enum';
|
|
2
|
+
import { ArrayableItems, CaseValue, CollapsedObject, DeepMergeObjects, EnsureObject, FlattenReach, FlipObject, IsBareObject, MapArrayKey, MapData, MapEntryKey, MapEntryValue, MergeObjects, NonKeyedItems, NonNullableObject, NonObjectItems, ObjectDeepPartial, ObjectFlatValue, ObjectKey, ObjectPathValue, ObjectResolvePath, ObjectValue, OmitObjectPath, OmitObjectPaths, PathKey, PathKeys, PluckValue, PrefixKeys, ReindexedObject, RenumberedObject, SetObjectPath, Simplify, SortSpec, SpreadArgs, SpreadItems, SpreadObjects, TruthyObject, UndotObjectValue } from '@tolki/types';
|
|
3
|
+
type SortCallback<T> = ((value: ObjectValue<T>, key: ObjectKey<T>) => unknown) | string | readonly SortSpec<ObjectValue<T>>[] | null;
|
|
4
|
+
type ObjectWriteResult<T, P, V> = string extends P ? Record<string, unknown> : number extends P ? Record<string, unknown> : SetObjectPath<T, `${P & (string | number)}`, V>;
|
|
5
|
+
type ObjectPullRest<T, P> = P extends keyof T ? Simplify<Omit<T, P>> : OmitObjectPath<T, `${P & (string | number)}`>;
|
|
6
|
+
type ArrayElementOf<T> = T extends readonly (infer E)[] ? E : never;
|
|
7
|
+
type PushedAt<X, V> = [ArrayElementOf<X> | V] extends [infer E] ? 0 extends 1 & X ? E[] : [PushedKeyed<X, V>] extends [never] ? E[] : PushedKeyed<X, V> | ([Extract<X, readonly unknown[]>] extends [never] ? never : E[]) : never;
|
|
8
|
+
type PushedKeyed<X, V> = X extends ReadonlyMap<infer MK, infer MV> ? Map<MK | number, MV | V> : X extends NonObjectItems | Date | RegExp | Promise<unknown> ? never : X extends object ? X & Record<number, V> : never;
|
|
9
|
+
type NonBooleanValue = string | number | bigint | symbol | object | null | undefined;
|
|
10
|
+
type AnyValueOr<TCallback> = TCallback | NonNullable<unknown> | null | undefined;
|
|
11
|
+
type NullishKeyValue<K, V> = [Extract<K, null | undefined>] extends [never] ? never : NoInfer<V>;
|
|
12
|
+
/**
|
|
13
|
+
* Mutation contract: pop, shift, splice and unshift mutate their first
|
|
14
|
+
* argument; every other function returns a new value. arr and obj agree
|
|
15
|
+
* on this — re-read Collection.php before "aligning" one to the other.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Map rows: a helper whose result carries a Map's keys or values declares first a `ReadonlyMap<TKey, TValue>` row,
|
|
19
|
+
* which also reads a Map typed by a type parameter, then a `MapData<TMap>` row, which reads a union of Maps; then an
|
|
20
|
+
* empty-result `NonKeyedItems` row and a `NonObjectItems` row, the widest result, for a union like `Map | string[]`.
|
|
21
|
+
*/
|
|
22
|
+
type Default<TDefault> = TDefault | (() => TDefault);
|
|
23
|
+
type PhpKeyString<V> = V extends string ? V : V extends number ? number extends V ? `${number}` | "NAN" | "INF" | "-INF" : `${V}` extends `${bigint}` ? `${V}` : string : V extends true ? "1" : V extends false | null | undefined ? "" : string;
|
|
24
|
+
type OperandValues<X> = ObjectValue<ArrayableItems<X>>;
|
|
25
|
+
type CombineRecord<K, V> = CombineKeyed<PhpKeyString<OperandValues<K>>, CombineSureKeys<K>, OperandValues<V>>;
|
|
26
|
+
type CombineKeyed<All extends PropertyKey, Sure, V> = [
|
|
27
|
+
Exclude<All, Sure>
|
|
28
|
+
] extends [never] ? Record<All, V> : [Sure] extends [never] ? Partial<Record<All, V>> : Record<Sure & All, V> & Partial<Record<Exclude<All, Sure>, V>>;
|
|
29
|
+
type CombineSureKeys<K> = K extends readonly unknown[] ? number extends K["length"] ? never : {
|
|
30
|
+
[I in keyof K]: CombineOneKey<K[I]>;
|
|
31
|
+
}[number] : K extends NonObjectItems | Iterable<unknown> | {
|
|
32
|
+
all: (...args: never[]) => unknown;
|
|
33
|
+
} | {
|
|
34
|
+
toArray: (...args: never[]) => unknown;
|
|
35
|
+
} | {
|
|
36
|
+
toJSON: (...args: never[]) => unknown;
|
|
37
|
+
} ? never : {
|
|
38
|
+
[P in keyof K]-?: string extends P ? never : number extends P ? never : Record<never, never> extends Pick<K, P> ? never : CombineOneKey<K[P]>;
|
|
39
|
+
}[keyof K];
|
|
40
|
+
type CombineOneKey<X, S = PhpKeyString<X>> = S extends unknown ? [PhpKeyString<X>] extends [S] ? S : never : never;
|
|
41
|
+
type BareObjectValue<T> = IsBareObject<T> extends true ? unknown : ObjectValue<T>;
|
|
42
|
+
type BareObjectKey<T> = IsBareObject<T> extends true ? string | number : ObjectKey<T>;
|
|
43
|
+
type MapWithKeysList<T extends readonly unknown[]> = number extends T["length"] ? Record<number, T[number]> : {
|
|
44
|
+
[I in keyof T & `${number}`]: T[I];
|
|
45
|
+
};
|
|
46
|
+
type TruthyValue<V> = Exclude<V, null | undefined | false | 0 | "">;
|
|
47
|
+
type KeyByResult<V, K> = [Extract<K, symbol>] extends [never] ? Record<MapArrayKey<K>, V> : [Exclude<K, symbol>] extends [never] ? {
|
|
48
|
+
[S in Extract<K, symbol>]?: V;
|
|
49
|
+
} : Record<MapArrayKey<Exclude<K, symbol>>, V> & {
|
|
50
|
+
[S in Extract<K, symbol>]?: V;
|
|
51
|
+
};
|
|
52
|
+
type KeyByPath<V, P> = string extends P ? string | number | Extract<ObjectPathValue<V>, symbol> : PluckValue<V, P>;
|
|
53
|
+
type PrependKey<K extends string | number> = K extends number ? `${K}` extends `${bigint}` ? K : `${K}` extends `${infer I extends number}.${string}` ? I : number : K;
|
|
54
|
+
type DotUndefined<T, D extends number = 5> = [D] extends [never] ? undefined : T extends readonly (infer E)[] ? Extract<E, undefined> | DotUndefined<NonNullable<E>, DotDepth[D]> : T extends (...args: never[]) => unknown ? never : T extends object ? {
|
|
55
|
+
[K in keyof T]-?: Extract<Required<T>[K], undefined> | DotUndefined<NonNullable<T[K]>, DotDepth[D]>;
|
|
56
|
+
}[keyof T] : never;
|
|
57
|
+
type DotDepth = [never, 0, 1, 2, 3, 4];
|
|
58
|
+
type PluckKey<TItem> = string | readonly (string | number)[] | ((item: TItem) => unknown);
|
|
59
|
+
type ForeachValue<V> = unknown extends V ? unknown : V extends readonly (infer E)[] ? E : V extends string | ((...args: never[]) => unknown) ? never : V extends ReadonlyMap<unknown, infer M> ? M : V extends Iterable<infer I> ? I : V extends object ? [keyof V] extends [never] ? unknown : ObjectValue<V> : never;
|
|
60
|
+
type CrossJoinEntries<T> = T extends readonly unknown[] ? Record<number, ForeachValue<T[number]>> : T extends ReadonlyMap<unknown, infer V> ? Record<string, ForeachValue<V>> : {
|
|
61
|
+
[K in keyof T as K extends symbol ? never : [ForeachValue<T[K]>] extends [never] ? never : K]: ForeachValue<T[K]>;
|
|
62
|
+
};
|
|
63
|
+
type CrossJoinRow<T extends readonly object[], Row = Record<never, never>> = T extends readonly [infer First, ...infer Rest extends readonly object[]] ? CrossJoinRow<Rest, SpreadObjects<Row, CrossJoinEntries<First>>> : T extends readonly [] ? Row : SpreadObjects<Row, Partial<CrossJoinEntries<T[number]>>>;
|
|
64
|
+
type KeyComparator<T1, T2> = (keyA: ObjectKey<T1> | ObjectKey<ArrayableItems<T2>>, keyB: ObjectKey<T1> | ObjectKey<ArrayableItems<T2>>) => boolean;
|
|
65
|
+
type WrapResult<T> = T extends null ? Record<string, never> : T extends readonly unknown[] | ((...args: never[]) => unknown) ? Record<0, T> : T extends object ? T : Record<0, T>;
|
|
66
|
+
/**
|
|
67
|
+
* Determine whether the given value is object accessible.
|
|
68
|
+
*
|
|
69
|
+
* A plain object and a `Map` both carry array entries, so both are accessible. A `Date`,
|
|
70
|
+
* a `Set` or a class instance keeps its state elsewhere, and PHP's `accessible` rejects a
|
|
71
|
+
* `DateTime` for the same reason. An array belongs to `@tolki/arr`, not here.
|
|
72
|
+
*
|
|
73
|
+
* @param value - The value to check.
|
|
74
|
+
* @returns True if the value is an accessible object, false otherwise.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
*
|
|
78
|
+
* accessible({}); -> true
|
|
79
|
+
* accessible({ a: 1, b: 2 }); -> true
|
|
80
|
+
* accessible(new Map()); -> true
|
|
81
|
+
* accessible(new Date()); -> false
|
|
82
|
+
* accessible([]); -> false
|
|
83
|
+
* accessible(null); -> false
|
|
84
|
+
*/
|
|
85
|
+
export declare function accessible(value: unknown): value is Record<PropertyKey, unknown>;
|
|
86
|
+
/**
|
|
87
|
+
* Determine whether the given value is objectifiable.
|
|
88
|
+
*
|
|
89
|
+
* Same rule as `accessible`: a plain object or a `Map` carries entries, a `Date`, a `Set`
|
|
90
|
+
* or a class instance does not. PHP's `arrayable` rejects a `DateTime` on the same grounds.
|
|
91
|
+
*
|
|
92
|
+
* @param value - The value to check.
|
|
93
|
+
* @returns True if the value can be treated as an object, false otherwise.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
*
|
|
97
|
+
* objectifiable({}); -> true
|
|
98
|
+
* objectifiable({ a: 1, b: 2 }); -> true
|
|
99
|
+
* objectifiable(new Date()); -> false
|
|
100
|
+
* objectifiable([]); -> false
|
|
101
|
+
*/
|
|
102
|
+
export declare function objectifiable(value: unknown): value is Record<string, unknown>;
|
|
103
|
+
/**
|
|
104
|
+
* Add an element to an object using "dot" notation if it doesn't exist.
|
|
105
|
+
*
|
|
106
|
+
* @param data - The object to add the element to.
|
|
107
|
+
* @param key - The key or dot-notated path where to add the value.
|
|
108
|
+
* @param value - The value to add.
|
|
109
|
+
* @returns A new object with the value added if the key didn't exist.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
*
|
|
113
|
+
* add({ name: 'John' }, 'age', 30); -> { name: 'John', age: 30 }
|
|
114
|
+
* add({ user: { name: 'John' } }, 'user.age', 30); -> { user: { name: 'John', age: 30 } }
|
|
115
|
+
* add({ name: 'John' }, 'name', 'Jane'); -> { name: 'John' } (no change, key exists)
|
|
116
|
+
* add({ m: new Map([[2, 'c']]) }, 'm.0', 'a'); -> { m: new Map([[2, 'c'], [0, 'a']]) } (a Map keeps its key order)
|
|
117
|
+
*/
|
|
118
|
+
export declare function add(data: ReadonlyMap<unknown, unknown>, key: PathKey, value: unknown): Record<string, unknown>;
|
|
119
|
+
export declare function add(data: NonObjectItems, key: PathKey, value: unknown): Record<string, unknown>;
|
|
120
|
+
export declare function add<T extends object, P extends string | number, V>(data: T, key: P, value: V): ObjectWriteResult<T, P, NonNullable<ObjectResolvePath<T, P, never>> | V>;
|
|
121
|
+
export declare function add(data: unknown, key: PathKey, value: unknown): Record<string, unknown>;
|
|
122
|
+
/**
|
|
123
|
+
* Get an object item from an object using "dot" notation.
|
|
124
|
+
*
|
|
125
|
+
* A list value is rejected: obj's analogue of a PHP array is an object.
|
|
126
|
+
*
|
|
127
|
+
* @param data - The object to get the item from.
|
|
128
|
+
* @param key - The key or dot-notated path of the item to get.
|
|
129
|
+
* @param defaultValue - The default value if key is not found.
|
|
130
|
+
* @returns The objct value.
|
|
131
|
+
* @throws InvalidArgumentException if the value is not an object.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
*
|
|
135
|
+
* objectItem({ items: { a: 1 } }, 'items'); -> { a: 1 }
|
|
136
|
+
* objectItem({ items: ['a', 'b'] }, 'items'); -> throws InvalidArgumentException (a list is not an object)
|
|
137
|
+
* objectItem({ user: { name: 'John' } }, 'user.name'); -> throws InvalidArgumentException
|
|
138
|
+
*/
|
|
139
|
+
export declare function objectItem(data: NonObjectItems, key: PathKey, defaultValue?: unknown): Record<string, unknown>;
|
|
140
|
+
export declare function objectItem<T extends object, P extends string | number, TDefault = null>(data: T, key: P, defaultValue?: Default<TDefault> | null): EnsureObject<ObjectResolvePath<T, P, TDefault>>;
|
|
141
|
+
export declare function objectItem(data: unknown, key: PathKey, defaultValue?: unknown): Record<string, unknown>;
|
|
142
|
+
/**
|
|
143
|
+
* Get a boolean item from an object using "dot" notation.
|
|
144
|
+
* Throws an error if the value is not a boolean.
|
|
145
|
+
*
|
|
146
|
+
* @param data - The object to get the item from.
|
|
147
|
+
* @param key - The key or dot-notated path of the item to get.
|
|
148
|
+
* @param defaultValue - The default value if key is not found.
|
|
149
|
+
* @returns The boolean value.
|
|
150
|
+
* @throws InvalidArgumentException if the value is not a boolean.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
*
|
|
154
|
+
* boolean({ active: true }, 'active'); -> true
|
|
155
|
+
* boolean({ user: { verified: false } }, 'user.verified'); -> false
|
|
156
|
+
* boolean({ user: { name: 'John' } }, 'user.name'); -> throws InvalidArgumentException
|
|
157
|
+
*/
|
|
158
|
+
export declare function boolean(data: unknown, key: PathKey, defaultValue?: Default<boolean> | null): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Chunk the object into chunks of the given size.
|
|
161
|
+
*
|
|
162
|
+
* A Map is chunked in its insertion order, so each chunk holds the entries PHP's would.
|
|
163
|
+
* A chunk is a plain object, so the integer keys inside one still enumerate ascending.
|
|
164
|
+
*
|
|
165
|
+
* @see Collection::chunk — `packages/collection/stubs/Collection.php:1533`.
|
|
166
|
+
* Wraps `array_chunk`; `preserveKeys` defaults to `true`.
|
|
167
|
+
*
|
|
168
|
+
* @param data - The record or Map to chunk
|
|
169
|
+
* @param size - The size of each chunk
|
|
170
|
+
* @param preserveKeys - Whether to preserve the original keys, defaults to true
|
|
171
|
+
* @returns Chunked record
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
*
|
|
175
|
+
* chunk({ a: 1, b: 2, c: 3 }, 2); -> { 0: { a: 1, b: 2 }, 1: { c: 3 } }
|
|
176
|
+
* chunk(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 2, false); -> { 0: { 0: 'c', 1: 'a' }, 1: { 0: 'b' } }
|
|
177
|
+
*/
|
|
178
|
+
export declare function chunk<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, size: number, preserveKeys: false): Record<number, Record<number, TValue>>;
|
|
179
|
+
export declare function chunk<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, size: number, preserveKeys?: boolean): Record<number, Record<string, TValue>>;
|
|
180
|
+
export declare function chunk<TMap>(data: MapData<TMap>, size: number, preserveKeys: false): Record<number, Record<number, MapEntryValue<TMap>>>;
|
|
181
|
+
export declare function chunk<TMap>(data: MapData<TMap>, size: number, preserveKeys?: boolean): Record<number, Record<string, MapEntryValue<TMap>>>;
|
|
182
|
+
export declare function chunk(data: NonKeyedItems, size: number, preserveKeys?: boolean): Record<number, never>;
|
|
183
|
+
export declare function chunk(data: NonObjectItems, size: number, preserveKeys?: boolean): Record<number, Record<string, unknown>>;
|
|
184
|
+
export declare function chunk<T extends object>(data: T, size: number, preserveKeys?: true | undefined): Record<number, Partial<T>>;
|
|
185
|
+
export declare function chunk<T extends object>(data: T, size: number, preserveKeys: false | undefined): Record<number, Record<number, ObjectValue<T>>>;
|
|
186
|
+
export declare function chunk<T extends object>(data: T, size: number, preserveKeys: boolean): Record<number, Partial<T> | Record<number, ObjectValue<T>>>;
|
|
187
|
+
export declare function chunk(data: unknown, size: number, preserveKeys?: boolean): Record<number, Record<string, unknown>>;
|
|
188
|
+
/**
|
|
189
|
+
* Chunk the object into chunks with a callback.
|
|
190
|
+
*
|
|
191
|
+
* A Map is walked in its insertion order, but the chunk the callback gets is a plain object that lists integer keys
|
|
192
|
+
* first, ascending, so `Object.values(chunk).at(-1)` is the item added last only when its key is listed last.
|
|
193
|
+
*
|
|
194
|
+
* @see Collection::chunkWhile — `packages/collection/stubs/Collection.php:1554`, which runs
|
|
195
|
+
* `LazyCollection::chunkWhile`. Keys are preserved inside each chunk.
|
|
196
|
+
*
|
|
197
|
+
* @param data - The record or Map to chunk
|
|
198
|
+
* @param callback - Receives the value, its key and the chunk built so far; return true to keep appending
|
|
199
|
+
* @returns Chunked record
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
*
|
|
203
|
+
* chunkWhile({ a: 1, b: 1, c: 2 }, (value, key, chunk) => Object.values(chunk).at(-1) === value);
|
|
204
|
+
* -> { 0: { a: 1, b: 1 }, 1: { c: 2 } }
|
|
205
|
+
* chunkWhile(new Map([[2, 'c'], [0, 'a']]), () => false); -> { 0: { 2: 'c' }, 1: { 0: 'a' } }
|
|
206
|
+
*/
|
|
207
|
+
export declare function chunkWhile<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>, chunk: Record<string, TValue>) => unknown): Record<number, Record<string, TValue>>;
|
|
208
|
+
export declare function chunkWhile<TMap>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>, chunk: Record<string, MapEntryValue<TMap>>) => unknown): Record<number, Record<string, MapEntryValue<TMap>>>;
|
|
209
|
+
export declare function chunkWhile(data: NonKeyedItems, callback: (value: unknown, key: string | number, chunk: Record<string, unknown>) => unknown): Record<number, never>;
|
|
210
|
+
export declare function chunkWhile(data: NonObjectItems, callback: (value: unknown, key: string | number, chunk: Record<string, unknown>) => unknown): Record<number, Record<string, unknown>>;
|
|
211
|
+
export declare function chunkWhile<T extends object>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>, chunk: Partial<T>) => unknown): Record<number, Partial<T>>;
|
|
212
|
+
export declare function chunkWhile(data: unknown, callback: (value: unknown, key: string | number, chunk: Record<string, unknown>) => unknown): Record<number, Record<string, unknown>>;
|
|
213
|
+
/**
|
|
214
|
+
* Chunk the object into chunks by comparing adjacent values using the given key or callback.
|
|
215
|
+
*
|
|
216
|
+
* A Map is walked in its insertion order, so the items compared as adjacent are the ones PHP compares.
|
|
217
|
+
*
|
|
218
|
+
* @see EnumeratesValues::chunkBy — `packages/collection/stubs/EnumeratesValues.php:939`.
|
|
219
|
+
* Adjacent values compare with PHP's `==`, so `1` and `"1"` share a chunk.
|
|
220
|
+
*
|
|
221
|
+
* @param data - The record or Map to chunk
|
|
222
|
+
* @param key - A path into each item, or a callback receiving the value and its key
|
|
223
|
+
* @returns Chunked record
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
*
|
|
227
|
+
* chunkBy({ a: 1, b: 1, c: 2 }, (value) => value); -> { 0: { a: 1, b: 1 }, 1: { c: 2 } }
|
|
228
|
+
* chunkBy(new Map([[2, 1], [0, 1], [1, 2]]), (value) => value); -> { 0: { 0: 1, 2: 1 }, 1: { 1: 2 } }
|
|
229
|
+
*/
|
|
230
|
+
export declare function chunkBy<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, key: PathKey | ((value: TValue, key: MapArrayKey<TKey>) => unknown)): Record<number, Record<string, TValue>>;
|
|
231
|
+
export declare function chunkBy<TMap>(data: MapData<TMap>, key: PathKey | ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown)): Record<number, Record<string, MapEntryValue<TMap>>>;
|
|
232
|
+
export declare function chunkBy(data: NonKeyedItems, key: PathKey | ((value: unknown, key: string | number) => unknown)): Record<number, never>;
|
|
233
|
+
export declare function chunkBy(data: NonObjectItems, key: PathKey | ((value: unknown, key: string | number) => unknown)): Record<number, Record<string, unknown>>;
|
|
234
|
+
export declare function chunkBy<T extends object>(data: T, key: PathKey | ((value: ObjectValue<T>, key: ObjectKey<T>) => unknown)): Record<number, Partial<T>>;
|
|
235
|
+
export declare function chunkBy(data: unknown, key: PathKey | ((value: unknown, key: string | number) => unknown)): Record<number, Record<string, unknown>>;
|
|
236
|
+
/**
|
|
237
|
+
* Collapse an object of objects or lists into a single object, renumbering integer keys as `array_merge` does.
|
|
238
|
+
*
|
|
239
|
+
* A Map is merged in its insertion order. A Collection-like item, a class instance with an `all()` method, unwraps
|
|
240
|
+
* through it, while a plain object is merged as data whatever members it has; any other item that isn't a list (a
|
|
241
|
+
* `Date`, a `Map`, another class instance) is skipped. Declared types, pinned in `obj-residuals.test-d.ts`, still
|
|
242
|
+
* copy a class instance's keys and leave an OPTIONAL `all?()` item unwrapped.
|
|
243
|
+
*
|
|
244
|
+
* @param object - The object or Map of objects or lists to collapse.
|
|
245
|
+
* @returns A new flattened object.
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
*
|
|
249
|
+
* collapse({ a: { x: 1 }, b: { y: 2 }, c: { z: 3 } }); -> { x: 1, y: 2, z: 3 }
|
|
250
|
+
* collapse({ users: { john: { age: 30 } }, admins: { jane: { role: 'admin' } } }); -> { john: { age: 30 }, jane: { role: 'admin' } }
|
|
251
|
+
* collapse([[1, 2], [3, 4]]); -> { 0: 1, 1: 2, 2: 3, 3: 4 }
|
|
252
|
+
* collapse(new Map([[1, { k: 1 }], [0, { k: 2 }]])); -> { k: 2 }
|
|
253
|
+
*/
|
|
254
|
+
export declare function collapse<T extends readonly unknown[]>(data: T): CollapsedObject<Record<number, T[number]>>;
|
|
255
|
+
export declare function collapse<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): CollapsedObject<Record<string, TValue>>;
|
|
256
|
+
export declare function collapse<TMap>(data: MapData<TMap>): CollapsedObject<Record<string, MapEntryValue<TMap>>>;
|
|
257
|
+
export declare function collapse(data: NonKeyedItems): Record<string, never>;
|
|
258
|
+
export declare function collapse(data: NonObjectItems): Record<string | number, unknown>;
|
|
259
|
+
export declare function collapse<T extends object>(data: T): CollapsedObject<T>;
|
|
260
|
+
export declare function collapse(data: unknown): Record<string | number, unknown>;
|
|
261
|
+
/**
|
|
262
|
+
* Combine two objects into one, using the values from the first object as
|
|
263
|
+
* keys, mirroring PHP's `array_combine()` / `Collection::combine()`
|
|
264
|
+
* (`Collection.php:936`).
|
|
265
|
+
*
|
|
266
|
+
* @see Collection::combine — `packages/collection/stubs/Collection.php:936`.
|
|
267
|
+
* Wraps `array_combine`.
|
|
268
|
+
*
|
|
269
|
+
* Declared-type limits, pinned in `obj-residuals.test-d.ts`: a literal `-0` key types as "0" and an
|
|
270
|
+
* integer-valued float past PHP_INT_MAX types as its decimal expansion, where the runtime stores "-0" and
|
|
271
|
+
* PHP's exponent form. TypeScript prints a number its own way; only the runtime applies PHP's cast.
|
|
272
|
+
*
|
|
273
|
+
* @param keysObject - The object or list whose values become the keys.
|
|
274
|
+
* @param valuesObject - The object or list whose values become the values.
|
|
275
|
+
* @returns A new object containing combined key-value pairs.
|
|
276
|
+
* @throws Error if `keysObject` and `valuesObject` do not have the same
|
|
277
|
+
* number of entries.
|
|
278
|
+
*/
|
|
279
|
+
export declare function combine<K extends object, V extends object>(keys: K, values: V): CombineRecord<K, V>;
|
|
280
|
+
export declare function combine(keys: unknown, values: unknown): Record<string, unknown>;
|
|
281
|
+
/**
|
|
282
|
+
* Cross join the given objects, returning all possible permutations.
|
|
283
|
+
* Each key is one dimension, walked like PHP's `foreach`: an array, a plain object, a Map or a Set gives its values,
|
|
284
|
+
* and a scalar gives none. A Map argument's keys are dimensions in its insertion order, so its first varies slowest,
|
|
285
|
+
* as in PHP, but each row keeps the Map's keys where PHP's spread renumbers integer keys `0..n-1`.
|
|
286
|
+
*
|
|
287
|
+
* @param objects - The objects or Maps to cross join.
|
|
288
|
+
* @returns A new array with all combinations of the input object values.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
*
|
|
292
|
+
* crossJoin({ a: [1] }, { b: ["x"] }); -> [{ a: 1, b: "x" }]
|
|
293
|
+
* crossJoin({ size: ['S', 'M'] }, { color: ['red', 'blue'] }); -> [{ size: 'S', color: 'red' }, { size: 'S', color: 'blue' }, { size: 'M', color: 'red' }, { size: 'M', color: 'blue' }]
|
|
294
|
+
* crossJoin({ a: [1], b: { k: "x", j: "y" } }); -> [{ a: 1, b: "x" }, { a: 1, b: "y" }]
|
|
295
|
+
* crossJoin(new Map([[1, ['a', 'b']], [0, ['x', 'y']]]));
|
|
296
|
+
* -> [{ 0: 'x', 1: 'a' }, { 0: 'y', 1: 'a' }, { 0: 'x', 1: 'b' }, { 0: 'y', 1: 'b' }]
|
|
297
|
+
*/
|
|
298
|
+
export declare function crossJoin(): Record<string, never>[];
|
|
299
|
+
export declare function crossJoin<T extends readonly object[]>(...objects: T): CrossJoinRow<T>[];
|
|
300
|
+
/**
|
|
301
|
+
* Divide an object into two objects. One with keys and the other with values.
|
|
302
|
+
*
|
|
303
|
+
* A Map is divided in its insertion order, each key the one PHP stores for it.
|
|
304
|
+
*
|
|
305
|
+
* @param object - The object or Map to divide; `null` or `undefined` gives two empty lists.
|
|
306
|
+
* @returns A tuple with an array of keys and an array of values.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
*
|
|
310
|
+
* divide({ name: "John", age: 30, city: "NYC" }); -> [['name', 'age', 'city'], ['John', 30, 'NYC']]
|
|
311
|
+
* divide(new Map([[2, 'c'], [0, 'a']])); -> [[2, 0], ['c', 'a']]
|
|
312
|
+
*/
|
|
313
|
+
export declare function divide<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): [MapArrayKey<TKey>[], TValue[]];
|
|
314
|
+
export declare function divide<TMap>(data: MapData<TMap>): [MapEntryKey<TMap>[], MapEntryValue<TMap>[]];
|
|
315
|
+
export declare function divide(data: NonKeyedItems): [(string | number)[], unknown[]];
|
|
316
|
+
export declare function divide(data: NonObjectItems): [(string | number)[], unknown[]];
|
|
317
|
+
export declare function divide<T extends object>(data: T): [ObjectKey<T>[], ObjectValue<T>[]];
|
|
318
|
+
export declare function divide(data: unknown): [(string | number)[], unknown[]];
|
|
319
|
+
/**
|
|
320
|
+
* Flatten a multi-dimensional object with "dot" notation.
|
|
321
|
+
*
|
|
322
|
+
* A Map, at the root or nested, is flattened in its insertion order. The result is a plain object, so a key that reads
|
|
323
|
+
* as an integer (possible with an empty or all-digit prefix) is listed first, ascending.
|
|
324
|
+
*
|
|
325
|
+
* @param data - The object or Map to flatten.
|
|
326
|
+
* @param prepend - An optional string to prepend to each key.
|
|
327
|
+
* @param depth - Maximum depth to flatten. Defaults to Infinity.
|
|
328
|
+
* @returns A new object with dot-notated keys.
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
*
|
|
332
|
+
* dot({ name: 'John', address: { city: 'NYC', zip: '10001' } }); -> { name: 'John', 'address.city': 'NYC', 'address.zip': '10001' }
|
|
333
|
+
* dot(new Map([[2, { z: 1 }], [0, { y: 2 }]])); -> { '2.z': 1, '0.y': 2 }
|
|
334
|
+
* dot({ m: new Map([[2, 'c'], [0, 'a']]) }); -> { 'm.2': 'c', 'm.0': 'a' }
|
|
335
|
+
* dot(new Map([[2, 'c'], [0, 'a']]), '1'); -> { 10: 'a', 12: 'c' }, where PHP keeps 12 first
|
|
336
|
+
*/
|
|
337
|
+
export declare function dot<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, prepend?: string, depth?: number): Record<string, ObjectPathValue<Record<string, TValue>> | DotUndefined<Record<string, TValue>>>;
|
|
338
|
+
export declare function dot<TMap>(data: MapData<TMap>, prepend?: string, depth?: number): Record<string, ObjectPathValue<Record<string, MapEntryValue<TMap>>> | DotUndefined<Record<string, MapEntryValue<TMap>>>>;
|
|
339
|
+
export declare function dot(data: NonKeyedItems, prepend?: string, depth?: number): Record<string, never>;
|
|
340
|
+
export declare function dot(data: NonObjectItems, prepend?: string, depth?: number): Record<string, unknown>;
|
|
341
|
+
export declare function dot<T extends object>(data: T, prepend?: string, depth?: number): Record<string, ObjectPathValue<T> | DotUndefined<T>>;
|
|
342
|
+
export declare function dot(data: unknown, prepend?: string, depth?: number): Record<string, unknown>;
|
|
343
|
+
/**
|
|
344
|
+
* Convert a flatten "dot" notation object into an expanded object.
|
|
345
|
+
*
|
|
346
|
+
* A nested container with consecutive integer keys `0..n-1` becomes a real array, even when they were written out of
|
|
347
|
+
* order (JS lists integer-like keys ascending), unlike PHP's `array_is_list`. A Map is written in its insertion order,
|
|
348
|
+
* so when a dotted key and a plain key name the same place, the one PHP writes last wins.
|
|
349
|
+
*
|
|
350
|
+
* @param map - The flat object or Map with dot-notated keys.
|
|
351
|
+
* @returns A new multi-dimensional object.
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
*
|
|
355
|
+
* undot({ 'a.b': 1, 'a.c': 2 }); -> { a: { b: 1, c: 2 } }
|
|
356
|
+
* undot(new Map([['0.a', 'y'], [0, 'x']])); -> { 0: 'x' }
|
|
357
|
+
*/
|
|
358
|
+
export declare function undot<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): Record<string, UndotObjectValue<TValue>>;
|
|
359
|
+
export declare function undot<TMap>(data: MapData<TMap>): Record<string, UndotObjectValue<MapEntryValue<TMap>>>;
|
|
360
|
+
export declare function undot(data: NonKeyedItems): Record<number, unknown>;
|
|
361
|
+
export declare function undot(data: NonObjectItems): Record<string, unknown>;
|
|
362
|
+
export declare function undot<T extends object>(data: T): Record<string, UndotObjectValue<ObjectValue<T>>>;
|
|
363
|
+
export declare function undot(data: unknown): Record<string, unknown>;
|
|
364
|
+
/**
|
|
365
|
+
* Union multiple objects into one, mirroring PHP's `+` array union
|
|
366
|
+
* operator: the left-most object to already hold a key wins that key's
|
|
367
|
+
* value, even `null`/`undefined` — the guard is presence, not truthiness.
|
|
368
|
+
*
|
|
369
|
+
* The first object is the data, read by its own entries (a list by its indices); each later
|
|
370
|
+
* one is read the way `arrayableItems` reads it, so a Collection-like operand unwraps.
|
|
371
|
+
*
|
|
372
|
+
* @see Collection::union — `packages/collection/stubs/Collection.php:947`.
|
|
373
|
+
* Uses PHP's `+` operator (key union: left keys win), not `array_merge`.
|
|
374
|
+
*
|
|
375
|
+
* @param objects - The objects to union.
|
|
376
|
+
* @returns A new object containing all key-value pairs from the input objects.
|
|
377
|
+
*/
|
|
378
|
+
export declare function union<T extends readonly unknown[]>(...objects: T): Simplify<MergeObjects<T>>;
|
|
379
|
+
/**
|
|
380
|
+
* Prepend one or more items to the beginning of the object, mutating it in place, like PHP's array_unshift.
|
|
381
|
+
*
|
|
382
|
+
* Each item, including an object or `null`, is prepended as one element under the next integer key. Existing
|
|
383
|
+
* integer keys are renumbered after the items, even when there are none, as `array_unshift` does.
|
|
384
|
+
* A Map is renumbered in its insertion order and rewritten in place, integer keys as numbers, even a `ReadonlyMap`.
|
|
385
|
+
*
|
|
386
|
+
* @see Collection::unshift — `packages/collection/stubs/Collection.php:1096`. Wraps `array_unshift`; mutates.
|
|
387
|
+
*
|
|
388
|
+
* @param items - The items to prepend; the first is the target object or Map, mutated in place when object-accessible.
|
|
389
|
+
* @returns The same object or Map reference, mutated (or a new object when the first item isn't object-accessible).
|
|
390
|
+
*
|
|
391
|
+
* @example
|
|
392
|
+
*
|
|
393
|
+
* unshift({ x: 1, 0: 'a' }, 'U'); -> { 0: 'U', 1: 'a', x: 1 }
|
|
394
|
+
* unshift(new Map([[2, 'c'], [0, 'a']]), 'U'); -> the same Map, now holding [[0, 'U'], [1, 'c'], [2, 'a']]
|
|
395
|
+
*/
|
|
396
|
+
export declare function unshift(): Record<string, never>;
|
|
397
|
+
export declare function unshift<TValue, TKey, TItems extends readonly unknown[]>(data: ReadonlyMap<TKey, TValue>, ...items: TItems): Map<Exclude<MapArrayKey<TKey>, number> | number, TValue | TItems[number]>;
|
|
398
|
+
export declare function unshift<TMap, TItems extends readonly unknown[]>(data: MapData<TMap>, ...items: TItems): Map<Exclude<MapEntryKey<TMap>, number> | number, MapEntryValue<TMap> | TItems[number]>;
|
|
399
|
+
export declare function unshift<TItems extends readonly unknown[]>(data: NonKeyedItems | null | undefined, ...items: TItems): Record<number, TItems[number]>;
|
|
400
|
+
export declare function unshift<TItems extends readonly unknown[]>(data: NonObjectItems | null | undefined, ...items: TItems): Map<string | number, unknown> | Record<number, TItems[number]>;
|
|
401
|
+
export declare function unshift<T extends object>(data: T): [Extract<keyof T, number | `${number}`>] extends [never] ? T : RenumberedObject<T, never>;
|
|
402
|
+
export declare function unshift<T extends object, TItems extends readonly unknown[]>(data: T, ...items: TItems): RenumberedObject<T, TItems[number]>;
|
|
403
|
+
export declare function unshift(data: unknown, ...items: unknown[]): Record<string | number, unknown>;
|
|
404
|
+
/**
|
|
405
|
+
* Get all of the given object except for a specified array of keys.
|
|
406
|
+
*
|
|
407
|
+
* @param data - The object to remove items from.
|
|
408
|
+
* @param keys - The keys of the items to remove.
|
|
409
|
+
* @returns A new object with the specified items removed.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
*
|
|
413
|
+
* except({ name: 'John', age: 30, city: 'NYC' }, 'age'); -> { name: 'John', city: 'NYC' }
|
|
414
|
+
* except({ name: 'John', age: 30, city: 'NYC' }, ['age', 'city']); -> { name: 'John' }
|
|
415
|
+
* except(new Map([['a', 1], ['b', 2]]), 'a'); -> { b: 2 }
|
|
416
|
+
*/
|
|
417
|
+
export declare function except(data: ReadonlyMap<unknown, unknown>, keys: PathKeys): Record<string, unknown>;
|
|
418
|
+
export declare function except(data: NonObjectItems, keys: PathKeys): Record<string, never>;
|
|
419
|
+
export declare function except<T extends object, const K extends keyof T>(data: T, keys: K): Simplify<Omit<T, K>>;
|
|
420
|
+
export declare function except<T extends object, const Ks extends readonly (keyof T)[]>(data: T, keys: Ks): Simplify<Omit<T, Ks[number]>>;
|
|
421
|
+
export declare function except<T extends object, const P extends string>(data: T, keys: P): OmitObjectPath<T, P>;
|
|
422
|
+
export declare function except<T extends object, const Ps extends readonly string[]>(data: T, keys: Ps): OmitObjectPaths<T, Ps>;
|
|
423
|
+
export declare function except<T extends object>(data: T, keys: PathKeys): ObjectDeepPartial<T>;
|
|
424
|
+
export declare function except(data: unknown, keys: PathKeys): Record<string, unknown>;
|
|
425
|
+
/**
|
|
426
|
+
* Get all of the given object except for a specified array of values.
|
|
427
|
+
*
|
|
428
|
+
* @param data - The object to filter.
|
|
429
|
+
* @param values - The value(s) to exclude from the object.
|
|
430
|
+
* @param strict - Whether to use strict comparison (default: false).
|
|
431
|
+
* @returns A new object with the specified values removed.
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
*
|
|
435
|
+
* exceptValues({ name: 'taylor', age: 26, city: 'austin' }, [26]); -> { name: 'taylor', city: 'austin' }
|
|
436
|
+
* exceptValues({ a: 1, b: 2, c: 1, d: 3 }, 1); -> { b: 2, d: 3 }
|
|
437
|
+
* exceptValues({ a: true, b: false, c: 1, d: 0 }, [1, 0], true); -> { a: true, b: false }
|
|
438
|
+
*/
|
|
439
|
+
export declare function exceptValues(data: NonObjectItems, values: unknown, strict?: boolean): Record<number, unknown>;
|
|
440
|
+
export declare function exceptValues<T extends object>(data: T, values: unknown, strict?: boolean): Partial<T>;
|
|
441
|
+
export declare function exceptValues(data: unknown, values: unknown, strict?: boolean): Record<string, unknown>;
|
|
442
|
+
/**
|
|
443
|
+
* Determine if the given key exists in the provided object.
|
|
444
|
+
*
|
|
445
|
+
* @param data - Object to check
|
|
446
|
+
* @param key - Key to check for
|
|
447
|
+
* @returns True if the key exists, false otherwise.
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
*
|
|
451
|
+
* exists({ name: 'John', age: 30 }, 'name'); -> true
|
|
452
|
+
* exists({ name: 'John', age: 30 }, 'email'); -> false
|
|
453
|
+
*/
|
|
454
|
+
export declare function exists(data: unknown, key: PathKey): boolean;
|
|
455
|
+
/**
|
|
456
|
+
* Get the first value from an object.
|
|
457
|
+
* Optionally pass a callback to find the first matching value.
|
|
458
|
+
*
|
|
459
|
+
* @param data - The object to search through.
|
|
460
|
+
* @param callback - Optional callback function to test values.
|
|
461
|
+
* @param defaultValue - Value to return if no value is found.
|
|
462
|
+
* @returns The first value or default value.
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
*
|
|
466
|
+
* first({ a: 1, b: 2, c: 3 }); -> 1
|
|
467
|
+
* first({}); -> null
|
|
468
|
+
* first({}, null, 'default'); -> 'default'
|
|
469
|
+
* first({ a: 1, b: 2, c: 3 }, x => x > 1); -> 2
|
|
470
|
+
* first({ a: 1, b: 2, c: 3 }, x => x > 5, 'none'); -> 'none'
|
|
471
|
+
* first(new Map([['a', 1], ['b', 2]])); -> 1
|
|
472
|
+
* first(new Items({ a: 1, b: 2 })); -> 1
|
|
473
|
+
* first(new Items([10, 20]), x => x > 10); -> 20
|
|
474
|
+
*/
|
|
475
|
+
export declare function first<TValue, TKey, TDefault = null>(data: ReadonlyMap<TKey, TValue>, callback?: ((value: TValue, key: MapArrayKey<TKey>) => unknown) | null, defaultValue?: Default<TDefault>): TValue | TDefault;
|
|
476
|
+
export declare function first<TMap, TDefault = null>(data: MapData<TMap>, callback?: ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown) | null, defaultValue?: Default<TDefault>): MapEntryValue<TMap> | TDefault;
|
|
477
|
+
export declare function first<TDefault = null>(data: NonKeyedItems, callback?: ((value: unknown, key: string | number) => unknown) | null, defaultValue?: Default<TDefault>): TDefault;
|
|
478
|
+
export declare function first<TDefault = null>(data: NonObjectItems, callback?: ((value: unknown, key: string | number) => unknown) | null, defaultValue?: Default<TDefault>): unknown;
|
|
479
|
+
export declare function first<TValue, TDefault = null>(data: {
|
|
480
|
+
all(): readonly TValue[];
|
|
481
|
+
}, callback?: ((value: TValue, key: number) => unknown) | null, defaultValue?: Default<TDefault>): TValue | TDefault;
|
|
482
|
+
export declare function first<TValue, TDefault = null>(data: {
|
|
483
|
+
all(): Readonly<Record<string, TValue>>;
|
|
484
|
+
}, callback?: ((value: TValue, key: string | number) => unknown) | null, defaultValue?: Default<TDefault>): TValue | TDefault;
|
|
485
|
+
export declare function first<T extends object, TDefault = null>(data: T, callback?: ((value: BareObjectValue<T>, key: BareObjectKey<T>) => unknown) | null, defaultValue?: Default<TDefault>): BareObjectValue<T> | TDefault;
|
|
486
|
+
export declare function first<TDefault = null>(data: unknown, callback?: ((value: unknown, key: string | number) => unknown) | null, defaultValue?: Default<TDefault>): unknown;
|
|
487
|
+
/**
|
|
488
|
+
* Get the last value from an object.
|
|
489
|
+
* Optionally pass a callback to find the last matching value.
|
|
490
|
+
*
|
|
491
|
+
* @param data - The object to search through.
|
|
492
|
+
* @param callback - Optional callback function to test values.
|
|
493
|
+
* @param defaultValue - Value to return if no value is found.
|
|
494
|
+
* @returns The last value or default value.
|
|
495
|
+
*
|
|
496
|
+
* @example
|
|
497
|
+
*
|
|
498
|
+
* last({ a: 1, b: 2, c: 3 }); -> 3
|
|
499
|
+
* last({}); -> null
|
|
500
|
+
* last({}, null, 'default'); -> 'default'
|
|
501
|
+
* last({ a: 1, b: 2, c: 3 }, x => x < 3); -> 2
|
|
502
|
+
* last({ a: 1, b: 2, c: 3 }, x => x > 5, 'none'); -> 'none'
|
|
503
|
+
* last(new Map([['a', 1], ['b', 2]])); -> 2
|
|
504
|
+
* last(new Items({ a: 1, b: 2 })); -> 2
|
|
505
|
+
* last(new Items([10, 20]), x => x < 20); -> 10
|
|
506
|
+
*/
|
|
507
|
+
export declare function last<TValue, TKey, TDefault = null>(data: ReadonlyMap<TKey, TValue>, callback?: ((value: TValue, key: MapArrayKey<TKey>) => unknown) | null, defaultValue?: Default<TDefault>): TValue | TDefault;
|
|
508
|
+
export declare function last<TMap, TDefault = null>(data: MapData<TMap>, callback?: ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown) | null, defaultValue?: Default<TDefault>): MapEntryValue<TMap> | TDefault;
|
|
509
|
+
export declare function last<TDefault = null>(data: NonKeyedItems, callback?: ((value: unknown, key: string | number) => unknown) | null, defaultValue?: Default<TDefault>): TDefault;
|
|
510
|
+
export declare function last<TDefault = null>(data: NonObjectItems, callback?: ((value: unknown, key: string | number) => unknown) | null, defaultValue?: Default<TDefault>): unknown;
|
|
511
|
+
export declare function last<TValue, TDefault = null>(data: {
|
|
512
|
+
all(): readonly TValue[];
|
|
513
|
+
}, callback?: ((value: TValue, key: number) => unknown) | null, defaultValue?: Default<TDefault>): TValue | TDefault;
|
|
514
|
+
export declare function last<TValue, TDefault = null>(data: {
|
|
515
|
+
all(): Readonly<Record<string, TValue>>;
|
|
516
|
+
}, callback?: ((value: TValue, key: string | number) => unknown) | null, defaultValue?: Default<TDefault>): TValue | TDefault;
|
|
517
|
+
export declare function last<T extends object, TDefault = null>(data: T, callback?: ((value: ObjectValue<T>, key: ObjectKey<T>) => unknown) | null, defaultValue?: Default<TDefault>): ObjectValue<T> | TDefault;
|
|
518
|
+
export declare function last<TDefault = null>(data: unknown, callback?: ((value: unknown, key: string | number) => unknown) | null, defaultValue?: Default<TDefault>): unknown;
|
|
519
|
+
/**
|
|
520
|
+
* Take the first or last `limit` items from an object.
|
|
521
|
+
*
|
|
522
|
+
* Positive limit => first `limit` items.
|
|
523
|
+
* Negative limit => last `abs(limit)` items.
|
|
524
|
+
*
|
|
525
|
+
* A Map is counted in its insertion order; each item keeps its key, and a plain object lists integer keys ascending.
|
|
526
|
+
*
|
|
527
|
+
* @param data The object or Map to take items from.
|
|
528
|
+
* @param limit The number of items to take. Positive for first N, negative for last N.
|
|
529
|
+
* @returns A new object containing the taken items.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
*
|
|
533
|
+
* take({ a: 1, b: 2, c: 3, d: 4, e: 5 }, 2); -> { a: 1, b: 2 }
|
|
534
|
+
* take({ a: 1, b: 2, c: 3, d: 4, e: 5 }, -2); -> { d: 4, e: 5 }
|
|
535
|
+
* take({ a: 1, b: 2, c: 3 }, 5); -> { a: 1, b: 2, c: 3 }
|
|
536
|
+
* take(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 2); -> { 2: 'c', 0: 'a' }
|
|
537
|
+
*/
|
|
538
|
+
export declare function take<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, limit: number): Record<string, TValue>;
|
|
539
|
+
export declare function take<TMap>(data: MapData<TMap>, limit: number): Record<string, MapEntryValue<TMap>>;
|
|
540
|
+
export declare function take(data: NonKeyedItems, limit: number): Record<string, never>;
|
|
541
|
+
export declare function take(data: NonObjectItems, limit: number): Record<string, unknown>;
|
|
542
|
+
export declare function take<T extends object>(data: T, limit: number): Partial<T>;
|
|
543
|
+
export declare function take(data: unknown, limit: number): Record<string, unknown>;
|
|
544
|
+
/**
|
|
545
|
+
* Flatten a multi-dimensional object into a single-level array.
|
|
546
|
+
*
|
|
547
|
+
* Arrays, plain objects, a root Map's values (in its insertion order) and a Collection-like item's `all()` items are
|
|
548
|
+
* flattened, a Collection-like item being a class instance with an `all()` method: a plain object's `all` member is
|
|
549
|
+
* one of its values. Any other object, a nested `Map`, `Date` or class instance included, is kept as a value.
|
|
550
|
+
* Declared types, pinned in `obj-residuals.test-d.ts`, walk a class instance or typed array and do not unwrap an
|
|
551
|
+
* OPTIONAL `all?()`.
|
|
552
|
+
*
|
|
553
|
+
* @see Arr::flatten — `packages/arr/stubs/Arr.php:378`.
|
|
554
|
+
*
|
|
555
|
+
* @param data - The object, Map (or value) to flatten.
|
|
556
|
+
* @param depth - Maximum depth to flatten, Infinity by default; depth 1 stops after one level.
|
|
557
|
+
* @returns A new flattened array of values.
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
*
|
|
561
|
+
* flatten({ a: 1, b: { c: 2, d: { e: 3 } } }); -> [1, 2, 3]
|
|
562
|
+
* flatten(new Map([[2, ['c']], [0, 'a']])); -> ['c', 'a']
|
|
563
|
+
*/
|
|
564
|
+
export declare function flatten<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): ObjectFlatValue<TValue>[];
|
|
565
|
+
export declare function flatten<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, depth: number): FlattenReach<TValue>[];
|
|
566
|
+
export declare function flatten<TMap>(data: MapData<TMap>): ObjectFlatValue<MapEntryValue<TMap>>[];
|
|
567
|
+
export declare function flatten<TMap>(data: MapData<TMap>, depth: number): FlattenReach<MapEntryValue<TMap>>[];
|
|
568
|
+
export declare function flatten(data: NonKeyedItems, depth?: number): unknown[];
|
|
569
|
+
export declare function flatten(data: NonObjectItems, depth?: number): unknown[];
|
|
570
|
+
export declare function flatten<T extends object>(data: T): ObjectFlatValue<ObjectValue<T>>[];
|
|
571
|
+
export declare function flatten<T extends object>(data: T, depth: number): FlattenReach<ObjectValue<T>>[];
|
|
572
|
+
export declare function flatten(data: unknown, depth?: number): unknown[];
|
|
573
|
+
/**
|
|
574
|
+
* Flatten a multi-dimensional object into dot-notation with depth control.
|
|
575
|
+
* Like `dot`, it walks only arrays, plain objects and Maps below the root; any other object is a leaf.
|
|
576
|
+
*
|
|
577
|
+
* One divergence from `Arr::dot`/`Obj.dot`: an empty nested container is dropped
|
|
578
|
+
* here, where PHP keeps it as a leaf value.
|
|
579
|
+
* @see docs/php-parity/Arr/dot.json, "dot-empty-leaf" and "dot-nested-empty-leaf".
|
|
580
|
+
*
|
|
581
|
+
* @param data - The object or Map to flatten.
|
|
582
|
+
* @param depth - Maximum depth for dot-notation keys.
|
|
583
|
+
* @returns A flat object with dot-notated keys.
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
*
|
|
587
|
+
* flattenDot({ users: { john: { name: 'John' } } }, 1); -> { 'users.john': { name: 'John' } }
|
|
588
|
+
* flattenDot(new Map([['a', 1], ['b', { c: 2 }]])); -> { a: 1, 'b.c': 2 }
|
|
589
|
+
*/
|
|
590
|
+
export declare function flattenDot<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, depth?: number): Record<string, ObjectPathValue<Record<string, TValue>> | DotUndefined<Record<string, TValue>>>;
|
|
591
|
+
export declare function flattenDot<TMap>(data: MapData<TMap>, depth?: number): Record<string, ObjectPathValue<Record<string, MapEntryValue<TMap>>> | DotUndefined<Record<string, MapEntryValue<TMap>>>>;
|
|
592
|
+
export declare function flattenDot(data: NonKeyedItems, depth?: number): Record<string, never>;
|
|
593
|
+
export declare function flattenDot(data: NonObjectItems, depth?: number): Record<string, unknown>;
|
|
594
|
+
export declare function flattenDot<T extends object>(data: T, depth?: number): Record<string, ObjectPathValue<T> | DotUndefined<T>>;
|
|
595
|
+
export declare function flattenDot(data: unknown, depth?: number): Record<string, unknown>;
|
|
596
|
+
/**
|
|
597
|
+
* Flip the keys and values of an object.
|
|
598
|
+
*
|
|
599
|
+
* A Map is flipped in its insertion order, so when two keys hold the same value, the key
|
|
600
|
+
* PHP reaches last is the one kept, and each key is the one PHP stores for it.
|
|
601
|
+
*
|
|
602
|
+
* @see Collection::flip — `packages/collection/stubs/Collection.php:464`.
|
|
603
|
+
*
|
|
604
|
+
* @param data - The object or Map of items to flip
|
|
605
|
+
* @returns The data items flipped
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* flip({name: 'taylor'}); -> {taylor: 'name'}
|
|
609
|
+
* flip({string: 'taylor', integer: 1, null: null, float: 1.5}); -> {taylor: 'string', 1: 'integer'}
|
|
610
|
+
* flip(new Map([[2, 'v'], [0, 'v']])); -> {v: 0}
|
|
611
|
+
*/
|
|
612
|
+
export declare function flip<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): Record<string, MapArrayKey<TKey>>;
|
|
613
|
+
export declare function flip<TMap>(data: MapData<TMap>): Record<string, MapEntryKey<TMap>>;
|
|
614
|
+
export declare function flip(data: NonKeyedItems): Record<string, never>;
|
|
615
|
+
export declare function flip(data: NonObjectItems): Record<string, string | number>;
|
|
616
|
+
export declare function flip<T extends object>(data: T): FlipObject<T>;
|
|
617
|
+
export declare function flip(data: unknown): Record<string, string | number>;
|
|
618
|
+
/**
|
|
619
|
+
* Get a float item from an object using "dot" notation.
|
|
620
|
+
* Throws an error if the value is not a number.
|
|
621
|
+
*
|
|
622
|
+
* Known divergence: PHP's `is_float()` rejects a whole-number int (`Arr::float`
|
|
623
|
+
* throws on `1`, see docs/php-parity/Arr/float.json, "Arr::float
|
|
624
|
+
* rejects a whole-number int"). JS has one number type, so `isNumber` accepts
|
|
625
|
+
* it — narrowing to reject whole numbers would also reject `1.0`.
|
|
626
|
+
*
|
|
627
|
+
* @param data - The object to get the item from.
|
|
628
|
+
* @param key - The key or dot-notated path of the item to get.
|
|
629
|
+
* @param defaultValue - The default value if key is not found.
|
|
630
|
+
* @returns The float value.
|
|
631
|
+
* @throws InvalidArgumentException if the value is not a number.
|
|
632
|
+
*
|
|
633
|
+
* @example
|
|
634
|
+
*
|
|
635
|
+
* float({ price: 19.99, discount: 0.1 }, 'price'); -> 19.99
|
|
636
|
+
* float({ product: { price: 19.99 } }, 'product.price'); -> 19.99
|
|
637
|
+
* float({ product: { name: 'Widget' } }, 'product.name'); -> throws InvalidArgumentException
|
|
638
|
+
*/
|
|
639
|
+
export declare function float(data: unknown, key: PathKey, defaultValue?: Default<number> | null): number;
|
|
640
|
+
/**
|
|
641
|
+
* Remove one or many object items from a given object using dot notation.
|
|
642
|
+
*
|
|
643
|
+
* @param data - The object to remove items from.
|
|
644
|
+
* @param keys - The keys of the items to remove.
|
|
645
|
+
* @returns A new object with the specified items removed.
|
|
646
|
+
*
|
|
647
|
+
* @example
|
|
648
|
+
*
|
|
649
|
+
* forget({ name: 'John', age: 30, city: 'NYC' }, 'age'); -> { name: 'John', city: 'NYC' }
|
|
650
|
+
* forget({ name: 'John', age: 30, city: 'NYC' }, ['age', 'city']); -> { name: 'John' }
|
|
651
|
+
* forget({ user: { name: 'John', age: 30 } }, 'user.age'); -> { user: { name: 'John' } }
|
|
652
|
+
*/
|
|
653
|
+
export declare function forget(data: ReadonlyMap<unknown, unknown>, keys: PathKeys): Record<string, unknown>;
|
|
654
|
+
export declare function forget(data: NonObjectItems, keys: PathKeys): Record<string, never>;
|
|
655
|
+
export declare function forget<T extends object, const K extends keyof T>(data: T, keys: K): Simplify<Omit<T, K>>;
|
|
656
|
+
export declare function forget<T extends object, const Ks extends readonly (keyof T)[]>(data: T, keys: Ks): Simplify<Omit<T, Ks[number]>>;
|
|
657
|
+
export declare function forget<T extends object, const P extends string>(data: T, keys: P): OmitObjectPath<T, P>;
|
|
658
|
+
export declare function forget<T extends object, const Ps extends readonly string[]>(data: T, keys: Ps): OmitObjectPaths<T, Ps>;
|
|
659
|
+
export declare function forget<T extends object>(data: T, keys: PathKeys): ObjectDeepPartial<T>;
|
|
660
|
+
export declare function forget(data: unknown, keys: PathKeys): Record<string, unknown>;
|
|
661
|
+
/**
|
|
662
|
+
* Get the underlying object from the given argument.
|
|
663
|
+
*
|
|
664
|
+
* @param items The object, Map, or other value to extract from.
|
|
665
|
+
* @returns The underlying object.
|
|
666
|
+
*
|
|
667
|
+
* @example
|
|
668
|
+
*
|
|
669
|
+
* from({ foo: 'bar' }); -> { foo: 'bar' }
|
|
670
|
+
* from(new Map([['foo', 'bar']])); -> { foo: 'bar' }
|
|
671
|
+
* from(new Map([[1, 'a'], ['1', 'b']])); -> { 1: 'b' }
|
|
672
|
+
*
|
|
673
|
+
* @remarks A Map's keys are cast as PHP casts an array key. The record lists out-of-sequence integer keys ascending,
|
|
674
|
+
* so the helpers that walk a Map in its insertion order read the Map itself, not this record.
|
|
675
|
+
*
|
|
676
|
+
* @throws InvalidArgumentException if items is a scalar value.
|
|
677
|
+
* @throws Error if items is a WeakMap, whose values JavaScript cannot enumerate.
|
|
678
|
+
*/
|
|
679
|
+
export declare function from<V>(items: ReadonlyMap<unknown, V>): Record<string, V>;
|
|
680
|
+
export declare function from<TMap>(items: MapData<TMap>): Record<string, MapEntryValue<TMap>>;
|
|
681
|
+
export declare function from(items: WeakMap<object, unknown>): never;
|
|
682
|
+
export declare function from<T extends readonly unknown[]>(items: T): Record<number, T[number]>;
|
|
683
|
+
export declare function from(items: ReadonlySet<unknown> | WeakSet<object>): Record<string, never>;
|
|
684
|
+
export declare function from(items: number | string | boolean | symbol | bigint | null | undefined | ((...args: never[]) => unknown)): never;
|
|
685
|
+
export declare function from(items: NonObjectItems): Record<string, unknown>;
|
|
686
|
+
export declare function from<T extends object>(items: T): SpreadItems<T>;
|
|
687
|
+
export declare function from(items: unknown): Record<string, unknown>;
|
|
688
|
+
/**
|
|
689
|
+
* Get an item from an object using "dot" notation.
|
|
690
|
+
*
|
|
691
|
+
* A literal key wins over dot-path traversal even when it contains dots, and a
|
|
692
|
+
* literal key whose value is `undefined` still counts as found.
|
|
693
|
+
*
|
|
694
|
+
* Declared-type limit, pinned in `obj-residuals.test-d.ts`: a path through a user class's PROTOTYPE
|
|
695
|
+
* method resolves to that method, where the runtime answers the default — only own keys are read. The path
|
|
696
|
+
* types name built-in prototype members as missing, but a user class's are indistinguishable from own ones.
|
|
697
|
+
*
|
|
698
|
+
* @param data - The object to get the item from.
|
|
699
|
+
* @param key - The key or dot-notated path of the item to get.
|
|
700
|
+
* @param defaultValue - The default value if key is not found
|
|
701
|
+
* @returns The value or the default
|
|
702
|
+
*
|
|
703
|
+
* @example
|
|
704
|
+
*
|
|
705
|
+
* get({ user: { name: 'John' } }, 'user.name'); -> 'John'
|
|
706
|
+
* get({ "products.desk": { price: 100 } }, 'products.desk'); -> { price: 100 } (literal key wins over traversal)
|
|
707
|
+
* get({ m: new Map([[2, 'c'], [0, 'a']]) }, 'm.0'); -> 'a' (a Map is read by the key PHP stores)
|
|
708
|
+
*/
|
|
709
|
+
export declare function get<T extends ReadonlyMap<unknown, unknown>, P extends PathKey, TDefault>(data: T, key: P, defaultValue: Default<TDefault>): ObjectResolvePath<T, P, TDefault>;
|
|
710
|
+
export declare function get<T extends ReadonlyMap<unknown, unknown>, P extends PathKey>(data: T, key: P): ObjectResolvePath<T, P, null>;
|
|
711
|
+
export declare function get<TDefault = null>(data: NonObjectItems, key: PathKey, defaultValue?: Default<TDefault>): TDefault;
|
|
712
|
+
export declare function get<T extends object>(data: T, key: null | undefined): T;
|
|
713
|
+
export declare function get<T extends object, P extends string | number, TDefault>(data: T, key: P, defaultValue: Default<TDefault>): ObjectResolvePath<T, P, TDefault>;
|
|
714
|
+
export declare function get<T extends object, P extends string | number>(data: T, key: P): ObjectResolvePath<T, P, null>;
|
|
715
|
+
export declare function get<T extends object, P extends string | number, TDefault>(data: T, key: P | null | undefined, defaultValue: Default<TDefault>): T | ObjectResolvePath<T, P, TDefault>;
|
|
716
|
+
export declare function get<T extends object, P extends string | number>(data: T, key: P | null | undefined): T | ObjectResolvePath<T, P, null>;
|
|
717
|
+
export declare function get(data: unknown, key: PathKey, defaultValue?: unknown): unknown;
|
|
718
|
+
/**
|
|
719
|
+
* Check if an item or items exist in an object using "dot" notation.
|
|
720
|
+
*
|
|
721
|
+
* @param data - The object to check.
|
|
722
|
+
* @param keys - The key or dot-notated path of the item to check.
|
|
723
|
+
* @returns True if the item or items exist, false otherwise.
|
|
724
|
+
*
|
|
725
|
+
* @example
|
|
726
|
+
*
|
|
727
|
+
* has({ name: 'John', address: { city: 'NYC' } }, 'name'); -> true
|
|
728
|
+
* has({ name: 'John' }, 'email'); -> false
|
|
729
|
+
* has({ name: 'John', address: { city: 'NYC' } }, ['name', 'address.city']); -> true
|
|
730
|
+
* has({ name: 'John', address: { city: 'NYC' } }, ['name', 'address.country']); -> false
|
|
731
|
+
*/
|
|
732
|
+
export declare function has(data: unknown, keys: PathKeys): boolean;
|
|
733
|
+
/**
|
|
734
|
+
* Determine if all keys exist in an object using "dot" notation.
|
|
735
|
+
*
|
|
736
|
+
* @param data - The object to check.
|
|
737
|
+
* @param keys - The key or dot-notated path of the item to check.
|
|
738
|
+
* @returns True if all keys exist, false otherwise.
|
|
739
|
+
*
|
|
740
|
+
* @example
|
|
741
|
+
*
|
|
742
|
+
* hasAll({ name: 'John', address: { city: 'NYC' } }, ['name', 'address.city']); -> true
|
|
743
|
+
* hasAll({ name: 'John', address: { city: 'NYC' } }, ['name', 'address.country']); -> false
|
|
744
|
+
*/
|
|
745
|
+
export declare function hasAll(data: unknown, keys: PathKeys): boolean;
|
|
746
|
+
/**
|
|
747
|
+
* Determine if any of the keys exist in an object using "dot" notation.
|
|
748
|
+
*
|
|
749
|
+
* @param data - The object to check.
|
|
750
|
+
* @param keys - The key or dot-notated path of the item to check.
|
|
751
|
+
* @returns True if any key exists, false otherwise.
|
|
752
|
+
*
|
|
753
|
+
* @example
|
|
754
|
+
*
|
|
755
|
+
* hasAny({ name: 'John', address: { city: 'NYC' } }, ['name', 'email']); -> true
|
|
756
|
+
* hasAny({ name: 'John', address: { city: 'NYC' } }, ['email', 'phone']); -> false
|
|
757
|
+
*/
|
|
758
|
+
export declare function hasAny(data: unknown, keys: PathKeys): boolean;
|
|
759
|
+
/**
|
|
760
|
+
* Determine if all items pass the given truth test.
|
|
761
|
+
*
|
|
762
|
+
* Accepts plain objects as well as Maps, which are the JavaScript equivalent
|
|
763
|
+
* of a PHP iterable with non numeric keys.
|
|
764
|
+
*
|
|
765
|
+
* @param data - The object or Map to iterate over.
|
|
766
|
+
* @param callback - The function to call for each item.
|
|
767
|
+
* @returns True if all items pass the test, false otherwise.
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
*
|
|
771
|
+
* every({ a: 2, b: 4, c: 6 }, (n) => n % 2 === 0); -> true
|
|
772
|
+
* every({ a: 1, b: 2, c: 3 }, (n) => n % 2 === 0); -> false
|
|
773
|
+
* every(new Map([['a', 2], ['b', 4]]), (n) => n % 2 === 0); -> true
|
|
774
|
+
*/
|
|
775
|
+
export declare function every<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => unknown): boolean;
|
|
776
|
+
export declare function every<TMap>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown): boolean;
|
|
777
|
+
export declare function every(data: NonKeyedItems, callback: (value: unknown, key: string | number) => unknown): boolean;
|
|
778
|
+
export declare function every(data: NonObjectItems, callback: (value: unknown, key: string | number) => unknown): boolean;
|
|
779
|
+
export declare function every<T extends object>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => unknown): boolean;
|
|
780
|
+
export declare function every(data: unknown, callback: (value: unknown, key: string | number) => unknown): boolean;
|
|
781
|
+
/**
|
|
782
|
+
* Determine if some items pass the given truth test.
|
|
783
|
+
*
|
|
784
|
+
* Accepts plain objects as well as Maps, which are the JavaScript equivalent
|
|
785
|
+
* of a PHP iterable with non numeric keys.
|
|
786
|
+
*
|
|
787
|
+
* @param data - The object or Map to iterate over.
|
|
788
|
+
* @param callback - The function to call for each item.
|
|
789
|
+
* @returns True if any item passes the test, false otherwise.
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
*
|
|
793
|
+
* some({ a: 1, b: 2, c: 3 }, (n) => n % 2 === 0); -> true
|
|
794
|
+
* some({ a: 1, b: 3, c: 5 }, (n) => n % 2 === 0); -> false
|
|
795
|
+
* some(new Map([['a', 1], ['b', 2]]), (n) => n % 2 === 0); -> true
|
|
796
|
+
*/
|
|
797
|
+
export declare function some<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => unknown): boolean;
|
|
798
|
+
export declare function some<TMap>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown): boolean;
|
|
799
|
+
export declare function some(data: NonKeyedItems, callback: (value: unknown, key: string | number) => unknown): boolean;
|
|
800
|
+
export declare function some(data: NonObjectItems, callback: (value: unknown, key: string | number) => unknown): boolean;
|
|
801
|
+
export declare function some<T extends object>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => unknown): boolean;
|
|
802
|
+
export declare function some(data: unknown, callback: (value: unknown, key: string | number) => unknown): boolean;
|
|
803
|
+
/**
|
|
804
|
+
* Get an integer item from an object using "dot" notation.
|
|
805
|
+
*
|
|
806
|
+
* @param data - The object to get the item from.
|
|
807
|
+
* @param key - The key or dot-notated path of the item to get.
|
|
808
|
+
* @param defaultValue - The default value if key is not found
|
|
809
|
+
*
|
|
810
|
+
* @returns The integer value.
|
|
811
|
+
*
|
|
812
|
+
* @throws InvalidArgumentException if the value is not an integer.
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
*
|
|
816
|
+
* integer({ age: 30, score: 100 }, 'age'); -> 30
|
|
817
|
+
* integer({ user: { age: 30 } }, 'user.age'); -> 30
|
|
818
|
+
* integer({ user: { name: 'John' } }, 'user.name'); -> throws InvalidArgumentException
|
|
819
|
+
*/
|
|
820
|
+
export declare function integer(data: unknown, key: PathKey, defaultValue?: Default<number> | null): number;
|
|
821
|
+
/**
|
|
822
|
+
* Join all items using a string. The final items can use a separate glue string.
|
|
823
|
+
*
|
|
824
|
+
* A Map is joined in its insertion order, which a record loses once its integer keys are out of sequence. Of Map keys
|
|
825
|
+
* PHP stores as one, such as `1` and `"1"`, the last value is joined, where the first of them stood.
|
|
826
|
+
*
|
|
827
|
+
* @param data - The object or Map to join.
|
|
828
|
+
* @param glue - The string to join all but the last item.
|
|
829
|
+
* @param finalGlue - The string to join the last item.
|
|
830
|
+
* @returns The items joined, each cast as PHP's (string) cast casts it: "Array" for an array, "1" for true.
|
|
831
|
+
* @throws Error `Object of class X could not be converted to string` for an object without its own toString.
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
*
|
|
835
|
+
* join({ a: 'a', b: 'b', c: 'c' }, ', '); -> 'a, b, c'
|
|
836
|
+
* join({ a: 'a', b: 'b', c: 'c' }, ', ', ' and '); -> 'a, b and c'
|
|
837
|
+
* join(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), ', ', ' and '); -> 'c, a and b'
|
|
838
|
+
*/
|
|
839
|
+
export declare function join(data: ReadonlyMap<unknown, unknown>, glue: string, finalGlue?: string): string;
|
|
840
|
+
export declare function join(data: unknown, glue: string, finalGlue?: string): string;
|
|
841
|
+
/**
|
|
842
|
+
* Key an object by a field or using a callback.
|
|
843
|
+
* Each resolved key is stored the way PHP stores an array key: `null` as `""`, a boolean as `0`/`1`,
|
|
844
|
+
* and a float truncated toward zero.
|
|
845
|
+
*
|
|
846
|
+
* A Map is walked in its insertion order, so of two items that resolve to the same key, the one PHP reaches last wins.
|
|
847
|
+
*
|
|
848
|
+
* @param data - The object or Map to key.
|
|
849
|
+
* @param keyBy - The field name to key by, or a callback function.
|
|
850
|
+
* @returns A new object keyed by the specified field or callback result.
|
|
851
|
+
*
|
|
852
|
+
* @example
|
|
853
|
+
*
|
|
854
|
+
* keyBy({ user1: { id: 1, name: 'John' }, user2: { id: 2, name: 'Jane' } }, 'name'); -> { John: { id: 1, name: 'John' }, Jane: { id: 2, name: 'Jane' } }
|
|
855
|
+
* keyBy({ a: { name: 'John' }, b: { name: 'Jane' } }, (item) => item.name); -> { John: { name: 'John' }, Jane: { name: 'Jane' } }
|
|
856
|
+
* keyBy(new Map([[2, { id: 'x', n: 'c' }], [0, { id: 'x', n: 'a' }]]), 'id'); -> { x: { id: 'x', n: 'a' } }
|
|
857
|
+
*/
|
|
858
|
+
export declare function keyBy<TValue, TKey, R extends PropertyKey | boolean | null | undefined>(data: ReadonlyMap<TKey, TValue>, keyBy: (item: TValue, key: MapArrayKey<TKey>) => R): KeyByResult<TValue, R>;
|
|
859
|
+
export declare function keyBy<TValue, TKey, R extends PropertyKey | boolean | null | undefined = never, P extends PathKey = never>(data: ReadonlyMap<TKey, TValue>, keyBy: P | ((item: TValue, key: MapArrayKey<TKey>) => R)): KeyByResult<TValue, R | KeyByPath<TValue, P>>;
|
|
860
|
+
export declare function keyBy<TMap, R extends PropertyKey | boolean | null | undefined>(data: MapData<TMap>, keyBy: (item: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => R): KeyByResult<MapEntryValue<TMap>, R>;
|
|
861
|
+
export declare function keyBy<TMap, R extends PropertyKey | boolean | null | undefined = never, P extends PathKey = never>(data: MapData<TMap>, keyBy: P | ((item: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => R)): KeyByResult<MapEntryValue<TMap>, R | KeyByPath<MapEntryValue<TMap>, P>>;
|
|
862
|
+
export declare function keyBy(data: NonKeyedItems, keyBy: PathKey | ((item: unknown, key: string | number) => PropertyKey | boolean | null | undefined)): Record<string, never>;
|
|
863
|
+
export declare function keyBy(data: NonObjectItems, keyBy: PathKey | ((item: unknown, key: string | number) => PropertyKey | boolean | null | undefined)): Record<string, unknown>;
|
|
864
|
+
export declare function keyBy<T extends object, R extends PropertyKey | boolean | null | undefined>(data: T, keyBy: (item: BareObjectValue<T>, key: BareObjectKey<T>) => R): KeyByResult<BareObjectValue<T>, R>;
|
|
865
|
+
export declare function keyBy<T extends object, R extends PropertyKey | boolean | null | undefined = never, P extends PathKey = never>(data: T, keyBy: P | ((item: BareObjectValue<T>, key: BareObjectKey<T>) => R)): KeyByResult<BareObjectValue<T>, R | KeyByPath<BareObjectValue<T>, P>>;
|
|
866
|
+
export declare function keyBy(data: unknown, keyBy: PathKey | ((item: unknown, key: string | number) => PropertyKey | boolean | null | undefined)): Record<string, unknown>;
|
|
867
|
+
/**
|
|
868
|
+
* Prepend the key names of an object.
|
|
869
|
+
*
|
|
870
|
+
* A Map is walked in its insertion order. The result is a plain object, so a prefix that can leave integer-like keys
|
|
871
|
+
* (an empty one, or one starting with a digit from 1 to 9) has them listed first, ascending.
|
|
872
|
+
*
|
|
873
|
+
* @param data - The object or Map to process.
|
|
874
|
+
* @param prependWith - The string to prepend to each key.
|
|
875
|
+
* @returns A new object with prepended keys.
|
|
876
|
+
*
|
|
877
|
+
* @example
|
|
878
|
+
*
|
|
879
|
+
* prependKeysWith({ a: 1, b: 2, c: 3 }, 'item_'); -> { item_a: 1, item_b: 2, item_c: 3 }
|
|
880
|
+
* prependKeysWith(new Map([[2, 'c'], [0, 'a']]), 'k'); -> { k2: 'c', k0: 'a' }
|
|
881
|
+
* prependKeysWith(new Map([[2, 'c'], [0, 'a']]), '1'); -> { 10: 'a', 12: 'c' }, where PHP keeps 12 first
|
|
882
|
+
*/
|
|
883
|
+
export declare function prependKeysWith<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, prependWith: string): Record<string, TValue>;
|
|
884
|
+
export declare function prependKeysWith<TMap>(data: MapData<TMap>, prependWith: string): Record<string, MapEntryValue<TMap>>;
|
|
885
|
+
export declare function prependKeysWith(data: NonKeyedItems, prependWith: string): Record<string, never>;
|
|
886
|
+
export declare function prependKeysWith(data: NonObjectItems, prependWith: string): Record<string, unknown>;
|
|
887
|
+
export declare function prependKeysWith<T extends object, const P extends string>(data: T, prependWith: P): PrefixKeys<T, P>;
|
|
888
|
+
export declare function prependKeysWith(data: unknown, prependWith: string): Record<string, unknown>;
|
|
889
|
+
/**
|
|
890
|
+
* Get a subset of the items from the given object.
|
|
891
|
+
*
|
|
892
|
+
* Mirrors PHP's `(array) $keys` cast in `Arr::only` (Arr.php:754): `null` becomes
|
|
893
|
+
* no keys, a bare string becomes a single-key selection.
|
|
894
|
+
*
|
|
895
|
+
* Items keep the data's order, not the order of `keys`, as with `array_intersect_key`; a Map's is its insertion order.
|
|
896
|
+
*
|
|
897
|
+
* @param data - The object or Map to get items from.
|
|
898
|
+
* @param keys - The key, keys, or null to select.
|
|
899
|
+
* @returns A new object with only the specified keys.
|
|
900
|
+
*
|
|
901
|
+
* @example
|
|
902
|
+
*
|
|
903
|
+
* only({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'c']); -> { a: 1, c: 3 }
|
|
904
|
+
* only({ b: 1, a: 2 }, ['a', 'b']); -> { b: 1, a: 2 }
|
|
905
|
+
* only(new Map([['b', 1], [0, 2], ['a', 3]]), ['a', 'b']); -> { b: 1, a: 3 }
|
|
906
|
+
*/
|
|
907
|
+
export declare function only<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, keys: PathKeys): Record<string, TValue>;
|
|
908
|
+
export declare function only<TMap>(data: MapData<TMap>, keys: PathKeys): Record<string, MapEntryValue<TMap>>;
|
|
909
|
+
export declare function only(data: NonKeyedItems, keys: PathKeys): Record<string, never>;
|
|
910
|
+
export declare function only(data: NonObjectItems, keys: PathKeys): Record<string, unknown>;
|
|
911
|
+
export declare function only<T extends object>(data: T, keys: null | undefined): Record<string, never>;
|
|
912
|
+
export declare function only<T extends object, const K extends keyof T>(data: T, keys: K): Simplify<Pick<T, K>>;
|
|
913
|
+
export declare function only<T extends object, const Ks extends readonly (keyof T)[]>(data: T, keys: Ks): Simplify<Pick<T, Ks[number]>>;
|
|
914
|
+
export declare function only<T extends object>(data: T, keys: PathKeys): Partial<T>;
|
|
915
|
+
export declare function only(data: unknown, keys: PathKeys): Record<string, unknown>;
|
|
916
|
+
/**
|
|
917
|
+
* Get a subset of the items from the given object by value.
|
|
918
|
+
*
|
|
919
|
+
* @param data - The object to filter.
|
|
920
|
+
* @param values - The value(s) to include in the result.
|
|
921
|
+
* @param strict - Whether to use strict comparison (default: false).
|
|
922
|
+
* @returns A new object containing only the specified values.
|
|
923
|
+
*
|
|
924
|
+
* @example
|
|
925
|
+
*
|
|
926
|
+
* onlyValues({ name: 'taylor', age: 26, city: 'austin' }, [26]); -> { age: 26 }
|
|
927
|
+
* onlyValues({ a: 1, b: 2, c: 1, d: 3 }, 1); -> { a: 1, c: 1 }
|
|
928
|
+
* onlyValues({ a: true, b: false, c: 1, d: 0 }, [1, 0], true); -> { c: 1, d: 0 }
|
|
929
|
+
*/
|
|
930
|
+
export declare function onlyValues(data: NonObjectItems, values: unknown, strict?: boolean): Record<number, unknown>;
|
|
931
|
+
export declare function onlyValues<T extends object>(data: T, values: unknown, strict?: boolean): Partial<T>;
|
|
932
|
+
export declare function onlyValues(data: unknown, values: unknown, strict?: boolean): Record<string, unknown>;
|
|
933
|
+
/**
|
|
934
|
+
* Select an object of values from each item in the object.
|
|
935
|
+
*
|
|
936
|
+
* An item PHP reads as an array (a list, a plain object or a Map) gives its own keys, as PHP stores each. An
|
|
937
|
+
* ArrayAccess item answers through `offsetExists` and `offsetGet` first; a key they miss, like a key of any other
|
|
938
|
+
* object, gives only a property PHP's `isset` finds, so a null one is left out, and an Enumerable gives none.
|
|
939
|
+
*
|
|
940
|
+
* @param data - The object to select from.
|
|
941
|
+
* @param keys - The key or keys to select from each item.
|
|
942
|
+
* @returns A new object with selected key/value pairs from each item.
|
|
943
|
+
* @throws TypeError for an array or object key over an item PHP reads as an array, as `array_key_exists` does.
|
|
944
|
+
*
|
|
945
|
+
* @example
|
|
946
|
+
*
|
|
947
|
+
* select({ user1: { a: 1, b: 2, c: 3 }, user2: { a: 4, b: 5, c: 6 } }, 'a'); -> { user1: { a: 1 }, user2: { a: 4 } }
|
|
948
|
+
* select({ user1: { a: 1, b: 2 }, user2: { a: 3, b: 4 } }, ['a', 'b']); -> { user1: { a: 1, b: 2 }, user2: { a: 3, b: 4 } }
|
|
949
|
+
* select({ row: [10, 20, 30] }, [0, 2]); -> { row: { 0: 10, 2: 30 } }
|
|
950
|
+
*/
|
|
951
|
+
export declare function select(data: NonObjectItems, keys: PathKeys): Record<string, never>;
|
|
952
|
+
export declare function select<T extends object, const K extends keyof ObjectValue<T> & string>(data: T, keys: K): {
|
|
953
|
+
-readonly [R in keyof T]: Simplify<Pick<T[R], K & keyof T[R]>>;
|
|
954
|
+
};
|
|
955
|
+
export declare function select<T extends object, const Ks extends readonly (keyof ObjectValue<T> & string)[]>(data: T, keys: Ks): {
|
|
956
|
+
-readonly [R in keyof T]: Simplify<Pick<T[R], Ks[number] & keyof T[R]>>;
|
|
957
|
+
};
|
|
958
|
+
export declare function select<T extends object>(data: T, keys: PathKeys): {
|
|
959
|
+
-readonly [R in keyof T]: Partial<T[R]>;
|
|
960
|
+
};
|
|
961
|
+
export declare function select(data: unknown, keys: PathKeys): Record<string, Record<string, unknown>>;
|
|
962
|
+
/**
|
|
963
|
+
* Pluck an array of values from an object.
|
|
964
|
+
*
|
|
965
|
+
* A Map is walked in its insertion order, so the list keeps PHP's order and the last item wins a shared key, though a
|
|
966
|
+
* keyed result is a plain object listing integer keys ascending. A path into a Map plucks `null`, a `*` into one `[]`.
|
|
967
|
+
*
|
|
968
|
+
* @param data - The object or Map to pluck from.
|
|
969
|
+
* @param value - The key path to pluck (dot-notated string, array of segments, or a
|
|
970
|
+
* `*` wildcard path), a callback, or `null`/`undefined` to keep each whole item.
|
|
971
|
+
* @param key - Optional key path (string, array of segments, or callback) to use as keys in the result.
|
|
972
|
+
* @returns A new array with plucked values or object with key-value pairs.
|
|
973
|
+
*
|
|
974
|
+
* @example
|
|
975
|
+
*
|
|
976
|
+
* pluck({ user1: { name: 'John' }, user2: { name: 'Jane' } }, 'name'); -> ['John', 'Jane']
|
|
977
|
+
* pluck(new Map([[2, { n: 'c' }], [0, { n: 'a' }], [1, { n: 'b' }]]), 'n'); -> ['c', 'a', 'b']
|
|
978
|
+
* pluck(new Map([[2, { n: 'c', k: 'x' }], [0, { n: 'a', k: 'x' }]]), 'n', 'k'); -> { x: 'a' }
|
|
979
|
+
*/
|
|
980
|
+
export declare function pluck<TValue, TKey, const P extends string>(data: ReadonlyMap<TKey, TValue>, value: P, key: PluckKey<TValue>): Record<string | number, PluckValue<TValue, P>>;
|
|
981
|
+
export declare function pluck<TValue, TKey, const P extends string>(data: ReadonlyMap<TKey, TValue>, value: P, key?: null | undefined): PluckValue<TValue, P>[];
|
|
982
|
+
export declare function pluck<TValue, TKey, R>(data: ReadonlyMap<TKey, TValue>, value: (item: TValue) => R, key: PluckKey<TValue>): Record<string | number, R>;
|
|
983
|
+
export declare function pluck<TValue, TKey, R>(data: ReadonlyMap<TKey, TValue>, value: (item: TValue) => R, key?: null | undefined): R[];
|
|
984
|
+
export declare function pluck<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: null | undefined, key: PluckKey<TValue>): Record<string | number, TValue>;
|
|
985
|
+
export declare function pluck<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: null | undefined, key?: null | undefined): TValue[];
|
|
986
|
+
export declare function pluck<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: readonly (string | number)[], key: PluckKey<TValue>): Record<string | number, unknown>;
|
|
987
|
+
export declare function pluck<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: readonly (string | number)[], key?: null | undefined): unknown[];
|
|
988
|
+
export declare function pluck<TValue, TKey, const P extends string>(data: ReadonlyMap<TKey, TValue>, value: P, key: PluckKey<TValue> | null | undefined): Record<string | number, PluckValue<TValue, P>> | PluckValue<TValue, P>[];
|
|
989
|
+
export declare function pluck<TValue, TKey, R>(data: ReadonlyMap<TKey, TValue>, value: (item: TValue) => R, key: PluckKey<TValue> | null | undefined): Record<string | number, R> | R[];
|
|
990
|
+
export declare function pluck<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: null | undefined, key: PluckKey<TValue> | null | undefined): Record<string | number, TValue> | TValue[];
|
|
991
|
+
export declare function pluck<TMap, const P extends string>(data: MapData<TMap>, value: P, key: PluckKey<MapEntryValue<TMap>>): Record<string | number, PluckValue<MapEntryValue<TMap>, P>>;
|
|
992
|
+
export declare function pluck<TMap, const P extends string>(data: MapData<TMap>, value: P, key?: null | undefined): PluckValue<MapEntryValue<TMap>, P>[];
|
|
993
|
+
export declare function pluck<TMap, R>(data: MapData<TMap>, value: (item: MapEntryValue<TMap>) => R, key: PluckKey<MapEntryValue<TMap>>): Record<string | number, R>;
|
|
994
|
+
export declare function pluck<TMap, R>(data: MapData<TMap>, value: (item: MapEntryValue<TMap>) => R, key?: null | undefined): R[];
|
|
995
|
+
export declare function pluck<TMap>(data: MapData<TMap>, value: null | undefined, key: PluckKey<MapEntryValue<TMap>>): Record<string | number, MapEntryValue<TMap>>;
|
|
996
|
+
export declare function pluck<TMap>(data: MapData<TMap>, value: null | undefined, key?: null | undefined): MapEntryValue<TMap>[];
|
|
997
|
+
export declare function pluck<TMap>(data: MapData<TMap>, value: readonly (string | number)[], key: PluckKey<MapEntryValue<TMap>>): Record<string | number, unknown>;
|
|
998
|
+
export declare function pluck<TMap>(data: MapData<TMap>, value: readonly (string | number)[], key?: null | undefined): unknown[];
|
|
999
|
+
export declare function pluck<TMap, const P extends string>(data: MapData<TMap>, value: P, key: PluckKey<MapEntryValue<TMap>> | null | undefined): Record<string | number, PluckValue<MapEntryValue<TMap>, P>> | PluckValue<MapEntryValue<TMap>, P>[];
|
|
1000
|
+
export declare function pluck<TMap, R>(data: MapData<TMap>, value: (item: MapEntryValue<TMap>) => R, key: PluckKey<MapEntryValue<TMap>> | null | undefined): Record<string | number, R> | R[];
|
|
1001
|
+
export declare function pluck<TMap>(data: MapData<TMap>, value: null | undefined, key: PluckKey<MapEntryValue<TMap>> | null | undefined): Record<string | number, MapEntryValue<TMap>> | MapEntryValue<TMap>[];
|
|
1002
|
+
export declare function pluck(data: NonKeyedItems, value: string | readonly (string | number)[] | ((item: unknown) => unknown) | null | undefined, key: PluckKey<unknown>): Record<string | number, never>;
|
|
1003
|
+
export declare function pluck(data: NonKeyedItems, value: string | readonly (string | number)[] | ((item: unknown) => unknown) | null | undefined, key: null | undefined): never[];
|
|
1004
|
+
export declare function pluck(data: NonKeyedItems, value: string | readonly (string | number)[] | ((item: unknown) => unknown) | null | undefined): never[];
|
|
1005
|
+
export declare function pluck(data: NonObjectItems, value: string | readonly (string | number)[] | ((item: unknown) => unknown) | null | undefined, key?: PluckKey<unknown> | null): unknown[] | Record<string | number, unknown>;
|
|
1006
|
+
export declare function pluck<T extends object, const P extends string>(data: T, value: P, key: PluckKey<BareObjectValue<T>>): Record<string | number, PluckValue<BareObjectValue<T>, P>>;
|
|
1007
|
+
export declare function pluck<T extends object, const P extends string>(data: T, value: P, key?: null | undefined): PluckValue<BareObjectValue<T>, P>[];
|
|
1008
|
+
export declare function pluck<T extends object, R>(data: T, value: (item: BareObjectValue<T>) => R, key: PluckKey<BareObjectValue<T>>): Record<string | number, R>;
|
|
1009
|
+
export declare function pluck<T extends object, R>(data: T, value: (item: BareObjectValue<T>) => R, key?: null | undefined): R[];
|
|
1010
|
+
export declare function pluck<T extends object>(data: T, value: null | undefined, key: PluckKey<BareObjectValue<T>>): Record<string | number, BareObjectValue<T>>;
|
|
1011
|
+
export declare function pluck<T extends object>(data: T, value: null | undefined, key?: null | undefined): BareObjectValue<T>[];
|
|
1012
|
+
export declare function pluck<T extends object>(data: T, value: readonly (string | number)[], key: PluckKey<BareObjectValue<T>>): Record<string | number, unknown>;
|
|
1013
|
+
export declare function pluck<T extends object>(data: T, value: readonly (string | number)[], key?: null | undefined): unknown[];
|
|
1014
|
+
export declare function pluck<T extends object, const P extends string>(data: T, value: P, key: PluckKey<BareObjectValue<T>> | null | undefined): Record<string | number, PluckValue<BareObjectValue<T>, P>> | PluckValue<BareObjectValue<T>, P>[];
|
|
1015
|
+
export declare function pluck<T extends object, R>(data: T, value: (item: BareObjectValue<T>) => R, key: PluckKey<BareObjectValue<T>> | null | undefined): Record<string | number, R> | R[];
|
|
1016
|
+
export declare function pluck<T extends object>(data: T, value: null | undefined, key: PluckKey<BareObjectValue<T>> | null | undefined): Record<string | number, BareObjectValue<T>> | BareObjectValue<T>[];
|
|
1017
|
+
export declare function pluck(data: unknown, value: string | readonly (string | number)[] | ((item: unknown) => unknown) | null | undefined, key?: PluckKey<unknown> | null): unknown[] | Record<string | number, unknown>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Get and remove the last N items from the collection.
|
|
1020
|
+
*
|
|
1021
|
+
* A Map is popped from the end of its insertion order and rewritten in place, its survivors keeping their keys
|
|
1022
|
+
* (integer keys as numbers), even if typed `ReadonlyMap`.
|
|
1023
|
+
*
|
|
1024
|
+
* @see Collection::pop — `packages/collection/stubs/Collection.php:1030`.
|
|
1025
|
+
* Mirrors `array_pop`, called `$count` times from the end; mutates.
|
|
1026
|
+
*
|
|
1027
|
+
* @param data - The object or Map to pop items from. Mutated in place.
|
|
1028
|
+
* @param count - The number of items to pop. Defaults to 1; a fraction is dropped, and NAN pops every item.
|
|
1029
|
+
* @returns The popped item(s) or null/empty array if none.
|
|
1030
|
+
* @throws Error for a fraction between 1 and 2 that the items do not cap, as PHP's range() throws its ValueError.
|
|
1031
|
+
*
|
|
1032
|
+
* @example
|
|
1033
|
+
*
|
|
1034
|
+
* pop({ a: 1, b: 2 }); -> 2
|
|
1035
|
+
* pop(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 2); -> ['b', 'a'], leaving the Map holding [[2, 'c']]
|
|
1036
|
+
*/
|
|
1037
|
+
export declare function pop<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, count?: 1 | undefined): TValue | null;
|
|
1038
|
+
export declare function pop<TValue, TKey, const N extends number>(data: ReadonlyMap<TKey, TValue>, count: N): number extends N ? TValue | TValue[] | null : TValue[];
|
|
1039
|
+
export declare function pop<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, count: number | undefined): TValue | TValue[] | null;
|
|
1040
|
+
export declare function pop<TMap>(data: MapData<TMap>, count?: 1 | undefined): MapEntryValue<TMap> | null;
|
|
1041
|
+
export declare function pop<TMap, const N extends number>(data: MapData<TMap>, count: N): number extends N ? MapEntryValue<TMap> | MapEntryValue<TMap>[] | null : MapEntryValue<TMap>[];
|
|
1042
|
+
export declare function pop<TMap>(data: MapData<TMap>, count: number | undefined): MapEntryValue<TMap> | MapEntryValue<TMap>[] | null;
|
|
1043
|
+
export declare function pop(data: NonKeyedItems | null | undefined, count?: 1 | undefined): null;
|
|
1044
|
+
export declare function pop<const N extends number>(data: NonKeyedItems | null | undefined, count: N): number extends N ? null | never[] : N extends 1 ? null : never[];
|
|
1045
|
+
export declare function pop(data: NonKeyedItems | null | undefined, count: number | undefined): null | never[];
|
|
1046
|
+
export declare function pop(data: NonObjectItems | null | undefined, count?: number): unknown;
|
|
1047
|
+
export declare function pop<T extends object>(data: T, count?: 1 | undefined): ObjectValue<T> | null;
|
|
1048
|
+
export declare function pop<T extends object, const N extends number>(data: T, count: N): number extends N ? ObjectValue<T> | ObjectValue<T>[] | null : ObjectValue<T>[];
|
|
1049
|
+
export declare function pop<T extends object>(data: T, count: number | undefined): ObjectValue<T> | ObjectValue<T>[] | null;
|
|
1050
|
+
export declare function pop(data: unknown, count?: number): unknown;
|
|
1051
|
+
/**
|
|
1052
|
+
* Run a map over each of the items in the object.
|
|
1053
|
+
*
|
|
1054
|
+
* A Map is walked in its insertion order, so the callback sees its items in PHP's order.
|
|
1055
|
+
*
|
|
1056
|
+
* @param data - The object or Map to map over.
|
|
1057
|
+
* @param callback - The function to call for each item (value, key) => newValue.
|
|
1058
|
+
* @returns A new object with transformed values.
|
|
1059
|
+
*
|
|
1060
|
+
* @example
|
|
1061
|
+
*
|
|
1062
|
+
* map({ a: 1, b: 2, c: 3 }, (value) => value * 2); -> { a: 2, b: 4, c: 6 }
|
|
1063
|
+
* map({ name: 'john', email: 'JOHN@EXAMPLE.COM' }, (value, key) => key === 'name' ? value.toUpperCase() : value.toLowerCase()); -> { name: 'JOHN', email: 'john@example.com' }
|
|
1064
|
+
* map(new Map([[2, 'c'], [0, 'a']]), (value, key) => `${value}!${key}`);
|
|
1065
|
+
* -> { 2: 'c!2', 0: 'a!0' }, calling back for key 2 first
|
|
1066
|
+
*/
|
|
1067
|
+
export declare function map<TValue, TKey, R>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => R): Record<string, R>;
|
|
1068
|
+
export declare function map<TMap, R>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => R): Record<string, R>;
|
|
1069
|
+
export declare function map<R>(data: NonKeyedItems, callback: (value: unknown, key: string | number) => R): Record<string, never>;
|
|
1070
|
+
export declare function map<R>(data: NonObjectItems, callback: (value: unknown, key: string | number) => R): Record<string, R>;
|
|
1071
|
+
export declare function map<T extends object, R>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => R): {
|
|
1072
|
+
-readonly [K in keyof T]: R;
|
|
1073
|
+
};
|
|
1074
|
+
export declare function map<R>(data: unknown, callback: (value: unknown, key: string | number) => R): Record<string, R>;
|
|
1075
|
+
/**
|
|
1076
|
+
* Run an associative map over each of the items; the callback should return an object with key/value pairs.
|
|
1077
|
+
*
|
|
1078
|
+
* Always returns a plain object, even when every mapped key is numeric-like —
|
|
1079
|
+
* there's no PHP `Map` concept to preserve here (Arr.php:890).
|
|
1080
|
+
*
|
|
1081
|
+
* A Map is walked in its insertion order, which orders the string keys returned and decides which item wins a key.
|
|
1082
|
+
*
|
|
1083
|
+
* @param data - The object or Map to map.
|
|
1084
|
+
* @param callback - Function that returns an object with key/value pairs.
|
|
1085
|
+
* @returns A new object with all mapped key/value pairs.
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
*
|
|
1089
|
+
* mapWithKeys({ user1: { id: 1, name: 'John' } }, (item) => ({ [item.name]: item.id })); -> { John: 1 }
|
|
1090
|
+
* mapWithKeys({ a: 'x', b: 'y' }, (value, key) => ({ [value]: key })); -> { x: 'a', y: 'b' }
|
|
1091
|
+
* mapWithKeys(new Map([[2, 'c'], [0, 'a']]), (value, key) => ({ [`k${key}`]: value })); -> { k2: 'c', k0: 'a' }
|
|
1092
|
+
* mapWithKeys(new Map([[2, 'c'], [0, 'a']]), (value) => ({ same: value })); -> { same: 'a' }
|
|
1093
|
+
*/
|
|
1094
|
+
export declare function mapWithKeys<TValue, TKey, TMapped extends readonly unknown[]>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => readonly [...TMapped]): MapWithKeysList<TMapped>;
|
|
1095
|
+
export declare function mapWithKeys<TValue, TKey, TMapKey extends PropertyKey, TMapValue>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => Record<TMapKey, TMapValue>): Record<TMapKey, TMapValue>;
|
|
1096
|
+
export declare function mapWithKeys<TMap, TMapped extends readonly unknown[]>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => readonly [...TMapped]): MapWithKeysList<TMapped>;
|
|
1097
|
+
export declare function mapWithKeys<TMap, TMapKey extends PropertyKey, TMapValue>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => Record<TMapKey, TMapValue>): Record<TMapKey, TMapValue>;
|
|
1098
|
+
export declare function mapWithKeys(data: NonKeyedItems, callback: (value: unknown, key: string | number) => Record<PropertyKey, unknown>): Record<string, never>;
|
|
1099
|
+
export declare function mapWithKeys<TMapped extends readonly unknown[]>(data: NonObjectItems, callback: (value: unknown, key: string | number) => readonly [...TMapped]): MapWithKeysList<TMapped>;
|
|
1100
|
+
export declare function mapWithKeys<TMapKey extends PropertyKey, TMapValue>(data: NonObjectItems, callback: (value: unknown, key: string | number) => Record<TMapKey, TMapValue>): Record<TMapKey, TMapValue>;
|
|
1101
|
+
export declare function mapWithKeys<T extends object, TMapped extends readonly unknown[]>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => readonly [...TMapped]): MapWithKeysList<TMapped>;
|
|
1102
|
+
export declare function mapWithKeys<T extends object, TMapKey extends PropertyKey, TMapValue>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => Record<TMapKey, TMapValue>): Record<TMapKey, TMapValue>;
|
|
1103
|
+
export declare function mapWithKeys<TMapKey extends PropertyKey, TMapValue>(data: unknown, callback: (value: unknown, key: string | number) => Record<TMapKey, TMapValue>): Record<TMapKey, TMapValue>;
|
|
1104
|
+
/**
|
|
1105
|
+
* Run a map over each row, spreading a list row's items (or a plain object's or a Map's values), then the key.
|
|
1106
|
+
*
|
|
1107
|
+
* A Map is walked in its insertion order, so the callback sees its rows in PHP's order.
|
|
1108
|
+
*
|
|
1109
|
+
* @param data - The object or Map to map over.
|
|
1110
|
+
* @param callback - The callback function that receives spread object values and the key.
|
|
1111
|
+
* @returns A new object with mapped values.
|
|
1112
|
+
*
|
|
1113
|
+
* @example
|
|
1114
|
+
*
|
|
1115
|
+
* mapSpread({ x: [1, 'a'], y: [2, 'b'] }, (n, c) => `${n}-${c}`); -> { x: '1-a', y: '2-b' }
|
|
1116
|
+
* mapSpread({ x: [1, 'a'], y: [2, 'b'] }, (n, c, key) => `${n}-${c}-${key}`); -> { x: '1-a-x', y: '2-b-y' }
|
|
1117
|
+
* mapSpread(new Map([[2, ['c', 1]], [0, ['a', 2]]]), (x, y, key) => `${x}${y}${key}`);
|
|
1118
|
+
* -> { 2: 'c12', 0: 'a20' }, calling back for key 2 first
|
|
1119
|
+
*/
|
|
1120
|
+
export declare function mapSpread<TValue, TKey, R>(data: ReadonlyMap<TKey, TValue>, callback: (...args: SpreadArgs<TValue, MapArrayKey<TKey>>) => R): Record<string, R>;
|
|
1121
|
+
export declare function mapSpread<TMap, R>(data: MapData<TMap>, callback: (...args: SpreadArgs<MapEntryValue<TMap>, MapEntryKey<TMap>>) => R): Record<string, R>;
|
|
1122
|
+
export declare function mapSpread<R>(data: NonKeyedItems, callback: (...args: unknown[]) => R): Record<string, never>;
|
|
1123
|
+
export declare function mapSpread<R>(data: NonObjectItems, callback: (...args: unknown[]) => R): Record<string, R>;
|
|
1124
|
+
export declare function mapSpread<T extends object, R>(data: T, callback: (...args: SpreadArgs<ObjectValue<T>, ObjectKey<T>>) => R): {
|
|
1125
|
+
-readonly [K in keyof T]: R;
|
|
1126
|
+
};
|
|
1127
|
+
export declare function mapSpread<R>(data: unknown, callback: (...args: unknown[]) => R): Record<string, R>;
|
|
1128
|
+
/**
|
|
1129
|
+
* Push an item onto the beginning of an object (as first entry).
|
|
1130
|
+
*
|
|
1131
|
+
* A Map is read in its insertion order. Without a key, its integer keys are renumbered in that
|
|
1132
|
+
* order, as `array_unshift` renumbers PHP's, so each value lands where PHP puts it.
|
|
1133
|
+
*
|
|
1134
|
+
* @param data - The object or Map to prepend to.
|
|
1135
|
+
* @param value - The value to prepend.
|
|
1136
|
+
* @param key - The key for the prepended value, cast as PHP casts an array key (a float truncates, a boolean
|
|
1137
|
+
* becomes 0 or 1, null becomes ""); omit it to unshift under key 0, as `Arr::prepend` does with two arguments.
|
|
1138
|
+
* @returns A new object with the value prepended.
|
|
1139
|
+
*
|
|
1140
|
+
* @example
|
|
1141
|
+
*
|
|
1142
|
+
* prepend({ b: 2, c: 3 }, 1, 'a'); -> { a: 1, b: 2, c: 3 }
|
|
1143
|
+
* prepend({ x: 1, y: 2 }, 0, 'z'); -> { z: 0, x: 1, y: 2 }
|
|
1144
|
+
* prepend(new Map([[2, 'c'], [0, 'a']]), 'z'); -> { 0: 'z', 1: 'c', 2: 'a' }
|
|
1145
|
+
*/
|
|
1146
|
+
export declare function prepend<TValue, TKey, V>(data: ReadonlyMap<TKey, TValue>, value: V, key?: PropertyKey | null): Record<string, TValue | V>;
|
|
1147
|
+
export declare function prepend<TMap, V>(data: MapData<TMap>, value: V, key?: PropertyKey | null): Record<string, MapEntryValue<TMap> | V>;
|
|
1148
|
+
export declare function prepend(data: NonKeyedItems, value: unknown, key?: PropertyKey | null): Record<string | number, unknown>;
|
|
1149
|
+
export declare function prepend(data: NonObjectItems, value: unknown, key?: PropertyKey | null): Record<string | number, unknown>;
|
|
1150
|
+
export declare function prepend<T extends object, V, const K extends string | number>(data: T, value: V, key: K): Simplify<{
|
|
1151
|
+
[P in `${PrependKey<K>}`]: V;
|
|
1152
|
+
} & Omit<T, PrependKey<K> | `${PrependKey<K>}`>>;
|
|
1153
|
+
export declare function prepend<T extends object, V>(data: T, value: V, key: null | undefined): Simplify<{
|
|
1154
|
+
"": V;
|
|
1155
|
+
} & Omit<T, "">>;
|
|
1156
|
+
export declare function prepend<T extends object, V>(data: T, value: V): RenumberedObject<T, V>;
|
|
1157
|
+
export declare function prepend(data: unknown, value: unknown, key?: PropertyKey | null): Record<string | number, unknown>;
|
|
1158
|
+
/**
|
|
1159
|
+
* Get a value from the object, and remove it.
|
|
1160
|
+
*
|
|
1161
|
+
* @param data - The object to pull the item from.
|
|
1162
|
+
* @param key - The key or dot-notated path of the item to pull.
|
|
1163
|
+
* @param defaultValue - The default value if key is not found.
|
|
1164
|
+
* @returns An object containing the pulled value (or default) and the updated object.
|
|
1165
|
+
*
|
|
1166
|
+
* @example
|
|
1167
|
+
*
|
|
1168
|
+
* pull({ a: 1, b: 2, c: 3 }, 'b'); -> { value: 2, data: { a: 1, c: 3 } }
|
|
1169
|
+
* pull({ user: { name: 'John', age: 30 } }, 'user.name'); -> { value: 'John', data: { user: { age: 30 } } }
|
|
1170
|
+
* pull({ a: 1, b: 2 }, 'x', 'default'); -> { value: 'default', data: { a: 1, b: 2 } }
|
|
1171
|
+
*/
|
|
1172
|
+
export declare function pull(data: ReadonlyMap<unknown, unknown>, key: PathKey, defaultValue?: unknown): {
|
|
1173
|
+
value: unknown;
|
|
1174
|
+
data: Record<string, unknown>;
|
|
1175
|
+
};
|
|
1176
|
+
export declare function pull<TDefault = null>(data: NonObjectItems, key: PathKey, defaultValue?: Default<TDefault>): {
|
|
1177
|
+
value: TDefault;
|
|
1178
|
+
data: Record<string, never>;
|
|
1179
|
+
};
|
|
1180
|
+
export declare function pull<T extends object, P extends string | number, TDefault>(data: T, key: P, defaultValue: Default<TDefault>): {
|
|
1181
|
+
value: ObjectResolvePath<T, P, TDefault>;
|
|
1182
|
+
data: ObjectPullRest<T, P>;
|
|
1183
|
+
};
|
|
1184
|
+
export declare function pull<T extends object, P extends string | number>(data: T, key: P): {
|
|
1185
|
+
value: ObjectResolvePath<T, P, null>;
|
|
1186
|
+
data: ObjectPullRest<T, P>;
|
|
1187
|
+
};
|
|
1188
|
+
export declare function pull(data: unknown, key: PathKey, defaultValue?: unknown): {
|
|
1189
|
+
value: unknown;
|
|
1190
|
+
data: Record<string, unknown>;
|
|
1191
|
+
};
|
|
1192
|
+
/**
|
|
1193
|
+
* Convert the object into a query string.
|
|
1194
|
+
*
|
|
1195
|
+
* A Map, at any depth, is read as the PHP array it stands for, in its insertion order, so its pairs come out in the
|
|
1196
|
+
* order `http_build_query` writes them.
|
|
1197
|
+
*
|
|
1198
|
+
* @param data - The object or Map to convert to a query string.
|
|
1199
|
+
* @returns A URL-encoded query string.
|
|
1200
|
+
*
|
|
1201
|
+
* @example
|
|
1202
|
+
*
|
|
1203
|
+
* query({ name: 'John', age: 30 }); -> 'name=John&age=30'
|
|
1204
|
+
* query({ user: { name: 'John', age: 30 } }); -> 'user%5Bname%5D=John&user%5Bage%5D=30'
|
|
1205
|
+
* query({ tags: ['php', 'js'] }); -> 'tags%5B0%5D=php&tags%5B1%5D=js'
|
|
1206
|
+
* query({ foo: 'bar', bar: true }); -> 'foo=bar&bar=1' (booleans cast like PHP's http_build_query)
|
|
1207
|
+
* query({ foo: 'bar', bar: false }); -> 'foo=bar&bar=0'
|
|
1208
|
+
* query(new Map([[2, 'c'], [0, 'a'], [1, 'b']])); -> '2=c&0=a&1=b'
|
|
1209
|
+
* query({ u: new Map([[1, 'p'], [0, 'q']]), v: 1 }); -> 'u%5B1%5D=p&u%5B0%5D=q&v=1'
|
|
1210
|
+
*/
|
|
1211
|
+
export declare function query(data: ReadonlyMap<unknown, unknown>): string;
|
|
1212
|
+
export declare function query(data: unknown): string;
|
|
1213
|
+
/**
|
|
1214
|
+
* Get one or a specified number of random values from an object.
|
|
1215
|
+
*
|
|
1216
|
+
* Which items are picked is random, but they come back in the object's order, a Map's being its insertion order, as
|
|
1217
|
+
* `Randomizer::pickArrayKeys` returns the picked keys in the array's order.
|
|
1218
|
+
*
|
|
1219
|
+
* @param data - The object or Map to get random values from.
|
|
1220
|
+
* @param number - The number of items to return, a fraction truncated. If null, returns a single item.
|
|
1221
|
+
* @param preserveKeys - Preserve original keys when returning multiple items. Defaults to `false` (Arr.php:981).
|
|
1222
|
+
* @returns A single random item, an object of random items, or null if object is empty.
|
|
1223
|
+
* @throws InvalidArgumentException if more items are requested than available, even against an empty object.
|
|
1224
|
+
* @throws TypeError for a NAN count or a string that is not numeric, which PHP's Randomizer rejects too.
|
|
1225
|
+
* @throws Error for a count between 0 and 1, which truncates to no item, as PHP's Randomizer rejects it.
|
|
1226
|
+
*
|
|
1227
|
+
* @example
|
|
1228
|
+
*
|
|
1229
|
+
* random({ a: 1, b: 2, c: 3 }); -> 2 (random)
|
|
1230
|
+
* random({ a: 1, b: 2, c: 3 }, 2); -> { 0: 1, 1: 3 } (random picks, in the object's order)
|
|
1231
|
+
* random(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 3); -> { 0: 'c', 1: 'a', 2: 'b' }
|
|
1232
|
+
*/
|
|
1233
|
+
export declare function random<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, number?: null | undefined): TValue;
|
|
1234
|
+
export declare function random<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, number: number, preserveKeys?: false | undefined): Record<number, TValue>;
|
|
1235
|
+
export declare function random<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, number: number, preserveKeys: true): Record<string, TValue>;
|
|
1236
|
+
export declare function random<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, number: number, preserveKeys: boolean): Record<string, TValue> | Record<number, TValue>;
|
|
1237
|
+
export declare function random<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, number: number | null | undefined, preserveKeys?: boolean): TValue | Record<string, TValue> | Record<number, TValue>;
|
|
1238
|
+
export declare function random<TMap>(data: MapData<TMap>, number?: null | undefined): MapEntryValue<TMap>;
|
|
1239
|
+
export declare function random<TMap>(data: MapData<TMap>, number: number, preserveKeys?: false | undefined): Record<number, MapEntryValue<TMap>>;
|
|
1240
|
+
export declare function random<TMap>(data: MapData<TMap>, number: number, preserveKeys: true): Record<string, MapEntryValue<TMap>>;
|
|
1241
|
+
export declare function random<TMap>(data: MapData<TMap>, number: number, preserveKeys: boolean): Record<string, MapEntryValue<TMap>> | Record<number, MapEntryValue<TMap>>;
|
|
1242
|
+
export declare function random<TMap>(data: MapData<TMap>, number: number | null | undefined, preserveKeys?: boolean): MapEntryValue<TMap> | Record<string, MapEntryValue<TMap>> | Record<number, MapEntryValue<TMap>>;
|
|
1243
|
+
export declare function random(data: NonKeyedItems, number?: number | null, preserveKeys?: boolean): null | Record<string, never>;
|
|
1244
|
+
export declare function random(data: NonObjectItems, number?: number | null, preserveKeys?: boolean): unknown;
|
|
1245
|
+
export declare function random<T extends object>(data: T, number?: null | undefined): BareObjectValue<T>;
|
|
1246
|
+
export declare function random<T extends object>(data: T, number: number, preserveKeys?: false | undefined): Record<number, BareObjectValue<T>>;
|
|
1247
|
+
export declare function random<T extends object>(data: T, number: number, preserveKeys: true | undefined): Partial<T>;
|
|
1248
|
+
export declare function random<T extends object>(data: T, number: number, preserveKeys: boolean): Partial<T> | Record<number, ObjectValue<T>>;
|
|
1249
|
+
export declare function random<T extends object>(data: T, number: number | null | undefined, preserveKeys?: boolean): BareObjectValue<T> | Partial<T> | Record<number, BareObjectValue<T>>;
|
|
1250
|
+
export declare function random(data: unknown, number?: number | string | null, preserveKeys?: boolean): unknown;
|
|
1251
|
+
/**
|
|
1252
|
+
* Get and remove the first N items from the object, mutating it in place, like PHP's array_shift.
|
|
1253
|
+
*
|
|
1254
|
+
* Survivors' integer keys, negative ones included, are renumbered from 0, matching `array_shift`; string keys keep
|
|
1255
|
+
* theirs. A Map is shifted and renumbered in its insertion order and rewritten in place, integer keys as numbers,
|
|
1256
|
+
* even if typed `ReadonlyMap`.
|
|
1257
|
+
*
|
|
1258
|
+
* @see Collection::shift — `packages/collection/stubs/Collection.php:1281`. Mirrors `array_shift`; mutates.
|
|
1259
|
+
*
|
|
1260
|
+
* @param data - The object or Map to shift items from. Mutated in place.
|
|
1261
|
+
* @param count - The number of items to shift. Defaults to 1; a fraction is dropped, and NAN shifts every item.
|
|
1262
|
+
* @returns The shifted item when count is 1, or null if there was none; an array of the shifted items otherwise.
|
|
1263
|
+
* @throws InvalidArgumentException if count is negative.
|
|
1264
|
+
* @throws Error for a fraction below 2 that the items do not cap, as PHP's range() throws its ValueError.
|
|
1265
|
+
*
|
|
1266
|
+
* @example
|
|
1267
|
+
*
|
|
1268
|
+
* shift({ a: 1, b: 2 }); -> 1
|
|
1269
|
+
* shift(new Map([[2, 'c'], [0, 'a'], [1, 'b']])); -> 'c', leaving the Map holding [[0, 'a'], [1, 'b']]
|
|
1270
|
+
*/
|
|
1271
|
+
export declare function shift<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, count?: 1 | undefined): TValue | null;
|
|
1272
|
+
export declare function shift<TValue, TKey, const N extends number>(data: ReadonlyMap<TKey, TValue>, count: N): number extends N ? TValue | TValue[] | null : TValue[];
|
|
1273
|
+
export declare function shift<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, count: number | undefined): TValue | TValue[] | null;
|
|
1274
|
+
export declare function shift<TMap>(data: MapData<TMap>, count?: 1 | undefined): MapEntryValue<TMap> | null;
|
|
1275
|
+
export declare function shift<TMap, const N extends number>(data: MapData<TMap>, count: N): number extends N ? MapEntryValue<TMap> | MapEntryValue<TMap>[] | null : MapEntryValue<TMap>[];
|
|
1276
|
+
export declare function shift<TMap>(data: MapData<TMap>, count: number | undefined): MapEntryValue<TMap> | MapEntryValue<TMap>[] | null;
|
|
1277
|
+
export declare function shift(data: NonKeyedItems | null | undefined, count?: 1 | undefined): null;
|
|
1278
|
+
export declare function shift<const N extends number>(data: NonKeyedItems | null | undefined, count: N): number extends N ? null | never[] : N extends 1 ? null : never[];
|
|
1279
|
+
export declare function shift(data: NonKeyedItems | null | undefined, count: number | undefined): null | never[];
|
|
1280
|
+
export declare function shift(data: NonObjectItems | null | undefined, count?: number): unknown;
|
|
1281
|
+
export declare function shift<T extends object>(data: T, count?: 1 | undefined): ObjectValue<T> | null;
|
|
1282
|
+
export declare function shift<T extends object, const N extends number>(data: T, count: N): number extends N ? ObjectValue<T> | ObjectValue<T>[] | null : ObjectValue<T>[];
|
|
1283
|
+
export declare function shift<T extends object>(data: T, count: number | undefined): ObjectValue<T> | ObjectValue<T>[] | null;
|
|
1284
|
+
export declare function shift(data: unknown, count?: number): unknown;
|
|
1285
|
+
/**
|
|
1286
|
+
* Set an object item to a given value using "dot" notation.
|
|
1287
|
+
*
|
|
1288
|
+
* If no key is given to the method, the entire object will be replaced.
|
|
1289
|
+
*
|
|
1290
|
+
* @param data - The object to set the item in.
|
|
1291
|
+
* @param key - The key or dot-notated path of the item to set.
|
|
1292
|
+
* @param value - The value to set.
|
|
1293
|
+
* @returns - A new object with the item set or the original object if the path is invalid.
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* set({ name: 'John', age: 30 }, 'age', 31); -> { name: 'John', age: 31 }
|
|
1297
|
+
* set({ user: { name: 'John' } }, 'user.age', 30); -> { user: { name: 'John', age: 30 } }
|
|
1298
|
+
* set({ m: new Map([[2, 'c'], [0, 'a']]) }, 'm.2', 'C'); -> { m: new Map([[2, 'C'], [0, 'a']]) } (it keeps its place)
|
|
1299
|
+
*/
|
|
1300
|
+
export declare function set<V>(data: unknown, key: null | undefined, value: V): V;
|
|
1301
|
+
export declare function set<K extends PathKey, V>(data: ReadonlyMap<unknown, unknown>, key: K, value: V): Record<string, unknown> | NullishKeyValue<K, V>;
|
|
1302
|
+
export declare function set<K extends PathKey, V>(data: NonObjectItems, key: K, value: V): Record<string, never> | NullishKeyValue<K, V>;
|
|
1303
|
+
export declare function set<T extends object, P extends PathKey, V>(data: T, key: P, value: V): ObjectWriteResult<T, NonNullable<P>, V> | NullishKeyValue<P, V>;
|
|
1304
|
+
export declare function set<K extends PathKey, V>(data: unknown, key: K, value: V): Record<string, unknown> | NullishKeyValue<K, V>;
|
|
1305
|
+
/**
|
|
1306
|
+
* Push one or more items into an object at a nested path using dot notation.
|
|
1307
|
+
*
|
|
1308
|
+
* An object or Map at the key is appended to under its next integer key, as Arr::push does.
|
|
1309
|
+
*
|
|
1310
|
+
* @param data - The object to push items into.
|
|
1311
|
+
* @param key - The key or dot-notated path of the array to push into. A null key appends
|
|
1312
|
+
* to the object itself under the next integer key, mirroring Arr::push.
|
|
1313
|
+
* @param values - The values to push.
|
|
1314
|
+
* @returns A new object with the values pushed in.
|
|
1315
|
+
* @throws InvalidArgumentException if the value at the key is not an array, object or Map.
|
|
1316
|
+
*
|
|
1317
|
+
* @example
|
|
1318
|
+
*
|
|
1319
|
+
* push({ items: ['a', 'b'] }, 'items', 'c', 'd'); -> { items: ['a', 'b', 'c', 'd'] }
|
|
1320
|
+
* push({ user: { tags: ['js'] } }, 'user.tags', 'ts', 'php'); -> { user: { tags: ['js', 'ts', 'php'] } }
|
|
1321
|
+
* push({ x: { k: 1 } }, 'x', 'v'); -> { x: { k: 1, 0: 'v' } }
|
|
1322
|
+
* push({ a: 1 }, null, 9); -> { a: 1, 0: 9 }
|
|
1323
|
+
*/
|
|
1324
|
+
export declare function push(data: ReadonlyMap<unknown, unknown>, key: PathKey, ...values: unknown[]): Record<string, unknown>;
|
|
1325
|
+
export declare function push<V>(data: NonObjectItems, key: PathKey, ...values: V[]): Record<string, unknown>;
|
|
1326
|
+
export declare function push<T extends object, V>(data: T, key: null | undefined, ...values: V[]): RenumberedObject<T, V>;
|
|
1327
|
+
export declare function push<T extends object, P extends string | number, V>(data: T, key: P, ...values: V[]): ObjectWriteResult<T, P, PushedAt<ObjectResolvePath<T, P, []>, V>>;
|
|
1328
|
+
export declare function push(data: unknown, key: PathKey, ...values: unknown[]): Record<string, unknown>;
|
|
1329
|
+
/**
|
|
1330
|
+
* Shuffle the object's values and return them under keys `0..n-1`, as `Arr::shuffle` returns a list.
|
|
1331
|
+
*
|
|
1332
|
+
* @param data - The object to shuffle.
|
|
1333
|
+
* @returns A new object holding the shuffled values under keys `0..n-1`.
|
|
1334
|
+
*
|
|
1335
|
+
* @example
|
|
1336
|
+
*
|
|
1337
|
+
* shuffle({ a: 1, b: 2, c: 3, d: 4, e: 5 }); -> { 0: 3, 1: 1, 2: 5, 3: 2, 4: 4 } (random order)
|
|
1338
|
+
* shuffle({ x: 'hello', y: 'world', z: 'test' }); -> { 0: 'test', 1: 'hello', 2: 'world' } (random order)
|
|
1339
|
+
*/
|
|
1340
|
+
export declare function shuffle(data: NonObjectItems): Record<number, never>;
|
|
1341
|
+
export declare function shuffle<T extends object>(data: T): Record<number, ObjectValue<T>>;
|
|
1342
|
+
export declare function shuffle(data: unknown): Record<number, unknown>;
|
|
1343
|
+
/**
|
|
1344
|
+
* Skip items in the object until the given condition is met.
|
|
1345
|
+
*
|
|
1346
|
+
* A value is compared with PHP's `===`; a callback is handed each value and key, and PHP truthiness judges its answer.
|
|
1347
|
+
* A Map is walked in its insertion order.
|
|
1348
|
+
*
|
|
1349
|
+
* @param data - The object or Map to skip items of.
|
|
1350
|
+
* @param value - The value to skip until, or a callback answering whether an item meets the condition.
|
|
1351
|
+
* @returns A new object of the items from the first that meets the condition on, each under its own key.
|
|
1352
|
+
*
|
|
1353
|
+
* @example
|
|
1354
|
+
*
|
|
1355
|
+
* skipUntil({ a: 1, b: 2, c: 3 }, 2); -> { b: 2, c: 3 }
|
|
1356
|
+
* skipUntil({ a: 1, b: 2, c: 3 }, (value, key) => key === 'b'); -> { b: 2, c: 3 }
|
|
1357
|
+
* skipUntil(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 'a'); -> { 0: 'a', 1: 'b' }
|
|
1358
|
+
*/
|
|
1359
|
+
export declare function skipUntil<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: NoInfer<TValue> | ((value: TValue, key: MapArrayKey<TKey>) => unknown)): Record<string, TValue>;
|
|
1360
|
+
export declare function skipUntil<TMap>(data: MapData<TMap>, value: MapEntryValue<TMap> | ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown)): Record<string, MapEntryValue<TMap>>;
|
|
1361
|
+
export declare function skipUntil(data: NonKeyedItems, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, never>;
|
|
1362
|
+
export declare function skipUntil(data: NonObjectItems, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, unknown>;
|
|
1363
|
+
export declare function skipUntil<T extends object>(data: T, value: ObjectValue<T> | ((value: ObjectValue<T>, key: ObjectKey<T>) => unknown)): Partial<T>;
|
|
1364
|
+
export declare function skipUntil(data: unknown, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, unknown>;
|
|
1365
|
+
/**
|
|
1366
|
+
* Skip items in the object while the given condition is met.
|
|
1367
|
+
*
|
|
1368
|
+
* A value is compared with PHP's `===`; a callback is handed each value and key, and PHP truthiness judges its answer.
|
|
1369
|
+
* A Map is walked in its insertion order.
|
|
1370
|
+
*
|
|
1371
|
+
* @param data - The object or Map to skip items of.
|
|
1372
|
+
* @param value - The value to skip while items equal it, or a callback answering whether an item meets the condition.
|
|
1373
|
+
* @returns A new object of the items from the first that fails the condition on, each under its own key.
|
|
1374
|
+
*
|
|
1375
|
+
* @example
|
|
1376
|
+
*
|
|
1377
|
+
* skipWhile({ a: 1, b: 2, c: 1 }, 1); -> { b: 2, c: 1 }
|
|
1378
|
+
* skipWhile({ a: 1, b: 2, c: 3 }, (value) => value < 3); -> { c: 3 }
|
|
1379
|
+
* skipWhile(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 'c'); -> { 0: 'a', 1: 'b' }
|
|
1380
|
+
*/
|
|
1381
|
+
export declare function skipWhile<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: NoInfer<TValue> | ((value: TValue, key: MapArrayKey<TKey>) => unknown)): Record<string, TValue>;
|
|
1382
|
+
export declare function skipWhile<TMap>(data: MapData<TMap>, value: MapEntryValue<TMap> | ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown)): Record<string, MapEntryValue<TMap>>;
|
|
1383
|
+
export declare function skipWhile(data: NonKeyedItems, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, never>;
|
|
1384
|
+
export declare function skipWhile(data: NonObjectItems, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, unknown>;
|
|
1385
|
+
export declare function skipWhile<T extends object>(data: T, value: ObjectValue<T> | ((value: ObjectValue<T>, key: ObjectKey<T>) => unknown)): Partial<T>;
|
|
1386
|
+
export declare function skipWhile(data: unknown, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, unknown>;
|
|
1387
|
+
/**
|
|
1388
|
+
* Slice the underlying object items, preserving keys — `array_slice($items,
|
|
1389
|
+
* $offset, $length, true)` (`Collection.php:1382`).
|
|
1390
|
+
*
|
|
1391
|
+
* A Map is sliced by its insertion order, so the offset and length count the items as PHP's array holds them.
|
|
1392
|
+
*
|
|
1393
|
+
* @see Collection::slice — `packages/collection/stubs/Collection.php:1382`.
|
|
1394
|
+
* Wraps `array_slice($items, $offset, $length, preserveKeys: true)`.
|
|
1395
|
+
*
|
|
1396
|
+
* @param data - The object or Map to slice
|
|
1397
|
+
* @param offset - The starting index
|
|
1398
|
+
* @param length - The number of items to include
|
|
1399
|
+
* @returns Sliced object
|
|
1400
|
+
*
|
|
1401
|
+
* @example
|
|
1402
|
+
*
|
|
1403
|
+
* slice({ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8 }, -2, 5); -> { g: 7, h: 8 }
|
|
1404
|
+
* slice(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 1); -> { 0: 'a', 1: 'b' }
|
|
1405
|
+
*/
|
|
1406
|
+
export declare function slice<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, offset: number, length?: number | null): Record<string, TValue>;
|
|
1407
|
+
export declare function slice<TMap>(data: MapData<TMap>, offset: number, length?: number | null): Record<string, MapEntryValue<TMap>>;
|
|
1408
|
+
export declare function slice(data: NonKeyedItems | null | undefined, offset: number, length?: number | null): Record<string, never>;
|
|
1409
|
+
export declare function slice(data: NonObjectItems | null | undefined, offset: number, length?: number | null): Record<string, unknown>;
|
|
1410
|
+
export declare function slice<T extends object>(data: T, offset: number, length?: number | null): Partial<T>;
|
|
1411
|
+
export declare function slice(data: unknown, offset: number, length?: number | null): Record<string, unknown>;
|
|
1412
|
+
/**
|
|
1413
|
+
* Get the first item in the object, but only if exactly one item exists. Otherwise, throw an exception.
|
|
1414
|
+
*
|
|
1415
|
+
* Throws Laravel's own exceptions: `ItemNotFoundException` with no message, `MultipleItemsFoundException` with the count.
|
|
1416
|
+
*
|
|
1417
|
+
* A Map is read in its insertion order, so the callback is handed its keys in the order PHP
|
|
1418
|
+
* walks the array, and keys PHP stores as one (`1` and `"1"`) count as one item.
|
|
1419
|
+
*
|
|
1420
|
+
* @param data - The object or Map to check.
|
|
1421
|
+
* @param callback - Optional callback to filter items.
|
|
1422
|
+
* @returns The single item in the object.
|
|
1423
|
+
* @throws ItemNotFoundException if no item matches, MultipleItemsFoundException if several do.
|
|
1424
|
+
*
|
|
1425
|
+
* @example
|
|
1426
|
+
*
|
|
1427
|
+
* sole({ only: 42 }); -> 42
|
|
1428
|
+
* sole({ a: 1, b: 2, c: 3 }, (value) => value > 2); -> 3
|
|
1429
|
+
* sole({}); -> throws ItemNotFoundException
|
|
1430
|
+
* sole({ a: 1, b: 2 }); -> throws MultipleItemsFoundException: 2 items were found.
|
|
1431
|
+
* sole({ a: 1, b: 2, c: 3 }, (value) => value > 1); -> throws MultipleItemsFoundException: 2 items were found.
|
|
1432
|
+
* sole(new Map([[1, 'a'], ['1', 'b']])); -> 'b'
|
|
1433
|
+
*/
|
|
1434
|
+
export declare function sole<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback?: (value: TValue, key: MapArrayKey<TKey>) => unknown): TValue;
|
|
1435
|
+
export declare function sole<TMap>(data: MapData<TMap>, callback?: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown): MapEntryValue<TMap>;
|
|
1436
|
+
export declare function sole(data: NonKeyedItems, callback?: (value: unknown, key: string | number) => unknown): never;
|
|
1437
|
+
export declare function sole(data: NonObjectItems, callback?: (value: unknown, key: string | number) => unknown): unknown;
|
|
1438
|
+
export declare function sole<T extends object>(data: T, callback?: (value: BareObjectValue<T>, key: BareObjectKey<T>) => unknown): BareObjectValue<T>;
|
|
1439
|
+
export declare function sole(data: unknown, callback?: (value: unknown, key: string | number) => unknown): unknown;
|
|
1440
|
+
/**
|
|
1441
|
+
* Sort the object using the given callback, "dot" notation, or an array of sort descriptors for multi-key sorting.
|
|
1442
|
+
*
|
|
1443
|
+
* Values are ordered by `compareValues`, never by falsiness (PHP's `asort` puts
|
|
1444
|
+
* `-1` before `0`). Integer-like keys are renumbered over the sorted sequence.
|
|
1445
|
+
*
|
|
1446
|
+
* A Map's ties keep its insertion order, and keys PHP stores as one (`1` and `"1"`) are one item, with the last value.
|
|
1447
|
+
*
|
|
1448
|
+
* @see Arr::sort — `packages/arr/stubs/Arr.php:1124`. Delegates to `Collection::sortBy`.
|
|
1449
|
+
*
|
|
1450
|
+
* @param data - The object or Map to sort.
|
|
1451
|
+
* @param callback - The sorting callback, field name, an array of sort descriptors, or null for natural sorting.
|
|
1452
|
+
* @returns A new object with sorted entries.
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
*
|
|
1456
|
+
* sort({ c: 3, a: 1, b: 2 }); -> { a: 1, b: 2, c: 3 }
|
|
1457
|
+
* sort(new Map([[2, { n: 1, id: 'p' }], [0, { n: 1, id: 'q' }], [1, { n: 0, id: 'r' }]]), 'n');
|
|
1458
|
+
* -> { 0: { n: 0, id: 'r' }, 1: { n: 1, id: 'p' }, 2: { n: 1, id: 'q' } }
|
|
1459
|
+
*/
|
|
1460
|
+
export declare function sort<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback?: ((value: TValue, key: MapArrayKey<TKey>) => unknown) | string | readonly SortSpec<TValue>[] | null): Record<string, TValue>;
|
|
1461
|
+
export declare function sort<TMap>(data: MapData<TMap>, callback?: ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown) | string | readonly SortSpec<MapEntryValue<TMap>>[] | null): Record<string, MapEntryValue<TMap>>;
|
|
1462
|
+
export declare function sort(data: NonKeyedItems, callback?: ((value: unknown, key: string | number) => unknown) | string | readonly SortSpec<unknown>[] | null): Record<string, never>;
|
|
1463
|
+
export declare function sort(data: NonObjectItems, callback?: ((value: unknown, key: string | number) => unknown) | string | readonly SortSpec<unknown>[] | null): Record<string, unknown>;
|
|
1464
|
+
export declare function sort<T extends object>(data: T, callback?: SortCallback<T>): ReindexedObject<T>;
|
|
1465
|
+
export declare function sort(data: unknown, callback?: ((value: unknown, key: string | number) => unknown) | string | readonly SortSpec<unknown>[] | null): Record<string, unknown>;
|
|
1466
|
+
/**
|
|
1467
|
+
* Sort the object in descending order using the given callback, "dot"
|
|
1468
|
+
* notation, or an array of sort descriptors for multi-key sorting.
|
|
1469
|
+
*
|
|
1470
|
+
* Integer-like keys are renumbered over the sorted sequence.
|
|
1471
|
+
*
|
|
1472
|
+
* A Map's ties keep its insertion order, and keys PHP stores as one (`1` and `"1"`) are one item, with the last value.
|
|
1473
|
+
*
|
|
1474
|
+
* @see Arr::sortDesc — `packages/arr/stubs/Arr.php:1139`. Delegates to `Collection::sortByDesc`.
|
|
1475
|
+
*
|
|
1476
|
+
* @param data - The object or Map to sort.
|
|
1477
|
+
* @param callback - The value extractor callback, field name, sort descriptors, or null for natural sorting.
|
|
1478
|
+
* @returns A new object with sorted entries in descending order.
|
|
1479
|
+
*
|
|
1480
|
+
* @example
|
|
1481
|
+
*
|
|
1482
|
+
* sortDesc({ a: 1, c: 3, b: 2 }); -> { c: 3, b: 2, a: 1 }
|
|
1483
|
+
* sortDesc(new Map([[2, { n: 1, id: 'p' }], [0, { n: 1, id: 'q' }], [1, { n: 0, id: 'r' }]]), 'n');
|
|
1484
|
+
* -> { 0: { n: 1, id: 'p' }, 1: { n: 1, id: 'q' }, 2: { n: 0, id: 'r' } }
|
|
1485
|
+
*/
|
|
1486
|
+
export declare function sortDesc<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback?: ((value: TValue, key: MapArrayKey<TKey>) => unknown) | string | readonly SortSpec<TValue>[] | null): Record<string, TValue>;
|
|
1487
|
+
export declare function sortDesc<TMap>(data: MapData<TMap>, callback?: ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown) | string | readonly SortSpec<MapEntryValue<TMap>>[] | null): Record<string, MapEntryValue<TMap>>;
|
|
1488
|
+
export declare function sortDesc(data: NonKeyedItems, callback?: ((value: unknown, key: string | number) => unknown) | string | readonly SortSpec<unknown>[] | null): Record<string, never>;
|
|
1489
|
+
export declare function sortDesc(data: NonObjectItems, callback?: ((value: unknown, key: string | number) => unknown) | string | readonly SortSpec<unknown>[] | null): Record<string, unknown>;
|
|
1490
|
+
export declare function sortDesc<T extends object>(data: T, callback?: SortCallback<T>): ReindexedObject<T>;
|
|
1491
|
+
export declare function sortDesc(data: unknown, callback?: ((value: unknown, key: string | number) => unknown) | string | readonly SortSpec<unknown>[] | null): Record<string, unknown>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Recursively sort an object by keys and values.
|
|
1494
|
+
* Only arrays and plain objects are sorted; any other object value (a class instance, Date or Map) is kept as it is.
|
|
1495
|
+
*
|
|
1496
|
+
* A Map passed as the data is read in its insertion order, so `[1 => 'a', 0 => 'b']` is not a list and sorts by key.
|
|
1497
|
+
* Declared types, pinned in `obj-residuals.test-d.ts`, keep a top-level `Date` (runtime `{}`) and a tuple unsorted.
|
|
1498
|
+
*
|
|
1499
|
+
* @param data - The object or Map to sort recursively.
|
|
1500
|
+
* @param descending - Whether to sort in descending order.
|
|
1501
|
+
* @returns A new recursively sorted object.
|
|
1502
|
+
*
|
|
1503
|
+
* @example
|
|
1504
|
+
*
|
|
1505
|
+
* sortRecursive({ b: { d: 2, c: 1 }, a: { f: 4, e: 3 } }); -> { a: { e: 3, f: 4 }, b: { c: 1, d: 2 } }
|
|
1506
|
+
* sortRecursive({ user1: { name: 'john', age: 30 }, user2: { name: 'jane', age: 25 } }); -> sorted objects with sorted keys
|
|
1507
|
+
* sortRecursive(new Map([[1, 'a'], [0, 'b']])); -> { 0: 'b', 1: 'a' }
|
|
1508
|
+
*/
|
|
1509
|
+
export declare function sortRecursive<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, descending?: CaseValue<typeof SortDirection> | boolean): Record<string, TValue>;
|
|
1510
|
+
export declare function sortRecursive<TMap>(data: MapData<TMap>, descending?: CaseValue<typeof SortDirection> | boolean): Record<string, MapEntryValue<TMap>>;
|
|
1511
|
+
export declare function sortRecursive(data: NonKeyedItems, descending?: CaseValue<typeof SortDirection> | boolean): Record<string, never>;
|
|
1512
|
+
export declare function sortRecursive(data: NonObjectItems, descending?: CaseValue<typeof SortDirection> | boolean): Record<string, unknown>;
|
|
1513
|
+
export declare function sortRecursive<T extends object>(data: T, descending?: CaseValue<typeof SortDirection> | boolean): T;
|
|
1514
|
+
export declare function sortRecursive(data: unknown, descending?: CaseValue<typeof SortDirection> | boolean): Record<string, unknown>;
|
|
1515
|
+
/**
|
|
1516
|
+
* Recursively sort an object by keys and values in descending order.
|
|
1517
|
+
*
|
|
1518
|
+
* A Map passed as the data is read in its insertion order, as `sortRecursive` reads it, so `[2 => 'c', 0 => 'a',
|
|
1519
|
+
* 1 => 'b']` is not a list and is sorted by key; a Map inside the data is kept as it is.
|
|
1520
|
+
*
|
|
1521
|
+
* @param data - The object or Map to sort recursively in descending order.
|
|
1522
|
+
* @returns A new recursively sorted object in descending order.
|
|
1523
|
+
*
|
|
1524
|
+
* @example
|
|
1525
|
+
*
|
|
1526
|
+
* sortRecursiveDesc({ a: { e: 3, f: 4 }, b: { c: 1, d: 2 } }); -> { b: { d: 2, c: 1 }, a: { f: 4, e: 3 } }
|
|
1527
|
+
* sortRecursiveDesc(new Map([[2, 'c'], [0, 'a'], [1, 'b']])); -> { 0: 'a', 1: 'b', 2: 'c' }
|
|
1528
|
+
*/
|
|
1529
|
+
export declare function sortRecursiveDesc<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): Record<string, TValue>;
|
|
1530
|
+
export declare function sortRecursiveDesc<TMap>(data: MapData<TMap>): Record<string, MapEntryValue<TMap>>;
|
|
1531
|
+
export declare function sortRecursiveDesc(data: NonKeyedItems): Record<string, never>;
|
|
1532
|
+
export declare function sortRecursiveDesc(data: NonObjectItems): Record<string, unknown>;
|
|
1533
|
+
export declare function sortRecursiveDesc<T extends object>(data: T): T;
|
|
1534
|
+
export declare function sortRecursiveDesc(data: unknown): Record<string, unknown>;
|
|
1535
|
+
/**
|
|
1536
|
+
* Splice a portion of the underlying object, mutating it in place, like PHP's `array_splice()`.
|
|
1537
|
+
*
|
|
1538
|
+
* String keys keep theirs; integer keys, negative ones included, reindex from 0. Writes go through `defineKey` so a
|
|
1539
|
+
* `__proto__` entry becomes a real own key. A Map, like a Map replacement, is spliced by its insertion order, and it
|
|
1540
|
+
* is rewritten in place, integer keys as numbers, even if typed `ReadonlyMap`.
|
|
1541
|
+
*
|
|
1542
|
+
* @see Collection::splice — `packages/collection/stubs/Collection.php:1768`. Wraps `array_splice`; mutates.
|
|
1543
|
+
*
|
|
1544
|
+
* @param data - The object or Map to splice. Mutated in place.
|
|
1545
|
+
* @param offset - The starting index, by entry order (not by key); a fraction is dropped, as array_splice() drops it
|
|
1546
|
+
* @param length - The number of entries to remove, a fraction dropped. Null or none removes everything from offset on.
|
|
1547
|
+
* @param replacement - Object(s) whose values are spliced in at offset, renumbered from 0
|
|
1548
|
+
* @returns The removed entries, as `array_splice` returns them: string keys kept, integer keys renumbered from 0.
|
|
1549
|
+
* @throws TypeError when the offset or the length is NAN, infinite or outside PHP's int range, which array_splice()
|
|
1550
|
+
* refuses.
|
|
1551
|
+
*
|
|
1552
|
+
* @example
|
|
1553
|
+
*
|
|
1554
|
+
* splice({ a: 1, b: 2, c: 3 }, 1, 1); -> { b: 2 }
|
|
1555
|
+
* splice({ 5: 'e', s: 'S' }, 0, 1); -> { 0: 'e' }
|
|
1556
|
+
* splice(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 1, 1, ['R']); -> { 0: 'a' },
|
|
1557
|
+
* leaving the Map holding [[0, 'c'], [1, 'R'], [2, 'b']]
|
|
1558
|
+
*/
|
|
1559
|
+
export declare function splice<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, offset: number, length?: number | null, ...replacement: unknown[]): Record<string, TValue>;
|
|
1560
|
+
export declare function splice<TMap>(data: MapData<TMap>, offset: number, length?: number | null, ...replacement: unknown[]): Record<string, MapEntryValue<TMap>>;
|
|
1561
|
+
export declare function splice(data: NonKeyedItems | null | undefined, offset: number, length?: number | null, ...replacement: unknown[]): Record<string, never>;
|
|
1562
|
+
export declare function splice(data: NonObjectItems | null | undefined, offset: number, length?: number | null, ...replacement: unknown[]): Record<string, unknown>;
|
|
1563
|
+
export declare function splice<T extends object>(data: T, offset: number, length?: number | null, ...replacement: unknown[]): Partial<ReindexedObject<T>>;
|
|
1564
|
+
export declare function splice(data: unknown, offset: number, length?: number | null, ...replacement: unknown[]): Record<string, unknown>;
|
|
1565
|
+
/**
|
|
1566
|
+
* Take items in the object until the given condition is met.
|
|
1567
|
+
*
|
|
1568
|
+
* A value is compared with PHP's `===`; a callback is handed each value and key, and PHP truthiness judges its answer.
|
|
1569
|
+
* A Map is walked in its insertion order.
|
|
1570
|
+
*
|
|
1571
|
+
* @param data - The object or Map to take items from.
|
|
1572
|
+
* @param value - The value to take until, or a callback answering whether an item meets the condition.
|
|
1573
|
+
* @returns A new object of the items before the first that meets the condition, each under its own key.
|
|
1574
|
+
*
|
|
1575
|
+
* @example
|
|
1576
|
+
*
|
|
1577
|
+
* takeUntil({ a: 1, b: 2, c: 3 }, 3); -> { a: 1, b: 2 }
|
|
1578
|
+
* takeUntil({ a: 1, b: 2, c: 3 }, (value, key) => key === 'c'); -> { a: 1, b: 2 }
|
|
1579
|
+
* takeUntil(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 'a'); -> { 2: 'c' }
|
|
1580
|
+
*/
|
|
1581
|
+
export declare function takeUntil<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: NoInfer<TValue> | ((value: TValue, key: MapArrayKey<TKey>) => unknown)): Record<string, TValue>;
|
|
1582
|
+
export declare function takeUntil<TMap>(data: MapData<TMap>, value: MapEntryValue<TMap> | ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown)): Record<string, MapEntryValue<TMap>>;
|
|
1583
|
+
export declare function takeUntil(data: NonKeyedItems, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, never>;
|
|
1584
|
+
export declare function takeUntil(data: NonObjectItems, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, unknown>;
|
|
1585
|
+
export declare function takeUntil<T extends object>(data: T, value: ObjectValue<T> | ((value: ObjectValue<T>, key: ObjectKey<T>) => unknown)): Partial<T>;
|
|
1586
|
+
export declare function takeUntil(data: unknown, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, unknown>;
|
|
1587
|
+
/**
|
|
1588
|
+
* Take items in the object while the given condition is met.
|
|
1589
|
+
*
|
|
1590
|
+
* A value is compared with PHP's `===`; a callback is handed each value and key, and PHP truthiness judges its answer.
|
|
1591
|
+
* A Map is walked in its insertion order.
|
|
1592
|
+
*
|
|
1593
|
+
* @param data - The object or Map to take items from.
|
|
1594
|
+
* @param value - The value to take while items equal it, or a callback answering whether an item meets the condition.
|
|
1595
|
+
* @returns A new object of the items before the first that fails the condition, each under its own key.
|
|
1596
|
+
*
|
|
1597
|
+
* @example
|
|
1598
|
+
*
|
|
1599
|
+
* takeWhile({ a: 1, b: 1, c: 2, d: 1 }, 1); -> { a: 1, b: 1 }
|
|
1600
|
+
* takeWhile({ a: 1, b: 2, c: 3 }, (value) => value < 3); -> { a: 1, b: 2 }
|
|
1601
|
+
* takeWhile(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 'c'); -> { 2: 'c' }
|
|
1602
|
+
*/
|
|
1603
|
+
export declare function takeWhile<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: NoInfer<TValue> | ((value: TValue, key: MapArrayKey<TKey>) => unknown)): Record<string, TValue>;
|
|
1604
|
+
export declare function takeWhile<TMap>(data: MapData<TMap>, value: MapEntryValue<TMap> | ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown)): Record<string, MapEntryValue<TMap>>;
|
|
1605
|
+
export declare function takeWhile(data: NonKeyedItems, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, never>;
|
|
1606
|
+
export declare function takeWhile(data: NonObjectItems, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, unknown>;
|
|
1607
|
+
export declare function takeWhile<T extends object>(data: T, value: ObjectValue<T> | ((value: ObjectValue<T>, key: ObjectKey<T>) => unknown)): Partial<T>;
|
|
1608
|
+
export declare function takeWhile(data: unknown, value: AnyValueOr<(value: unknown, key: string | number) => unknown>): Record<string, unknown>;
|
|
1609
|
+
/**
|
|
1610
|
+
* Get a string item from an object using "dot" notation.
|
|
1611
|
+
* Throws an error if the value is not a string.
|
|
1612
|
+
*
|
|
1613
|
+
* @param data - The object to get the item from.
|
|
1614
|
+
* @param key - The key or dot-notated path of the item to get.
|
|
1615
|
+
* @param defaultValue - The default value if key is not found.
|
|
1616
|
+
* @returns The string value.
|
|
1617
|
+
* @throws InvalidArgumentException if the value is not a string.
|
|
1618
|
+
*
|
|
1619
|
+
* @example
|
|
1620
|
+
*
|
|
1621
|
+
* string({ name: 'John', age: 30 }, 'name'); -> 'John'
|
|
1622
|
+
* string({ user: { name: 'John' } }, 'user.name'); -> 'John'
|
|
1623
|
+
* string({ user: { age: 30 } }, 'user.age'); -> throws InvalidArgumentException
|
|
1624
|
+
*/
|
|
1625
|
+
export declare function string(data: unknown, key: PathKey, defaultValue?: Default<string> | null): string;
|
|
1626
|
+
/**
|
|
1627
|
+
* Conditionally compile CSS classes from an object into a CSS class list.
|
|
1628
|
+
*
|
|
1629
|
+
* A Map is read in its insertion order, so integer and string keys stay interleaved as they were written.
|
|
1630
|
+
*
|
|
1631
|
+
* @param data - The object or Map to convert to CSS classes.
|
|
1632
|
+
* @returns A string of CSS classes separated by spaces.
|
|
1633
|
+
*
|
|
1634
|
+
* @example
|
|
1635
|
+
*
|
|
1636
|
+
* toCssClasses({ 'font-bold': true, 'mt-4': true }); -> 'font-bold mt-4'
|
|
1637
|
+
* toCssClasses({ 'font-bold': true, 'text-red': false, 'ml-2': true }); -> 'font-bold ml-2'
|
|
1638
|
+
* toCssClasses({ primary: true, secondary: false }); -> 'primary'
|
|
1639
|
+
* toCssClasses({ 0: 'font-bold', 1: 'mt-4', 'ml-2': true, 'mr-2': false }); -> 'font-bold mt-4 ml-2'
|
|
1640
|
+
* toCssClasses(new Map([[2, 'c2'], ['x', true], [0, 'c0']])); -> 'c2 x c0'
|
|
1641
|
+
*/
|
|
1642
|
+
export declare function toCssClasses(data: ReadonlyMap<unknown, unknown>): string;
|
|
1643
|
+
export declare function toCssClasses(data: unknown): string;
|
|
1644
|
+
/**
|
|
1645
|
+
* Conditionally compile CSS styles from an object into a CSS style list.
|
|
1646
|
+
*
|
|
1647
|
+
* A Map is read in its insertion order, so integer and string keys stay interleaved as they were written.
|
|
1648
|
+
*
|
|
1649
|
+
* @param data - The object or Map to convert to CSS styles.
|
|
1650
|
+
* @returns A string of CSS styles separated by spaces, each ending with semicolon.
|
|
1651
|
+
*
|
|
1652
|
+
* @example
|
|
1653
|
+
*
|
|
1654
|
+
* toCssStyles({ 'font-weight: bold': true, 'margin-top: 4px': true }); -> 'font-weight: bold; margin-top: 4px;'
|
|
1655
|
+
* toCssStyles({ 'font-weight: bold': true, 'color: red': false, 'margin-left: 2px': true }); -> 'font-weight: bold; margin-left: 2px;'
|
|
1656
|
+
* toCssStyles({ 0: 'font-weight: bold', 'margin-left: 2px;': true }); -> 'font-weight: bold; margin-left: 2px;'
|
|
1657
|
+
* toCssStyles(new Map([['x:1', true], [0, 'z:0'], ['y:1', true]])); -> 'x:1; z:0; y:1;'
|
|
1658
|
+
*/
|
|
1659
|
+
export declare function toCssStyles(data: ReadonlyMap<unknown, unknown>): string;
|
|
1660
|
+
export declare function toCssStyles(data: unknown): string;
|
|
1661
|
+
/**
|
|
1662
|
+
* Filter the object using the given callback.
|
|
1663
|
+
*
|
|
1664
|
+
* A Map is walked in its insertion order, so the callback sees its items in PHP's order.
|
|
1665
|
+
*
|
|
1666
|
+
* @param data - The object or Map to filter.
|
|
1667
|
+
* @param callback - The function to call for each item (value, key) => boolean.
|
|
1668
|
+
* @returns A new filtered object.
|
|
1669
|
+
*
|
|
1670
|
+
* @example
|
|
1671
|
+
*
|
|
1672
|
+
* where({ a: 1, b: 2, c: 3, d: 4 }, (value) => value > 2); -> { c: 3, d: 4 }
|
|
1673
|
+
* where({ name: 'John', age: null, city: 'NYC' }, (value) => value !== null); -> { name: 'John', city: 'NYC' }
|
|
1674
|
+
* where(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), () => ++calls <= 1); -> { 2: 'c' }
|
|
1675
|
+
*/
|
|
1676
|
+
export declare function where<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => unknown): Record<string, TValue>;
|
|
1677
|
+
export declare function where<TMap>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown): Record<string, MapEntryValue<TMap>>;
|
|
1678
|
+
export declare function where(data: NonKeyedItems, callback: (value: unknown, key: string | number) => unknown): Record<string, never>;
|
|
1679
|
+
export declare function where(data: NonObjectItems, callback: (value: unknown, key: string | number) => unknown): Record<string, unknown>;
|
|
1680
|
+
export declare function where<T extends object>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => unknown): Partial<T>;
|
|
1681
|
+
export declare function where(data: unknown, callback: (value: unknown, key: string | number) => unknown): Record<string, unknown>;
|
|
1682
|
+
/**
|
|
1683
|
+
* Filter the object using the negation of the given callback.
|
|
1684
|
+
*
|
|
1685
|
+
* A Map is walked in its insertion order, as `where` walks it.
|
|
1686
|
+
*
|
|
1687
|
+
* @param data - The object or Map to filter.
|
|
1688
|
+
* @param callback - The function to call for each item (value, key) => boolean.
|
|
1689
|
+
* @returns A new filtered object with items that fail the test.
|
|
1690
|
+
*
|
|
1691
|
+
* @example
|
|
1692
|
+
*
|
|
1693
|
+
* reject({ a: 1, b: 2, c: 3, d: 4 }, (value) => value > 2); -> { a: 1, b: 2 }
|
|
1694
|
+
* reject({ name: 'John', age: null, city: 'NYC' }, (value) => value === null); -> { name: 'John', city: 'NYC' }
|
|
1695
|
+
* reject(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), () => ++calls <= 1); -> { 0: 'a', 1: 'b' }
|
|
1696
|
+
*/
|
|
1697
|
+
export declare function reject<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => unknown): Record<string, TValue>;
|
|
1698
|
+
export declare function reject<TMap>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown): Record<string, MapEntryValue<TMap>>;
|
|
1699
|
+
export declare function reject(data: NonKeyedItems, callback: (value: unknown, key: string | number) => unknown): Record<string, never>;
|
|
1700
|
+
export declare function reject(data: NonObjectItems, callback: (value: unknown, key: string | number) => unknown): Record<string, unknown>;
|
|
1701
|
+
export declare function reject<T extends object>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => unknown): Partial<T>;
|
|
1702
|
+
export declare function reject(data: unknown, callback: (value: unknown, key: string | number) => unknown): Record<string, unknown>;
|
|
1703
|
+
/**
|
|
1704
|
+
* Replace the data items with the given replacer items, like PHP's
|
|
1705
|
+
* `array_replace()` / `Collection::replace()`.
|
|
1706
|
+
*
|
|
1707
|
+
* Returns a new object rather than mutating `data`; a `null`/`undefined` replacer
|
|
1708
|
+
* is a no-op (`CollectionTest.php:1515`). Writes go through `defineKey` so a
|
|
1709
|
+
* `__proto__` key on `replacerData` becomes a real own key (see `isUnsafeKey`,
|
|
1710
|
+
* AGENTS.md:189).
|
|
1711
|
+
*
|
|
1712
|
+
* @see Collection::replace — `packages/collection/stubs/Collection.php:1183`. Wraps `array_replace`.
|
|
1713
|
+
*
|
|
1714
|
+
* @param data - The original object to replace items in. Never mutated.
|
|
1715
|
+
* @param replacerData - The object or list containing items to replace. `null`/`undefined` is a no-op.
|
|
1716
|
+
* @returns A new object with the replaced items.
|
|
1717
|
+
*/
|
|
1718
|
+
export declare function replace<T2>(data: NonObjectItems | null | undefined, replacerData: T2): SpreadObjects<Record<number, unknown>, ArrayableItems<T2>>;
|
|
1719
|
+
export declare function replace<T1 extends object>(data: T1, replacerData: null | undefined): T1;
|
|
1720
|
+
export declare function replace<T1 extends object, T2 extends object>(data: T1, replacerData: T2): SpreadObjects<T1, ArrayableItems<T2>>;
|
|
1721
|
+
export declare function replace<T1 extends object, T2 extends object>(data: T1, replacerData: T2 | null | undefined): T1 | SpreadObjects<T1, ArrayableItems<T2>>;
|
|
1722
|
+
export declare function replace(data: unknown, replacerData: unknown): Record<string, unknown>;
|
|
1723
|
+
/**
|
|
1724
|
+
* Recursively replace the data items with the given items, like PHP's
|
|
1725
|
+
* `array_replace_recursive()` / `Collection::replaceRecursive()`.
|
|
1726
|
+
*
|
|
1727
|
+
* Builds a new object at every recursion level rather than mutating `data`. A
|
|
1728
|
+
* `null`/`undefined` replacer is a no-op (`CollectionTest.php:1557`). Only
|
|
1729
|
+
* `__proto__` is skipped on `replacerData` — the sole prototype-pollution hazard
|
|
1730
|
+
* (see `isUnsafeKey`, AGENTS.md:189); `constructor`/`prototype` write normally.
|
|
1731
|
+
*
|
|
1732
|
+
* @see Collection::replaceRecursive — `packages/collection/stubs/Collection.php:1194`. Wraps `array_replace_recursive`.
|
|
1733
|
+
*
|
|
1734
|
+
* @param data - The original object to replace items in. Never mutated. `null`/`undefined` is treated as empty.
|
|
1735
|
+
* @param replacerData - The object containing items to replace. `null`/`undefined` is a no-op.
|
|
1736
|
+
* @returns A new, recursively merged object.
|
|
1737
|
+
*/
|
|
1738
|
+
export declare function replaceRecursive<T2>(data: NonObjectItems | null | undefined, replacerData: T2): DeepMergeObjects<Record<number, unknown>, T2>;
|
|
1739
|
+
export declare function replaceRecursive<T1 extends object>(data: T1, replacerData: null | undefined): T1;
|
|
1740
|
+
export declare function replaceRecursive<T1 extends object, T2 extends object>(data: T1, replacerData: T2): DeepMergeObjects<T1, T2>;
|
|
1741
|
+
export declare function replaceRecursive<T1 extends object, T2 extends object>(data: T1, replacerData: T2 | null | undefined): T1 | DeepMergeObjects<T1, T2>;
|
|
1742
|
+
export declare function replaceRecursive(data: unknown, replacerData: unknown): Record<string, unknown>;
|
|
1743
|
+
/**
|
|
1744
|
+
* Reverse the order of the object's entries.
|
|
1745
|
+
*
|
|
1746
|
+
* String keys keep theirs; integer-like keys are renumbered over the reversed
|
|
1747
|
+
* sequence, since JS always re-sorts them ascending on write (ECMA-262).
|
|
1748
|
+
*
|
|
1749
|
+
* A Map is reversed from its insertion order, and its integer keys are renumbered over that reversed order.
|
|
1750
|
+
*
|
|
1751
|
+
* @see Collection::reverse — `packages/collection/stubs/Collection.php:1204`. Wraps `array_reverse($items, true)`.
|
|
1752
|
+
*
|
|
1753
|
+
* @param data - The object or Map to reverse.
|
|
1754
|
+
* @returns A new object with reversed entries.
|
|
1755
|
+
*
|
|
1756
|
+
* @example
|
|
1757
|
+
*
|
|
1758
|
+
* reverse({ a: 1, b: 2, c: 3 }); -> { c: 3, b: 2, a: 1 }
|
|
1759
|
+
* reverse(new Map([[2, 'c'], [0, 'a'], [1, 'b']])); -> { 0: 'b', 1: 'a', 2: 'c' }
|
|
1760
|
+
*/
|
|
1761
|
+
export declare function reverse<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): Record<string, TValue>;
|
|
1762
|
+
export declare function reverse<TMap>(data: MapData<TMap>): Record<string, MapEntryValue<TMap>>;
|
|
1763
|
+
export declare function reverse(data: NonKeyedItems): Record<string, never>;
|
|
1764
|
+
export declare function reverse(data: NonObjectItems): Record<string, unknown>;
|
|
1765
|
+
export declare function reverse<T extends object>(data: T): ReindexedObject<T>;
|
|
1766
|
+
export declare function reverse(data: unknown): Record<string, unknown>;
|
|
1767
|
+
/**
|
|
1768
|
+
* Pad object to the specified length with a value.
|
|
1769
|
+
*
|
|
1770
|
+
* Pad slots join the integer-key sequence, as `array_pad` numbers them, renumbering negative keys too; string keys
|
|
1771
|
+
* keep theirs, though JS lists integer-like keys first. A Map's integer keys are renumbered in its insertion order,
|
|
1772
|
+
* and a Map that needs no padding comes back as a record of its entries, keys unchanged.
|
|
1773
|
+
*
|
|
1774
|
+
* @see Collection::pad — `packages/collection/stubs/Collection.php:1917`. Wraps `array_pad`.
|
|
1775
|
+
*
|
|
1776
|
+
* @param data - The object or Map to pad.
|
|
1777
|
+
* @param size - The desired size of the object after padding. Positive to pad at the end, negative to pad at the beginning.
|
|
1778
|
+
* A fraction is dropped.
|
|
1779
|
+
* @param value - The value to use for padding.
|
|
1780
|
+
* @returns A new padded object.
|
|
1781
|
+
* @throws TypeError when the size is NAN, infinite or outside PHP's int range, as array_pad() refuses it.
|
|
1782
|
+
* @throws Error when the size is past PHP's maximum array size, as array_pad()'s ValueError.
|
|
1783
|
+
*
|
|
1784
|
+
* @example
|
|
1785
|
+
*
|
|
1786
|
+
* pad({ a: 1, b: 2 }, 4, 0); -> { 0: 0, 1: 0, a: 1, b: 2 }
|
|
1787
|
+
* pad(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), 4, 'P'); -> { 0: 'c', 1: 'a', 2: 'b', 3: 'P' }
|
|
1788
|
+
*/
|
|
1789
|
+
export declare function pad<TValue, TKey, P>(data: ReadonlyMap<TKey, TValue>, size: number, value: P): Record<string, TValue | P>;
|
|
1790
|
+
export declare function pad<TMap, P>(data: MapData<TMap>, size: number, value: P): Record<string, MapEntryValue<TMap> | P>;
|
|
1791
|
+
export declare function pad<P>(data: NonKeyedItems, size: number, value: P): Record<number, P>;
|
|
1792
|
+
export declare function pad<P>(data: NonObjectItems, size: number, value: P): Record<string | number, unknown>;
|
|
1793
|
+
export declare function pad<T extends object, P>(data: T, size: number, value: P): RenumberedObject<T, P>;
|
|
1794
|
+
export declare function pad<P>(data: unknown, size: number, value: P): Record<string | number, unknown>;
|
|
1795
|
+
/**
|
|
1796
|
+
* Partition the object into two objects using the given callback.
|
|
1797
|
+
*
|
|
1798
|
+
* A Map is walked in its insertion order, so the callback sees its items in PHP's order.
|
|
1799
|
+
*
|
|
1800
|
+
* @param data - The object or Map to partition.
|
|
1801
|
+
* @param callback - The function to call for each item (value, key) => boolean.
|
|
1802
|
+
* @returns A tuple containing [passed, failed] objects.
|
|
1803
|
+
*
|
|
1804
|
+
* @example
|
|
1805
|
+
*
|
|
1806
|
+
* partition({ a: 1, b: 2, c: 3, d: 4 }, (value) => value > 2); -> [{ c: 3, d: 4 }, { a: 1, b: 2 }]
|
|
1807
|
+
* partition({ name: 'John', age: null, city: 'NYC' }, (value) => value !== null); -> [{ name: 'John', city: 'NYC' }, { age: null }]
|
|
1808
|
+
* partition(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), () => ++calls <= 1); -> [{ 2: 'c' }, { 0: 'a', 1: 'b' }]
|
|
1809
|
+
*/
|
|
1810
|
+
export declare function partition<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => unknown): [Record<string, TValue>, Record<string, TValue>];
|
|
1811
|
+
export declare function partition<TMap>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown): [Record<string, MapEntryValue<TMap>>, Record<string, MapEntryValue<TMap>>];
|
|
1812
|
+
export declare function partition(data: NonKeyedItems, callback: (value: unknown, key: string | number) => unknown): [Record<string, never>, Record<string, never>];
|
|
1813
|
+
export declare function partition(data: NonObjectItems, callback: (value: unknown, key: string | number) => unknown): [Record<string, unknown>, Record<string, unknown>];
|
|
1814
|
+
export declare function partition<T extends object>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => unknown): [Partial<T>, Partial<T>];
|
|
1815
|
+
export declare function partition(data: unknown, callback: (value: unknown, key: string | number) => unknown): [Record<string, unknown>, Record<string, unknown>];
|
|
1816
|
+
/**
|
|
1817
|
+
* Filter items where the value is not null.
|
|
1818
|
+
*
|
|
1819
|
+
* A Map is walked in its insertion order, as `where` walks it. Of the Map keys PHP stores as
|
|
1820
|
+
* one, such as `1` and `"1"`, only the last value is tested, so a `null` written last drops the key.
|
|
1821
|
+
*
|
|
1822
|
+
* @param data - The object or Map to filter.
|
|
1823
|
+
* @returns A new object with null values removed.
|
|
1824
|
+
*
|
|
1825
|
+
* @example
|
|
1826
|
+
*
|
|
1827
|
+
* whereNotNull({ a: 1, b: null, c: 2, d: undefined, e: 3 }); -> { a: 1, c: 2, d: undefined, e: 3 }
|
|
1828
|
+
* whereNotNull({ name: 'John', age: null, city: 'NYC' }); -> { name: 'John', city: 'NYC' }
|
|
1829
|
+
* whereNotNull(new Map([[1, 'a'], ['x', 'm'], ['1', null]])); -> { x: 'm' }
|
|
1830
|
+
*/
|
|
1831
|
+
export declare function whereNotNull<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): Record<string, Exclude<TValue, null>>;
|
|
1832
|
+
export declare function whereNotNull<TMap>(data: MapData<TMap>): Record<string, Exclude<MapEntryValue<TMap>, null>>;
|
|
1833
|
+
export declare function whereNotNull(data: NonKeyedItems): Record<string, never>;
|
|
1834
|
+
export declare function whereNotNull(data: NonObjectItems): Record<string, unknown>;
|
|
1835
|
+
export declare function whereNotNull<T extends object>(data: T): NonNullableObject<T>;
|
|
1836
|
+
export declare function whereNotNull(data: unknown): Record<string, unknown>;
|
|
1837
|
+
/**
|
|
1838
|
+
* Determine if an object contains a given value, a matching entry, or a matching key path.
|
|
1839
|
+
*
|
|
1840
|
+
* With no fourth argument, a boolean or absent third is the `strict` flag and any other is the key/value form's value;
|
|
1841
|
+
* a fourth makes the third the operator. So a value that may be `boolean` (`unknown`, or a union or type parameter
|
|
1842
|
+
* holding it) is written `contains(data, key, "=", value)`. A Map is read in its insertion order.
|
|
1843
|
+
*
|
|
1844
|
+
* @see Collection::contains — `packages/collection/stubs/Collection.php:196`.
|
|
1845
|
+
*
|
|
1846
|
+
* @param data - The object or Map to search in.
|
|
1847
|
+
* @param value - The value to search for, or the key path when a third argument follows.
|
|
1848
|
+
* @param key - The dot path read from each entry, a predicate, or null for the entry itself.
|
|
1849
|
+
* @param operator - One of PHP's `where()` operators when a fourth argument follows; any other shares the `=` arm.
|
|
1850
|
+
* @param strict - Whether to use strict comparison.
|
|
1851
|
+
* @returns True if the value is found, false otherwise.
|
|
1852
|
+
*
|
|
1853
|
+
* @example
|
|
1854
|
+
*
|
|
1855
|
+
* contains({ name: 'John', age: 30, city: 'NYC' }, 'John'); -> true
|
|
1856
|
+
* contains({ name: 'John', age: 30, city: 'NYC' }, 'Jane'); -> false
|
|
1857
|
+
* contains({ users: { 1: 'John', 2: 'Jane' } }, 'John'); -> false (nested values)
|
|
1858
|
+
* contains({ a: { age: 30 } }, 'age', 30); -> true (key/value)
|
|
1859
|
+
* contains({ a: { age: 30 } }, 'age', '>', 25); -> true (key/operator/value)
|
|
1860
|
+
* contains({ a: { on: true } }, 'on', '=', true); -> true (a boolean value needs the operator)
|
|
1861
|
+
* contains(new Map([[2, null], [0, 'a']]), () => true, true); -> true (a match holding null counts)
|
|
1862
|
+
* contains(new Map([[1, 'a'], ['1', 'b']]), 'a'); -> false (PHP keeps only 'b')
|
|
1863
|
+
*/
|
|
1864
|
+
export declare function contains<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, value: (value: TValue, key: MapArrayKey<TKey>) => unknown, strict?: boolean): boolean;
|
|
1865
|
+
export declare function contains<TMap>(data: MapData<TMap>, value: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown, strict?: boolean): boolean;
|
|
1866
|
+
export declare function contains(data: ReadonlyMap<unknown, unknown>, value: unknown, strict?: boolean): boolean;
|
|
1867
|
+
export declare function contains(data: NonKeyedItems, value: unknown, strict?: boolean): boolean;
|
|
1868
|
+
export declare function contains(data: NonObjectItems, value: (value: unknown, key: string | number) => unknown, strict?: boolean): boolean;
|
|
1869
|
+
export declare function contains(data: NonObjectItems, value: unknown, strict?: boolean): boolean;
|
|
1870
|
+
export declare function contains<T extends object>(data: T, value: (value: ObjectValue<T>, key: ObjectKey<T>) => unknown, strict?: boolean): boolean;
|
|
1871
|
+
export declare function contains(data: unknown, value: unknown, strict?: boolean): boolean;
|
|
1872
|
+
export declare function contains<TValue>(data: unknown, key: PathKey | ((value: TValue, key: PropertyKey) => unknown), operator: unknown, value: unknown): boolean;
|
|
1873
|
+
export declare function contains<TValue>(data: unknown, key: PathKey | ((value: TValue, key: PropertyKey) => unknown), value: NonBooleanValue): boolean;
|
|
1874
|
+
/**
|
|
1875
|
+
* Check if an object contains a given value, using strict comparison.
|
|
1876
|
+
*
|
|
1877
|
+
* With a second argument, each entry's `key` path is compared with it the way PHP's
|
|
1878
|
+
* `===` compares — so an array or plain object matches by value, in order. Without one,
|
|
1879
|
+
* this is `contains(data, key, true)`: `in_array($key, $items, true)` for a value, and
|
|
1880
|
+
* `array_any($items, $key)` for a callback, so a match holding null counts.
|
|
1881
|
+
*
|
|
1882
|
+
* @see Collection::containsStrict — `packages/collection/stubs/Collection.php:216`.
|
|
1883
|
+
*
|
|
1884
|
+
* @param data - The object to search in.
|
|
1885
|
+
* @param key - The value to search for, or the path to compare when `value` is given.
|
|
1886
|
+
* @param value - The value the path must strictly equal.
|
|
1887
|
+
* @returns True if the item is found, false otherwise.
|
|
1888
|
+
*
|
|
1889
|
+
* @example
|
|
1890
|
+
*
|
|
1891
|
+
* containsStrict({ a: 1, b: '02' }, '02'); -> true
|
|
1892
|
+
* containsStrict({ a: 1, b: '02' }, 2); -> false
|
|
1893
|
+
* containsStrict({ row: { tags: ['a', 'b'] } }, 'tags', ['a', 'b']); -> true
|
|
1894
|
+
* containsStrict({ a: 1, b: null }, (value) => value === null); -> true
|
|
1895
|
+
*/
|
|
1896
|
+
export declare function containsStrict<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, key: TValue | ((value: TValue, key: MapArrayKey<TKey>) => unknown)): boolean;
|
|
1897
|
+
export declare function containsStrict<TMap>(data: MapData<TMap>, key: MapEntryValue<TMap> | ((value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown)): boolean;
|
|
1898
|
+
export declare function containsStrict(data: NonKeyedItems, key: unknown): boolean;
|
|
1899
|
+
export declare function containsStrict(data: NonObjectItems, key: (value: unknown, key: string | number) => unknown): boolean;
|
|
1900
|
+
export declare function containsStrict(data: NonObjectItems, key: unknown): boolean;
|
|
1901
|
+
export declare function containsStrict<T extends object>(data: T, key: ObjectValue<T> | ((value: ObjectValue<T>, key: ObjectKey<T>) => unknown)): boolean;
|
|
1902
|
+
export declare function containsStrict(data: unknown, key: AnyValueOr<(value: unknown, key: string | number) => unknown>, value?: unknown): boolean;
|
|
1903
|
+
/**
|
|
1904
|
+
* Filter the object using the given callback.
|
|
1905
|
+
*
|
|
1906
|
+
* A Map is walked in its insertion order, so the callback sees its items in PHP's order.
|
|
1907
|
+
*
|
|
1908
|
+
* @see Collection::filter — `packages/collection/stubs/Collection.php:425`.
|
|
1909
|
+
* With a callback, delegates to `Arr::where()`; without one, wraps `array_filter`.
|
|
1910
|
+
*
|
|
1911
|
+
* @param data - The object or Map to filter.
|
|
1912
|
+
* @param callback - The function to call for each item (value, key) => boolean.
|
|
1913
|
+
* @returns A new filtered object.
|
|
1914
|
+
*
|
|
1915
|
+
* @example
|
|
1916
|
+
*
|
|
1917
|
+
* filter({ a: 1, b: 2, c: 3, d: 4 }, (value) => value > 2); -> { c: 3, d: 4 }
|
|
1918
|
+
* filter({ name: 'John', age: null, city: 'NYC' }, (value) => value !== null); -> { name: 'John', city: 'NYC' }
|
|
1919
|
+
* filter({ a: "0", b: "", c: 0, d: "x" }); -> { d: "x" }
|
|
1920
|
+
* filter({ a: "00", b: "0.0" }); -> { a: "00", b: "0.0" }
|
|
1921
|
+
* filter(new Map([[2, 'c'], [0, 'a'], [1, 'b']]), () => ++calls <= 2); -> { 2: 'c', 0: 'a' }
|
|
1922
|
+
*/
|
|
1923
|
+
export declare function filter<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback?: null | undefined): Record<string, TruthyValue<TValue>>;
|
|
1924
|
+
export declare function filter<TValue, TKey>(data: ReadonlyMap<TKey, TValue>, callback: (value: TValue, key: MapArrayKey<TKey>) => unknown): Record<string, TValue>;
|
|
1925
|
+
export declare function filter<TMap>(data: MapData<TMap>, callback?: null | undefined): Record<string, TruthyValue<MapEntryValue<TMap>>>;
|
|
1926
|
+
export declare function filter<TMap>(data: MapData<TMap>, callback: (value: MapEntryValue<TMap>, key: MapEntryKey<TMap>) => unknown): Record<string, MapEntryValue<TMap>>;
|
|
1927
|
+
export declare function filter(data: NonKeyedItems | null | undefined, callback?: ((value: unknown, key: string | number) => unknown) | null): Record<string, never>;
|
|
1928
|
+
export declare function filter(data: NonObjectItems | null | undefined, callback?: ((value: unknown, key: string | number) => unknown) | null): Record<string, unknown>;
|
|
1929
|
+
export declare function filter<T extends object>(data: T, callback?: null | undefined): TruthyObject<T>;
|
|
1930
|
+
export declare function filter<T extends object>(data: T, callback: (value: ObjectValue<T>, key: ObjectKey<T>) => unknown): Partial<T>;
|
|
1931
|
+
export declare function filter(data: unknown, callback?: ((value: unknown, key: string | number) => unknown) | null): Record<string, unknown>;
|
|
1932
|
+
/**
|
|
1933
|
+
* If the given value is not an object and not null, wrap it in one.
|
|
1934
|
+
*
|
|
1935
|
+
* A plain object or a `Map` already holds array entries and is returned as-is. A `Date`,
|
|
1936
|
+
* a `Set` or a class instance is wrapped, as PHP's `Arr::wrap` wraps every non-array.
|
|
1937
|
+
*
|
|
1938
|
+
* @param value - The value to wrap.
|
|
1939
|
+
* @returns An object containing the value, or an empty object if null.
|
|
1940
|
+
*
|
|
1941
|
+
* @example
|
|
1942
|
+
*
|
|
1943
|
+
* wrap('hello'); -> { 0: 'hello' }
|
|
1944
|
+
* wrap({ hello: 'world' }); -> { hello: 'world' }
|
|
1945
|
+
* wrap(new Date()); -> { 0: Date }
|
|
1946
|
+
* wrap(null); -> {}
|
|
1947
|
+
* wrap(undefined); -> { 0: undefined }
|
|
1948
|
+
*/
|
|
1949
|
+
export declare function wrap(value: null): Record<string, never>;
|
|
1950
|
+
export declare function wrap<T>(value: T): WrapResult<T>;
|
|
1951
|
+
/**
|
|
1952
|
+
* Get all keys from an object.
|
|
1953
|
+
*
|
|
1954
|
+
* Reads a record's own enumerable string keys, as `Object.keys()` does, so its length always matches `values()`'s.
|
|
1955
|
+
* A Map's keys come back in its insertion order, each the key PHP stores for it, and keys PHP stores as one, such as
|
|
1956
|
+
* `1` and `"1"`, are reported once, where the first of them stood.
|
|
1957
|
+
*
|
|
1958
|
+
* @see Collection::keys — `packages/collection/stubs/Collection.php:793`. Wraps `array_keys`.
|
|
1959
|
+
*
|
|
1960
|
+
* @param data - The object or Map to get keys from.
|
|
1961
|
+
* @returns An array of all keys.
|
|
1962
|
+
*
|
|
1963
|
+
* @example
|
|
1964
|
+
*
|
|
1965
|
+
* keys({ name: 'John', 1: 'one' }); -> [1, 'name']
|
|
1966
|
+
* keys(new Map([[2, 'c'], [0, 'a'], [1, 'b']])); -> [2, 0, 1]
|
|
1967
|
+
*/
|
|
1968
|
+
export declare function keys<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): MapArrayKey<TKey>[];
|
|
1969
|
+
export declare function keys<TMap>(data: MapData<TMap>): MapEntryKey<TMap>[];
|
|
1970
|
+
export declare function keys(data: NonKeyedItems): [];
|
|
1971
|
+
export declare function keys(data: NonObjectItems): (string | number)[];
|
|
1972
|
+
export declare function keys<T extends object>(data: T): BareObjectKey<T>[];
|
|
1973
|
+
export declare function keys(data: unknown): (string | number)[];
|
|
1974
|
+
/**
|
|
1975
|
+
* Get all values from an object.
|
|
1976
|
+
*
|
|
1977
|
+
* A Map's values come back in its insertion order, as `array_values` lists the PHP array it stands for; of Map keys
|
|
1978
|
+
* PHP stores as one, such as `1` and `"1"`, only the last value is listed, where the first of them stood.
|
|
1979
|
+
*
|
|
1980
|
+
* @see Collection::values — `packages/collection/stubs/Collection.php:1883`.
|
|
1981
|
+
* Wraps `array_values`.
|
|
1982
|
+
*
|
|
1983
|
+
* @param data - The object or Map to get values from.
|
|
1984
|
+
* @returns An array of all values.
|
|
1985
|
+
*
|
|
1986
|
+
* @example
|
|
1987
|
+
*
|
|
1988
|
+
* values({ name: 'John', age: 30, city: 'NYC' }); -> ['John', 30, 'NYC']
|
|
1989
|
+
* values({}); -> []
|
|
1990
|
+
* values(new Map([[2, 'c'], [0, 'a'], [1, 'b']])); -> ['c', 'a', 'b']
|
|
1991
|
+
*/
|
|
1992
|
+
export declare function values<TValue, TKey>(data: ReadonlyMap<TKey, TValue>): TValue[];
|
|
1993
|
+
export declare function values<TMap>(data: MapData<TMap>): MapEntryValue<TMap>[];
|
|
1994
|
+
export declare function values(data: NonKeyedItems): [];
|
|
1995
|
+
export declare function values(data: NonObjectItems): unknown[];
|
|
1996
|
+
export declare function values<T extends object>(data: T): BareObjectValue<T>[];
|
|
1997
|
+
export declare function values(data: unknown): unknown[];
|
|
1998
|
+
/**
|
|
1999
|
+
* Get the items that are not present in the given object.
|
|
2000
|
+
*
|
|
2001
|
+
* Compares by value only, using PHP's `(string) $a === (string) $b` rule (see
|
|
2002
|
+
* `phpValueMatch`); unlike `diffAssoc`, a matching key on `other` with a different
|
|
2003
|
+
* value does not save the item. `other` is normalized by `arrayableValues`.
|
|
2004
|
+
*
|
|
2005
|
+
* @see Collection::diff — `packages/collection/stubs/Collection.php:277`. Wraps `array_diff`.
|
|
2006
|
+
*
|
|
2007
|
+
* @param data - The original object.
|
|
2008
|
+
* @param other - The object (or array) to compare against.
|
|
2009
|
+
* @returns A new object containing items from data whose value is not present in other.
|
|
2010
|
+
*/
|
|
2011
|
+
export declare function diff(data: NonObjectItems, other: unknown): Record<string, never>;
|
|
2012
|
+
export declare function diff<T1 extends object>(data: T1, other: unknown): Partial<T1>;
|
|
2013
|
+
export declare function diff(data: unknown, other: unknown): Record<string, unknown>;
|
|
2014
|
+
/**
|
|
2015
|
+
* Diff the object with the given other object, comparing both keys and values.
|
|
2016
|
+
*
|
|
2017
|
+
* This is `array_diff_assoc` — unlike `diff`, matching by key+value, not by value
|
|
2018
|
+
* alone. A non-accessible `other` is treated as empty, so every entry of `data` survives.
|
|
2019
|
+
*
|
|
2020
|
+
* @see Collection::diffAssoc — `packages/collection/stubs/Collection.php:300`. Wraps `array_diff_assoc`.
|
|
2021
|
+
*
|
|
2022
|
+
* @param data - The original object
|
|
2023
|
+
* @param other - The object to diff against
|
|
2024
|
+
* @returns A new object containing key-value pairs not present in other
|
|
2025
|
+
*/
|
|
2026
|
+
export declare function diffAssoc(data: NonObjectItems, other: unknown): Record<string, never>;
|
|
2027
|
+
export declare function diffAssoc<T1 extends object>(data: T1, other: unknown): Partial<T1>;
|
|
2028
|
+
export declare function diffAssoc(data: unknown, other: unknown): Record<string, unknown>;
|
|
2029
|
+
/**
|
|
2030
|
+
* Get the entries whose key is not present in the given other object.
|
|
2031
|
+
*
|
|
2032
|
+
* This is `array_diff_key` — values are ignored entirely; only the key decides.
|
|
2033
|
+
* `other` is normalized by `arrayableItems`, so a nullish operand keeps every entry.
|
|
2034
|
+
*
|
|
2035
|
+
* @see Collection::diffKeys — `packages/collection/stubs/Collection.php:323`. Wraps `array_diff_key`.
|
|
2036
|
+
*
|
|
2037
|
+
* @param data - The original object
|
|
2038
|
+
* @param other - The object to diff against
|
|
2039
|
+
* @returns A new object holding the entries whose key is not in other
|
|
2040
|
+
*
|
|
2041
|
+
* @example
|
|
2042
|
+
*
|
|
2043
|
+
* diffKeys({ id: 1, first_word: 'Hello' }, { id: 123, foo_bar: 'Hello' }); -> { first_word: 'Hello' }
|
|
2044
|
+
* diffKeys({ a: 1, b: 2 }, { a: 999 }); -> { b: 2 }
|
|
2045
|
+
*/
|
|
2046
|
+
export declare function diffKeys(data: NonObjectItems, other: unknown): Record<string, never>;
|
|
2047
|
+
export declare function diffKeys<T1 extends object>(data: T1, other: unknown): Partial<T1>;
|
|
2048
|
+
export declare function diffKeys(data: unknown, other: unknown): Record<string, unknown>;
|
|
2049
|
+
/**
|
|
2050
|
+
* Get the entries whose value is not present in the given other object, comparing with a callback.
|
|
2051
|
+
*
|
|
2052
|
+
* This is `array_udiff` — the callback replaces `diff`'s `(string)` cast comparison and
|
|
2053
|
+
* reports whether two values are equal. `other` is normalized by `arrayableValues`.
|
|
2054
|
+
*
|
|
2055
|
+
* @see Collection::diffUsing — `packages/collection/stubs/Collection.php:289`. Wraps `array_udiff`.
|
|
2056
|
+
*
|
|
2057
|
+
* @param data - The original object
|
|
2058
|
+
* @param other - The object to diff against
|
|
2059
|
+
* @param callable - Function that reports whether two values are equal
|
|
2060
|
+
* @returns A new object holding the entries no value of other is equal to
|
|
2061
|
+
*
|
|
2062
|
+
* @example
|
|
2063
|
+
*
|
|
2064
|
+
* const strcasecmp = (a: unknown, b: unknown) => String(a).toLowerCase() === String(b).toLowerCase();
|
|
2065
|
+
* diffUsing({ a: 'green', b: 'brown' }, { A: 'GREEN' }, strcasecmp); -> { b: 'brown' }
|
|
2066
|
+
*/
|
|
2067
|
+
export declare function diffUsing(data: NonObjectItems, other: unknown, callable: (a: unknown, b: unknown) => boolean): Record<string, never>;
|
|
2068
|
+
export declare function diffUsing<T1 extends object, T2 extends object>(data: T1, other: T2 | null | undefined, callable: (a: ObjectValue<T1>, b: ObjectValue<ArrayableItems<T2>>) => boolean): Partial<T1>;
|
|
2069
|
+
export declare function diffUsing(data: unknown, other: unknown, callable: (a: unknown, b: unknown) => boolean): Record<string, unknown>;
|
|
2070
|
+
/**
|
|
2071
|
+
* Diff the data object with the given other object using a callback for key comparison.
|
|
2072
|
+
* Compares keys using the callback and values using PHP's `(string)` cast rule.
|
|
2073
|
+
*
|
|
2074
|
+
* @see Collection::diffAssocUsing — `packages/collection/stubs/Collection.php:312`.
|
|
2075
|
+
* Wraps `array_diff_uassoc`. Obj-only — `Arr.php` has no equivalent, so there is no `arr.diffAssocUsing`.
|
|
2076
|
+
*
|
|
2077
|
+
* @param data - The original object
|
|
2078
|
+
* @param other - The object to diff against
|
|
2079
|
+
* @param callback - Function to compare keys (returns true if keys match)
|
|
2080
|
+
* @returns A new object containing key-value pairs not present in other
|
|
2081
|
+
*
|
|
2082
|
+
* @example
|
|
2083
|
+
*
|
|
2084
|
+
* const strcasecmp = (a: unknown, b: unknown) => String(a).toLowerCase() === String(b).toLowerCase();
|
|
2085
|
+
* diffAssocUsing({a: 'green', b: 'brown'}, {A: 'green', c: 'blue'}, strcasecmp); -> {b: 'brown'}
|
|
2086
|
+
* diffAssocUsing({a: 'green', b: 'brown'}, {A: 'yellow'}, strcasecmp); -> {a: 'green', b: 'brown'}
|
|
2087
|
+
*/
|
|
2088
|
+
export declare function diffAssocUsing(data: NonObjectItems, other: unknown, callback: (keyA: string | number, keyB: string | number) => boolean): Record<string, never>;
|
|
2089
|
+
export declare function diffAssocUsing<T1 extends object, T2 extends object>(data: T1, other: T2 | null | undefined, callback: KeyComparator<T1, T2>): Partial<T1>;
|
|
2090
|
+
export declare function diffAssocUsing(data: unknown, other: unknown, callback: (keyA: string | number, keyB: string | number) => boolean): Record<string, unknown>;
|
|
2091
|
+
/**
|
|
2092
|
+
* Diff the data object with the given other object using a callback for key comparison only.
|
|
2093
|
+
* Compares keys using the callback and ignores values completely.
|
|
2094
|
+
*
|
|
2095
|
+
* @see Collection::diffKeysUsing — `packages/collection/stubs/Collection.php:335`.
|
|
2096
|
+
* Wraps `array_diff_ukey`. Obj-only — `Arr.php` has no equivalent, so there is no `arr.diffKeysUsing`.
|
|
2097
|
+
*
|
|
2098
|
+
* @param data - The original object
|
|
2099
|
+
* @param other - The object to diff against
|
|
2100
|
+
* @param callback - Function to compare keys (returns true if keys match)
|
|
2101
|
+
* @returns A new object containing key-value pairs whose keys are not present in other
|
|
2102
|
+
*
|
|
2103
|
+
* @example
|
|
2104
|
+
*
|
|
2105
|
+
* const strcasecmp = (a: unknown, b: unknown) => String(a).toLowerCase() === String(b).toLowerCase();
|
|
2106
|
+
* diffKeysUsing({id: 1, first_word: 'Hello'}, {ID: 123, foo_bar: 'Hello'}, strcasecmp); -> {first_word: 'Hello'}
|
|
2107
|
+
* diffKeysUsing({a: 1, b: 2}, {A: 999}, strcasecmp); -> {b: 2}
|
|
2108
|
+
*/
|
|
2109
|
+
export declare function diffKeysUsing(data: NonObjectItems, other: unknown, callback: (keyA: string | number, keyB: string | number) => boolean): Record<string, never>;
|
|
2110
|
+
export declare function diffKeysUsing<T1 extends object, T2 extends object>(data: T1, other: T2 | null | undefined, callback: KeyComparator<T1, T2>): Partial<T1>;
|
|
2111
|
+
export declare function diffKeysUsing(data: unknown, other: unknown, callback: (keyA: string | number, keyB: string | number) => boolean): Record<string, unknown>;
|
|
2112
|
+
/**
|
|
2113
|
+
* Intersect the data object with the given other object.
|
|
2114
|
+
*
|
|
2115
|
+
* Compares by value only, using PHP's `(string) $a === (string) $b` rule (see
|
|
2116
|
+
* `phpValueMatch`); unlike `intersectAssoc`, `key in other` is not required.
|
|
2117
|
+
* `callable`, when given, replaces the comparator (PHP's `array_uintersect()`
|
|
2118
|
+
* style; folds Laravel's `intersectUsing()` into this parameter). `other` is
|
|
2119
|
+
* normalized by `arrayableValues`.
|
|
2120
|
+
*
|
|
2121
|
+
* @see Collection::intersect — `packages/collection/stubs/Collection.php:663`. Wraps `array_intersect`.
|
|
2122
|
+
*
|
|
2123
|
+
* @param data - The original object
|
|
2124
|
+
* @param other - The object to intersect with
|
|
2125
|
+
* @param callable - Optional function to compare values (array_uintersect-style)
|
|
2126
|
+
* @returns A new object containing data's items whose value is also present in other
|
|
2127
|
+
*/
|
|
2128
|
+
export declare function intersect(data: NonObjectItems, other: unknown, callable?: ((a: unknown, b: unknown) => boolean) | null): Record<string, never>;
|
|
2129
|
+
export declare function intersect<T1 extends object, T2 extends object>(data: T1, other: T2 | null | undefined, callable: (a: ObjectValue<T1>, b: ObjectValue<ArrayableItems<T2>>) => boolean): Partial<T1>;
|
|
2130
|
+
export declare function intersect<T1 extends object>(data: T1, other: unknown, callable?: null | undefined): Partial<T1>;
|
|
2131
|
+
export declare function intersect(data: unknown, other: unknown, callable?: ((a: unknown, b: unknown) => boolean) | null): Record<string, unknown>;
|
|
2132
|
+
/**
|
|
2133
|
+
* Intersect the object with the given items, comparing values with a callback.
|
|
2134
|
+
*
|
|
2135
|
+
* This is `array_uintersect`. It is `intersect`'s third parameter under its own name,
|
|
2136
|
+
* so the two share one algorithm; the callback reports whether two values are equal.
|
|
2137
|
+
*
|
|
2138
|
+
* @see Collection::intersectUsing — `packages/collection/stubs/Collection.php:675`.
|
|
2139
|
+
* Wraps `array_uintersect`.
|
|
2140
|
+
*
|
|
2141
|
+
* @param data - The original object
|
|
2142
|
+
* @param other - The object to intersect with
|
|
2143
|
+
* @param callable - Function that reports whether two values are equal
|
|
2144
|
+
* @returns A new object holding the entries some value of other is equal to
|
|
2145
|
+
*
|
|
2146
|
+
* @example
|
|
2147
|
+
*
|
|
2148
|
+
* const strcasecmp = (a: unknown, b: unknown) => String(a).toLowerCase() === String(b).toLowerCase();
|
|
2149
|
+
* intersectUsing({ a: 'green', b: 'brown' }, { A: 'GREEN' }, strcasecmp); -> { a: 'green' }
|
|
2150
|
+
*/
|
|
2151
|
+
export declare function intersectUsing(data: NonObjectItems, other: unknown, callable: (a: unknown, b: unknown) => boolean): Record<string, never>;
|
|
2152
|
+
export declare function intersectUsing<T1 extends object, T2 extends object>(data: T1, other: T2 | null | undefined, callable: (a: ObjectValue<T1>, b: ObjectValue<ArrayableItems<T2>>) => boolean): Partial<T1>;
|
|
2153
|
+
export declare function intersectUsing(data: unknown, other: unknown, callable: (a: unknown, b: unknown) => boolean): Record<string, unknown>;
|
|
2154
|
+
/**
|
|
2155
|
+
* Intersect the object with the given items with additional key check.
|
|
2156
|
+
* Returns items where both the key AND value match.
|
|
2157
|
+
*
|
|
2158
|
+
* This is `array_intersect_assoc` — unlike `intersect`, `key in other` is required.
|
|
2159
|
+
* A non-accessible `data` or `other` is treated as empty, so the result is `{}`.
|
|
2160
|
+
*
|
|
2161
|
+
* @see Collection::intersectAssoc — `packages/collection/stubs/Collection.php:686`. Wraps `array_intersect_assoc`.
|
|
2162
|
+
*
|
|
2163
|
+
* @param data - The original object
|
|
2164
|
+
* @param other - The object to intersect with
|
|
2165
|
+
* @returns A new object containing items where both key and value match
|
|
2166
|
+
*/
|
|
2167
|
+
export declare function intersectAssoc(data: NonObjectItems, other: unknown): Record<string, never>;
|
|
2168
|
+
export declare function intersectAssoc<T1 extends object>(data: T1, other: unknown): Partial<T1>;
|
|
2169
|
+
export declare function intersectAssoc(data: unknown, other: unknown): Record<string, unknown>;
|
|
2170
|
+
/**
|
|
2171
|
+
* Intersect the object with the given items with additional key check, using the callback.
|
|
2172
|
+
* Values are compared by PHP's `(string)` cast rule; `callback` compares keys.
|
|
2173
|
+
*
|
|
2174
|
+
* A non-accessible `data` or `other` is treated as empty, so the result is `{}`.
|
|
2175
|
+
*
|
|
2176
|
+
* @see Collection::intersectAssocUsing — `packages/collection/stubs/Collection.php:698`. Wraps `array_intersect_uassoc`
|
|
2177
|
+
*
|
|
2178
|
+
* @param data - The original object
|
|
2179
|
+
* @param other - The object to intersect with
|
|
2180
|
+
* @param callback - The callback function to compare keys (returns true if keys match)
|
|
2181
|
+
* @returns A new object containing items where both key (via callback) and value match
|
|
2182
|
+
*/
|
|
2183
|
+
export declare function intersectAssocUsing(data: NonObjectItems, other: unknown, callback: (keyA: string | number, keyB: string | number) => boolean): Record<string, never>;
|
|
2184
|
+
export declare function intersectAssocUsing<T1 extends object, T2 extends object>(data: T1, other: T2 | null | undefined, callback: KeyComparator<T1, T2>): Partial<T1>;
|
|
2185
|
+
export declare function intersectAssocUsing(data: unknown, other: unknown, callback: (keyA: string | number, keyB: string | number) => boolean): Record<string, unknown>;
|
|
2186
|
+
/**
|
|
2187
|
+
* Intersect the object with the given items by key.
|
|
2188
|
+
*
|
|
2189
|
+
* A non-accessible `data` or `other` is treated as empty, so the result is `{}`.
|
|
2190
|
+
*
|
|
2191
|
+
* @see Collection::intersectByKeys — `packages/collection/stubs/Collection.php:709`. Wraps `array_intersect_key`.
|
|
2192
|
+
*
|
|
2193
|
+
* @param data - The original object
|
|
2194
|
+
* @param other - The object to intersect with
|
|
2195
|
+
* @returns A new object containing items with keys present in both objects
|
|
2196
|
+
*/
|
|
2197
|
+
export declare function intersectByKeys(data: NonObjectItems, other: unknown): Record<string, never>;
|
|
2198
|
+
export declare function intersectByKeys<T1 extends object>(data: T1, other: unknown): Partial<T1>;
|
|
2199
|
+
export declare function intersectByKeys(data: unknown, other: unknown): Record<string, unknown>;
|
|
2200
|
+
export {};
|
|
2201
|
+
//# sourceMappingURL=obj.d.ts.map
|