index.js 830 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*!
  2. * object.omit <https://github.com/jonschlinkert/object.omit>
  3. *
  4. * Copyright (c) 2014-2015, Jon Schlinkert.
  5. * Licensed under the MIT License.
  6. */
  7. 'use strict';
  8. var isObject = require('is-extendable');
  9. var forOwn = require('for-own');
  10. module.exports = function omit(obj, keys) {
  11. if (!isObject(obj)) return {};
  12. keys = [].concat.apply([], [].slice.call(arguments, 1));
  13. var last = keys[keys.length - 1];
  14. var res = {}, fn;
  15. if (typeof last === 'function') {
  16. fn = keys.pop();
  17. }
  18. var isFunction = typeof fn === 'function';
  19. if (!keys.length && !isFunction) {
  20. return obj;
  21. }
  22. forOwn(obj, function(value, key) {
  23. if (keys.indexOf(key) === -1) {
  24. if (!isFunction) {
  25. res[key] = value;
  26. } else if (fn(value, key, obj)) {
  27. res[key] = value;
  28. }
  29. }
  30. });
  31. return res;
  32. };