UNPKG

709 BJavaScriptView Raw
1/*!
2 * collection-visit <https://github.com/jonschlinkert/collection-visit>
3 *
4 * Copyright (c) 2015, 2017, Jon Schlinkert.
5 * Released under the MIT License.
6 */
7
8'use strict';
9
10var visit = require('object-visit');
11var mapVisit = require('map-visit');
12
13module.exports = function(collection, method, val) {
14 var result;
15
16 if (typeof val === 'string' && (method in collection)) {
17 var args = [].slice.call(arguments, 2);
18 result = collection[method].apply(collection, args);
19 } else if (Array.isArray(val)) {
20 result = mapVisit.apply(null, arguments);
21 } else {
22 result = visit.apply(null, arguments);
23 }
24
25 if (typeof result !== 'undefined') {
26 return result;
27 }
28
29 return collection;
30};