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.

index.js 806B

123456789101112131415161718192021222324252627282930313233
  1. /*!
  2. * object-visit <https://github.com/jonschlinkert/object-visit>
  3. *
  4. * Copyright (c) 2015, 2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. var isObject = require('isobject');
  9. module.exports = function visit(thisArg, method, target, val) {
  10. if (!isObject(thisArg) && typeof thisArg !== 'function') {
  11. throw new Error('object-visit expects `thisArg` to be an object.');
  12. }
  13. if (typeof method !== 'string') {
  14. throw new Error('object-visit expects `method` name to be a string');
  15. }
  16. if (typeof thisArg[method] !== 'function') {
  17. return thisArg;
  18. }
  19. var args = [].slice.call(arguments, 3);
  20. target = target || {};
  21. for (var key in target) {
  22. var arr = [key, target[key]].concat(args);
  23. thisArg[method].apply(thisArg, arr);
  24. }
  25. return thisArg;
  26. };