You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
747 B

4 years ago
  1. /*!
  2. * object.omit <https://github.com/jonschlinkert/object.omit>
  3. *
  4. * Copyright (c) 2014-2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. var isObject = require('is-extendable');
  9. module.exports = function omit(obj, props, fn) {
  10. if (!isObject(obj)) return {};
  11. if (typeof props === 'function') {
  12. fn = props;
  13. props = [];
  14. }
  15. if (typeof props === 'string') {
  16. props = [props];
  17. }
  18. var isFunction = typeof fn === 'function';
  19. var keys = Object.keys(obj);
  20. var res = {};
  21. for (var i = 0; i < keys.length; i++) {
  22. var key = keys[i];
  23. var val = obj[key];
  24. if (!props || (props.indexOf(key) === -1 && (!isFunction || fn(val, key, obj)))) {
  25. res[key] = val;
  26. }
  27. }
  28. return res;
  29. };