UNPKG

566 BJavaScriptView Raw
1/*!
2 * object.pick <https://github.com/jonschlinkert/object.pick>
3 *
4 * Copyright (c) 2014-2015 Jon Schlinkert, contributors.
5 * Licensed under the MIT License
6 */
7
8'use strict';
9
10module.exports = function pick(obj, keys) {
11 var res = {};
12 var i = 0;
13
14 if (typeof obj !== 'object') {
15 return res;
16 }
17
18 if (typeof keys === 'string') {
19 if (keys in obj) {
20 res[keys] = obj[keys];
21 }
22 return res;
23 }
24
25 var len = keys.length;
26
27 while (len--) {
28 var key = keys[i++];
29 if (key in obj) {
30 res[key] = obj[key];
31 }
32 }
33 return res;
34};