index.js
 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  
10  var isObject = require('isobject');
11  
12  module.exports = function pick(obj, keys) {
13    if (!isObject(obj) && typeof obj !== 'function') {
14      return {};
15    }
16  
17    var res = {};
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    var idx = -1;
27  
28    while (++idx < len) {
29      var key = keys[idx];
30      if (key in obj) {
31        res[key] = obj[key];
32      }
33    }
34    return res;
35  };