Repository URL to install this package:
|
Version:
5.0.0-rc.11 ▾
|
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var util = require('util');
var util__default = _interopDefault(util);
var index = require('../object-visit/index.js');
/**
* Map `visit` over an array of objects.
*
* @param {Object} `collection` The context in which to invoke `method`
* @param {String} `method` Name of the method to call on `collection`
* @param {Object} `arr` Array of objects.
*/
var mapVisit = function mapVisit(collection, method, val) {
if (isObject(val)) {
return index.default.apply(null, arguments);
}
if (!Array.isArray(val)) {
throw new TypeError('expected an array: ' + util__default.inspect(val));
}
var args = [].slice.call(arguments, 3);
for (var i = 0; i < val.length; i++) {
var ele = val[i];
if (isObject(ele)) {
index.default.apply(null, [collection, method, ele].concat(args));
} else {
collection[method].apply(collection, [ele].concat(args));
}
}
};
function isObject(val) {
return val && (typeof val === 'function' || (!Array.isArray(val) && typeof val === 'object'));
}
exports.__moduleExports = mapVisit;
exports.default = mapVisit;
//# sourceMappingURL=index.js.map