wallet-core/node_modules/collection-visit/index.js

31 lines
709 B
JavaScript
Raw Normal View History

2017-08-14 05:01:11 +02:00
/*!
* collection-visit <https://github.com/jonschlinkert/collection-visit>
*
2017-12-10 21:51:33 +01:00
* Copyright (c) 2015, 2017, Jon Schlinkert.
* Released under the MIT License.
2017-08-14 05:01:11 +02:00
*/
'use strict';
2017-12-10 21:51:33 +01:00
var visit = require('object-visit');
var mapVisit = require('map-visit');
2017-08-14 05:01:11 +02:00
2017-12-10 21:51:33 +01:00
module.exports = function(collection, method, val) {
2017-08-14 05:01:11 +02:00
var result;
if (typeof val === 'string' && (method in collection)) {
2017-12-10 21:51:33 +01:00
var args = [].slice.call(arguments, 2);
result = collection[method].apply(collection, args);
2017-08-14 05:01:11 +02:00
} else if (Array.isArray(val)) {
2017-12-10 21:51:33 +01:00
result = mapVisit.apply(null, arguments);
2017-08-14 05:01:11 +02:00
} else {
2017-12-10 21:51:33 +01:00
result = visit.apply(null, arguments);
2017-08-14 05:01:11 +02:00
}
if (typeof result !== 'undefined') {
return result;
}
2017-12-10 21:51:33 +01:00
return collection;
};