millermedeiros / amd-utils

modular JavaScript utilities written in the AMD format
http://millermedeiros.github.com/amd-utils
142 stars 11 forks source link

Add object/filterValues and object/mapValues #77

Closed conradz closed 12 years ago

conradz commented 12 years ago

This adds the object/filterValues() and object/mapValues() functions, which basically do the same thing as array/filter and array/map, except that they use objects instead of arrays.

The use case I had for this was converting a complex object into simple a JSON object, using filterValues() to remove unneeded values and mapValues() to convert to simpler JSON values.

millermedeiros commented 12 years ago

Nice, these methods are indeed useful.

What about naming it object/filter and object/map instead? I know it might sound confusing but in AMD we can give the local variables different names to avoid collisions so having different packages is enough to differ both:

define(['amd-utils/array/map', 'amd-utils/object/map'], function(arrMap, objMap){
  // ...
});

PS: we already have a math/map module and we will probably have other functions in different packages with similar names.

conradz commented 12 years ago

OK, done.

I knew that you could have the same names, but I didn't know if this was desirable. I guess the functions are almost identical except for using objects, so they probably should have the same name.