Although I hoped to wait another day or two to talk about this on my blog, circumstances have force my hand. Therefore, I would like to take a few of your spare moments to talk about a new project that I’m working on called underscore-contrib — an extensions library / proving ground for Underscore.js.1
TLDR; The official Github repository is at https://github.com/documentcloud/underscore-contrib — go there and read code.
- Some functions are limited in scope.
- Some functions are lesser known, but are highly useful.
In the case of #1, underscore-contrib can serve as a home for functions that solve certain pointed problems; stopping somewhere below domain-specific. In the case of #2 underscore-contrib will work as a proving ground for features that should be in Underscore proper, but need some advocacy and/or evolution (or devolution) to get them there.
What’s in underscore-contrib?
At the moment, the following contrib libraries are in place:
- underscore.array.builders.js – building arrays
- underscore.array.selectors.js – getting stuff from arrays
- underscore.function.arity.js – partial application/currying
- underscore.function.combinators.js – function combinators
- underscore.function.predicates.js – isX functions return true|false
- underscore.object.builders.js – building objects
- underscore.object.selectors.js – getting stuff from objects
- underscore.util.existential.js – truthiness
- underscore.util.trampolines.js – function trampolining
How to use underscore.contrib
First, you’ll need Underscore. Next you can grab the relevant underscore-contrib libraries and simply add something like the following to your pages:
At the moment there are no cross-contrib dependencies (i.e. each library can stand by itself), but that may change in the future.
How you can help
There is still a lot of work to do around perf, documentation, examples, testing and distribution so any help in those areas is welcomed. Pull requests are accepted, but please search the underscore-contrib issues before proposing a new sub-contrib or addition. Additionally, all patches and proposals should have strong documentation, motivating cases and tests. It would be nice if we could not only provide useful tools built on Underscore, but also provide an educational experience for why and how one might use them
Other (potentially) useful sub-contribs include the following:
- String utilities
- Date/time utilities
What do these mean? Well, that’s up for discussion. :-)