@monstermann/fn
Version:
A utility library for TypeScript.
25 lines (23 loc) • 582 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
import { markAsMutable } from "@monstermann/remmi";
//#region src/object/pick.ts
/**
* `pick(target, keys)`
*
* Creates a new object containing only the properties specified in the `keys` iterable.
*
* ```ts
* pick({ a: 1, b: 2, c: 3 }, ["a", "c"]); // { a: 1, c: 3 }
* ```
*
* ```ts
* pipe({ a: 1, b: 2, c: 3 }, pick(["a", "c"])); // { a: 1, c: 3 }
* ```
*/
const pick = dfdlT((target, keys) => {
const result = {};
for (const key of keys) result[key] = target[key];
return markAsMutable(result);
}, 2);
//#endregion
export { pick };