omit.js 751 B

12345678910111213141516171819202122232425
  1. var restArguments = require('./restArguments.js');
  2. var isFunction = require('./isFunction.js');
  3. var negate = require('./negate.js');
  4. var map = require('./map.js');
  5. var _flatten = require('./_flatten.js');
  6. var contains = require('./contains.js');
  7. var pick = require('./pick.js');
  8. // Return a copy of the object without the disallowed properties.
  9. var omit = restArguments(function(obj, keys) {
  10. var iteratee = keys[0], context;
  11. if (isFunction(iteratee)) {
  12. iteratee = negate(iteratee);
  13. if (keys.length > 1) context = keys[1];
  14. } else {
  15. keys = map(_flatten(keys, false, false), String);
  16. iteratee = function(value, key) {
  17. return !contains(keys, key);
  18. };
  19. }
  20. return pick(obj, iteratee, context);
  21. });
  22. module.exports = omit;