forked from jashkenas/underscore
-
Notifications
You must be signed in to change notification settings - Fork 0
Mixin Catalog
toekneestuck edited this page Feb 21, 2012
·
61 revisions
This page serves to catalog shared underscore mixins, here and elsewhere.
_.mixin(object)
Allows you to extend Underscore with your own utility functions. Pass a hash of {name: function} definitions to have your functions added to the Underscore object, as well as the OOP wrapper.
_.mixin({
capitalize : function(string) {
return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
}
});
_("fabio").capitalize();
=> "Fabio"
(update me!)
- (Newest) Sam Breed, underscore.deferred implements jQuery-like deferreds in Underscore.
- Matt Mueller, Underscore Extension: Observer Pattern is a set of four Node-like methods – _.on, _.once, _.emit, and _.removeEvent.
- Oleg Slobodskoi (@oleg008) nodejs style _.inherits method using Object.create and fallback to cloning via prototype
- Esa-Matti Suuronen has a sweet git repo named underscore.string which adds many string functions to Underscore.js through mixins.
- Tim Wood created a mixin called underscore.date which is a javascript date library for parsing, manipulating, and formatting dates, without modifying the Date.prototype.
- Omar Yasin published a mixin in this gist that provides a ‘printf’-like functionality
- Xavier Spriet has this gist that has a mixin to emulate ruby’s Array#each_slice method.
- Francesco Agati provides this gist with _.selectIf
- Steven Black, in this gist _.filterObj: Return an object who’s members are culled to match a reference array of keys.
- Vladimir Dronnikov: object helpers _.freeze, _.proxy, _.get
- Vladimir Dronnikov: Practical JSON-schema validator
- Vladimir Dronnikov: Query Language For Arrays/Hashes
- thegrandpoobah suggests this _.retry mixin.
- OnesimusUnbound: counter and cycle generator mixin
- Marçal Juan: compact function for Objects mixin
- Mario T. Lanza: Roll your own objects using not just dynamic values, but dynamic keys.
- Arnau Sanchez: Mixins: merge, mash, takeWhile, mapDetect, uniqWith, flatten1.
- Adrian Lang: _.mapValues mapping Objects to Objects
- Paul Harper (benekastah): underscore.loop – adds scheme/clojure like recursive looping with tail-call optimization.
- Kevin Malakoff (kmalakoff): underscore-awesomer – many “awesome” functions like ‘toJSON’/‘parseJSON’ for instance serializaion/deserializaion, ‘compare’, ‘keypath’ for accessing nested properties, ‘remove’, ‘own’/‘disown’, ‘cloneToDepth’, ‘toType’ conversions using to{X} function as a fallback if the types don’t match, etc.
- Julian Burgess (aubergene): _.rotate – Array rotate mixin
- Trevor Parscal (trevorparscal): more-underscore – More stuff for underscore, such as ‘extendClass’ (prototypical inheritance), ‘objectify’ (combine array values with property names) and ‘traverse’ (get a value from a multi-level collection using an array of keys and indexes).
- tobias104 provides this _.indexBy gist – Combination of _.find and _.indexOf, that returns the index of the first item that passes the test.
- Mark Rushakoff (mark-rushakoff): function binding helpers – provides two functions similar to _.bindAll. _.bindFiltered takes a filter function that operates on function names, and _.bindMatching takes a regex for the names of which functions to bind.
- Adrian Rossouw (Vertice): Partial function application binders – provides a function called _.partial which allows you to bind specific arguments, leaving a closure. Also contains a _.wrapAsync, which turns non-async calls into the format node.js expects. _.partialAsync does both.
- Andreas Briese (AndreasBriese): Addon functions sum, mean, median and nrange (~enhanced range)
-
Simon Kågedal Reimer (skagedal): underscore-pickrandom.js — provides a function,
_.pickRandom(array, [n])
that picks random elements from an array. It works similar to_.first(_.shuffle(array, n))
, but is more efficient; it operates in time proportional ton
rather than the length of the whole array.
- Tony Stuck (toekneestuck): underscore.nl2br – A simple port of nl2br to Underscore for string manipulation.
This page is a bit hard to browse and quickly find what you need. I’d suggest: 1. group mixins by functionality; 2. emphasize what functions each mixin provides with a short description for each function (more like the underscore main page); 3. put less emphasis on the author. /skagedal (sorry if this isn’t the proper way of discussing wiki pages)