blob: a431d51890820a32cfdc1431c6f66a93a6fe3c73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
/*!
* collection-visit <https://github.com/jonschlinkert/collection-visit>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var utils = require('./utils');
function collectionVisit(collection, method, val) {
var result;
if (typeof val === 'string' && (method in collection)) {
result = collection[method](val);
} else if (Array.isArray(val)) {
result = utils.mapVisit(collection, method, val);
} else {
result = utils.visit(collection, method, val);
}
if (typeof result !== 'undefined') {
return result;
}
return collection;
}
/**
* Expose `collectionVisit`
*/
module.exports = collectionVisit;
|