source: node_modules/ramda/es/pick.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 935 bytes
Line 
1import _curry2 from "./internal/_curry2.js";
2/**
3 * Returns a partial copy of an object containing only the keys specified. If
4 * the key does not exist, the property is ignored.
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.omit, R.props
15 * @example
16 *
17 * R.pick(['a', 'd'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1, d: 4}
18 * R.pick(['a', 'e', 'f'], {a: 1, b: 2, c: 3, d: 4}); //=> {a: 1}
19 */
20
21var pick =
22/*#__PURE__*/
23_curry2(function pick(names, obj) {
24 var result = {};
25 var idx = 0;
26
27 while (idx < names.length) {
28 if (names[idx] in obj) {
29 result[names[idx]] = obj[names[idx]];
30 }
31
32 idx += 1;
33 }
34
35 return result;
36});
37
38export default pick;
Note: See TracBrowser for help on using the repository browser.