UNPKG

map-fns

Version:

<h1 align="center"> <code>map-fns</code> </h1>

28 lines (26 loc) 840 B
/** * Creates a new `map` populated with every key in the original `map` except the * keys that exist in the `keys` array. * * ```tsx * const out = removeKeysFromMap({ a: 1, b: 2 }, ["b"]); * console.log(out); // { a: 1 } * ``` * * @param map - The map to remove keys from. * @param keys - The keys to remove from the map. * @returns A new map with the removed. */ function removeKeysFromMap(map, keys) { var mapKeys = Object.keys(map); var originalKeyList = Array.isArray(keys) ? keys : [keys]; var stringifiedKeyList = originalKeyList.map(String); var removeKeySet = new Set(stringifiedKeyList); return mapKeys.reduce(function (newMap, key) { if (!removeKeySet.has(key)) { newMap[key] = map[key]; } return newMap; }, {}); } export { removeKeysFromMap as default };