No Description

index.js 630B

1234567891011121314151617181920212223242526272829303132333435
  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. 'use strict';
  8. var isObject = require('isobject');
  9. module.exports = function pick(obj, keys) {
  10. if (!isObject(obj) && typeof obj !== 'function') {
  11. return {};
  12. }
  13. var res = {};
  14. if (typeof keys === 'string') {
  15. if (keys in obj) {
  16. res[keys] = obj[keys];
  17. }
  18. return res;
  19. }
  20. var len = keys.length;
  21. var idx = -1;
  22. while (++idx < len) {
  23. var key = keys[idx];
  24. if (key in obj) {
  25. res[key] = obj[key];
  26. }
  27. }
  28. return res;
  29. };