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