millermedeiros / amd-utils

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

create a "generic" string/makePath() #67

Closed millermedeiros closed 12 years ago

millermedeiros commented 12 years ago

makePath could be easily abstract to accept any kind of separator and not only "/".

Maybe it should be on the array package and accept a single array instead of multiple arguments. It would be an advanced Array#join().

conradz commented 12 years ago

Any idea of what to name the generic function? Maybe array/joinPath (but this doesn't really emphasize that it can be used with other separators). I was thinking of working on this. Also, the isValidString helper function in makePath should probably be moved to a public module, maybe string/notEmpty or string/isEmpty.

millermedeiros commented 12 years ago

unsure about the name, I was considering maybe just naming it join() since it is basically the way I would like Array#join to work on most cases, but joinPath() and joinSegments() would also make sense.

I didn't created a string/isEmpty() since we can easily compare with str === '' (easier to type). I think a generic lang/isEmpty() would be more useful (which checked for empty arrays, empty objects and empty strings). For now I would probably keep the internal isValidString or avoid the filter altogether and just do a simple loop or change it to a reduce.