index.js 613 B

12345678910111213141516171819202122232425
  1. /*!
  2. * collection-map <https://github.com/jonschlinkert/collection-map>
  3. *
  4. * Copyright (c) 2015, 2017, Jon Schlinkert.
  5. * Released under the MIT License.
  6. */
  7. 'use strict';
  8. var makeIterator = require('make-iterator');
  9. var forOwn = require('for-own');
  10. var map = require('arr-map');
  11. module.exports = function(collection, fn, thisArg) {
  12. if (!Array.isArray(collection)) {
  13. var iterator = makeIterator(fn, thisArg);
  14. var result = [];
  15. forOwn(collection, function(value, key) {
  16. result.push(iterator(value, key, collection));
  17. });
  18. return result;
  19. }
  20. return map(collection, fn, thisArg);
  21. };