UNPKG

944 BJavaScriptView Raw
1import _curry2 from "./internal/_curry2.js";
2/**
3 * Similar to `pick` except that this one includes a `key: undefined` pair for
4 * properties that don't exist.
5 *
6 * @func
7 * @memberOf R
8 * @since v0.1.0
9 * @category Object
10 * @sig [k] -> {k: v} -> {k: v}
11 * @param {Array} names an array of String property names to copy onto a new object
12 * @param {Object} obj The object to copy from
13 * @return {Object} A new object with only properties from `names` on it.
14 * @see R.pick
15 * @example
16 *
17 * R.pickAll(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
18 * R.pickAll(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, e: undefined, f: undefined}
19 */
20
21var pickAll =
22/*#__PURE__*/
23_curry2(function pickAll(names, obj) {
24 var result = {};
25 var idx = 0;
26 var len = names.length;
27
28 while (idx < len) {
29 var name = names[idx];
30 result[name] = obj[name];
31 idx += 1;
32 }
33
34 return result;
35});
36
37export default pickAll;
\No newline at end of file