import { Key, KeyedValue, PlainObject, Simplify } from "../models.mjs"; //#region src/array/to-record.d.ts /** * Create a record from an array of items using callbacks * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Callback to get an item's grouping key * @param value Callback to get an item's value * @returns Record of keyed values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * item => item.id, * ); // => { 10: 3, 20: 2 } * ``` */ declare function toRecord Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record, ReturnType>; /** * Create a record from an array of items using a callback and value * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param callback Callback to get an item's grouping key * @param value Key to use for value * @returns Record with keys * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 'id', * ); // => { 10: 3, 20: 2 } * ``` */ declare function toRecord Key, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record, Item[ItemValue]>; /** * Create a record from an array of items using a key and callback * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Key to use for grouping * @param callback Callback to get an item's value * @returns Record with keys * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * item => item.id, * ); // => { 10: 3, 20: 2 } * ``` */ declare function toRecord unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify, ReturnType>>; /** * Create a record from an array of items using a key and value * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Key to use for grouping * @param value Key to use for value * @returns Record of keyed values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 'id', * ); // => { 10: 3, 20: 2 } * ``` */ declare function toRecord(array: Item[], key: ItemKey, value: ItemValue): Simplify, Item[ItemValue]>>; /** * Create a record from an array of items using a callback * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param callback Callback to get an item's grouping key * @returns Record of keyed values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} } * ``` */ declare function toRecord Key>(array: Item[], callback: Callback): Record, Item>; /** * Create a record from an array of items using a key * * If multiple items have the same key, the latest item will be used * * @param array Array to convert * @param key Key to use for grouping * @returns Record of keyed values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * ); // => { 10: {id: 3, value: 10}, 20: {id: 2, value: 20} } * ``` */ declare function toRecord(array: Item[], key: ItemKey): Simplify, Item>>; /** * Create a record from an array of items _(using indices as keys)_ * * @param array Array to convert * @returns Record of indiced values * * @example * ```typescript * toRecord( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * ); // => { 0: {id: 1, value: 10}, 1: {id: 2, value: 20}, 2: {id: 3, value: 10} } * ``` */ declare function toRecord(array: Item[]): Record; declare namespace toRecord { var arrays: typeof toRecordArrays; } /** * Create a record from an array of items using callbacks, grouping values into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param key Callback to get an item's grouping key * @param value Callback to get an item's value * @returns Record of keyed arrays of values * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * item => item.id, * ); // => { 10: [1, 3], 20: [2] } * ``` */ declare function toRecordArrays Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record, ReturnType[]>; /** * Create a record from an array of items using a callback and value, grouping values into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param callback Callback to get an item's grouping key * @param value Key to use for value * @returns Record of keyed arrays of values * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * 'id', * ); // => { 10: [1, 3], 20: [2] } * ``` */ declare function toRecordArrays Key, ItemValue extends keyof Item>(array: Item[], callback: Callback, value: ItemValue): Record, Item[ItemValue][]>; /** * Create a record from an array of items using a key and callback, grouping values into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @param callback Callback to get an item's value * @returns Record of keyed arrays of values * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * item => item.id, * ); // => { 10: [1, 3], 20: [2] } * ``` */ declare function toRecordArrays unknown>(array: Item[], key: ItemKey, callback: Callback): Simplify, ReturnType[]>>; /** * Create a record from an array of items using a key and value, grouping values into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @param value Key to use for value * @returns Record of keyed arrays of values * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * 'id', * ); // => { 10: [1, 3], 20: [2] } * ``` */ declare function toRecordArrays(array: Item[], key: ItemKey, value: ItemValue): Simplify, Item[ItemValue][]>>; /** * Create a record from an array of items using a callback, grouping items into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param callback Callback to get an item's grouping key * @returns Record of keyed arrays of items * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * item => item.value, * ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] } * ``` */ declare function toRecordArrays Key>(array: Item[], callback: Callback): Record, Item[]>; /** * Create a record from an array of items using a key, grouping items into arrays * * _Available as `toRecordArrays` and `toRecord.arrays`_ * * @param array Array to convert * @param key Key to use for grouping * @returns Record of keyed arrays of items * * @example * ```typescript * toRecordArrays( * [{id: 1, value: 10}, {id: 2, value: 20}, {id: 3, value: 10}], * 'value', * ); // => { 10: [{id: 1, value: 10}, {id: 3, value: 10}], 20: [{id: 2, value: 20}] } * ``` */ declare function toRecordArrays(array: Item[], key: ItemKey): Simplify, Item[]>>; //#endregion export { toRecord, toRecordArrays };