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