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

27 lines 1.11 kB
/** * @callback ArrayToObjectKeyFn * @template T,K * @param {T} item - The item in the array. * @param {number} index - The index of the item. * @param {T[]} array - The array. * @returns {K} The key for the object. */ /** * @callback ArrayToObjectValueFn * @template T * @param {T} item - The item in the array. * @param {number} index - The index of the item. * @param {T[]} array - The array. * @returns {T} The value for the object. */ /** * Converts an array to an object using key and value selector functions. * @template T,K * @param {T[]} array - The array to convert. * @param {ArrayToObjectKeyFn} [keyFn] - Function to select keys. * @param {ArrayToObjectValueFn} [valueFn] - Function to select values. * @returns {Record<K, any>} The resulting object. * @throws {TypeError} If array is not an array or selectors are not functions. */ export default function arrayToObject<T, K extends PropertyKey>(array: T[], keyFn?: (item: T, index: number, array: T[]) => K, valueFn?: (item: T, index: number, array: T[]) => T): Record<K, any>; //# sourceMappingURL=arrayToObject.d.ts.map