sindresorhus / npm-keyword

Get a list of npm packages with keywords
MIT License
52 stars 8 forks source link

allow custom format for returned array #3

Closed eddiemonge closed 9 years ago

eddiemonge commented 9 years ago

Allows the returned array members to use a custom format. Good for returning an array of strings or different output saving an additional loop after this. (like in https://github.com/yeoman/yeoman-generator-list/pull/23/files#diff-7e051b4df176cc4ddd6101faa1cfd585R22)

kevva commented 9 years ago

Hmm, could we come up with a better name than format?

eddiemonge commented 9 years ago

Hmm, could we come up with a better name than format?

Yes please. I couldn't think of one and did not like format either

sindresorhus commented 9 years ago

As I commented on that PR, something like that doesn't belong in this module. You should rather use filter-obj.

saving an additional loop after this.

Extreme premature optimization.

eddiemonge commented 9 years ago

its not really premature in this instance. with this change, it only requires a map loop through 3000 object once instead of at least twice.

sindresorhus commented 9 years ago

That's exactly the definition of premature optimization. 3000 iterations is negligible.

I wonder though, instead of having the description option, what if we had a new method called npmKeyword.name() that only returned an array of names. That way all this would be moot. Thoughts?

eddiemonge commented 9 years ago

I feel like adding that would internally do the same exact thing as this PR but be less flexible. As a compromise I suppose it could be acceptable.

sindresorhus commented 9 years ago

I feel like adding that would internally do the same exact thing as this PR but be less flexible.

I prefer designing minimalistic interfaces that solve actual problems than prematurely designing for everything. Different mindset I guess.

sindresorhus commented 9 years ago

@eddiemonge Alright. Upgrade to 3.0.0: https://github.com/sindresorhus/npm-keyword#npmkeywordnameskeyword-callback ;)