blob: fcaeda92595e0d7068a1fe4a6d8f5acf189f3be5 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001/*!
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
8'use strict';
9
10var isObject = require('isobject');
11
12module.exports = function visit(thisArg, method, target, val) {
13 if (!isObject(thisArg) && typeof thisArg !== 'function') {
14 throw new Error('object-visit expects `thisArg` to be an object.');
15 }
16
17 if (typeof method !== 'string') {
18 throw new Error('object-visit expects `method` name to be a string');
19 }
20
21 if (typeof thisArg[method] !== 'function') {
22 return thisArg;
23 }
24
25 var args = [].slice.call(arguments, 3);
26 target = target || {};
27
28 for (var key in target) {
29 var arr = [key, target[key]].concat(args);
30 thisArg[method].apply(thisArg, arr);
31 }
32 return thisArg;
33};