helperCreatePickOmit.js 866 B

1234567891011121314151617181920212223242526272829303132
  1. var isFunction = require('./isFunction')
  2. var isArray = require('./isArray')
  3. var each = require('./each')
  4. var findIndexOf = require('./findIndexOf')
  5. function helperCreatePickOmit (case1, case2) {
  6. return function (obj, callback) {
  7. var item, index
  8. var rest = {}
  9. var result = []
  10. var context = this
  11. var args = arguments
  12. var len = args.length
  13. if (!isFunction(callback)) {
  14. for (index = 1; index < len; index++) {
  15. item = args[index]
  16. result.push.apply(result, isArray(item) ? item : [item])
  17. }
  18. callback = 0
  19. }
  20. each(obj, function (val, key) {
  21. if ((callback ? callback.call(context, val, key, obj) : findIndexOf(result, function (name) {
  22. return name === key
  23. }) > -1) ? case1 : case2) {
  24. rest[key] = val
  25. }
  26. })
  27. return rest
  28. }
  29. }
  30. module.exports = helperCreatePickOmit