wallet-core/node_modules/object-visit/index.js

34 lines
806 B
JavaScript
Raw Normal View History

2017-08-14 05:01:11 +02:00
/*!
* object-visit <https://github.com/jonschlinkert/object-visit>
*
2017-12-10 21:51:33 +01:00
* Copyright (c) 2015, 2017, Jon Schlinkert.
* Released under the MIT License.
2017-08-14 05:01:11 +02:00
*/
'use strict';
var isObject = require('isobject');
2017-12-10 21:51:33 +01:00
module.exports = function visit(thisArg, method, target, val) {
2017-08-14 05:01:11 +02:00
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;
}
2017-12-10 21:51:33 +01:00
var args = [].slice.call(arguments, 3);
2017-08-14 05:01:11 +02:00
target = target || {};
2017-12-10 21:51:33 +01:00
2017-08-14 05:01:11 +02:00
for (var key in target) {
2017-12-10 21:51:33 +01:00
var arr = [key, target[key]].concat(args);
thisArg[method].apply(thisArg, arr);
2017-08-14 05:01:11 +02:00
}
return thisArg;
};