diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-12-10 21:51:33 +0100 |
commit | 0469abd4a9c9270a1fdc962969e36e63699af8b4 (patch) | |
tree | f9864d4a4148621378958794cbbfdc2393733283 /node_modules/map-visit/index.js | |
parent | 6947e79bbc258f7bc96af424ddb71a511f0c15a3 (diff) |
upgrade dependencies
Diffstat (limited to 'node_modules/map-visit/index.js')
-rw-r--r-- | node_modules/map-visit/index.js | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/node_modules/map-visit/index.js b/node_modules/map-visit/index.js index 426735d9f..bc54ccc4e 100644 --- a/node_modules/map-visit/index.js +++ b/node_modules/map-visit/index.js @@ -1,6 +1,7 @@ 'use strict'; -var utils = require('./utils'); +var util = require('util'); +var visit = require('object-visit'); /** * Map `visit` over an array of objects. @@ -10,16 +11,27 @@ var utils = require('./utils'); * @param {Object} `arr` Array of objects. */ -module.exports = function mapVisit(collection, method, arr) { - if (!Array.isArray(arr)) { - throw new TypeError('expected an array'); +module.exports = function mapVisit(collection, method, val) { + if (isObject(val)) { + return visit.apply(null, arguments); } - arr.forEach(function(val) { - if (typeof val === 'string') { - collection[method](val); + if (!Array.isArray(val)) { + throw new TypeError('expected an array: ' + util.inspect(val)); + } + + var args = [].slice.call(arguments, 3); + + for (var i = 0; i < val.length; i++) { + var ele = val[i]; + if (isObject(ele)) { + visit.apply(null, [collection, method, ele].concat(args)); } else { - utils.visit(collection, method, val); + collection[method].apply(collection, [ele].concat(args)); } - }); + } }; + +function isObject(val) { + return val && (typeof val === 'function' || (!Array.isArray(val) && typeof val === 'object')); +} |