remeda
Version:
A utility library for JavaScript and Typescript.
68 lines (66 loc) • 3.08 kB
TypeScript
import { IterableContainer } from "./IterableContainer-B2PfkIAC.js";
import { BoundedPartial } from "./BoundedPartial-BWnS4AxG.js";
//#region src/pullObject.d.ts
/**
* Creates an object that maps the result of `valueExtractor` with a key
* resulting from running `keyExtractor` on each item in `data`. Duplicate keys
* are overwritten, guaranteeing that the extractor functions are run on each
* item in `data`.
*
* There are several other functions that could be used to build an object from
* an array:
* * `fromKeys` - Builds an object from an array of *keys* and a mapper for values.
* * `indexBy` - Builds an object from an array of *values* and a mapper for keys.
* * `fromEntries` - Builds an object from an array of key-value pairs.
* Refer to the docs for more details.
*
* @param data - The items used to pull/extract the keys and values from.
* @param keyExtractor - Computes the key for item.
* @param valueExtractor - Computes the value for the item.
* @signature
* R.pullObject(data, keyExtractor, valueExtractor);
* @example
* R.pullObject(
* [
* { name: "john", email: "john@remedajs.com" },
* { name: "jane", email: "jane@remedajs.com" }
* ],
* R.prop("name"),
* R.prop("email"),
* ); // => { john: "john@remedajs.com", jane: "jane@remedajs.com" }
* @dataFirst
* @category Object
*/
declare function pullObject<T extends IterableContainer, K extends PropertyKey, V>(data: T, keyExtractor: (item: T[number], index: number, data: T) => K, valueExtractor: (item: T[number], index: number, data: T) => V): BoundedPartial<Record<K, V>>;
/**
* Creates an object that maps the result of `valueExtractor` with a key
* resulting from running `keyExtractor` on each item in `data`. Duplicate keys
* are overwritten, guaranteeing that the extractor functions are run on each
* item in `data`.
*
* There are several other functions that could be used to build an object from
* an array:
* * `fromKeys` - Builds an object from an array of *keys* and a mapper for values.
* * `indexBy` - Builds an object from an array of *values* and a mapper for keys.
* * `fromEntries` - Builds an object from an array of key-value pairs.
* Refer to the docs for more details.
*
* @param keyExtractor - Computes the key for item.
* @param valueExtractor - Computes the value for the item.
* @signature
* R.pullObject(keyExtractor, valueExtractor)(data);
* @example
* R.pipe(
* [
* { name: "john", email: "john@remedajs.com" },
* { name: "jane", email: "jane@remedajs.com" }
* ],
* R.pullObject(R.prop("email"), R.prop("name")),
* ); // => { john: "john@remedajs.com", jane: "jane@remedajs.com" }
* @dataLast
* @category Object
*/
declare function pullObject<T extends IterableContainer, K extends PropertyKey, V>(keyExtractor: (item: T[number], index: number, data: T) => K, valueExtractor: (item: T[number], index: number, data: T) => V): (data: T) => BoundedPartial<Record<K, V>>;
//#endregion
export { pullObject };
//# sourceMappingURL=pullObject-DfIYY9qy.d.ts.map