index.js 640 B

123456789101112131415161718192021222324252627282930313233
  1. /*!
  2. * omit-key <https://github.com/jonschlinkert/omit-key>
  3. *
  4. * Copyright (c) 2014 Jon Schlinkert, contributors.
  5. * Licensed under the MIT License
  6. */
  7. 'use strict';
  8. var isObject = require('isobject');
  9. var difference = require('array-difference');
  10. module.exports = function omit(obj, keys) {
  11. if (!isObject(obj)) {
  12. return {};
  13. }
  14. var props = Object.keys(obj);
  15. var len = props.length;
  16. keys = Array.isArray(keys) ? keys : [keys];
  17. var diff = difference(props, keys);
  18. var o = {};
  19. for (var i = 0; i < len; i++) {
  20. var key = diff[i];
  21. if (obj.hasOwnProperty(key)) {
  22. o[key] = obj[key];
  23. }
  24. }
  25. return o;
  26. };