map-fns
Version:
<h1 align="center"> <code>map-fns</code> </h1>
19 lines (18 loc) • 780 B
TypeScript
import { AnyMap, ItemInMap } from "../types";
/**
* Returns a new array of key, value entries from the provided map. The keys of the entries
* to return may be provided via the `keys` argument.
*
* ```tsx
* const entries = mapEntries({ a: 1, b: 2, c: 3 });
* // > [["a", 1], ["b", 2] ["c", 3]]
*
* const entries = mapEntries({ a: 1, b: 2, c: 3 }, ["b", "a"]);
* // > [["b", 2], ["a", 1]]
* ```
*
* @param map The map to get the entries of.
* @param keys The keys in the map to return as entries.
* @returns An array of key, value pairs for every entry in the map. If `keys` is provided, only the entries for those keys are included.
*/
export default function mapEntries<M extends AnyMap, K extends keyof M = keyof M>(map: M, keys?: K[]): Array<[K, ItemInMap<M>]>;