UNPKG

@utilify/core

Version:

Modern, strongly typed, and safe utility function library for JavaScript and TypeScript. Includes type checking, manipulation of arrays, objects, strings, dates, colors, numbers, regular expressions, and more. Compatible with Browser, Node.js, Deno, and B

17 lines 698 B
/** * @callback GroupByKeySelector * @template T,K * @param {T} value - The item in the array. * @param {number} index - The index of the item. * @returns {K} The key for grouping. */ /** * Groups array elements by a key selector function. * @template T,K * @param {T[]} array - The array to group. * @param {GroupByKeySelector} [keySelector] - Function to select group key. * @returns {Record<K, T[]>} Object with grouped arrays. * @throws {TypeError} If array is not an array or keySelector is not a function. */ export default function groupBy<T, K extends PropertyKey>(array: T[], keySelector?: (value: T, index: number) => K): Record<K, T[]>; //# sourceMappingURL=groupBy.d.ts.map