1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | 'use strict';
|
9 |
|
10 | var visit = require('object-visit');
|
11 | var mapVisit = require('map-visit');
|
12 |
|
13 | module.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 | };
|