Ei kuvausta

index.js 709B

123456789101112131415161718192021222324252627282930
  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. 'use strict';
  8. var visit = require('object-visit');
  9. var mapVisit = require('map-visit');
  10. module.exports = function(collection, method, val) {
  11. var result;
  12. if (typeof val === 'string' && (method in collection)) {
  13. var args = [].slice.call(arguments, 2);
  14. result = collection[method].apply(collection, args);
  15. } else if (Array.isArray(val)) {
  16. result = mapVisit.apply(null, arguments);
  17. } else {
  18. result = visit.apply(null, arguments);
  19. }
  20. if (typeof result !== 'undefined') {
  21. return result;
  22. }
  23. return collection;
  24. };