lodash @ 0.7.0 - README.md
1
# Lo-Dash <sup>v0.7.0</sup>
2
3
A drop-in replacement<sup>[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer)</sup> for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), delivering [performance](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#resolved-underscorejs-issues-20), and [additional features](https://github.com/bestiejs/lodash#features).
4
5
Lo-Dash’s performance is gained by avoiding slower native methods, instead opting for simplified non-ES5 compliant methods optimized for common usage, and by leveraging function compilation to reduce the number of overall function calls.
6
7
## Download
8
9
* [Development source](https://raw.github.com/bestiejs/lodash/v0.7.0/lodash.js)
10
* [Production source](https://raw.github.com/bestiejs/lodash/v0.7.0/lodash.min.js)
11
* CDN copies of ≤ [v0.7.0](http://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.7.0/lodash.min.js) are available on [cdnjs](http://cdnjs.com/) thanks to [CloudFlare](http://www.cloudflare.com/)
12
* For optimal performance, [create a custom build](https://github.com/bestiejs/lodash#custom-builds) with only the features you need
13
14
## Dive in
15
16
We’ve got [API docs](http://lodash.com/docs), [benchmarks](http://lodash.com/benchmarks), and [unit tests](http://lodash.com/tests).
17
18
Create your own benchmarks at [jsPerf](http://jsperf.com), or [search](http://jsperf.com/search?q=lodash) for existing ones.
19
20
For a list of upcoming features, check out our [roadmap](https://github.com/bestiejs/lodash/wiki/Roadmap).
21
22
## Screencasts
23
24
For more information check out these screencasts over Lo-Dash:
25
26
* [Introducing Lo-Dash](https://vimeo.com/44154599)
27
* [Lo-Dash optimizations and custom builds](https://vimeo.com/44154601)
28
* [Lo-Dash’s origin and why it’s a better utility belt](https://vimeo.com/44154600)
29
* [Unit testing in Lo-Dash](https://vimeo.com/45865290)
30
* [Lo-Dash’s approach to native method use](https://vimeo.com/48576012)
31
32
## Features
33
34
* AMD loader support ([RequireJS](http://requirejs.org/), [curl.js](https://github.com/cujojs/curl), etc.)
35
* [_.bind](http://lodash.com/docs#bind) supports *“lazy”* binding
36
* [_.clone](http://lodash.com/docs#clone) supports *“deep”* cloning
37
* [_.countBy](http://lodash.com/docs#countBy) as a companion function for [_.groupBy](http://lodash.com/docs#groupBy) and [_.sortBy](http://lodash.com/docs#sortBy)
38
* [_.debounce](http://lodash.com/docs#debounce)’ed functions match [_.throttle](http://lodash.com/docs#throttle)’ed functions’ return value behavior
39
* [_.forEach](http://lodash.com/docs#forEach) is chainable and supports exiting iteration early
40
* [_.forIn](http://lodash.com/docs#forIn) for iterating over an object’s own and inherited properties
41
* [_.forOwn](http://lodash.com/docs#forOwn) for iterating over an object’s own properties
42
* [_.indexOf](http://lodash.com/docs#indexOf) and [_.lastIndexOf](http://lodash.com/docs#lastIndexOf) accept a `fromIndex` argument
43
* [_.invert](http://lodash.com/docs#invert) to create inverted objects
44
* [_.merge](http://lodash.com/docs#merge) for a *“deep”* [_.extend](http://lodash.com/docs#extend)
45
* [_.object](http://lodash.com/docs#object) and [_.pairs](http://lodash.com/docs#pairs) for composing objects
46
* [_.omit](http://lodash.com/docs#omit) for the inverse functionality of [_.pick](http://lodash.com/docs#pick)
47
* [_.partial](http://lodash.com/docs#partial) for partial application without `this` binding
48
* [_.pick](http://lodash.com/docs#pick) and [_.omit](http://lodash.com/docs#omit) accept `callback` and `thisArg` arguments
49
* [_.random](http://lodash.com/docs#random) for generating random numbers within a given range
50
* [_.sortBy](http://lodash.com/docs#sortBy) performs a [stable](http://en.wikipedia.org/wiki/Sorting_algorithm#Stability) sort
51
* [_.template](http://lodash.com/docs#template) utilizes [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) for easier debugging
52
* [_.unescape](http://lodash.com/docs#unescape) to unescape strings escaped by [_.escape](http://lodash.com/docs#escape)
53
* [_.where](http://lodash.com/docs#where) for filtering collections by contained properties
54
* [_.countBy](http://lodash.com/docs#countBy), [_.groupBy](http://lodash.com/docs#groupBy), [_.sortedIndex](http://lodash.com/docs#sortedIndex), and [_.uniq](http://lodash.com/docs#uniq) accept a `thisArg` argument
55
* [_.contains](http://lodash.com/docs#contains), [_.size](http://lodash.com/docs#size), [_.toArray](http://lodash.com/docs#toArray),
56
[and more…](http://lodash.com/docs "_.countBy, _.every, _.filter, _.find, _.forEach, _.groupBy, _.invoke, _.map, _.pluck, _.reduce, _.reduceRight, _.reject, _.some, _.sortBy, _.where") accept strings
57
58
## Support
59
60
Lo-Dash has been tested in at least Chrome 5-21, Firefox 1-15, IE 6-9, Opera 9.25-12, Safari 3-6, Node.js 0.4.8-0.8.8, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5.
61
62
## Custom builds
63
64
Custom builds make it easy to create lightweight versions of Lo-Dash containing only the methods you need.
65
To top it off, we handle all method dependency and alias mapping for you.
66
67
* Backbone builds, with only methods required by Backbone, may be created using the `backbone` modifier argument.
68
```bash
69
lodash backbone
70
```
71
72
* CSP builds, supporting default Content Security Policy restrictions, may be created using the `csp` modifier argument.
73
```bash
74
lodash csp
75
```
76
77
* Legacy builds, tailored for older browsers without [ES5 support](http://es5.github.com/), may be created using the `legacy` modifier argument.
78
```bash
79
lodash legacy
80
```
81
82
* Mobile builds, with IE < 9 bug fixes and method compilation removed, may be created using the `mobile` modifier argument.
83
```bash
84
lodash mobile
85
```
86
87
* Strict builds, with `_.bindAll`, `_.defaults`, and `_.extend` in [strict mode](http://es5.github.com/#C), may be created using the `strict` modifier argument.
88
```bash
89
lodash strict
90
```
91
92
* Underscore builds, with iteration fixes removed and only Underscore’s API, may be created using the `underscore` modifier argument.
93
```bash
94
lodash underscore
95
```
96
97
Custom builds may be created using the following commands:
98
99
* Use the `category` argument to pass comma separated categories of methods to include in the build.<br>
100
Valid categories are *“arrays”*, *“chaining”*, *“collections”*, *“functions”*, *“objects”*, and *“utilities”*.
101
```bash
102
lodash category=collections,functions
103
lodash category="collections, functions"
104
```
105
106
* Use the `exclude` argument to pass comma separated names of methods to exclude from the build.
107
```bash
108
lodash exclude=union,uniq,zip
109
lodash exclude="union, uniq, zip"
110
```
111
112
* Use the `exports` argument to pass comma separated names of ways to export the `LoDash` function.<br>
113
Valid exports are *“amd”*, *“commonjs”*, *“global”*, *“node”*, and *“none”*.
114
```bash
115
lodash exports=amd,commonjs,node
116
lodash include="amd, commonjs, node"
117
```
118
119
* Use the `iife` argument to specify code to replace the immediately-invoked function expression that wraps Lo-Dash.
120
```bash
121
lodash iife="!function(window,undefined){%output%}(this)"
122
```
123
124
* Use the `include` argument to pass comma separated names of methods to include in the build.
125
```bash
126
lodash include=each,filter,map
127
lodash include="each, filter, map"
128
```
129
130
All arguments, except `exclude` with `include` and `legacy` with `csp`/`mobile`, may be combined.
131
132
```bash
133
lodash backbone legacy exports=global category=utilities exclude=first,last
134
lodash -s underscore mobile strict exports=amd category=functions include=pick,uniq
135
```
136
137
The following options are also supported:
138
139
* `-c`, `--stdout` Write output to standard output
140
* `-h`, `--help` Display help information
141
* `-o`, `--output` Write output to a given path/filename
142
* `-s`, `--silent` Skip status updates normally logged to the console
143
* `-V`, `--version` Output current version of Lo-Dash
144
145
The `lodash` command-line utility is available when Lo-Dash is installed as a global package (i.e. `npm install -g lodash`).
146
147
Custom builds are saved to `lodash.custom.js` and `lodash.custom.min.js`.
148
149
## Installation and usage
150
151
In browsers:
152
153
```html
154
<script src="lodash.js"></script>
155
```
156
157
Using [npm](http://npmjs.org/):
158
159
```bash
160
npm install lodash
161
npm install -g lodash
162
```
163
164
In [Node.js](http://nodejs.org/) and [RingoJS v0.8.0+](http://ringojs.org/):
165
166
```js
167
var _ = require('lodash');
168
```
169
170
In [RingoJS v0.7.0-](http://ringojs.org/):
171
172
```js
173
var _ = require('lodash')._;
174
```
175
176
In [Rhino](http://www.mozilla.org/rhino/):
177
178
```js
179
load('lodash.js');
180
```
181
182
In an AMD loader like [RequireJS](http://requirejs.org/):
183
184
```js
185
require({
186
'paths': {
187
'underscore': 'path/to/lodash'
188
}
189
},
190
['underscore'], function(_) {
191
console.log(_.VERSION);
192
});
193
```
194
195
## Resolved Underscore.js issues <sup>(20+)</sup>
196
197
* Allow iteration of objects with a `length` property [[#148](https://github.com/documentcloud/underscore/issues/148), [#154](https://github.com/documentcloud/underscore/issues/154), [#252](https://github.com/documentcloud/underscore/issues/252), [#448](https://github.com/documentcloud/underscore/issues/448), [#659](https://github.com/documentcloud/underscore/issues/659), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L543-549)]
198
* Ensure array-like objects with invalid `length` properties are treated like regular objects [[#741](https://github.com/documentcloud/underscore/issues/741), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L491-501)]
199
* Ensure *“Arrays”*, *“Collections”*, and *“Objects”* methods don’t error when passed falsey arguments [[#650](https://github.com/documentcloud/underscore/pull/650), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1719-1754)]
200
* Ensure *“Collections”* methods allow string `collection` arguments [[#247](https://github.com/documentcloud/underscore/issues/247), [#276](https://github.com/documentcloud/underscore/issues/276), [#561](https://github.com/documentcloud/underscore/pull/561), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L503-520)]
201
* Fix cross-browser object iteration bugs [[#60](https://github.com/documentcloud/underscore/issues/60), [#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L554-579)]
202
* Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [#742](https://github.com/documentcloud/underscore/issues/742), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L134-140)]
203
* Register as an AMD module, but still export to global [[#431](https://github.com/documentcloud/underscore/pull/431), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L118-132)]
204
* `_.clone` should allow `deep` cloning [[#595](https://github.com/documentcloud/underscore/pull/595), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L223-234)]
205
* `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L289-298)]
206
* `_.countBy` and `_.groupBy` should only add values to own, not inherited, properties [[#736](https://github.com/documentcloud/underscore/issues/736), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L306-313)]
207
* `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [#718](https://github.com/documentcloud/underscore/issues/718), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L946-968)]
208
* `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L486-489)]
209
* `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L581-600)]
210
* `_.isElement` should use strict equality for its duck type check [[#734](https://github.com/documentcloud/underscore/issues/734), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L696-705)]
211
* `_.isEmpty` should support jQuery/MooTools DOM query collections [[#690](https://github.com/documentcloud/underscore/pull/690), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L732-737)]
212
* `_.isEqual` should return `true` for like-objects from different documents [[#733](https://github.com/documentcloud/underscore/issues/733), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L784-795)]
213
* `_.isEqual` should use custom `isEqual` methods before checking strict equality [[#748](https://github.com/documentcloud/underscore/issues/748), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L758-761)]
214
* `_.isObject` should avoid V8 bug [#2291](http://code.google.com/p/v8/issues/detail?id=2291) [[#605](https://github.com/documentcloud/underscore/issues/605), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L803-815)]
215
* `_.isNaN(new Number(NaN))` should return `true` [[#749](https://github.com/documentcloud/underscore/issues/749), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L823-825)]
216
* `_.keys` should work with `arguments` objects cross-browser [[#396](https://github.com/documentcloud/underscore/issues/396), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L879-881)]
217
* `_.range` should coerce arguments to numbers [[#634](https://github.com/documentcloud/underscore/issues/634), [#683](https://github.com/documentcloud/underscore/issues/683), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1222-1225)]
218
* `_.reduceRight` should pass correct callback arguments when iterating objects [[test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1257-1271)]
219
* `_.sortedIndex` should support arrays with high `length` values [[#735](https://github.com/documentcloud/underscore/issues/735), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1404-1413)]
220
* `_.throttle` should work when called in a loop [[#502](https://github.com/documentcloud/underscore/issues/502), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1534-1544)]
221
* `_.toArray` uses custom `toArray` methods of arrays and strings [[#747](https://github.com/documentcloud/underscore/issues/747), [test](https://github.com/bestiejs/lodash/blob/v0.7.0/test/test.js#L1571-1579)]
222
223
## Optimized methods <sup>(50+)</sup>
224
225
* `_.bind`
226
* `_.bindAll`
227
* `_.clone`
228
* `_.compact`
229
* `_.contains`, `_.include`
230
* `_.defaults`
231
* `_.defer`
232
* `_.difference`
233
* `_.each`
234
* `_.every`, `_.all`
235
* `_.extend`
236
* `_.filter`, `_.select`
237
* `_.find`, `_.detect`
238
* `_.flatten`
239
* `_.forEach`, `_.each`
240
* `_.functions`, `_.methods`
241
* `_.groupBy`
242
* `_.indexOf`
243
* `_.intersection`
244
* `_.invert`
245
* `_.invoke`
246
* `_.isArguments`
247
* `_.isDate`
248
* `_.isEmpty`
249
* `_.isFinite`
250
* `_.isFunction`
251
* `_.isObject`
252
* `_.isNumber`
253
* `_.isRegExp`
254
* `_.isString`
255
* `_.keys`
256
* `_.lastIndexOf`
257
* `_.map`, `_.collect`
258
* `_.max`
259
* `_.memoize`
260
* `_.min`
261
* `_.mixin`
262
* `_.omit`
263
* `_.pairs`
264
* `_.pick`
265
* `_.pluck`
266
* `_.reduce`, `_.foldl`, `_.inject`
267
* `_.reject`
268
* `_.result`
269
* `_.shuffle`
270
* `_.some`, `_.any`
271
* `_.sortBy`
272
* `_.sortedIndex`
273
* `_.template`
274
* `_.throttle`
275
* `_.times`
276
* `_.toArray`
277
* `_.union`
278
* `_.uniq`, `_.unique`
279
* `_.values`
280
* `_.without`
281
* `_.wrap`
282
* `_.zip`
283
* plus all `_(…)` method wrappers
284
285
## Release Notes
286
287
### <sup>v0.7.0</sup>
288
289
#### Compatibility Warnings ####
290
291
* Renamed `_.zipObject` to `_.object`
292
* Replaced `_.drop` with `_.omit`
293
* Made `_.drop` alias `_.rest`
294
295
#### Changes ####
296
297
* Added [_.invert](http://lodash.com/docs#invert), [_.pairs](http://lodash.com/docs#pairs), and [_.random](http://lodash.com/docs#random)
298
* Added `_.result` to the `backbone` build
299
* Added `exports`, `iife`, `-c`/`--stdout`, `-o`/`--output`, and `-s`/`--silent` build options
300
* Ensured `isPlainObject` works with objects from other documements
301
* Ensured `_.isEqual` compares values with circular references correctly
302
* Ensured `_.merge` work with four or more arguments
303
* Ensured `_.sortBy` performs a stable sort for `undefined` values
304
* Ensured `_.template` works with "interpolate" delimiters containing ternary operators
305
* Ensured the production build works in Node.js
306
* Ensured template delimiters are tokenized correctly
307
* Made pseudo private properties `_chain` and `_wrapped` double-underscored to avoid conflicts
308
* Made `minify.js` support `underscore.js`
309
* Reduced the size of `mobile` and `underscore` builds
310
* Simplified `_.isEqual` and `_.size`
311
312
The full changelog is available [here](https://github.com/bestiejs/lodash/wiki/Changelog).
313
314
## BestieJS
315
316
Lo-Dash is part of the BestieJS *“Best in Class”* module collection. This means we promote solid browser/environment support, ES5 precedents, unit testing, and plenty of documentation.
317
318
## Author
319
320
* [John-David Dalton](http://allyoucanleet.com/)
321
[![twitter/jdalton](http://gravatar.com/avatar/299a3d891ff1920b69c364d061007043?s=70)](https://twitter.com/jdalton "Follow @jdalton on Twitter")
322
323
## Contributors
324
325
* [Kit Cambridge](http://kitcambridge.github.com/)
326
[![twitter/kitcambridge](http://gravatar.com/avatar/6662a1d02f351b5ef2f8b4d815804661?s=70)](https://twitter.com/kitcambridge "Follow @kitcambridge on Twitter")
327
* [Mathias Bynens](http://mathiasbynens.be/)
328
[![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter")
329