ddopson / underscore-cli

Command-line utility-belt for hacking JSON and Javascript.
Other
1.72k stars 83 forks source link

fix broken iteration via _.map #48

Closed zayass closed 8 years ago

zayass commented 8 years ago

Fix for https://github.com/ddopson/underscore-cli/issues/47

zayass commented 8 years ago

_.map works strange with array of strings Its looks like they cast array to string and then iterate over string

May be it is bug inside underscore However .each looks better for iteration then .map

zayass commented 8 years ago

Looks like problem is here https://github.com/ddopson/underscore-cli/blob/master/lib/underscore.js#L2

Because console.log(_.map.toString()) prints

function(str, callback) {
  str = makeString(str);

  if (str.length === 0 || typeof callback !== 'function') return str;

  return str.replace(/./g, callback);
};

from here https://github.com/epeli/underscore.string/blob/master/map.js

ddopson commented 8 years ago

Strange bug. Thanks for the fix!

This looks like a very safe change.

If you've got an interest in maintaining this tool, let me know. I don't really have much attention span for it these days.