wallet-core/node_modules/collection-visit/index.js
2017-08-14 05:02:09 +02:00

34 lines
683 B
JavaScript

/*!
* 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;