From fcede4290312d240660d0935f5ed188d1cb4dfa5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 16 Jul 2012 18:23:10 -0400 Subject: [PATCH 01/77] Add Unit testing video link to README and minor cleanup to build.js help text. Former-commit-id: 504b69acede1bb4759ba942d01dfd0b899715f00 --- README.md | 9 +++++---- build.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e0d8492004..d4fca49b38 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,9 @@ For a list of upcoming features, check out our [roadmap](https://github.com/best For more information check out these screencasts over Lo-Dash: * [Introducing Lo-Dash](https://vimeo.com/44154599) - * [Optimizations and custom builds](https://vimeo.com/44154601) + * [Lo-Dash optimizations and custom builds](https://vimeo.com/44154601) * [Lo-Dash’s origin and why it’s a better utility belt](https://vimeo.com/44154600) + * [Unit testing in Lo-Dash](https://vimeo.com/45865290) ## Features @@ -66,7 +67,7 @@ lodash legacy lodash mobile ~~~ - * Strict builds, with `_.bindAll`, `_.extend`, and `_.defaults` in [strict mode](http://es5.github.com/#C), may be created using the `strict` modifier argument. + * Strict builds, with `_.bindAll`, `_.defaults`, and `_.extend` in [strict mode](http://es5.github.com/#C), may be created using the `strict` modifier argument. ~~~ bash lodash strict ~~~ @@ -153,7 +154,7 @@ require({ * 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.4.2/test/test.js#L364-370)] * Ensure array-like objects with invalid `length` properties are treated like regular objects [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L315-321), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L665-679), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L921-924)] - * Ensure *"Arrays"* methods allow falsey `array` arguments [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L989-1027)] + * Ensure *"Arrays"* methods allow falsey `array` arguments [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L989-1028)] * 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.4.2/test/test.js#L148-157), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L323-341), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L681-698), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L926-929)] * Ensure templates compiled with errors are inspectable [[#666](https://github.com/documentcloud/underscore/issues/666), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L795-802)] * Fix cross-browser object iteration bugs [[#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L224-236), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L375-400), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L496-507), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L515-517), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L535-555), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L725-727)] @@ -241,7 +242,7 @@ require({ ### v0.4.2 * Added `strict` build - * Ensured `_.bindAll`, `_.extend`, and `_.defaults` avoid strict mode errors when attempting to augment read-only properties + * Ensured `_.bindAll`, `_.defaults`, and `_.extend` avoid strict mode errors when attempting to augment read-only properties * Optimized the iteration of large arrays in `_.difference`, `_.intersection`, and `_.without` * Fixed build bugs related to removing variables diff --git a/build.js b/build.js index 9b34b18369..0f56e40815 100755 --- a/build.js +++ b/build.js @@ -291,7 +291,7 @@ ' lodash backbone Build containing all methods required by Backbone', ' lodash legacy Build tailored for older browsers without ES5 support', ' lodash mobile Build with IE < 9 bug fixes and method compilation removed', - ' lodash strict Build with `_.bindAll`, `_.extend`, and `_.defaults` in strict mode', + ' lodash strict Build with `_.bindAll`, `_.defaults`, and `_.extend` in strict mode', ' lodash category=... Comma separated categories of methods to include in the build', ' lodash exclude=... Comma separated names of methods to exclude from the build', ' lodash include=... Comma separated names of methods to include in the build', From 0f8bae950ea179694c40844990eec183fe3e2648 Mon Sep 17 00:00:00 2001 From: Jay Phelps Date: Mon, 16 Jul 2012 16:35:35 -0700 Subject: [PATCH 02/77] Ensure running in IE if concated with other files that enable conditional compilation /*@cc_on @/`. Former-commit-id: cf2d9c01ce92b8b85149116d48145bc4342471a4 --- lodash.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index af689d3aa7..a18cb94a2f 100644 --- a/lodash.js +++ b/lodash.js @@ -141,8 +141,10 @@ /** Detect if sourceURL syntax is usable without erroring */ try { - // Adobe's and Narwhal's JS engines will error - var useSourceURL = (Function('//@')(), true); + // Adobe's and Narwhal's JS engines will error. IE 8/9/etc also evaluate + // @ symbols as part of a non-standard conditional include system, so it + // parses /a/a as a malformed regular expression, so we know to exclude them. + var useSourceURL = (Function('//@/a/a')(), true); } catch(e){ } /** From 624b045ac0b740cd5b546631bbe2b239b9d5a711 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 17 Jul 2012 01:39:51 -0400 Subject: [PATCH 03/77] Add unit tests and code comments for the conditional compilation patch. Former-commit-id: 557aa43dc7c8db738452a9f3afb8ff2aadf8061a --- lodash.js | 15 +++++++++++---- test/test.js | 13 +++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index a18cb94a2f..6cf221460b 100644 --- a/lodash.js +++ b/lodash.js @@ -141,10 +141,14 @@ /** Detect if sourceURL syntax is usable without erroring */ try { - // Adobe's and Narwhal's JS engines will error. IE 8/9/etc also evaluate - // @ symbols as part of a non-standard conditional include system, so it - // parses /a/a as a malformed regular expression, so we know to exclude them. - var useSourceURL = (Function('//@/a/a')(), true); + // The JS engine in Adobe products, like InDesign, will throw a syntax error + // when it encounters a single line comment beginning with the `@` symbol. + // The JS engine in Narwhal will generate the function `function anonymous(){//}` + // and throw a syntax error. In IE, `@` symbols are part of its non-standard + // conditional compilation support. The `@cc_on` statement activates its + // support while the trailing `!` induces a syntax error to exlude it. + // See http://msdn.microsoft.com/en-us/library/121hztk3(v=vs.94).aspx + var useSourceURL = (Function('//@cc_on!')(), true); } catch(e){ } /** @@ -3444,6 +3448,9 @@ try { result = Function('_', 'return ' + text)(lodash); } catch(e) { + // defer syntax errors until the compiled template is executed to allow + // examining the `source` property beforehand and for consistency, + // because other template related errors occur at execution result = function() { throw e; }; } diff --git a/test/test.js b/test/test.js index 05f40104fe..b0e2477a49 100644 --- a/test/test.js +++ b/test/test.js @@ -855,6 +855,19 @@ ok(false); } }); + + test('should not error with IE conditional comments enabled (test with development build)', function() { + var compiled = _.template(''), + pass = true; + + /*@cc_on @*/ + try { + compiled(); + } catch(e) { + pass = false; + } + ok(pass); + }); }()); /*--------------------------------------------------------------------------*/ From 5f5806a98ef16f0154ed7192548811de7b6e1dd5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 17 Jul 2012 01:41:21 -0400 Subject: [PATCH 04/77] Update CDN link and rebuild documentation. Former-commit-id: 32210baffaed31b7fb4daed58a0c0a4f22daf4f0 --- README.md | 2 +- doc/README.md | 186 +++++++++++++++++++++++++------------------------- 2 files changed, 94 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index d4fca49b38..9450a5d46a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Lo-Dash’s performance is gained by avoiding slower native methods, instead opt * [Development source](https://raw.github.com/bestiejs/lodash/v0.4.2/lodash.js) * [Production source](https://raw.github.com/bestiejs/lodash/v0.4.2/lodash.min.js) - * CDN copies of ≤ [v0.4.1](http://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.4.1/lodash.min.js) are available on [cdnjs](http://cdnjs.com/) thanks to [CloudFlare](http://www.cloudflare.com/) + * CDN copies of ≤ [v0.4.2](http://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.4.2/lodash.min.js) are available on [cdnjs](http://cdnjs.com/) thanks to [CloudFlare](http://www.cloudflare.com/) * For optimal performance, [create a custom build](https://github.com/bestiejs/lodash#custom-builds) with only the features you need ## Dive in diff --git a/doc/README.md b/doc/README.md index 75930cb596..e01403666a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -130,7 +130,7 @@ ### `_(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L192 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L198 "View in source") [Ⓣ][1] The `lodash` function. @@ -148,7 +148,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3608 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3617 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -160,7 +160,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1985 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1991 "View in source") [Ⓣ][1] Creates a new function that is restricted to executing only after it is called `n` times. @@ -188,7 +188,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2039 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2045 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. Lazy defined methods may be bound by passing the object they are bound to as `func` and the method name as `thisArg`. @@ -239,7 +239,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2109 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2115 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -270,7 +270,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3533 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3542 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -304,7 +304,7 @@ var youngest = _.chain(stooges) ### `_.clone(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2439 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2445 "View in source") [Ⓣ][1] Create a shallow clone of the `value`. Any nested objects or arrays will be assigned by reference and not cloned. @@ -328,7 +328,7 @@ _.clone({ 'name': 'moe' }); ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1227 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1233 "View in source") [Ⓣ][1] Produces a new array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -352,7 +352,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2145 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2151 "View in source") [Ⓣ][1] Creates a new function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -379,7 +379,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L762 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L768 "View in source") [Ⓣ][1] Checks if a given `target` value is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -410,7 +410,7 @@ _.contains('curly', 'ur'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2178 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2184 "View in source") [Ⓣ][1] Creates a new function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -436,7 +436,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, defaults1, defaults2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2462 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2468 "View in source") [Ⓣ][1] Assigns missing properties on `object` with default values from the defaults objects. Once a property is set, additional defaults of the same property will be ignored. @@ -462,7 +462,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2243 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2249 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments are passed to `func` when it is invoked. @@ -487,7 +487,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2223 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2229 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments are passed to `func` when it is invoked. @@ -514,7 +514,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1259 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1265 "View in source") [Ⓣ][1] Produces a new array of `array` values not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -539,7 +539,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3173 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3179 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -563,7 +563,7 @@ _.escape('Curly, Larry & Moe'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L790 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L796 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -589,7 +589,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2481 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2487 "View in source") [Ⓣ][1] Copies enumerable properties from the source objects to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -614,7 +614,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L810 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L816 "View in source") [Ⓣ][1] Examines each value in a `collection`, returning an array of all values the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -640,7 +640,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L831 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L837 "View in source") [Ⓣ][1] Examines each value in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -666,7 +666,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1296 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1302 "View in source") [Ⓣ][1] Gets the first value of the `array`. Pass `n` to return the first `n` values of the `array`. @@ -692,7 +692,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1320 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1326 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -720,7 +720,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L857 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L863 "View in source") [Ⓣ][1] Iterates over a `collection`, executing the `callback` for each value in the `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -749,7 +749,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2510 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2516 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -785,7 +785,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2533 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2539 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -813,7 +813,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2550 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2556 "View in source") [Ⓣ][1] Produces a sorted array of the enumerable properties, own and inherited, of `object` that have function values. @@ -837,7 +837,7 @@ _.functions(_); ### `_.groupBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L884 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L890 "View in source") [Ⓣ][1] Splits `collection` into sets, grouped by the result of running each value through `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to group by. @@ -869,7 +869,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2573 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2579 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -894,7 +894,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3198 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -919,7 +919,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1364 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1370 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -951,7 +951,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1404 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1410 "View in source") [Ⓣ][1] Gets all but the last value of `array`. Pass `n` to exclude the last `n` values from the result. @@ -977,7 +977,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1425 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1431 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays. @@ -1001,7 +1001,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L918 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L924 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1030,7 +1030,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2593 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2599 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1057,7 +1057,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2620 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2626 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1084,7 +1084,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2637 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2643 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1108,7 +1108,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2654 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2660 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1132,7 +1132,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2671 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2677 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1156,7 +1156,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2695 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2701 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays or strings with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1186,7 +1186,7 @@ _.isEmpty(''); ### `_.isEqual(a, b [, stack])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2729 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2735 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1218,7 +1218,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2891 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2897 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1248,7 +1248,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2908 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2914 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1272,7 +1272,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2960 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2966 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1305,7 +1305,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2983 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2989 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1332,7 +1332,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3000 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3006 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1356,7 +1356,7 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2929 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2935 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexps, `new Number(0)`, and `new String('')`)* @@ -1383,7 +1383,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3017 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3023 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1407,7 +1407,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3034 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3040 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1431,7 +1431,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3052 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3058 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1455,7 +1455,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3069 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3075 "View in source") [Ⓣ][1] Produces an array of object`'s own enumerable property names. @@ -1479,7 +1479,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1466 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1472 "View in source") [Ⓣ][1] Gets the last value of the `array`. Pass `n` to return the lasy `n` values of the `array`. @@ -1505,7 +1505,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1492 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1498 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1534,7 +1534,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L954 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L960 "View in source") [Ⓣ][1] Produces a new array of values by mapping each element in the `collection` through a transformation `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -1563,7 +1563,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1532 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1538 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1595,7 +1595,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2266 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2272 "View in source") [Ⓣ][1] Creates a new function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1621,7 +1621,7 @@ var fibonacci = _.memoize(function(n) { ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1582 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1588 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1647,7 +1647,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3218 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3224 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1677,7 +1677,7 @@ _('larry').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3249 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3255 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1697,7 +1697,7 @@ var lodash = _.noConflict(); ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2292 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2298 "View in source") [Ⓣ][1] Creates a new function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1723,7 +1723,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2325 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2331 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the partially applied function. This method is similar `bind`, except it does **not** alter the `this` binding. @@ -1750,7 +1750,7 @@ hi('moe'); ### `_.pick(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3091 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3097 "View in source") [Ⓣ][1] Creates an object composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -1775,7 +1775,7 @@ _.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L977 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L983 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -1806,7 +1806,7 @@ _.pluck(stooges, 'name'); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1643 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1649 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -1844,7 +1844,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1005 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1011 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -1871,7 +1871,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1042 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1048 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -1899,7 +1899,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1097 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1103 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -1925,7 +1925,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1680 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1686 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -1951,7 +1951,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3281 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3287 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -1986,7 +1986,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1701 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1707 "View in source") [Ⓣ][1] Produces a new array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2010,7 +2010,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3130 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3136 "View in source") [Ⓣ][1] Gets the size of `value` by returning `value.length` if `value` is a string or array, or the number of own enumerable properties if `value` is an object. @@ -2040,7 +2040,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1120 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1126 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -2066,7 +2066,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1152 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1158 "View in source") [Ⓣ][1] Produces a new sorted array, sorted in ascending order by the results of running each element of `collection` through a transformation `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2098,7 +2098,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1753 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1759 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with `1` argument; *(value)*. @@ -2139,7 +2139,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3560 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3569 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2169,7 +2169,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3341 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3347 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -2228,7 +2228,7 @@ _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' }); ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2361 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2367 "View in source") [Ⓣ][1] Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2253,7 +2253,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3476 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3485 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2279,7 +2279,7 @@ _.times(3, function() { this.grantWish(); }, genie); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1195 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1201 "View in source") [Ⓣ][1] Converts the `collection`, into an array. Useful for converting the `arguments` object. @@ -2303,7 +2303,7 @@ Converts the `collection`, into an array. Useful for converting the `arguments` ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1793 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1799 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays. @@ -2327,7 +2327,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1838 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1844 "View in source") [Ⓣ][1] Produces a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each value of `array` is passed through a transformation `callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -2363,7 +2363,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3503 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3512 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2387,7 +2387,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3151 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3157 "View in source") [Ⓣ][1] Produces an array of `object`'s own enumerable property values. @@ -2411,7 +2411,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1887 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1893 "View in source") [Ⓣ][1] Produces a new array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2436,7 +2436,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(func, wrapper [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2413 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2419 "View in source") [Ⓣ][1] Create a new function that passes the `func` function to the `wrapper` function as its first argument. Additional arguments are appended to those passed to the `wrapper` function. @@ -2466,7 +2466,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1920 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1926 "View in source") [Ⓣ][1] Merges the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2490,7 +2490,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.zipObject(keys)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1949 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1955 "View in source") [Ⓣ][1] Merges an array of `keys` and an array of `values` into a single object. @@ -2521,7 +2521,7 @@ _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3578 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3587 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2542,7 +2542,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3595 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3604 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -2570,7 +2570,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L220 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L226 "View in source") [Ⓣ][1] *(Object)*: By default, Lo-Dash uses embedded Ruby *(ERB)* style template delimiters, change the following template settings to use alternative delimiters. @@ -2582,7 +2582,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.escape` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L229 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L235 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to be HTML-escaped. @@ -2594,7 +2594,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.evaluate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L238 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L244 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect code to be evaluated. @@ -2606,7 +2606,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.interpolate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L247 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L253 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to inject. @@ -2618,7 +2618,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.variable` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L256 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L262 "View in source") [Ⓣ][1] *(String)*: Used to reference the data object in the template text. From 1c8cd8c168212fc305e664798e71d4abbe857900 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 18 Jul 2012 01:53:15 -0400 Subject: [PATCH 05/77] Ensure `reEvaluateDelimiter` is assigned an initial value if `evaluateDelimiter` is undefined by default. [closes #52] Former-commit-id: 6cefeeca164901e611009ce1413e5080027592c9 --- lodash.js | 22 ++++++++++++---------- lodash.min.js | 26 +++++++++++++------------- test/test.js | 10 ++++++++++ 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/lodash.js b/lodash.js index 6cf221460b..b388c0a021 100644 --- a/lodash.js +++ b/lodash.js @@ -707,17 +707,17 @@ * * @private * @param {String} match The matched template delimiter. - * @param {String} value The delimiter value. - * @param {String} escapeValue The "escape" delimiter value. - * @param {String} interpolateValue The "interpolate" delimiter value. + * @param {String} escapeValue The complex "escape" delimiter value. + * @param {String} interpolateValue The complex "interpolate" delimiter value. + * @param {String} [evaluateValue] The "evaluate" delimiter value. * @returns {String} Returns a token. */ - function tokenizeEvaluate(match, value, escapeValue, interpolateValue) { + function tokenizeEvaluate(match, escapeValue, interpolateValue, evaluateValue) { var index = tokenized.length; - if (value) { - tokenized[index] = "';\n" + value + ";\n__p += '" - } else if (escapeValue) { + if (escapeValue) { tokenized[index] = "' +\n__e(" + escapeValue + ") +\n'"; + } else if (evaluateValue) { + tokenized[index] = "';\n" + evaluateValue + ";\n__p += '"; } else if (interpolateValue) { tokenized[index] = "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'"; } @@ -3364,7 +3364,9 @@ escapeDelimiter = settings.escape; } if (evaluateDelimiter == null) { - evaluateDelimiter = settings.evaluate; + // use `false` as the fallback value so the initial assignment of + // `reEvaluateDelimiter` will still occur + evaluateDelimiter = settings.evaluate || false; } if (interpolateDelimiter == null) { interpolateDelimiter = settings.interpolate; @@ -3382,8 +3384,8 @@ // and internal ``, `` delimiters lastEvaluateDelimiter = evaluateDelimiter; reEvaluateDelimiter = RegExp( - (evaluateDelimiter ? evaluateDelimiter.source : '($^)') + - '||' + '|' + + (evaluateDelimiter ? '|' + evaluateDelimiter.source : '') , 'g'); } isEvaluating = tokenized.length; diff --git a/lodash.min.js b/lodash.min.js index 42c9d5a95b..2ad67f2433 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -3,10 +3,10 @@ Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE */ ;(function(e,t){"use strict";function s(e){return new o(e)}function o(e){if(e&&e._wrapped)return e;this._wrapped=e}function u(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||30),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="n='"+u.o[n]+"';if(","constructor"==u.o[n]&&(t+="!(i&&i.prototype===p)&&"),t+="l.call(p,n)){"+u.m.i+"}"}u.c&&(t+="}")}return t+=u.e+";return D",Function("c,d,h,j,l,m,r,x,u,C,F,G,J" -,"return function("+e+"){"+t+"}")(ut,C,f,lt,Y,L,p,St,ot,et,tt,pt,nt)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return Q[t]}function c(e){return"\\"+xt[e]}function h(e){return Et[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+__e("+t+")+'",K+n}function m(e,t,n,r){return e=Q.length,t?Q[e]="';"+t+";__p+='":n?Q[e]="'+__e("+n+")+'":r&&(Q[e]="'+((__t=("+ -r+"))==null?'':__t)+'"),K+e}function g(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+((__t=("+t+"))==null?'':__t)+'",K+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=yt&&nt.call(e)==pt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=Zt(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:tt.call(e,0,t)}function w(e,t){var n=[];if(!e) +("string"==typeof n&&(n={b:n,l:n}),u.c[t]=n.b,u.m[t]=n.l):u[t]=n;e=u.a,t=/^[^,]+/.exec(e)[0],u.g=t,u.h=mt,u.k=wt,u.o=J,u.q=u.q!==i,u.r=u.r!==i,"n"in u||(u.n=yt),u.f||(u.f="if(!"+t+")return G");if("h"!=t||!u.c.i)u.c=r;t="",u.r&&(t+="'use strict';"),t+="var p,s="+u.g+",G",u.j&&(t+="="+u.j),t+=";"+u.f+";"+u.p+";",u.c&&(t+="var v=s.length;p=-1;",u.m&&(t+="if(v===v>>>0){"),u.n&&(t+="if(M.call(s)==J){s=s.split('')}"),t+=u.c.d+";while(++pn;n++)t+="p='"+u.o[n]+"';if(","constructor"==u.o[n]&&(t+="!(k&&k.prototype===s)&&"),t+="n.call(s,p)){"+u.m.i+"}"}u.c&&(t+="}")}return t+=u.e+";return G",Function("c,e,i,l,n,o,u,A,x,F,I,J,M" +,"return function("+e+"){"+t+"}")(ut,C,f,lt,Y,L,p,St,ot,et,tt,pt,nt)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return Q[t]}function c(e){return"\\"+xt[e]}function h(e){return Et[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+__e("+t+")+'",K+n}function m(e,t,n,r){return e=Q.length,t?Q[e]="'+__e("+t+")+'":r?Q[e]="';"+r+";__p+='":n&&(Q[e]="'+((__t=("+ +n+"))==null?'':__t)+'"),K+e}function g(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+((__t=("+t+"))==null?'':__t)+'",K+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=yt&&nt.call(e)==pt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=Zt(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:tt.call(e,0,t)}function w(e,t){var n=[];if(!e) return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e?tt.call(e,t==r|| n?1:t):[]}function T(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=C(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]E(a,r))a.push(r),s.push(e[o]);return s}function C(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?G.apply(s,o) :s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&St[typeof o]?o:u):e.apply(u,o)}var r,i=nt.call(e)==lt;if(i){if(bt||rt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,q=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,U=/(__e\(.*?\)|\b__t\))\+'';/g,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(B.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/__token__(\d+)/g,V=/[&<"']/g,$=/['\n\r\t\u2028\u2029\\]/g ,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K="__token__",Q=[],G=H.concat,Y=B.hasOwnProperty,Z=H.push,et=B.propertyIsEnumerable,tt=H.slice,nt=B.toString,rt=W.test(rt=tt.bind)&&rt,it=W.test(it=Array.isArray)&&it,st=e.isFinite,ot=W.test(ot=Object.keys)&&ot,ut="[object Array]",at="[object Boolean]",ft="[object Date]",lt="[object Function]",ct="[object Number]",ht="[object RegExp]",pt="[object String]",dt=e.clearTimeout,vt=e.setTimeout ,mt=!et.call({valueOf:0},"valueOf"),gt="x"!=tt.call("x")[0],yt="xx"!="x"[0]+Object("x")[0],bt=rt&&/\n|Opera/.test(rt+nt.call(e.opera)),wt=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Et={"&":"&","<":"<",'"':""","'":"'"},St={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},xt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj" -};var Tt={a:"g,e,I",j:"g",p:"if(!e){e=m}else if(I)e=r(e,I)",i:"e(p[n],n,g)"},Nt={j:"true",i:"if(!e(p[n],n,g))return!D"},Ct={q:i,r:i,a:"w",j:"w",p:"for(var q=1,s=arguments.length;q-1"},i:"if(p[n]===H)return true"}),Dt=a(Tt,Nt),Pt=a(Tt,kt),Ht=a(Tt,Lt,{j:"",i:"if(e(p[n],n,g))return p[n]"}),Bt=a(Tt,Lt),jt=a(Tt,{j:"{}",p:"var y,o=typeof e=='function';if(o&&I)e=r(e,I)",i:"y=o?e(p[n],n,g):p[n][e];(l.call(D,y)?D[y]:D[y]=[]).push(p[n])"}),Ft=a(Ot,{a:"g,t",p:"var b=F.call(arguments,2),o=typeof t=='function'",i:{b:"D[n]=(o?t:p[n][t]).apply(p[n],b)",l:"D"+(wt?"[z]=":".push")+"((o?t:p[n][t]).apply(p[n],b))" -}}),It=a(Tt,Ot),qt=a(Ot,{a:"g,B",i:{b:"D[n]=p[n][B]",l:"D"+(wt?"[z]=":".push")+"(p[n][B])"}}),Rt=a({a:"g,e,a,I",j:"a",p:"var v=arguments.length<3;if(I)e=r(e,I)",d:{b:"if(v)D=g[++n]"},i:{b:"D=e(D,p[n],n,g)",l:"D=v?(v=false,p[n]):e(D,p[n],n,g)"}}),Ut=a(Tt,kt,{i:"!"+kt.i}),zt=a(Tt,Nt,{j:"false",i:Nt.i.replace("!","")}),Wt=a(Tt,Ot,{p:"if(typeof e=='string'){var y=e;e=function(g){return g[y]}}else if(I)e=r(e,I)",i:{b:"D[n]={a:e(p[n],n,g),b:p[n]}",l:"D"+(wt?"[z]=":".push")+"({a:e(p[n],n,g),b:p[n]})"},e -:"D.sort(h);s=D.length;while(s--){D[s]=D[s].b}"}),Xt=a({q:i,r:i,a:"w",j:"w",p:"var k=arguments,s=k.length;if(s>1){for(var n=1;ne?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=Xt,s.chain=function(e) +};var Tt={a:"h,f,L",j:"h",p:"if(!f){f=o}else if(L)f=u(f,L)",i:"f(s[p],p,h)"},Nt={j:"true",i:"if(!f(s[p],p,h))return!G"},Ct={q:i,r:i,a:"z",j:"z",p:"for(var t=1,v=arguments.length;t-1"},i:"if(s[p]===K)return true"}),Dt=a(Tt,Nt),Pt=a(Tt,kt),Ht=a(Tt,Lt,{j:"",i:"if(f(s[p],p,h))return s[p]"}),Bt=a(Tt,Lt),jt=a(Tt,{j:"{}",p:"var B,r=typeof f=='function';if(r&&L)f=u(f,L)",i:"B=r?f(s[p],p,h):s[p][f];(n.call(G,B)?G[B]:G[B]=[]).push(s[p])"}),Ft=a(Ot,{a:"h,w",p:"var b=I.call(arguments,2),r=typeof w=='function'",i:{b:"G[p]=(r?w:s[p][w]).apply(s[p],b)",l:"G"+(wt?"[C]=":".push")+"((r?w:s[p][w]).apply(s[p],b))" +}}),It=a(Tt,Ot),qt=a(Ot,{a:"h,E",i:{b:"G[p]=s[p][E]",l:"G"+(wt?"[C]=":".push")+"(s[p][E])"}}),Rt=a({a:"h,f,a,L",j:"a",p:"var y=arguments.length<3;if(L)f=u(f,L)",d:{b:"if(y)G=h[++p]"},i:{b:"G=f(G,s[p],p,h)",l:"G=y?(y=false,s[p]):f(G,s[p],p,h)"}}),Ut=a(Tt,kt,{i:"!"+kt.i}),zt=a(Tt,Nt,{j:"false",i:Nt.i.replace("!","")}),Wt=a(Tt,Ot,{p:"if(typeof f=='string'){var B=f;f=function(h){return h[B]}}else if(L)f=u(f,L)",i:{b:"G[p]={a:f(s[p],p,h),b:s[p]}",l:"G"+(wt?"[C]=":".push")+"({a:f(s[p],p,h),b:s[p]})"},e +:"G.sort(i);v=G.length;while(v--){G[v]=G[v].b}"}),Xt=a({q:i,r:i,a:"z",j:"z",p:"var m=arguments,v=m.length;if(v>1){for(var p=1;pe?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=Xt,s.chain=function(e) {return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&St[typeof e]?Gt(e)?e.slice():$t({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&Dt(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=Ft,s.isArray=Gt,s.isBoolean=function(e){return e===n||e===i||nt.call(e)==at},s.isElement=function(e){return!! e&&1==e.nodeType},s.isEmpty=Yt,s.isEqual=k,s.isFinite=function(e){return st(e)&&nt.call(e)==ct},s.isNaN=function(e){return nt.call(e)==ct&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&St[typeof e]},s.isUndefined=function(e){return e===t},s.keys=Zt,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:tt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if( e[r]===t)return r;return-1},s.map=It,s.max=S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Y.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?e.length:Zt(e).length},s.some=zt,s.sortBy=Wt,s.sortedIndex=T,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var i,o;i=n.escape;var u=n.evaluate, -a=n.interpolate,f=s.templateSettings,n=n.variable;i==r&&(i=f.escape),u==r&&(u=f.evaluate),a==r&&(a=f.interpolate),i&&(e=e.replace(i,v)),a&&(e=e.replace(a,g)),u!=O&&(O=u,D=RegExp((u?u.source:"($^)")+"||","g")),i=Q.length,e=e.replace(D,m),i=i!=Q.length,e="__p += '"+e.replace($,c).replace(X,l)+"';",Q.length=0,n||(n=f.variable||M||"obj",i?e="with("+n+"){"+e+"}":(n!=M&&(M=n,_=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(z,"$&"+n+".").replace(_,"$1__d"))),e=( -i?e.replace(q,""):e).replace(R,"$1").replace(U,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{o=Function("_","return "+e)(s)}catch(h){o=function(){throw h}}return t?o(t):(o.source=e,o)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e -.apply(o,i)):u||(u=vt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(gt?nt.call(e)==pt:"string"==typeof e)?e.split(""):tt.call(e):en(e)},s.union=function(){for(var e=-1,t=[],n=G.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=j++;return e?e+t:t},s.values=en,s.without= +Rt,s.reduceRight=y,s.reject=Ut,s.rest=x,s.result=function(e,t){if(!e)return r;var n=e[t];return nt.call(n)==lt?e[t]():n},s.shuffle=function(e){if(!e)return[];for(var t,n=-1,r=e.length,i=Array(r);++n>>0?e.length:Zt(e).length},s.some=zt,s.sortBy=Wt,s.sortedIndex=T,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var o,u;o=n.escape;var a=n.evaluate, +f=n.interpolate,h=s.templateSettings,n=n.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=O&&(O=a,D=RegExp("|"+(a?"|"+a.source:""),"g")),o=Q.length,e=e.replace(D,m),o=o!=Q.length,e="__p += '"+e.replace($,c).replace(X,l)+"';",Q.length=0,n||(n=h.variable||M||"obj",o?e="with("+n+"){"+e+"}":(n!=M&&(M=n,_=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(z,"$&"+n+".").replace(_,"$1__d"))),e= +(o?e.replace(q,""):e).replace(R,"$1").replace(U,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s= +e.apply(o,i)):u||(u=vt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(gt?nt.call(e)==pt:"string"==typeof e)?e.split(""):tt.call(e):en(e)},s.union=function(){for(var e=-1,t=[],n=G.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=j++;return e?e+t:t},s.values=en,s.without= function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n Date: Wed, 18 Jul 2012 02:15:16 -0400 Subject: [PATCH 06/77] Add Underscore ticket reference to `Fix cross-browser object iteration bugs` bullet in README.md. Former-commit-id: 9814daf6b81f1c60b3c6681c10c1fc7b94ac61b8 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9450a5d46a..a1c4c00b6e 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ require({ * Ensure *"Arrays"* methods allow falsey `array` arguments [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L989-1028)] * 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.4.2/test/test.js#L148-157), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L323-341), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L681-698), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L926-929)] * Ensure templates compiled with errors are inspectable [[#666](https://github.com/documentcloud/underscore/issues/666), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L795-802)] - * Fix cross-browser object iteration bugs [[#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L224-236), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L375-400), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L496-507), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L515-517), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L535-555), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L725-727)] + * 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.4.2/test/test.js#L224-236), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L375-400), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L496-507), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L515-517), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L535-555), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L725-727)] * Handle arrays with `undefined` values correctly in IE < 9 [[#601](https://github.com/documentcloud/underscore/issues/601)] * Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L96-102)] * 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.4.2/test/test.js#L80-94)] From 9836b274b9abf4818890cbf6543261876a968fe9 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 18 Jul 2012 03:55:16 -0400 Subject: [PATCH 07/77] Add `_.drop`, unit tests, and cleanup documentation for `_.extend`, `_.defaults`, and `_.pick`. Former-commit-id: a45b0c45d52fdbe5f71984412d631f3dfe87965b --- build.js | 1 + build/pre-compile.js | 4 +++ lodash.js | 64 +++++++++++++++++++++++++++++++------------- test/test.js | 41 ++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 18 deletions(-) diff --git a/build.js b/build.js index 0f56e40815..a2d1c93cb4 100755 --- a/build.js +++ b/build.js @@ -155,6 +155,7 @@ 'defer': [], 'delay': [], 'difference': ['indexOf'], + 'drop': ['indexOf'], 'escape': [], 'every': ['identity'], 'extend': [], diff --git a/build/pre-compile.js b/build/pre-compile.js index 7e0c049447..7da3dab109 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -10,17 +10,20 @@ 'accumulator', 'args', 'arrayClass', + 'ArrayProto', 'bind', 'callback', 'className', 'collection', 'compareAscending', + 'concat', 'ctor', 'funcClass', 'funcs', 'hasOwnProperty', 'identity', 'index', + 'indexOf', 'isFunc', 'iteratee', 'iterateeIndex', @@ -97,6 +100,7 @@ 'delay', 'detect', 'difference', + 'drop', 'each', 'environment', 'escape', diff --git a/lodash.js b/lodash.js index b388c0a021..8422da923e 100644 --- a/lodash.js +++ b/lodash.js @@ -575,16 +575,16 @@ } // create the function factory var factory = Function( - 'arrayClass, bind, compareAscending, funcClass, hasOwnProperty, identity, ' + - 'iteratorBind, objectTypes, nativeKeys, propertyIsEnumerable, slice, ' + - 'stringClass, toString', + 'arrayClass, ArrayProto, bind, compareAscending, concat, funcClass, ' + + 'hasOwnProperty, identity, indexOf, iteratorBind, objectTypes, nativeKeys, ' + + 'propertyIsEnumerable, slice, stringClass, toString', 'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}' ); // return the compiled function return factory( - arrayClass, bind, compareAscending, funcClass, hasOwnProperty, identity, - iteratorBind, objectTypes, nativeKeys, propertyIsEnumerable, slice, - stringClass, toString + arrayClass, ArrayProto, bind, compareAscending, concat, funcClass, + hasOwnProperty, identity, indexOf, iteratorBind, objectTypes, nativeKeys, + propertyIsEnumerable, slice, stringClass, toString ); } @@ -2449,16 +2449,17 @@ } /** - * Assigns missing properties on `object` with default values from the defaults - * objects. Once a property is set, additional defaults of the same property - * will be ignored. + * Assigns enumerable properties of the default object(s) to the `destination` + * object for all `destination` properties that resolve to `null`/`undefined`. + * Once a property is set, additional defaults of the same property will be + * ignored. * * @static * @memberOf _ * @category Objects - * @param {Object} object The object to populate. - * @param {Object} [defaults1, defaults2, ...] The defaults objects to apply to `object`. - * @returns {Object} Returns `object`. + * @param {Object} object The destination object. + * @param {Object} [default1, default2, ...] The default objects. + * @returns {Object} Returns the `object`. * @example * * var iceCream = { 'flavor': 'chocolate' }; @@ -2470,15 +2471,40 @@ }); /** - * Copies enumerable properties from the source objects to the `destination` object. - * Subsequent sources will overwrite propery assignments of previous sources. + * Creates a shallow clone of `object` excluding the specified properties. + * Property names may be specified as individual arguments or as arrays of + * property names. + * + * @static + * @memberOf _ + * @category Objects + * @param {Object} object The source object. + * @param {Object} [prop1, prop2, ...] The properties to drop. + * @returns {Object} Returns an object without the dropped properties. + * @example + * + * _.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); + * // => { 'name': 'moe', 'age': 40 } + */ + var drop = createIterator({ + 'useHas': false, + 'args': 'object', + 'init': '{}', + 'top': 'var props = concat.apply(ArrayProto, arguments)', + 'inLoop': 'if (indexOf(props, index) < 0) result[index] = iteratee[index]' + }); + + /** + * Assigns enumerable properties of the source object(s) to the `destination` + * object. Subsequent sources will overwrite propery assignments of previous + * sources. * * @static * @memberOf _ * @category Objects * @param {Object} object The destination object. * @param {Object} [source1, source2, ...] The source objects. - * @returns {Object} Returns the destination object. + * @returns {Object} Returns the `object`. * @example * * _.extend({ 'name': 'moe' }, { 'age': 40 }); @@ -3080,13 +3106,14 @@ }; /** - * Creates an object composed of the specified properties. Property names may - * be specified as individual arguments or as arrays of property names. + * Creates a shallow clone of `object` composed of the specified properties. + * Property names may be specified as individual arguments or as arrays of + * property names. * * @static * @memberOf _ * @category Objects - * @param {Object} object The object to pluck. + * @param {Object} object The source object. * @param {Object} [prop1, prop2, ...] The properties to pick. * @returns {Object} Returns an object composed of the picked properties. * @example @@ -3632,6 +3659,7 @@ lodash.defer = defer; lodash.delay = delay; lodash.difference = difference; + lodash.drop = drop; lodash.escape = escape; lodash.every = every; lodash.extend = extend; diff --git a/test/test.js b/test/test.js index 9f8c717898..08662de9c2 100644 --- a/test/test.js +++ b/test/test.js @@ -201,6 +201,34 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.drop'); + + (function() { + var object = { 'a': 1, 'b': 2, 'c': 3 }, + actual = { 'b': 2 }; + + test('should accept individual property names', function() { + deepEqual(_.drop(object, 'a', 'c'), actual); + }); + + test('should accept an array of property names', function() { + deepEqual(_.drop(object, ['a', 'c']), actual); + }); + + test('should accept mixes of individual and arrays of property names', function() { + deepEqual(_.drop(object, ['a'], 'c'), actual); + }); + + test('should iterate over inherited properties', function() { + function Foo() {} + Foo.prototype = object; + + deepEqual(_.drop(new Foo, 'a', 'c'), actual); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.escape'); (function() { @@ -642,6 +670,19 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.pick'); + + (function() { + test('should iterate over inherited properties', function() { + function Foo() {} + Foo.prototype = { 'a': 1, 'b': 2, 'c': 3 }; + + deepEqual(_.pick(new Foo, 'b'), { 'b': 2 }); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.pluck'); (function() { From be11c848f4b2cf9f66026abde05236d9a2699337 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 18 Jul 2012 04:51:08 -0400 Subject: [PATCH 08/77] Add "underscore" build. Former-commit-id: 44e9f4543631cbf342ae7571cf540214623352db --- build.js | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/build.js b/build.js index a2d1c93cb4..e963737cfd 100755 --- a/build.js +++ b/build.js @@ -11,7 +11,7 @@ /** The current working directory */ var cwd = process.cwd(); - /** Flag used to specify a backbone build */ + /** Flag used to specify a Backbone build */ var isBackbone = process.argv.indexOf('backbone') > -1; /** Flag used to specify a legacy build */ @@ -26,6 +26,9 @@ */ var isStrict = process.argv.indexOf('strict') > -1; + /** Flag used to specify an Underscore build */ + var isUnderscore = process.argv.indexOf('underscore') > -1; + /** Flag used to specify if the build should include the "use strict" directive */ var useStrict = isStrict || !(isLegacy || isMobile); @@ -256,6 +259,13 @@ includeMethods, allMethods = Object.keys(dependencyMap); + var underscoreMethods = lodash.without.apply(lodash, [allMethods].concat([ + 'drop', + 'forIn', + 'forOwn', + 'partial' + ])); + /** Used to specify whether filtering is for exclusion or inclusion */ var filterType = process.argv.reduce(function(result, value) { if (result) { @@ -293,11 +303,13 @@ ' lodash legacy Build tailored for older browsers without ES5 support', ' lodash mobile Build with IE < 9 bug fixes and method compilation removed', ' lodash strict Build with `_.bindAll`, `_.defaults`, and `_.extend` in strict mode', + ' lodash underscore Build containing only methods included in Underscore', ' lodash category=... Comma separated categories of methods to include in the build', ' lodash exclude=... Comma separated names of methods to exclude from the build', ' lodash include=... Comma separated names of methods to include in the build', '', - ' All arguments, except `exclude` with `include` and `legacy` with `mobile`, may be combined.', + ' All arguments, except `backbone` with `underscore`, `exclude` with `include`,', + ' and `legacy` with `mobile`, may be combined.', '', ' Options:', '', @@ -630,25 +642,36 @@ /*--------------------------------------------------------------------------*/ - // Backbone build - if (isBackbone) { + // add methods required by Backbone or Underscore + [ + { 'flag': isBackbone, 'methodNames': backboneDependencies }, + { 'flag': isUnderscore, 'methodNames': underscoreMethods } + ] + .some(function(data) { + var flag = data.flag, + methodNames = data.methodNames; + + if (!flag) { + return false; + } // add any additional sub-dependencies - backboneDependencies = getDependencies(backboneDependencies); + methodNames = getDependencies(methodNames); if (filterType == 'exclude') { - // remove excluded methods from `backboneDependencies` - includeMethods = lodash.without.apply(lodash, [backboneDependencies].concat(excludeMethods)); + // remove excluded methods from `methodNames` + includeMethods = lodash.without.apply(lodash, [methodNames].concat(excludeMethods)); } else if (filterType) { - // merge backbone dependencies into `includeMethods` - includeMethods = lodash.union(includeMethods, backboneDependencies); + // merge `methodNames` into `includeMethods` + includeMethods = lodash.union(includeMethods, methodNames); } else { - // include only the Backbone dependencies - includeMethods = backboneDependencies; + // include only the `methodNames` + includeMethods = methodNames; } filterType = 'include'; - } + return true; + }); /*--------------------------------------------------------------------------*/ @@ -988,7 +1011,7 @@ source = source.replace(/^ *;\n/gm, ''); // begin the minification process - if (filterType || isBackbone || isLegacy || isMobile || isStrict) { + if (filterType || isBackbone || isLegacy || isMobile || isStrict || isUnderscore) { fs.writeFileSync(path.join(cwd, 'lodash.custom.js'), source); minify(source, 'lodash.custom.min', function(result) { From 7487497d1fc40bd055fb3b24177cd3ddabd08c24 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 18 Jul 2012 04:52:13 -0400 Subject: [PATCH 09/77] Update minified build and rebuild documentation. Former-commit-id: e674d7a30c1e5745b0acf90e38aa5757b15a3423 --- doc/README.md | 124 ++++++++++++++++++++++++++++++-------------------- lodash.min.js | 40 ++++++++-------- 2 files changed, 95 insertions(+), 69 deletions(-) diff --git a/doc/README.md b/doc/README.md index e01403666a..d3a0687aaa 100644 --- a/doc/README.md +++ b/doc/README.md @@ -17,10 +17,11 @@ * [`_.compose`](#_composefunc1-func2-) * [`_.contains`](#_containscollection-target) * [`_.debounce`](#_debouncefunc-wait-immediate) -* [`_.defaults`](#_defaultsobject--defaults1-defaults2-) +* [`_.defaults`](#_defaultsobject--default1-default2-) * [`_.defer`](#_deferfunc--arg1-arg2-) * [`_.delay`](#_delayfunc-wait--arg1-arg2-) * [`_.difference`](#_differencearray--array1-array2-) +* [`_.drop`](#_dropobject--prop1-prop2-) * [`_.escape`](#_escapestring) * [`_.every`](#_everycollection--callbackidentity-thisarg) * [`_.extend`](#_extendobject--source1-source2-) @@ -148,7 +149,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3617 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3646 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -270,7 +271,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3542 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3571 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -435,17 +436,17 @@ jQuery(window).on('resize', lazyLayout); -### `_.defaults(object [, defaults1, defaults2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2468 "View in source") [Ⓣ][1] +### `_.defaults(object [, default1, default2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2469 "View in source") [Ⓣ][1] -Assigns missing properties on `object` with default values from the defaults objects. Once a property is set, additional defaults of the same property will be ignored. +Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. #### Arguments -1. `object` *(Object)*: The object to populate. -2. `[defaults1, defaults2, ...]` *(Object)*: The defaults objects to apply to `object`. +1. `object` *(Object)*: The destination object. +2. `[default1, default2, ...]` *(Object)*: The default objects. #### Returns -*(Object)*: Returns `object`. +*(Object)*: Returns the `object`. #### Example ~~~ js @@ -536,10 +537,35 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); + + +### `_.drop(object [, prop1, prop2, ...])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2489 "View in source") [Ⓣ][1] + +Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. + +#### Arguments +1. `object` *(Object)*: The source object. +2. `[prop1, prop2, ...]` *(Object)*: The properties to drop. + +#### Returns +*(Object)*: Returns an object without the dropped properties. + +#### Example +~~~ js +_.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); +// => { 'name': 'moe', 'age': 40 } +~~~ + +* * * + + + + ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3179 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3206 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -589,16 +615,16 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2487 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2513 "View in source") [Ⓣ][1] -Copies enumerable properties from the source objects to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. +Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. #### Arguments 1. `object` *(Object)*: The destination object. 2. `[source1, source2, ...]` *(Object)*: The source objects. #### Returns -*(Object)*: Returns the destination object. +*(Object)*: Returns the `object`. #### Example ~~~ js @@ -749,7 +775,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2516 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2542 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -785,7 +811,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2539 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2565 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -813,7 +839,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2556 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2582 "View in source") [Ⓣ][1] Produces a sorted array of the enumerable properties, own and inherited, of `object` that have function values. @@ -869,7 +895,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2579 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2605 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -894,7 +920,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3198 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3225 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -1030,7 +1056,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2599 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2625 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1057,7 +1083,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2626 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2652 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1084,7 +1110,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2643 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2669 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1108,7 +1134,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2660 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2686 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1132,7 +1158,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2677 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2703 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1156,7 +1182,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2701 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2727 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays or strings with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1186,7 +1212,7 @@ _.isEmpty(''); ### `_.isEqual(a, b [, stack])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2735 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2761 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1218,7 +1244,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2897 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2923 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1248,7 +1274,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2914 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2940 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1272,7 +1298,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2966 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2992 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1305,7 +1331,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2989 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3015 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1332,7 +1358,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3006 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3032 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1356,7 +1382,7 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2935 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2961 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexps, `new Number(0)`, and `new String('')`)* @@ -1383,7 +1409,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3023 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3049 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1407,7 +1433,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3040 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3066 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1431,7 +1457,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3058 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3084 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1455,7 +1481,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3075 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3101 "View in source") [Ⓣ][1] Produces an array of object`'s own enumerable property names. @@ -1647,7 +1673,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3224 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3251 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1677,7 +1703,7 @@ _('larry').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3255 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3282 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1750,12 +1776,12 @@ hi('moe'); ### `_.pick(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3097 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3124 "View in source") [Ⓣ][1] -Creates an object composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. +Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. #### Arguments -1. `object` *(Object)*: The object to pluck. +1. `object` *(Object)*: The source object. 2. `[prop1, prop2, ...]` *(Object)*: The properties to pick. #### Returns @@ -1951,7 +1977,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3287 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3314 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2010,7 +2036,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3136 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3163 "View in source") [Ⓣ][1] Gets the size of `value` by returning `value.length` if `value` is a string or array, or the number of own enumerable properties if `value` is an object. @@ -2139,7 +2165,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3569 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3598 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2169,7 +2195,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3347 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3374 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -2253,7 +2279,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3485 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3514 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2363,7 +2389,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3512 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3541 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2387,7 +2413,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3157 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3184 "View in source") [Ⓣ][1] Produces an array of `object`'s own enumerable property values. @@ -2521,7 +2547,7 @@ _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3587 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3616 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2542,7 +2568,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3604 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3633 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.min.js b/lodash.min.js index 2ad67f2433..911cb3f740 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -4,32 +4,32 @@ */ ;(function(e,t){"use strict";function s(e){return new o(e)}function o(e){if(e&&e._wrapped)return e;this._wrapped=e}function u(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||30),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="p='"+u.o[n]+"';if(","constructor"==u.o[n]&&(t+="!(k&&k.prototype===s)&&"),t+="n.call(s,p)){"+u.m.i+"}"}u.c&&(t+="}")}return t+=u.e+";return G",Function("c,e,i,l,n,o,u,A,x,F,I,J,M" -,"return function("+e+"){"+t+"}")(ut,C,f,lt,Y,L,p,St,ot,et,tt,pt,nt)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return Q[t]}function c(e){return"\\"+xt[e]}function h(e){return Et[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+__e("+t+")+'",K+n}function m(e,t,n,r){return e=Q.length,t?Q[e]="'+__e("+t+")+'":r?Q[e]="';"+r+";__p+='":n&&(Q[e]="'+((__t=("+ -n+"))==null?'':__t)+'"),K+e}function g(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+((__t=("+t+"))==null?'':__t)+'",K+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=yt&&nt.call(e)==pt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=Zt(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:tt.call(e,0,t)}function w(e,t){var n=[];if(!e) -return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e?tt.call(e,t==r|| +),u.k&&u.q?t+="var D=x(s),C=-1,v=D.length;"+u.m.d+";while(++Cn;n++)t+="p='"+u.o[n]+"';if(","constructor"==u.o[n]&&(t+="!(k&&k.prototype===s)&&"),t+="n.call(s,p)){"+u.m.i+"}"}u.c&&(t+="}")}return t+=u.e+";return G",Function("c,d,e,i,j,l,n,o,q,u,A,x,F,I,J,M" +,"return function("+e+"){"+t+"}")(ut,H,C,f,G,lt,Y,L,E,p,St,ot,et,tt,pt,nt)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return Q[t]}function c(e){return"\\"+xt[e]}function h(e){return Et[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+__e("+t+")+'",K+n}function m(e,t,n,r){return e=Q.length,t?Q[e]="'+__e("+t+")+'":r?Q[e]="';"+r+";__p+='":n&&(Q[e]="'+((__t=("+ +n+"))==null?'':__t)+'"),K+e}function g(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+((__t=("+t+"))==null?'':__t)+'",K+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=yt&&nt.call(e)==pt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=en(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:tt.call(e,0,t)}function w(e,t){var n=[];if(!e) +return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e?tt.call(e,t==r|| n?1:t):[]}function T(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=C(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]E(a,r))a.push(r),s.push(e[o]);return s}function C(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?G.apply(s,o) :s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&St[typeof o]?o:u):e.apply(u,o)}var r,i=nt.call(e)==lt;if(i){if(bt||rt&&2++u&&(l=J[u],!Y.call(e,l)||!!(a=Y.call(t,l)&&k(e[l],t[l],s))););}return s.pop(),a}function L(e){return e}function A(e){Bt(Qt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Z.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,O,M,_,D +t.constructor)return i;for(var l in e)if(Y.call(e,l)&&(f++,!(a=Y.call(t,l)&&k(e[l],t[l],s))))break;if(a){for(l in t)if(Y.call(t,l)&&!(f--))break;a=!f}if(a&&mt)for(;7>++u&&(l=J[u],!Y.call(e,l)||!!(a=Y.call(t,l)&&k(e[l],t[l],s))););}return s.pop(),a}function L(e){return e}function A(e){Bt(Gt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Z.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,O,M,_,D ,P="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),H=Array.prototype,B=Object.prototype,j=0,F=e._,I=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,q=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,U=/(__e\(.*?\)|\b__t\))\+'';/g,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(B.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/__token__(\d+)/g,V=/[&<"']/g,$=/['\n\r\t\u2028\u2029\\]/g ,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K="__token__",Q=[],G=H.concat,Y=B.hasOwnProperty,Z=H.push,et=B.propertyIsEnumerable,tt=H.slice,nt=B.toString,rt=W.test(rt=tt.bind)&&rt,it=W.test(it=Array.isArray)&&it,st=e.isFinite,ot=W.test(ot=Object.keys)&&ot,ut="[object Array]",at="[object Boolean]",ft="[object Date]",lt="[object Function]",ct="[object Number]",ht="[object RegExp]",pt="[object String]",dt=e.clearTimeout,vt=e.setTimeout ,mt=!et.call({valueOf:0},"valueOf"),gt="x"!=tt.call("x")[0],yt="xx"!="x"[0]+Object("x")[0],bt=rt&&/\n|Opera/.test(rt+nt.call(e.opera)),wt=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Et={"&":"&","<":"<",'"':""","'":"'"},St={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},xt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj" };var Tt={a:"h,f,L",j:"h",p:"if(!f){f=o}else if(L)f=u(f,L)",i:"f(s[p],p,h)"},Nt={j:"true",i:"if(!f(s[p],p,h))return!G"},Ct={q:i,r:i,a:"z",j:"z",p:"for(var t=1,v=arguments.length;t-1"},i:"if(s[p]===K)return true"}),Dt=a(Tt,Nt),Pt=a(Tt,kt),Ht=a(Tt,Lt,{j:"",i:"if(f(s[p],p,h))return s[p]"}),Bt=a(Tt,Lt),jt=a(Tt,{j:"{}",p:"var B,r=typeof f=='function';if(r&&L)f=u(f,L)",i:"B=r?f(s[p],p,h):s[p][f];(n.call(G,B)?G[B]:G[B]=[]).push(s[p])"}),Ft=a(Ot,{a:"h,w",p:"var b=I.call(arguments,2),r=typeof w=='function'",i:{b:"G[p]=(r?w:s[p][w]).apply(s[p],b)",l:"G"+(wt?"[C]=":".push")+"((r?w:s[p][w]).apply(s[p],b))" }}),It=a(Tt,Ot),qt=a(Ot,{a:"h,E",i:{b:"G[p]=s[p][E]",l:"G"+(wt?"[C]=":".push")+"(s[p][E])"}}),Rt=a({a:"h,f,a,L",j:"a",p:"var y=arguments.length<3;if(L)f=u(f,L)",d:{b:"if(y)G=h[++p]"},i:{b:"G=f(G,s[p],p,h)",l:"G=y?(y=false,s[p]):f(G,s[p],p,h)"}}),Ut=a(Tt,kt,{i:"!"+kt.i}),zt=a(Tt,Nt,{j:"false",i:Nt.i.replace("!","")}),Wt=a(Tt,Ot,{p:"if(typeof f=='string'){var B=f;f=function(h){return h[B]}}else if(L)f=u(f,L)",i:{b:"G[p]={a:f(s[p],p,h),b:s[p]}",l:"G"+(wt?"[C]=":".push")+"({a:f(s[p],p,h),b:s[p]})"},e -:"G.sort(i);v=G.length;while(v--){G[v]=G[v].b}"}),Xt=a({q:i,r:i,a:"z",j:"z",p:"var m=arguments,v=m.length;if(v>1){for(var p=1;pe?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=Xt,s.chain=function(e) -{return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&St[typeof e]?Gt(e)?e.slice():$t({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&Dt(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=Ft,s.isArray=Gt,s.isBoolean=function(e){return e===n||e===i||nt.call(e)==at},s.isElement=function(e){return!! -e&&1==e.nodeType},s.isEmpty=Yt,s.isEqual=k,s.isFinite=function(e){return st(e)&&nt.call(e)==ct},s.isNaN=function(e){return nt.call(e)==ct&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&St[typeof e]},s.isUndefined=function(e){return e===t},s.keys=Zt,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:tt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if( -e[r]===t)return r;return-1},s.map=It,s.max=S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Y.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?e.length:Zt(e).length},s.some=zt,s.sortBy=Wt,s.sortedIndex=T,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var o,u;o=n.escape;var a=n.evaluate, -f=n.interpolate,h=s.templateSettings,n=n.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=O&&(O=a,D=RegExp("|"+(a?"|"+a.source:""),"g")),o=Q.length,e=e.replace(D,m),o=o!=Q.length,e="__p += '"+e.replace($,c).replace(X,l)+"';",Q.length=0,n||(n=h.variable||M||"obj",o?e="with("+n+"){"+e+"}":(n!=M&&(M=n,_=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(z,"$&"+n+".").replace(_,"$1__d"))),e= -(o?e.replace(q,""):e).replace(R,"$1").replace(U,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s= -e.apply(o,i)):u||(u=vt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(gt?nt.call(e)==pt:"string"==typeof e)?e.split(""):tt.call(e):en(e)},s.union=function(){for(var e=-1,t=[],n=G.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=j++;return e?e+t:t},s.values=en,s.without= -function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n1){for(var p=1;pe?t():function(){if(1>-- +e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=Xt,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&St[typeof e]?Yt(e)?e.slice():Jt({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&Dt(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=Ft,s.isArray=Yt,s.isBoolean=function( +e){return e===n||e===i||nt.call(e)==at},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=Zt,s.isEqual=k,s.isFinite=function(e){return st(e)&&nt.call(e)==ct},s.isNaN=function(e){return nt.call(e)==ct&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&St[typeof e]},s.isUndefined=function(e){return e===t},s.keys=en,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:tt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof +n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=It,s.max=S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Y.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?e.length:en(e).length},s.some=zt,s.sortBy=Wt,s.sortedIndex=T,s.tap=function(e,t){return t(e),e},s.template=function(e, +t,n){n||(n={});var o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,h=s.templateSettings,n=n.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=O&&(O=a,D=RegExp("|"+(a?"|"+a.source:""),"g")),o=Q.length,e=e.replace(D,m),o=o!=Q.length,e="__p += '"+e.replace($,c).replace(X,l)+"';",Q.length=0,n||(n=h.variable||M||"obj",o?e="with("+n+"){"+e+"}":(n!=M&&(M=n,_=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g" +)),e=e.replace(z,"$&"+n+".").replace(_,"$1__d"))),e=(o?e.replace(q,""):e).replace(R,"$1").replace(U,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date +,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=vt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(gt?nt.call(e)==pt:"string"==typeof e)?e.split(""):tt.call(e):tn(e)},s.union=function(){for(var e=-1,t=[],n=G.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function( +e){var t=j++;return e?e+t:t},s.values=tn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n Date: Thu, 19 Jul 2012 01:29:51 -0400 Subject: [PATCH 10/77] Add `_.countBy` and related unit tests, benchmarks, and documentation. Former-commit-id: 915eaf414883a1dc344a558b08c7a1337ab5a225 --- build.js | 5 +- build/pre-compile.js | 4 +- doc/README.md | 254 ++++++++++++++++++++++++------------------- lodash.js | 141 ++++++++++++++---------- lodash.min.js | 42 +++---- perf/perf.js | 62 +++++++++-- test/test.js | 31 ++++-- 7 files changed, 332 insertions(+), 207 deletions(-) diff --git a/build.js b/build.js index e963737cfd..05a52103c9 100755 --- a/build.js +++ b/build.js @@ -153,6 +153,7 @@ 'compact': [], 'compose': [], 'contains': [], + 'countBy': [], 'debounce': [], 'defaults': [], 'defer': [], @@ -260,10 +261,12 @@ allMethods = Object.keys(dependencyMap); var underscoreMethods = lodash.without.apply(lodash, [allMethods].concat([ + 'countBy', 'drop', 'forIn', 'forOwn', - 'partial' + 'partial', + 'zipObject' ])); /** Used to specify whether filtering is for exclusion or inclusion */ diff --git a/build/pre-compile.js b/build/pre-compile.js index 7da3dab109..455f06dfaf 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -46,7 +46,8 @@ 'target', 'thisArg', 'toString', - 'value' + 'value', + 'valueProp' ]; /** Used to minify `compileIterator` option properties */ @@ -93,6 +94,7 @@ 'compact', 'compose', 'contains', + 'countBy', 'criteria', 'debounce', 'defaults', diff --git a/doc/README.md b/doc/README.md index d3a0687aaa..783bb2cf81 100644 --- a/doc/README.md +++ b/doc/README.md @@ -16,6 +16,7 @@ * [`_.compact`](#_compactarray) * [`_.compose`](#_composefunc1-func2-) * [`_.contains`](#_containscollection-target) +* [`_.countBy`](#_countbycollection-callback--thisarg) * [`_.debounce`](#_debouncefunc-wait-immediate) * [`_.defaults`](#_defaultsobject--default1-default2-) * [`_.defer`](#_deferfunc--arg1-arg2-) @@ -90,7 +91,7 @@ * [`_.uniqueId`](#_uniqueidprefix) * [`_.values`](#_valuesobject) * [`_.without`](#_withoutarray--value1-value2-) -* [`_.wrap`](#_wrapfunc-wrapper--arg1-arg2-) +* [`_.wrap`](#_wrapfunc-wrapper) * [`_.zip`](#_ziparray1-array2-) * [`_.zipObject`](#_zipobjectkeys) @@ -149,7 +150,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3646 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3674 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -161,7 +162,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1991 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2020 "View in source") [Ⓣ][1] Creates a new function that is restricted to executing only after it is called `n` times. @@ -189,7 +190,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2045 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2074 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. Lazy defined methods may be bound by passing the object they are bound to as `func` and the method name as `thisArg`. @@ -240,7 +241,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2115 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2144 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -271,7 +272,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3571 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3599 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -305,7 +306,7 @@ var youngest = _.chain(stooges) ### `_.clone(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2445 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2473 "View in source") [Ⓣ][1] Create a shallow clone of the `value`. Any nested objects or arrays will be assigned by reference and not cloned. @@ -329,9 +330,9 @@ _.clone({ 'name': 'moe' }); ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1233 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1263 "View in source") [Ⓣ][1] -Produces a new array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. +Creates a new array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. #### Arguments 1. `array` *(Array)*: The array to compact. @@ -353,7 +354,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2151 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2180 "View in source") [Ⓣ][1] Creates a new function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -380,7 +381,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L768 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L785 "View in source") [Ⓣ][1] Checks if a given `target` value is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -408,10 +409,42 @@ _.contains('curly', 'ur'); + + +### `_.countBy(collection, callback [, thisArg])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L821 "View in source") [Ⓣ][1] + +Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. + +#### Arguments +1. `collection` *(Array|Object|String)*: The collection to iterate over. +2. `callback` *(Function|String)*: The function called per iteration or property name to count by. +3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. + +#### Returns +*(Object)*: Returns the composed aggregate object. + +#### Example +~~~ js +_.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); +// => { '4': 1, '6': 2 } + +_.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); +// => { '4': 1, '6': 2 } + +_.countBy(['one', 'two', 'three'], 'length'); +// => { '3': 2, '5': 1 } +~~~ + +* * * + + + + ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2184 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2213 "View in source") [Ⓣ][1] Creates a new function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -437,7 +470,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2469 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2497 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -463,9 +496,9 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2249 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2278 "View in source") [Ⓣ][1] -Defers executing the `func` function until the current call stack has cleared. Additional arguments are passed to `func` when it is invoked. +Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. #### Arguments 1. `func` *(Function)*: The function to defer. @@ -488,9 +521,9 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2229 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2258 "View in source") [Ⓣ][1] -Executes the `func` function after `wait` milliseconds. Additional arguments are passed to `func` when it is invoked. +Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. #### Arguments 1. `func` *(Function)*: The function to delay. @@ -515,9 +548,9 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1265 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1295 "View in source") [Ⓣ][1] -Produces a new array of `array` values not present in the other arrays using strict equality for comparisons, i.e. `===`. +Creates a new array of `array` values not present in the other arrays using strict equality for comparisons, i.e. `===`. #### Arguments 1. `array` *(Array)*: The array to process. @@ -540,7 +573,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.drop(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2489 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2517 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -565,7 +598,7 @@ _.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3206 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3234 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -589,7 +622,7 @@ _.escape('Curly, Larry & Moe'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L796 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L841 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -615,7 +648,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2513 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2541 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -640,7 +673,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L816 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L861 "View in source") [Ⓣ][1] Examines each value in a `collection`, returning an array of all values the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -666,7 +699,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L837 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L882 "View in source") [Ⓣ][1] Examines each value in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -692,7 +725,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1302 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1332 "View in source") [Ⓣ][1] Gets the first value of the `array`. Pass `n` to return the first `n` values of the `array`. @@ -718,7 +751,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1326 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1356 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -746,7 +779,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L863 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L908 "View in source") [Ⓣ][1] Iterates over a `collection`, executing the `callback` for each value in the `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -775,7 +808,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2542 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2570 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -811,7 +844,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2565 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2593 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -839,9 +872,9 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2582 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2610 "View in source") [Ⓣ][1] -Produces a sorted array of the enumerable properties, own and inherited, of `object` that have function values. +Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. #### Arguments 1. `object` *(Object)*: The object to inspect. @@ -863,9 +896,9 @@ _.functions(_); ### `_.groupBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L890 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L936 "View in source") [Ⓣ][1] -Splits `collection` into sets, grouped by the result of running each value through `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to group by. +Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -873,15 +906,15 @@ Splits `collection` into sets, grouped by the result of running each value throu 3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. #### Returns -*(Object)*: Returns an object of grouped values. +*(Object)*: Returns the composed aggregate object. #### Example ~~~ js -_.groupBy([1.3, 2.1, 2.4], function(num) { return Math.floor(num); }); -// => { '1': [1.3], '2': [2.1, 2.4] } +_.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); +// => { '4': [4.2], '6': [6.1, 6.4] } -_.groupBy([1.3, 2.1, 2.4], function(num) { return this.floor(num); }, Math); -// => { '1': [1.3], '2': [2.1, 2.4] } +_.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); +// => { '4': [4.2], '6': [6.1, 6.4] } _.groupBy(['one', 'two', 'three'], 'length'); // => { '3': ['one', 'two'], '5': ['three'] } @@ -895,7 +928,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2605 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2633 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -920,7 +953,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3225 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3253 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -945,7 +978,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1370 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1400 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -977,7 +1010,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1410 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1440 "View in source") [Ⓣ][1] Gets all but the last value of `array`. Pass `n` to exclude the last `n` values from the result. @@ -1003,7 +1036,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1431 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1461 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays. @@ -1027,7 +1060,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L924 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L964 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1056,7 +1089,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2625 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2653 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1083,7 +1116,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2652 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2680 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1110,7 +1143,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2669 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2697 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1134,7 +1167,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2686 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2714 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1158,7 +1191,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2703 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2731 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1182,7 +1215,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2727 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2755 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays or strings with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1212,7 +1245,7 @@ _.isEmpty(''); ### `_.isEqual(a, b [, stack])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2761 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2789 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1244,7 +1277,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2923 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2951 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1274,7 +1307,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2940 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2968 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1298,7 +1331,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2992 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3020 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1331,7 +1364,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3015 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3043 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1358,7 +1391,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3032 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3060 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1382,7 +1415,7 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2961 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2989 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexps, `new Number(0)`, and `new String('')`)* @@ -1409,7 +1442,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3049 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3077 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1433,7 +1466,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3066 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3094 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1457,7 +1490,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3084 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3112 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1481,9 +1514,9 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3101 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3129 "View in source") [Ⓣ][1] -Produces an array of object`'s own enumerable property names. +Creates an array composed of the own enumerable property names of `object`. #### Arguments 1. `object` *(Object)*: The object to inspect. @@ -1505,7 +1538,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1472 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1502 "View in source") [Ⓣ][1] Gets the last value of the `array`. Pass `n` to return the lasy `n` values of the `array`. @@ -1531,7 +1564,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1498 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1528 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1560,9 +1593,9 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L960 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1000 "View in source") [Ⓣ][1] -Produces a new array of values by mapping each element in the `collection` through a transformation `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. +Creates a new array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -1589,7 +1622,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1538 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1568 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1621,7 +1654,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2272 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2301 "View in source") [Ⓣ][1] Creates a new function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1647,7 +1680,7 @@ var fibonacci = _.memoize(function(n) { ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1588 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1618 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1673,7 +1706,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3251 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3279 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1703,7 +1736,7 @@ _('larry').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3282 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3310 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1723,7 +1756,7 @@ var lodash = _.noConflict(); ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2298 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2327 "View in source") [Ⓣ][1] Creates a new function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1749,7 +1782,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2331 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2360 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the partially applied function. This method is similar `bind`, except it does **not** alter the `this` binding. @@ -1776,7 +1809,7 @@ hi('moe'); ### `_.pick(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3124 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3152 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -1801,7 +1834,7 @@ _.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L983 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1023 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -1832,7 +1865,7 @@ _.pluck(stooges, 'name'); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1649 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1679 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -1870,7 +1903,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1011 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1051 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -1897,7 +1930,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1048 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1088 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -1925,7 +1958,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1103 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1143 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -1951,7 +1984,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1686 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1716 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -1977,7 +2010,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3314 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3342 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2012,9 +2045,9 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1707 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1737 "View in source") [Ⓣ][1] -Produces a new array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. +Creates a new array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. #### Arguments 1. `array` *(Array)*: The array to shuffle. @@ -2036,7 +2069,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3163 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3191 "View in source") [Ⓣ][1] Gets the size of `value` by returning `value.length` if `value` is a string or array, or the number of own enumerable properties if `value` is an object. @@ -2066,7 +2099,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1126 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1166 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -2092,9 +2125,9 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1158 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1196 "View in source") [Ⓣ][1] -Produces a new sorted array, sorted in ascending order by the results of running each element of `collection` through a transformation `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. +Creates a new sorted array, sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -2124,7 +2157,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1759 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1789 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with `1` argument; *(value)*. @@ -2165,12 +2198,12 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3598 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3626 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. #### Arguments -1. `value` *(Mixed)*: The value to pass to `callback`. +1. `value` *(Mixed)*: The value to pass to `interceptor`. 2. `interceptor` *(Function)*: The function to invoke. #### Returns @@ -2195,7 +2228,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3374 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3402 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -2254,7 +2287,7 @@ _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' }); ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2367 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2396 "View in source") [Ⓣ][1] Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2279,7 +2312,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3514 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3542 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2305,7 +2338,7 @@ _.times(3, function() { this.grantWish(); }, genie); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1201 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1231 "View in source") [Ⓣ][1] Converts the `collection`, into an array. Useful for converting the `arguments` object. @@ -2329,7 +2362,7 @@ Converts the `collection`, into an array. Useful for converting the `arguments` ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1799 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1829 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays. @@ -2353,9 +2386,9 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1844 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1873 "View in source") [Ⓣ][1] -Produces a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each value of `array` is passed through a transformation `callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. +Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. #### Arguments 1. `array` *(Array)*: The array to process. @@ -2389,7 +2422,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3541 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3569 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2413,9 +2446,9 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3184 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3212 "View in source") [Ⓣ][1] -Produces an array of `object`'s own enumerable property values. +Creates an array composed of the own enumerable property values of `object`. #### Arguments 1. `object` *(Object)*: The object to inspect. @@ -2437,9 +2470,9 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1893 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1922 "View in source") [Ⓣ][1] -Produces a new array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. +Creates a new array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. #### Arguments 1. `array` *(Array)*: The array to filter. @@ -2461,15 +2494,14 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); -### `_.wrap(func, wrapper [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2419 "View in source") [Ⓣ][1] +### `_.wrap(func, wrapper)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2447 "View in source") [Ⓣ][1] -Create a new function that passes the `func` function to the `wrapper` function as its first argument. Additional arguments are appended to those passed to the `wrapper` function. +Create a new function that passes `func` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. #### Arguments 1. `func` *(Function)*: The function to wrap. 2. `wrapper` *(Function)*: The wrapper function. -3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to append to those passed to the wrapper. #### Returns *(Function)*: Returns the new function. @@ -2492,7 +2524,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1926 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1955 "View in source") [Ⓣ][1] Merges the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2516,7 +2548,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.zipObject(keys)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1955 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1984 "View in source") [Ⓣ][1] Merges an array of `keys` and an array of `values` into a single object. @@ -2547,7 +2579,7 @@ _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3616 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3644 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2568,7 +2600,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3633 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3661 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index 8422da923e..b778785979 100644 --- a/lodash.js +++ b/lodash.js @@ -391,6 +391,23 @@ 'inLoop': 'callback(iteratee[index], index, collection)' }; + /** Reusable iterator options for `countBy`, `groupBy`, and `sortBy` */ + var countByIteratorOptions = { + 'init': '{}', + 'top': + 'var prop;\n' + + 'if (typeof callback != \'function\') {\n' + + ' var valueProp = callback;\n' + + ' callback = function(value) { return value[valueProp] }\n' + + '}\n' + + 'else if (thisArg) {\n' + + ' callback = iteratorBind(callback, thisArg)\n' + + '}', + 'inLoop': + 'prop = callback(iteratee[index], index, collection);\n' + + '(hasOwnProperty.call(result, prop) ? result[prop]++ : result[prop] = 1)' + }; + /** Reusable iterator options for `every` and `some` */ var everyIteratorOptions = { 'init': 'true', @@ -775,6 +792,34 @@ 'inLoop': 'if (iteratee[index] === target) return true' }); + /** + * Creates an object composed of keys returned from running each element of + * `collection` through a `callback`. The corresponding value of each key is + * the number of times the key was returned by `callback`. The `callback` is + * bound to `thisArg` and invoked with 3 arguments; (value, index|key, collection). + * The `callback` argument may also be the name of a property to count by (e.g. 'length'). + * + * @static + * @memberOf _ + * @category Collections + * @param {Array|Object|String} collection The collection to iterate over. + * @param {Function|String} callback The function called per iteration or + * property name to count by. + * @param {Mixed} [thisArg] The `this` binding for the callback. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); + * // => { '4': 1, '6': 2 } + * + * _.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); + * // => { '4': 1, '6': 2 } + * + * _.countBy(['one', 'two', 'three'], 'length'); + * // => { '3': 2, '5': 1 } + */ + var countBy = createIterator(baseIteratorOptions, countByIteratorOptions); + /** * Checks if the `callback` returns a truthy value for **all** elements of a * `collection`. The `callback` is bound to `thisArg` and invoked with 3 @@ -863,10 +908,11 @@ var forEach = createIterator(baseIteratorOptions, forEachIteratorOptions); /** - * Splits `collection` into sets, grouped by the result of running each value - * through `callback`. The `callback` is bound to `thisArg` and invoked with - * 3 arguments; (value, index|key, collection). The `callback` argument may - * also be the name of a property to group by. + * Creates an object composed of keys returned from running each element of + * `collection` through a `callback`. The corresponding value of each key is an + * array of elements passed to `callback` that returned the key. The `callback` + * is bound to `thisArg` and invoked with 3 arguments; (value, index|key, collection). + * The `callback` argument may also be the name of a property to count by (e.g. 'length'). * * @static * @memberOf _ @@ -875,27 +921,21 @@ * @param {Function|String} callback The function called per iteration or * property name to group by. * @param {Mixed} [thisArg] The `this` binding for the callback. - * @returns {Object} Returns an object of grouped values. + * @returns {Object} Returns the composed aggregate object. * @example * - * _.groupBy([1.3, 2.1, 2.4], function(num) { return Math.floor(num); }); - * // => { '1': [1.3], '2': [2.1, 2.4] } + * _.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); + * // => { '4': [4.2], '6': [6.1, 6.4] } * - * _.groupBy([1.3, 2.1, 2.4], function(num) { return this.floor(num); }, Math); - * // => { '1': [1.3], '2': [2.1, 2.4] } + * _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); + * // => { '4': [4.2], '6': [6.1, 6.4] } * * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ - var groupBy = createIterator(baseIteratorOptions, { - 'init': '{}', - 'top': - 'var prop, isFunc = typeof callback == \'function\';\n' + - 'if (isFunc && thisArg) callback = iteratorBind(callback, thisArg)', + var groupBy = createIterator(baseIteratorOptions, countByIteratorOptions, { 'inLoop': - 'prop = isFunc\n' + - ' ? callback(iteratee[index], index, collection)\n' + - ' : iteratee[index][callback];\n' + + 'prop = callback(iteratee[index], index, collection);\n' + '(hasOwnProperty.call(result, prop) ? result[prop] : result[prop] = []).push(iteratee[index])' }); @@ -937,9 +977,9 @@ }); /** - * Produces a new array of values by mapping each element in the `collection` - * through a transformation `callback`. The `callback` is bound to `thisArg` - * and invoked with 3 arguments; (value, index|key, collection). + * Creates a new array of values by running each element in the `collection` + * through a `callback`. The `callback` is bound to `thisArg` and invoked with + * 3 arguments; (value, index|key, collection). * * @static * @memberOf _ @@ -1128,13 +1168,11 @@ 'inLoop': everyIteratorOptions.inLoop.replace('!', '') }); - /** - * Produces a new sorted array, sorted in ascending order by the results of - * running each element of `collection` through a transformation `callback`. - * The `callback` is bound to `thisArg` and invoked with 3 arguments; - * (value, index|key, collection). The `callback` argument may also be the - * name of a property to sort by (e.g. 'length'). + * Creates a new sorted array, sorted in ascending order by the results of + * running each element of `collection` through a `callback`. The `callback` is + * bound to `thisArg` and invoked with 3 arguments; (value, index|key, collection). + * The `callback` argument may also be the name of a property to sort by (e.g. 'length'). * * @static * @memberOf _ @@ -1155,15 +1193,7 @@ * _.sortBy(['larry', 'brendan', 'moe'], 'length'); * // => ['moe', 'larry', 'brendan'] */ - var sortBy = createIterator(baseIteratorOptions, mapIteratorOptions, { - 'top': - 'if (typeof callback == \'string\') {\n' + - ' var prop = callback;\n' + - ' callback = function(collection) { return collection[prop] }\n' + - '}\n' + - 'else if (thisArg) {\n' + - ' callback = iteratorBind(callback, thisArg)\n' + - '}', + var sortBy = createIterator(baseIteratorOptions, countByIteratorOptions, mapIteratorOptions, { 'inLoop': { 'array': 'result[index] = {\n' + @@ -1217,7 +1247,7 @@ /*--------------------------------------------------------------------------*/ /** - * Produces a new array with all falsey values of `array` removed. The values + * Creates a new array with all falsey values of `array` removed. The values * `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. * * @static @@ -1247,7 +1277,7 @@ } /** - * Produces a new array of `array` values not present in the other arrays + * Creates a new array of `array` values not present in the other arrays * using strict equality for comparisons, i.e. `===`. * * @static @@ -1691,7 +1721,7 @@ } /** - * Produces a new array of shuffled `array` values, using a version of the + * Creates a new array of shuffled `array` values, using a version of the * Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. * * @static @@ -1811,12 +1841,11 @@ } /** - * Produces a duplicate-value-free version of the `array` using strict equality + * Creates a duplicate-value-free version of the `array` using strict equality * for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` - * for `isSorted` will run a faster algorithm. If `callback` is passed, - * each value of `array` is passed through a transformation `callback` before - * uniqueness is computed. The `callback` is bound to `thisArg` and invoked - * with 3 arguments; (value, index, array). + * for `isSorted` will run a faster algorithm. If `callback` is passed, each + * element of `array` is passed through a callback` before uniqueness is computed. + * The `callback` is bound to `thisArg` and invoked with 3 arguments; (value, index, array). * * @static * @memberOf _ @@ -1876,7 +1905,7 @@ } /** - * Produces a new array with all occurrences of the passed values removed using + * Creates a new array with all occurrences of the passed values removed using * strict equality for comparisons, i.e. `===`. * * @static @@ -2211,7 +2240,7 @@ /** * Executes the `func` function after `wait` milliseconds. Additional arguments - * are passed to `func` when it is invoked. + * will be passed to `func` when it is invoked. * * @static * @memberOf _ @@ -2233,7 +2262,7 @@ /** * Defers executing the `func` function until the current call stack has cleared. - * Additional arguments are passed to `func` when it is invoked. + * Additional arguments will be passed to `func` when it is invoked. * * @static * @memberOf _ @@ -2396,16 +2425,15 @@ } /** - * Create a new function that passes the `func` function to the `wrapper` - * function as its first argument. Additional arguments are appended to those - * passed to the `wrapper` function. + * Create a new function that passes `func` to the `wrapper` function as its + * first argument. Additional arguments passed to the new function are appended + * to those passed to the `wrapper` function. * * @static * @memberOf _ * @category Functions * @param {Function} func The function to wrap. * @param {Function} wrapper The wrapper function. - * @param {Mixed} [arg1, arg2, ...] Arguments to append to those passed to the wrapper. * @returns {Function} Returns the new function. * @example * @@ -2565,7 +2593,7 @@ var forOwn = createIterator(baseIteratorOptions, forEachIteratorOptions, forOwnIteratorOptions); /** - * Produces a sorted array of the enumerable properties, own and inherited, + * Creates a sorted array of all enumerable properties, own and inherited, * of `object` that have function values. * * @static @@ -3086,7 +3114,7 @@ } /** - * Produces an array of object`'s own enumerable property names. + * Creates an array composed of the own enumerable property names of `object`. * * @static * @memberOf _ @@ -3169,7 +3197,7 @@ } /** - * Produces an array of `object`'s own enumerable property values. + * Creates an array composed of the own enumerable property values of `object`. * * @static * @memberOf _ @@ -3391,8 +3419,8 @@ escapeDelimiter = settings.escape; } if (evaluateDelimiter == null) { - // use `false` as the fallback value so the initial assignment of - // `reEvaluateDelimiter` will still occur + // use `false` as the fallback value, instead of leaving it `undefined`, + // so the initial assignment of `reEvaluateDelimiter` will still occur evaluateDelimiter = settings.evaluate || false; } if (interpolateDelimiter == null) { @@ -3582,7 +3610,7 @@ * @static * @memberOf _ * @category Chaining - * @param {Mixed} value The value to pass to `callback`. + * @param {Mixed} value The value to pass to `interceptor`. * @param {Function} interceptor The function to invoke. * @returns {Mixed} Returns `value`. * @example @@ -3654,6 +3682,7 @@ lodash.compact = compact; lodash.compose = compose; lodash.contains = contains; + lodash.countBy = countBy; lodash.debounce = debounce; lodash.defaults = defaults; lodash.defer = defer; diff --git a/lodash.min.js b/lodash.min.js index 911cb3f740..fa01813d11 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -6,30 +6,30 @@ ("string"==typeof n&&(n={b:n,l:n}),u.c[t]=n.b,u.m[t]=n.l):u[t]=n;e=u.a,t=/^[^,]+/.exec(e)[0],u.g=t,u.h=mt,u.k=wt,u.o=J,u.q=u.q!==i,u.r=u.r!==i,"n"in u||(u.n=yt),u.f||(u.f="if(!"+t+")return G");if("h"!=t||!u.c.i)u.c=r;t="",u.r&&(t+="'use strict';"),t+="var p,s="+u.g+",G",u.j&&(t+="="+u.j),t+=";"+u.f+";"+u.p+";",u.c&&(t+="var v=s.length;p=-1;",u.m&&(t+="if(v===v>>>0){"),u.n&&(t+="if(M.call(s)==J){s=s.split('')}"),t+=u.c.d+";while(++pn;n++)t+="p='"+u.o[n]+"';if(","constructor"==u.o[n]&&(t+="!(k&&k.prototype===s)&&"),t+="n.call(s,p)){"+u.m.i+"}"}u.c&&(t+="}")}return t+=u.e+";return G",Function("c,d,e,i,j,l,n,o,q,u,A,x,F,I,J,M" ,"return function("+e+"){"+t+"}")(ut,H,C,f,G,lt,Y,L,E,p,St,ot,et,tt,pt,nt)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return Q[t]}function c(e){return"\\"+xt[e]}function h(e){return Et[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+__e("+t+")+'",K+n}function m(e,t,n,r){return e=Q.length,t?Q[e]="'+__e("+t+")+'":r?Q[e]="';"+r+";__p+='":n&&(Q[e]="'+((__t=("+ -n+"))==null?'':__t)+'"),K+e}function g(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+((__t=("+t+"))==null?'':__t)+'",K+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=yt&&nt.call(e)==pt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=en(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:tt.call(e,0,t)}function w(e,t){var n=[];if(!e) -return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e?tt.call(e,t==r|| +n+"))==null?'':__t)+'"),K+e}function g(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+((__t=("+t+"))==null?'':__t)+'",K+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=yt&&nt.call(e)==pt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=nn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:tt.call(e,0,t)}function w(e,t){var n=[];if(!e) +return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e?tt.call(e,t==r|| n?1:t):[]}function T(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=C(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]E(a,r))a.push(r),s.push(e[o]);return s}function C(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?G.apply(s,o) :s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&St[typeof o]?o:u):e.apply(u,o)}var r,i=nt.call(e)==lt;if(i){if(bt||rt&&2++u&&(l=J[u],!Y.call(e,l)||!!(a=Y.call(t,l)&&k(e[l],t[l],s))););}return s.pop(),a}function L(e){return e}function A(e){Bt(Gt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Z.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,O,M,_,D +t.constructor)return i;for(var l in e)if(Y.call(e,l)&&(f++,!(a=Y.call(t,l)&&k(e[l],t[l],s))))break;if(a){for(l in t)if(Y.call(t,l)&&!(f--))break;a=!f}if(a&&mt)for(;7>++u&&(l=J[u],!Y.call(e,l)||!!(a=Y.call(t,l)&&k(e[l],t[l],s))););}return s.pop(),a}function L(e){return e}function A(e){Ft(Zt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Z.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,O,M,_,D ,P="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),H=Array.prototype,B=Object.prototype,j=0,F=e._,I=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,q=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,U=/(__e\(.*?\)|\b__t\))\+'';/g,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(B.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/__token__(\d+)/g,V=/[&<"']/g,$=/['\n\r\t\u2028\u2029\\]/g ,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K="__token__",Q=[],G=H.concat,Y=B.hasOwnProperty,Z=H.push,et=B.propertyIsEnumerable,tt=H.slice,nt=B.toString,rt=W.test(rt=tt.bind)&&rt,it=W.test(it=Array.isArray)&&it,st=e.isFinite,ot=W.test(ot=Object.keys)&&ot,ut="[object Array]",at="[object Boolean]",ft="[object Date]",lt="[object Function]",ct="[object Number]",ht="[object RegExp]",pt="[object String]",dt=e.clearTimeout,vt=e.setTimeout ,mt=!et.call({valueOf:0},"valueOf"),gt="x"!=tt.call("x")[0],yt="xx"!="x"[0]+Object("x")[0],bt=rt&&/\n|Opera/.test(rt+nt.call(e.opera)),wt=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Et={"&":"&","<":"<",'"':""","'":"'"},St={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},xt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj" -};var Tt={a:"h,f,L",j:"h",p:"if(!f){f=o}else if(L)f=u(f,L)",i:"f(s[p],p,h)"},Nt={j:"true",i:"if(!f(s[p],p,h))return!G"},Ct={q:i,r:i,a:"z",j:"z",p:"for(var t=1,v=arguments.length;t-1"},i:"if(s[p]===K)return true"}),Dt=a(Tt,Nt),Pt=a(Tt,kt),Ht=a(Tt,Lt,{j:"",i:"if(f(s[p],p,h))return s[p]"}),Bt=a(Tt,Lt),jt=a(Tt,{j:"{}",p:"var B,r=typeof f=='function';if(r&&L)f=u(f,L)",i:"B=r?f(s[p],p,h):s[p][f];(n.call(G,B)?G[B]:G[B]=[]).push(s[p])"}),Ft=a(Ot,{a:"h,w",p:"var b=I.call(arguments,2),r=typeof w=='function'",i:{b:"G[p]=(r?w:s[p][w]).apply(s[p],b)",l:"G"+(wt?"[C]=":".push")+"((r?w:s[p][w]).apply(s[p],b))" -}}),It=a(Tt,Ot),qt=a(Ot,{a:"h,E",i:{b:"G[p]=s[p][E]",l:"G"+(wt?"[C]=":".push")+"(s[p][E])"}}),Rt=a({a:"h,f,a,L",j:"a",p:"var y=arguments.length<3;if(L)f=u(f,L)",d:{b:"if(y)G=h[++p]"},i:{b:"G=f(G,s[p],p,h)",l:"G=y?(y=false,s[p]):f(G,s[p],p,h)"}}),Ut=a(Tt,kt,{i:"!"+kt.i}),zt=a(Tt,Nt,{j:"false",i:Nt.i.replace("!","")}),Wt=a(Tt,Ot,{p:"if(typeof f=='string'){var B=f;f=function(h){return h[B]}}else if(L)f=u(f,L)",i:{b:"G[p]={a:f(s[p],p,h),b:s[p]}",l:"G"+(wt?"[C]=":".push")+"({a:f(s[p],p,h),b:s[p]})"},e -:"G.sort(i);v=G.length;while(v--){G[v]=G[v].b}"}),Xt=a({q:i,r:i,a:"z",j:"z",p:"var m=arguments,v=m.length;if(v>1){for(var p=1;pe?t():function(){if(1>-- -e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=Xt,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&St[typeof e]?Yt(e)?e.slice():Jt({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&Dt(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=Ft,s.isArray=Yt,s.isBoolean=function( -e){return e===n||e===i||nt.call(e)==at},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=Zt,s.isEqual=k,s.isFinite=function(e){return st(e)&&nt.call(e)==ct},s.isNaN=function(e){return nt.call(e)==ct&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&St[typeof e]},s.isUndefined=function(e){return e===t},s.keys=en,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:tt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof -n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=It,s.max=S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Y.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?e.length:en(e).length},s.some=zt,s.sortBy=Wt,s.sortedIndex=T,s.tap=function(e,t){return t(e),e},s.template=function(e, -t,n){n||(n={});var o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,h=s.templateSettings,n=n.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=O&&(O=a,D=RegExp("|"+(a?"|"+a.source:""),"g")),o=Q.length,e=e.replace(D,m),o=o!=Q.length,e="__p += '"+e.replace($,c).replace(X,l)+"';",Q.length=0,n||(n=h.variable||M||"obj",o?e="with("+n+"){"+e+"}":(n!=M&&(M=n,_=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g" -)),e=e.replace(z,"$&"+n+".").replace(_,"$1__d"))),e=(o?e.replace(q,""):e).replace(R,"$1").replace(U,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date -,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=vt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(gt?nt.call(e)==pt:"string"==typeof e)?e.split(""):tt.call(e):tn(e)},s.union=function(){for(var e=-1,t=[],n=G.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function( -e){var t=j++;return e?e+t:t},s.values=tn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n-1"},i:"if(s[p]===K)return true"}),Pt=a(Tt,Nt),Ht=a(Tt,Ct),Bt=a(Tt,Lt),jt=a(Tt,At,{j:"",i:"if(f(s[p],p,h))return s[p]"}),Ft=a(Tt,At),It=a(Tt,Nt,{i:"B=f(s[p],p,h);(n.call(G,B)?G[B]:G[B]=[]).push(s[p])"}),qt=a(Mt,{a:"h,w",p:"var b=I.call(arguments,2),r=typeof w=='function'" +,i:{b:"G[p]=(r?w:s[p][w]).apply(s[p],b)",l:"G"+(wt?"[C]=":".push")+"((r?w:s[p][w]).apply(s[p],b))"}}),Rt=a(Tt,Mt),Ut=a(Mt,{a:"h,E",i:{b:"G[p]=s[p][E]",l:"G"+(wt?"[C]=":".push")+"(s[p][E])"}}),zt=a({a:"h,f,a,L",j:"a",p:"var y=arguments.length<3;if(L)f=u(f,L)",d:{b:"if(y)G=h[++p]"},i:{b:"G=f(G,s[p],p,h)",l:"G=y?(y=false,s[p]):f(G,s[p],p,h)"}}),Wt=a(Tt,Lt,{i:"!"+Lt.i}),Xt=a(Tt,Ct,{j:"false",i:Ct.i.replace("!","")}),Vt=a(Tt,Nt,Mt,{i:{b:"G[p]={a:f(s[p],p,h),b:s[p]}",l:"G"+(wt?"[C]=":".push")+"({a:f(s[p],p,h),b:s[p]})" +},e:"G.sort(i);v=G.length;while(v--){G[v]=G[v].b}"}),$t=a({q:i,r:i,a:"z",j:"z",p:"var m=arguments,v=m.length;if(v>1){for(var p=1;pe?t():function(){ +if(1>--e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=$t,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&St[typeof e]?en(e)?e.slice():Qt({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&Ht(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=qt, +s.isArray=en,s.isBoolean=function(e){return e===n||e===i||nt.call(e)==at},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=tn,s.isEqual=k,s.isFinite=function(e){return st(e)&&nt.call(e)==ct},s.isNaN=function(e){return nt.call(e)==ct&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&St[typeof e]},s.isUndefined=function(e){return e===t},s.keys=nn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:tt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(! +e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Rt,s.max=S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Y.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?e.length:nn(e).length},s.some=Xt,s.sortBy=Vt,s.sortedIndex=T, +s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,h=s.templateSettings,n=n.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=O&&(O=a,D=RegExp("|"+(a?"|"+a.source:""),"g")),o=Q.length,e=e.replace(D,m),o=o!=Q.length,e="__p += '"+e.replace($,c).replace(X,l)+"';",Q.length=0,n||(n=h.variable||M||"obj",o?e="with("+n+"){"+e+"}" +:(n!=M&&(M=n,_=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(z,"$&"+n+".").replace(_,"$1__d"))),e=(o?e.replace(q,""):e).replace(R,"$1").replace(U,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply +(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=vt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(gt?nt.call(e)==pt:"string"==typeof e)?e.split(""):tt.call(e):rn(e)},s.union=function(){for(var e=-1,t=[],n=G.apply(t,arguments),r=n.length;++eE(t,n[ +e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=j++;return e?e+t:t},s.values=rn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n> 1; }); + }) + .add('Underscore', function() { + _.countBy(numbers, function(num) { return num >> 1; }); + }) + ); + + suites.push( + Benchmark.Suite('`_.countBy` with `property` name iterating an array') + .add('Lo-Dash', { + 'fn': function() { + lodash.countBy(words, 'length'); + }, + 'teardown': 'function countBy(){}' + }) + .add('Underscore', { + 'fn': function() { + _.countBy(words, 'length'); + }, + 'teardown': 'function countBy(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.countBy` with `callback` iterating an object') + .add('Lo-Dash', { + 'fn': function() { + lodash.countBy(wordToNumber, function(num) { return num >> 1; }); + }, + 'teardown': 'function countBy(){}' + }) + .add('Underscore', { + 'fn': function() { + _.countBy(wordToNumber, function(num) { return num >> 1; }); + }, + 'teardown': 'function countBy(){}' + }) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.difference`') .add('Lo-Dash', function() { @@ -749,13 +793,13 @@ 'fn': function() { lodash.groupBy(words, 'length'); }, - 'teardown': 'function groupBy(){}' + 'teardown': 'function countBy(){}' }) .add('Underscore', { 'fn': function() { _.groupBy(words, 'length'); }, - 'teardown': 'function groupBy(){}' + 'teardown': 'function countBy(){}' }) ); @@ -765,13 +809,13 @@ 'fn': function() { lodash.groupBy(wordToNumber, function(num) { return num >> 1; }); }, - 'teardown': 'function groupBy(){}' + 'teardown': 'function countBy(){}' }) .add('Underscore', { 'fn': function() { _.groupBy(wordToNumber, function(num) { return num >> 1; }); }, - 'teardown': 'function groupBy(){}' + 'teardown': 'function countBy(){}' }) ); @@ -1149,13 +1193,13 @@ 'fn': function() { lodash.sortBy(words, 'length'); }, - 'teardown': 'function groupBy(){}' + 'teardown': 'function countBy(){}' }) .add('Underscore', { 'fn': function() { _.sortBy(words, 'length'); }, - 'teardown': 'function groupBy(){}' + 'teardown': 'function countBy(){}' }) ); @@ -1179,7 +1223,7 @@ return wordToNumber[value]; }); }, - 'teardown': 'function groupBy(){}' + 'teardown': 'function countBy(){}' }) .add('Underscore', { 'fn': function() { @@ -1187,7 +1231,7 @@ return wordToNumber[value]; }); }, - 'teardown': 'function groupBy(){}' + 'teardown': 'function countBy(){}' }) ); diff --git a/test/test.js b/test/test.js index 08662de9c2..8cfc755911 100644 --- a/test/test.js +++ b/test/test.js @@ -169,6 +169,21 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.countBy'); + + (function() { + test('should only add elements to own, not inherited, properties', function() { + var actual = _.countBy([4.2, 6.1, 6.4], function(num) { + return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor'; + }); + + deepEqual(actual.constructor, 1); + deepEqual(actual.hasOwnProperty, 2); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.debounce'); (function() { @@ -443,28 +458,28 @@ (function() { test('supports the `thisArg` argument', function() { - var actual = _.groupBy([1.3, 2.1, 2.4], function(num) { + var actual = _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); - deepEqual(actual, { '1': [1.3], '2': [2.1, 2.4] }); + deepEqual(actual, { '4': [4.2], '6': [6.1, 6.4] }); }); test('should only add elements to own, not inherited, properties', function() { - var actual = _.groupBy([1.3, 2.1, 2.4], function(num) { - return Math.floor(num) > 1 ? 'hasOwnProperty' : 'constructor'; + var actual = _.groupBy([4.2, 6.1, 6.4], function(num) { + return Math.floor(num) > 4 ? 'hasOwnProperty' : 'constructor'; }); - deepEqual(actual.constructor, [1.3]); - deepEqual(actual.hasOwnProperty, [2.1, 2.4]); + deepEqual(actual.constructor, [4.2]); + deepEqual(actual.hasOwnProperty, [6.1, 6.4]); }); test('should work with an object for `collection`', function() { - var actual = _.groupBy({ 'a': 1.3, 'b': 2.1, 'c': 2.4 }, function(num) { + var actual = _.groupBy({ 'a': 4.2, 'b': 6.1, 'c': 6.4 }, function(num) { return Math.floor(num); }); - deepEqual(actual, { '1': [1.3], '2': [2.1, 2.4] }); + deepEqual(actual, { '4': [4.2], '6': [6.1, 6.4] }); }); }()); From d43ede3a118e93e44461457f75dfed4dcd2318c4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 19 Jul 2012 01:32:47 -0400 Subject: [PATCH 11/77] Update vendor/underscore and backbone. Former-commit-id: 614926653b0b1669f8a5533666adb0aecbd46c03 --- vendor/backbone/backbone.js | 47 +++++++++++---------------- vendor/underscore/test/collections.js | 12 +++++++ vendor/underscore/underscore.js | 40 ++++++++++++++++++----- 3 files changed, 62 insertions(+), 37 deletions(-) diff --git a/vendor/backbone/backbone.js b/vendor/backbone/backbone.js index 15a74d10e6..a307e09ff9 100644 --- a/vendor/backbone/backbone.js +++ b/vendor/backbone/backbone.js @@ -295,7 +295,7 @@ // If the new and previous value differ, record the change. If not, // then remove changes for this attribute. - if (!_.isEqual(prev[attr], val) || (_.has(now, attr) != _.has(prev, attr))) { + if (!_.isEqual(prev[attr], val) || (_.has(now, attr) !== _.has(prev, attr))) { this.changed[attr] = val; if (!options.silent) this._pending[attr] = true; } else { @@ -432,7 +432,7 @@ url: function() { var base = getValue(this, 'urlRoot') || getValue(this.collection, 'url') || urlError(); if (this.isNew()) return base; - return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + encodeURIComponent(this.id); + return base + (base.charAt(base.length - 1) === '/' ? '' : '/') + encodeURIComponent(this.id); }, // **parse** converts a response into the hash of attributes to be `set` on @@ -555,7 +555,7 @@ var Collection = Backbone.Collection = function(models, options) { options || (options = {}); if (options.model) this.model = options.model; - if (options.comparator !== undefined) this.comparator = options.comparator; + if (options.comparator !== void 0) this.comparator = options.comparator; this._reset(); this.initialize.apply(this, arguments); if (models) this.reset(models, {silent: true, parse: options.parse}); @@ -628,9 +628,7 @@ // Merge in duplicate models. if (options.merge) { for (i = 0, length = dups.length; i < length; i++) { - if (model = this._byId[dups[i].id]) { - model.set(dups[i], options); - } + if (model = this._byId[dups[i].id]) model.set(dups[i], options); } } @@ -737,7 +735,7 @@ options || (options = {}); if (!this.comparator) throw new Error('Cannot sort a set without a comparator'); var boundComparator = _.bind(this.comparator, this); - if (this.comparator.length == 1) { + if (this.comparator.length === 1) { this.models = this.sortBy(boundComparator); } else { this.models.sort(boundComparator); @@ -771,7 +769,7 @@ // models to the collection instead of resetting. fetch: function(options) { options = options ? _.clone(options) : {}; - if (options.parse === undefined) options.parse = true; + if (options.parse === void 0) options.parse = true; var collection = this; var success = options.success; options.success = function(resp, status, xhr) { @@ -842,9 +840,7 @@ // Internal method to remove a model's ties to a collection. _removeReference: function(model) { - if (this == model.collection) { - delete model.collection; - } + if (this === model.collection) delete model.collection; model.off('all', this._onModelEvent, this); }, @@ -853,10 +849,8 @@ // events simply proxy through. "add" and "remove" events that originate // in other collections are ignored. _onModelEvent: function(event, model, collection, options) { - if ((event == 'add' || event == 'remove') && collection != this) return; - if (event == 'destroy') { - this.remove(model, options); - } + if ((event === 'add' || event === 'remove') && collection !== this) return; + if (event === 'destroy') this.remove(model, options); if (model && event === 'change:' + model.idAttribute) { delete this._byId[model.previous(model.idAttribute)]; if (model.id != null) this._byId[model.id] = model; @@ -1048,7 +1042,7 @@ // opened by a non-pushState browser. this.fragment = fragment; var loc = this.location; - var atRoot = (loc.pathname == this.options.root) && !loc.search; + var atRoot = (loc.pathname === this.options.root) && !loc.search; // If we've started off with a route from a `pushState`-enabled browser, // but we're currently in a browser that doesn't support it... @@ -1065,9 +1059,7 @@ this.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment); } - if (!this.options.silent) { - return this.loadUrl(); - } + if (!this.options.silent) return this.loadUrl(); }, // Disable Backbone.history, perhaps temporarily. Not useful in a real app, @@ -1088,10 +1080,10 @@ // calls `loadUrl`, normalizing across the hidden iframe. checkUrl: function(e) { var current = this.getFragment(); - if (current == this.fragment && this.iframe) { + if (current === this.fragment && this.iframe) { current = this.getFragment(this.getHash(this.iframe)); } - if (current == this.fragment) return false; + if (current === this.fragment) return false; if (this.iframe) this.navigate(current); this.loadUrl() || this.loadUrl(this.getHash()); }, @@ -1121,9 +1113,9 @@ if (!History.started) return false; if (!options || options === true) options = {trigger: options}; var frag = (fragment || '').replace(routeStripper, ''); - if (this.fragment == frag) return; + if (this.fragment === frag) return; this.fragment = frag; - var url = (frag.indexOf(this.options.root) != 0 ? this.options.root : '') + frag; + var url = (frag.indexOf(this.options.root) !== 0 ? this.options.root : '') + frag; // If pushState is available, we use it to set the fragment as a real URL. if (this._hasPushState) { @@ -1133,7 +1125,7 @@ // fragment to store history. } else if (this._wantsHashChange) { this._updateHash(this.location, frag, options.replace); - if (this.iframe && (frag != this.getFragment(this.getHash(this.iframe)))) { + if (this.iframe && (frag !== this.getFragment(this.getHash(this.iframe)))) { // Opening and closing the iframe tricks IE7 and earlier to push a // history entry on hash-tag change. When replace is true, we don't // want this. @@ -1158,6 +1150,7 @@ location.hash = fragment; } } + }); // Backbone.View @@ -1303,9 +1296,7 @@ // The self-propagating extend function that Backbone classes use. var extend = function(protoProps, classProps) { - var child = inherits(this, protoProps, classProps); - child.extend = this.extend; - return child; + return inherits(this, protoProps, classProps); }; // Set up inheritance for the model, collection, and view. @@ -1352,7 +1343,7 @@ } // Ensure that we have the appropriate request data. - if (!options.data && model && (method == 'create' || method == 'update')) { + if (!options.data && model && (method === 'create' || method === 'update')) { params.contentType = 'application/json'; params.data = JSON.stringify(model); } diff --git a/vendor/underscore/test/collections.js b/vendor/underscore/test/collections.js index 4d9fdaa5d2..711053a90e 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -253,6 +253,18 @@ $(document).ready(function() { equal(grouped['5'].join(' '), 'three seven eight'); }); + test('collections: countBy', function() { + var parity = _.countBy([1, 2, 3, 4, 5], function(num){ return num % 2 == 0; }); + equal(parity['true'], 2); + equal(parity['false'], 3); + + var list = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]; + var grouped = _.countBy(list, 'length'); + equal(grouped['3'], 4); + equal(grouped['4'], 3); + equal(grouped['5'], 3); + }); + test('collections: sortedIndex', function() { var numbers = [10, 20, 30, 40, 50], num = 35; var indexForNum = _.sortedIndex(numbers, num); diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index a23ef78724..88141d1684 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -267,7 +267,7 @@ // Sort the object's values by a criterion produced by an iterator. _.sortBy = function(obj, val, context) { - var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; }; + var iterator = lookupIterator(obj, val); return _.pluck(_.map(obj, function(value, index, list) { return { value : value, @@ -281,18 +281,40 @@ }), 'value'); }; - // Groups the object's values by a criterion. Pass either a string attribute - // to group by, or a function that returns the criterion. - _.groupBy = function(obj, val) { + // An internal function to generate lookup iterators. + var lookupIterator = function(obj, val) { + return _.isFunction(val) ? val : function(obj) { return obj[val]; }; + }; + + // An internal function used for aggregate "group by" operations. + var group = function(obj, val, behavior) { var result = {}; - var iterator = _.isFunction(val) ? val : function(obj) { return obj[val]; }; + var iterator = lookupIterator(obj, val); each(obj, function(value, index) { var key = iterator(value, index); - (result[key] || (result[key] = [])).push(value); + behavior(result, key, value); }); return result; }; + // Groups the object's values by a criterion. Pass either a string attribute + // to group by, or a function that returns the criterion. + _.groupBy = function(obj, val) { + return group(obj, val, function(result, key, value) { + (result[key] || (result[key] = [])).push(value); + }); + }; + + // Counts instances of an object that group by a certain criterion. Pass + // either a string attribute to count by, or a function that returns the + // criterion. + _.countBy = function(obj, val) { + return group(obj, val, function(result, key, value) { + result[key] || (result[key] = 0); + result[key]++; + }); + }; + // Use a comparator function to figure out the smallest index at which // an object should be inserted so as to maintain order. Uses binary search. _.sortedIndex = function(array, obj, iterator) { @@ -709,7 +731,7 @@ }; // Internal recursive comparison function for `isEqual`. - function eq(a, b, stack) { + var eq = function(a, b, stack) { // Identical objects are equal. `0 === -0`, but they aren't identical. // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal. if (a === b) return a !== 0 || 1 / a == 1 / b; @@ -794,7 +816,7 @@ // Remove the first object from the stack of traversed objects. stack.pop(); return result; - } + }; // Perform a deep comparison to check if two objects are equal. _.isEqual = function(a, b) { @@ -832,7 +854,7 @@ return toString.call(obj) == '[object ' + name + ']'; }; }); - + // Define a fallback version of the method in browsers (ahem, IE), where // there isn't any inspectable "Arguments" type. if (!_.isArguments(arguments)) { From a192410498753735248aae04ea4e2f00d2032027 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 19 Jul 2012 08:01:04 -0400 Subject: [PATCH 12/77] Remove Narwhal link from README.md. Former-commit-id: b8bd53c9a19ef18480db14cfa82545aa872416b1 --- README.md | 2 +- vendor/benchmark.js/README.md | 2 +- vendor/platform.js/README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a1c4c00b6e..71ee0dd0d1 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ In [Node.js](http://nodejs.org/) and [RingoJS v0.8.0+](http://ringojs.org/): var _ = require('lodash'); ~~~ -In [Narwhal](http://narwhaljs.org/) and [RingoJS v0.7.0-](http://ringojs.org/): +In [RingoJS v0.7.0-](http://ringojs.org/): ~~~ js var _ = require('lodash')._; diff --git a/vendor/benchmark.js/README.md b/vendor/benchmark.js/README.md index 7b2a42ef60..49e412cc7d 100644 --- a/vendor/benchmark.js/README.md +++ b/vendor/benchmark.js/README.md @@ -48,7 +48,7 @@ Optionally, use the [microtime module](https://github.com/wadey/node-microtime) npm install microtime ~~~ -In [Narwhal](http://narwhaljs.org/) and [RingoJS v0.7.0-](http://ringojs.org/): +In [RingoJS v0.7.0-](http://ringojs.org/): ~~~ js var Benchmark = require('benchmark').Benchmark; diff --git a/vendor/platform.js/README.md b/vendor/platform.js/README.md index 4e5c08a90c..eb56ff77ec 100644 --- a/vendor/platform.js/README.md +++ b/vendor/platform.js/README.md @@ -30,7 +30,7 @@ Via [npm](http://npmjs.org/): npm install platform ~~~ -In [Narwhal](http://narwhaljs.org/), [Node.js](http://nodejs.org/), and [RingoJS](http://ringojs.org/): +In [Node.js](http://nodejs.org/) and [RingoJS](http://ringojs.org/): ~~~ js var platform = require('platform'); From befe0fccaf0bec08d29060add699988b6c44e6d3 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 20 Jul 2012 02:06:13 -0400 Subject: [PATCH 13/77] Cleanup `_.isEqual` comments and ensure `_.isEmpty`/`_.size` detect `arguments` objects correctly. Former-commit-id: 75b044d27b990d55393bf27234aad6ce369f6abe --- build.js | 20 +++----- build/pre-compile.js | 11 +++-- lodash.js | 107 ++++++++++++++++++++++--------------------- test/test.js | 16 ++++++- 4 files changed, 85 insertions(+), 69 deletions(-) diff --git a/build.js b/build.js index 05a52103c9..156fd14a3f 100755 --- a/build.js +++ b/build.js @@ -51,6 +51,7 @@ } if (isLegacy) { + source = replaceVar(source, 'noArgsClass', 'true'); ['isBindFast', 'isKeysFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) { source = replaceVar(source, varName, 'false'); }); @@ -401,7 +402,7 @@ * @returns {String} Returns the `isArguments` fallback snippet. */ function getIsArgumentsFallback(source) { - return (source.match(/(?:\s*\/\/.*)*\s*if *\(!(?:lodash\.)?isArguments[^)]+\)[\s\S]+?};\s*}/) || [''])[0]; + return (source.match(/(?:\s*\/\/.*)*\s*if *\(noArgsClass[\s\S]+?};\s*}/) || [''])[0]; } /** @@ -773,15 +774,15 @@ // build replacement code lodash.forOwn({ - 'Arguments': "'[object Arguments]'", + 'Arguments': 'argsClass', 'Date': 'dateClass', 'Function': 'funcClass', 'Number': 'numberClass', 'RegExp': 'regexpClass', 'String': 'stringClass' }, function(value, key) { - // skip `isArguments` if a legacy build - if (isLegacy && key == 'Arguments') { + // skip `isArguments` if not a mobile build + if (!isMobile && key == 'Arguments') { return; } var funcName = 'is' + key, @@ -818,13 +819,6 @@ ' };\n' + ' });' ); - - // tweak `isArguments` fallback - snippet = !isLegacy && getIsArgumentsFallback(source); - if (snippet) { - var modified = '\n' + snippet.replace(/isArguments/g, 'lodash.$&'); - source = source.replace(snippet, modified); - } }()); /*--------------------------------------------------------------------------*/ @@ -861,8 +855,8 @@ // replace `_.isArguments` with fallback if (!isRemoved(source, 'isArguments')) { source = source.replace( - matchFunction(source, 'isArguments').replace(/[\s\S]+?var isArguments *=/, ''), - getIsArgumentsFallback(source).match(/isArguments *=([\s\S]+?) *};/)[1] + ' };\n' + matchFunction(source, 'isArguments').replace(/[\s\S]+?function isArguments/, ''), + getIsArgumentsFallback(source).match(/isArguments *= *function([\s\S]+?) *};/)[1] + ' }\n' ); source = removeIsArgumentsFallback(source); diff --git a/build/pre-compile.js b/build/pre-compile.js index 455f06dfaf..d488c0dfea 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -10,10 +10,10 @@ 'accumulator', 'args', 'arrayClass', + 'arrayLikeClasses', 'ArrayProto', 'bind', 'callback', - 'className', 'collection', 'compareAscending', 'concat', @@ -24,6 +24,7 @@ 'identity', 'index', 'indexOf', + 'isArguments', 'isFunc', 'iteratee', 'iterateeIndex', @@ -215,6 +216,10 @@ // remove unrecognized JSDoc tags so Closure Compiler won't complain source = source.replace(/@(?:alias|category)\b.*/g, ''); + // manually convert `arrayLikeClasses` property assignments because + // Closure Compiler errors trying to minify them + source = source.replace(/(arrayLikeClasses =)[\s\S]+?= *true/g, "$1{'[object Arguments]': true, '[object Array]': true, '[object String]': true }"); + // add brackets to whitelisted properties so Closure Compiler won't mung them // http://code.google.com/closure/compiler/docs/api-tutorial3.html#export source = source.replace(RegExp('\\.(' + propWhitelist.join('|') + ')\\b', 'g'), "['$1']"); @@ -239,7 +244,7 @@ }); }); - // remove whitespace from `_.template` related regexpes + // remove whitespace from `_.template` related regexes source = source.replace(/(?:reDelimiterCode\w+|reEmptyString\w+|reInsertVariable) *=.+/g, function(match) { return match.replace(/ |\\n/g, ''); }); @@ -346,7 +351,7 @@ else { // minify property name strings modified = modified.replace(RegExp("'" + property + "'", 'g'), "'" + minNames[index] + "'"); - // minify property names in regexps and accessors + // minify property names in regexes and accessors if (isCreateIterator) { modified = modified.replace(RegExp('([\\.|/])' + property + '\\b' , 'g'), '$1' + minNames[index]); } diff --git a/lodash.js b/lodash.js index b778785979..ce4db50d42 100644 --- a/lodash.js +++ b/lodash.js @@ -104,7 +104,8 @@ nativeKeys = reNative.test(nativeKeys = Object.keys) && nativeKeys; /** `Object#toString` result shortcuts */ - var arrayClass = '[object Array]', + var argsClass = '[object Arguments]', + arrayClass = '[object Array]', boolClass = '[object Boolean]', dateClass = '[object Date]', funcClass = '[object Function]', @@ -123,6 +124,9 @@ */ var hasDontEnumBug = !propertyIsEnumerable.call({ 'valueOf': 0 }, 'valueOf'); + /** Detect if an `arguments` object's [[Class]] is unresolvable (Firefox < 4, IE < 9) */ + var noArgsClass = !isArguments(arguments); + /** Detect if `Array#slice` cannot be used to convert strings to arrays (Opera < 10.52) */ var noArraySliceOnStrings = slice.call('x')[0] != 'x'; @@ -136,7 +140,7 @@ /* Detect if `Function#bind` exists and is inferred to be fast (all but V8) */ var isBindFast = nativeBind && /\n|Opera/.test(nativeBind + toString.call(window.opera)); - /* Detect if `Object.keys` exists and is inferred to be fast (V8, Opera, IE) */ + /* Detect if `Object.keys` exists and is inferred to be fast (IE, Opera, V8) */ var isKeysFast = nativeKeys && /^.+$|true/.test(nativeKeys + !!window.attachEvent); /** Detect if sourceURL syntax is usable without erroring */ @@ -151,6 +155,10 @@ var useSourceURL = (Function('//@cc_on!')(), true); } catch(e){ } + /** Used to identify object classifications that are array-like */ + var arrayLikeClasses = {}; + arrayLikeClasses[argsClass] = arrayLikeClasses[arrayClass] = arrayLikeClasses[stringClass] = true; + /** * Used to escape characters for inclusion in HTML. * The `>` and `/` characters don't require escaping in HTML and have no @@ -592,16 +600,16 @@ } // create the function factory var factory = Function( - 'arrayClass, ArrayProto, bind, compareAscending, concat, funcClass, ' + - 'hasOwnProperty, identity, indexOf, iteratorBind, objectTypes, nativeKeys, ' + - 'propertyIsEnumerable, slice, stringClass, toString', + 'arrayClass, arrayLikeClasses, ArrayProto, bind, compareAscending, concat, ' + + 'funcClass, hasOwnProperty, identity, indexOf, isArguments, iteratorBind, ' + + 'objectTypes, nativeKeys, propertyIsEnumerable, slice, stringClass, toString', 'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}' ); // return the compiled function return factory( - arrayClass, ArrayProto, bind, compareAscending, concat, funcClass, - hasOwnProperty, identity, indexOf, iteratorBind, objectTypes, nativeKeys, - propertyIsEnumerable, slice, stringClass, toString + arrayClass, arrayLikeClasses, ArrayProto, bind, compareAscending, concat, + funcClass, hasOwnProperty, identity, indexOf, isArguments, iteratorBind, + objectTypes, nativeKeys, propertyIsEnumerable, slice, stringClass, toString ); } @@ -2650,12 +2658,11 @@ * _.isArguments([1, 2, 3]); * // => false */ - var isArguments = function(value) { - return toString.call(value) == '[object Arguments]'; - }; - // fallback for browser like Firefox < 4 and IE < 9 which detect - // `arguments` as `[object Object]` - if (!isArguments(arguments)) { + function isArguments(value) { + return toString.call(value) == argsClass; + } + // fallback for browsers that can't detect `arguments` objects by [[Class]] + if (noArgsClass) { isArguments = function(value) { return !!(value && hasOwnProperty.call(value, 'callee')); }; @@ -2733,8 +2740,9 @@ } /** - * Checks if `value` is empty. Arrays or strings with a length of `0` and - * objects with no own enumerable properties are considered "empty". + * Checks if `value` is empty. Arrays, strings, or `arguments` objects with a + * length of `0` and objects with no own enumerable properties are considered + * "empty". * * @static * @memberOf _ @@ -2756,8 +2764,9 @@ 'args': 'value', 'init': 'true', 'top': - 'var className = toString.call(value);\n' + - 'if (className == arrayClass || className == stringClass) return !value.length', + 'if (arrayLikeClasses[toString.call(value)]' + + (noArgsClass ? ' || isArguments(value)' : '') + + ') return !value.length', 'inLoop': { 'object': 'return false' } @@ -2794,7 +2803,7 @@ // treat `+0` vs. `-0` as not equal return a !== 0 || (1 / a == 1 / b); } - // a strict comparison is necessary because `undefined == null` + // a strict comparison is necessary because `null == undefined` if (a == null || b == null) { return a === b; } @@ -2818,11 +2827,11 @@ return false; } switch (className) { - // strings, numbers, dates, and booleans are compared by value - case stringClass: - // primitives and their corresponding object instances are equivalent; - // thus, `'5'` is quivalent to `new String('5')` - return a == String(b); + case boolClass: + case dateClass: + // coerce dates and booleans to numbers, dates to milliseconds and booleans + // to `1` or `0`, treating invalid dates coerced to `NaN` as not equal + return +a == +b; case numberClass: // treat `NaN` vs. `NaN` as equal @@ -2831,28 +2840,21 @@ // but treat `+0` vs. `-0` as not equal : (a == 0 ? (1 / a == 1 / b) : a == +b); - case boolClass: - case dateClass: - // coerce dates and booleans to numeric values, dates to milliseconds and - // booleans to 1 or 0; treat invalid dates coerced to `NaN` as not equal - return +a == +b; - - // regexps are compared by their source and flags case regexpClass: - return a.source == b.source && - a.global == b.global && - a.multiline == b.multiline && - a.ignoreCase == b.ignoreCase; + case stringClass: + // coerce regexes to strings (http://es5.github.com/#x15.10.6.4) + // treat string primitives and their corresponding object instances as equal + return a == b + ''; } if (typeof a != 'object' || typeof b != 'object') { + // for unequal function values return false; } - // Assume equality for cyclic structures. The algorithm for detecting cyclic - // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. + // assume cyclic structures are equal + // the algorithm for detecting cyclic structures is adapted from ES 5.1 + // section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3) var length = stack.length; while (length--) { - // Linear search. Performance is inversely proportional to the number of - // unique nested structures. if (stack[length] == a) { return true; } @@ -2865,7 +2867,7 @@ // add the first collection to the stack of traversed objects stack.push(a); - // recursively compare objects and arrays + // recursively compare objects and arrays (susceptible to call stack limits) if (className == arrayClass) { // compare array lengths to determine if a deep comparison is necessary size = a.length; @@ -2881,11 +2883,11 @@ } } else { - // objects with different constructors are not equivalent + // objects with different constructors are not equal if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) { return false; } - // deep compare objects. + // deep compare objects for (var prop in a) { if (hasOwnProperty.call(a, prop)) { // count the number of properties. @@ -2899,14 +2901,14 @@ // ensure both objects have the same number of properties if (result) { for (prop in b) { - // Adobe's JS engine, embedded in applications like InDesign, has a - // bug that causes `!size--` to throw an error so it must be wrapped - // in parentheses. + // The JS engine in Adobe products, like InDesign, has a bug that causes + // `!size--` to throw an error so it must be wrapped in parentheses. // https://github.com/documentcloud/underscore/issues/355 if (hasOwnProperty.call(b, prop) && !(size--)) { break; } } + // `size` will be `-1` if `b` has more properties than `a` result = !size; } // handle JScript [[DontEnum]] bug @@ -2971,7 +2973,7 @@ /** * Checks if `value` is the language type of Object. - * (e.g. arrays, functions, objects, regexps, `new Number(0)`, and `new String('')`) + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) * * @static * @memberOf _ @@ -3167,16 +3169,16 @@ } /** - * Gets the size of `value` by returning `value.length` if `value` is a string - * or array, or the number of own enumerable properties if `value` is an object. + * Gets the size of `value` by returning `value.length` if `value` is an + * array, string, or `arguments` object. If `value` is an object, size is + * determined by returning the number of own enumerable properties it has. * * @deprecated * @static * @memberOf _ * @category Objects * @param {Array|Object|String} value The value to inspect. - * @returns {Number} Returns `value.length` if `value` is a string or array, - * or the number of own enumerable properties if `value` is an object. + * @returns {Number} Returns `value.length` or number of own enumerable properties. * @example * * _.size([1, 2]); @@ -3192,8 +3194,9 @@ if (!value) { return 0; } - var length = value.length; - return length === length >>> 0 ? value.length : keys(value).length; + return arrayLikeClasses[toString.call(value)] || (noArgsClass && isArguments(value)) + ? value.length + : keys(value).length; } /** diff --git a/test/test.js b/test/test.js index 8cfc755911..6a143ddd7b 100644 --- a/test/test.js +++ b/test/test.js @@ -546,6 +546,8 @@ QUnit.module('lodash.isEmpty'); (function() { + var args = arguments; + test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { equal(_.isEmpty(shadowed), false); }); @@ -558,7 +560,15 @@ Foo.prototype = { 'a': 1 }; equal(_.isEmpty(Foo), true); }); - }()); + + test('should work with an object that has a `length` property', function() { + equal(_.isEmpty({ 'length': 0 }), false); + }); + + test('should work with `arguments` objects (test in IE < 9)', function() { + equal(_.isEmpty(args), false); + }); + }(1, 2, 3)); /*--------------------------------------------------------------------------*/ @@ -784,6 +794,10 @@ deepEqual(actual, [0, 0, 0, 0, 0]); }); + test('should work with an object that has a `length` property', function() { + equal(_.size({ 'length': 3 }), 1); + }); + test('should work with `arguments` objects (test in IE < 9)', function() { equal(_.size(args), 3); }); From d4688bd76bb9e7b72dc8fe8b385cfc59b71d496b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 20 Jul 2012 03:21:18 -0400 Subject: [PATCH 14/77] Adjust `_.wrap` docs and rebuild/update the minified build/docs. Former-commit-id: b33c4489bde49c98e7e161d0f831e07388a9da22 --- doc/README.md | 208 +++++++++++++++++++++++++------------------------- lodash.js | 13 ++-- lodash.min.js | 62 +++++++-------- 3 files changed, 141 insertions(+), 142 deletions(-) diff --git a/doc/README.md b/doc/README.md index 783bb2cf81..929833ec64 100644 --- a/doc/README.md +++ b/doc/README.md @@ -91,7 +91,7 @@ * [`_.uniqueId`](#_uniqueidprefix) * [`_.values`](#_valuesobject) * [`_.without`](#_withoutarray--value1-value2-) -* [`_.wrap`](#_wrapfunc-wrapper) +* [`_.wrap`](#_wrapvalue-wrapper) * [`_.zip`](#_ziparray1-array2-) * [`_.zipObject`](#_zipobjectkeys) @@ -132,7 +132,7 @@ ### `_(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L198 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L206 "View in source") [Ⓣ][1] The `lodash` function. @@ -150,7 +150,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3674 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3676 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -162,7 +162,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2020 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2028 "View in source") [Ⓣ][1] Creates a new function that is restricted to executing only after it is called `n` times. @@ -190,7 +190,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2074 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2082 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. Lazy defined methods may be bound by passing the object they are bound to as `func` and the method name as `thisArg`. @@ -241,7 +241,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2144 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2152 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -272,7 +272,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3599 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3601 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -306,7 +306,7 @@ var youngest = _.chain(stooges) ### `_.clone(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2473 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2480 "View in source") [Ⓣ][1] Create a shallow clone of the `value`. Any nested objects or arrays will be assigned by reference and not cloned. @@ -330,7 +330,7 @@ _.clone({ 'name': 'moe' }); ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1263 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1271 "View in source") [Ⓣ][1] Creates a new array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -354,7 +354,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2180 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2188 "View in source") [Ⓣ][1] Creates a new function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -381,7 +381,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L785 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L793 "View in source") [Ⓣ][1] Checks if a given `target` value is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -412,7 +412,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L821 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L829 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -444,7 +444,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2213 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2221 "View in source") [Ⓣ][1] Creates a new function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -470,7 +470,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2497 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2504 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -496,7 +496,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2278 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2286 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -521,7 +521,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2258 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2266 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -548,7 +548,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1295 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1303 "View in source") [Ⓣ][1] Creates a new array of `array` values not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -573,7 +573,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.drop(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2517 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2524 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -598,7 +598,7 @@ _.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3234 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3236 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -622,7 +622,7 @@ _.escape('Curly, Larry & Moe'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L841 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L849 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -648,7 +648,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2541 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2548 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -673,7 +673,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L861 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L869 "View in source") [Ⓣ][1] Examines each value in a `collection`, returning an array of all values the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -699,7 +699,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L882 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L890 "View in source") [Ⓣ][1] Examines each value in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -725,7 +725,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1332 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1340 "View in source") [Ⓣ][1] Gets the first value of the `array`. Pass `n` to return the first `n` values of the `array`. @@ -751,7 +751,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1356 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1364 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -779,7 +779,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L908 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L916 "View in source") [Ⓣ][1] Iterates over a `collection`, executing the `callback` for each value in the `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -808,7 +808,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2570 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2577 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -844,7 +844,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2593 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2600 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -872,7 +872,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2610 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2617 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -896,7 +896,7 @@ _.functions(_); ### `_.groupBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L936 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L944 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -928,7 +928,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2633 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2640 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -953,7 +953,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3253 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3255 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -978,7 +978,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1400 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1408 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1010,7 +1010,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1440 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1448 "View in source") [Ⓣ][1] Gets all but the last value of `array`. Pass `n` to exclude the last `n` values from the result. @@ -1036,7 +1036,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1461 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1469 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays. @@ -1060,7 +1060,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L964 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L972 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1089,7 +1089,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2653 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2660 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1116,7 +1116,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2680 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2686 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1143,7 +1143,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2697 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2703 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1167,7 +1167,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2714 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2720 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1191,7 +1191,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2731 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2737 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1215,9 +1215,9 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2755 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2762 "View in source") [Ⓣ][1] -Checks if `value` is empty. Arrays or strings with a length of `0` and objects with no own enumerable properties are considered "empty". +Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". #### Arguments 1. `value` *(Array|Object|String)*: The value to inspect. @@ -1245,7 +1245,7 @@ _.isEmpty(''); ### `_.isEqual(a, b [, stack])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2789 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2797 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1277,7 +1277,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2951 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2952 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1307,7 +1307,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2968 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2969 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1331,7 +1331,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3020 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3021 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1364,7 +1364,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3043 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3044 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1391,7 +1391,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3060 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3061 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1415,9 +1415,9 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2989 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2990 "View in source") [Ⓣ][1] -Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexps, `new Number(0)`, and `new String('')`)* +Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* #### Arguments 1. `value` *(Mixed)*: The value to check. @@ -1442,7 +1442,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3077 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3078 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1466,7 +1466,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3094 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3095 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1490,7 +1490,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3112 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3113 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1514,7 +1514,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3129 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3130 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1538,7 +1538,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1502 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1510 "View in source") [Ⓣ][1] Gets the last value of the `array`. Pass `n` to return the lasy `n` values of the `array`. @@ -1564,7 +1564,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1528 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1536 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1593,7 +1593,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1000 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1008 "View in source") [Ⓣ][1] Creates a new array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -1622,7 +1622,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1568 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1576 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1654,7 +1654,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2301 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2309 "View in source") [Ⓣ][1] Creates a new function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1680,7 +1680,7 @@ var fibonacci = _.memoize(function(n) { ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1618 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1626 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1706,7 +1706,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3279 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3281 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1736,7 +1736,7 @@ _('larry').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3310 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3312 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1756,7 +1756,7 @@ var lodash = _.noConflict(); ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2327 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2335 "View in source") [Ⓣ][1] Creates a new function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1782,9 +1782,9 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2360 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2367 "View in source") [Ⓣ][1] -Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the partially applied function. This method is similar `bind`, except it does **not** alter the `this` binding. +Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar `bind`, except it does **not** alter the `this` binding. #### Arguments 1. `func` *(Function)*: The function to partially apply arguments to. @@ -1809,7 +1809,7 @@ hi('moe'); ### `_.pick(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3152 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3153 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -1834,7 +1834,7 @@ _.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1023 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1031 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -1865,7 +1865,7 @@ _.pluck(stooges, 'name'); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1679 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1687 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -1903,7 +1903,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1051 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1059 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -1930,7 +1930,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1088 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1096 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -1958,7 +1958,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1143 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1151 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -1984,7 +1984,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1716 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1724 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2010,7 +2010,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3342 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3344 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2045,7 +2045,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1737 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1745 "View in source") [Ⓣ][1] Creates a new array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2069,15 +2069,15 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3191 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "View in source") [Ⓣ][1] -Gets the size of `value` by returning `value.length` if `value` is a string or array, or the number of own enumerable properties if `value` is an object. +Gets the size of `value` by returning `value.length` if `value` is an array, string, or `arguments` object. If `value` is an object, size is determined by returning the number of own enumerable properties it has. #### Arguments 1. `value` *(Array|Object|String)*: The value to inspect. #### Returns -*(Number)*: Returns `value.length` if `value` is a string or array, or the number of own enumerable properties if `value` is an object. +*(Number)*: Returns `value.length` or number of own enumerable properties. #### Example ~~~ js @@ -2099,7 +2099,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1166 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1174 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -2125,7 +2125,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1196 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1204 "View in source") [Ⓣ][1] Creates a new sorted array, sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2157,7 +2157,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1789 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1797 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with `1` argument; *(value)*. @@ -2198,7 +2198,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3626 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3628 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2228,7 +2228,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3402 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3404 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -2287,7 +2287,7 @@ _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' }); ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2396 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2403 "View in source") [Ⓣ][1] Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2312,7 +2312,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3542 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3544 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2338,7 +2338,7 @@ _.times(3, function() { this.grantWish(); }, genie); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1231 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1239 "View in source") [Ⓣ][1] Converts the `collection`, into an array. Useful for converting the `arguments` object. @@ -2362,7 +2362,7 @@ Converts the `collection`, into an array. Useful for converting the `arguments` ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1829 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1837 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays. @@ -2386,7 +2386,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1873 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1881 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -2422,7 +2422,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3569 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3571 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2446,7 +2446,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3212 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3214 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2470,7 +2470,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1922 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1930 "View in source") [Ⓣ][1] Creates a new array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2494,13 +2494,13 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); -### `_.wrap(func, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2447 "View in source") [Ⓣ][1] +### `_.wrap(value, wrapper)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2454 "View in source") [Ⓣ][1] -Create a new function that passes `func` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. +Creates a new function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. #### Arguments -1. `func` *(Function)*: The function to wrap. +1. `value` *(Mixed)*: The value to wrap. 2. `wrapper` *(Function)*: The wrapper function. #### Returns @@ -2524,7 +2524,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1955 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1963 "View in source") [Ⓣ][1] Merges the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2548,7 +2548,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.zipObject(keys)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1984 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1992 "View in source") [Ⓣ][1] Merges an array of `keys` and an array of `values` into a single object. @@ -2579,7 +2579,7 @@ _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3644 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3646 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2600,7 +2600,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3661 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3663 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -2628,7 +2628,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L226 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L234 "View in source") [Ⓣ][1] *(Object)*: By default, Lo-Dash uses embedded Ruby *(ERB)* style template delimiters, change the following template settings to use alternative delimiters. @@ -2640,7 +2640,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.escape` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L235 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L243 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to be HTML-escaped. @@ -2652,7 +2652,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.evaluate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L244 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L252 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect code to be evaluated. @@ -2664,7 +2664,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.interpolate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L253 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L261 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to inject. @@ -2676,7 +2676,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.variable` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L262 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L270 "View in source") [Ⓣ][1] *(String)*: Used to reference the data object in the template text. diff --git a/lodash.js b/lodash.js index ce4db50d42..104b2fa1a7 100644 --- a/lodash.js +++ b/lodash.js @@ -2348,9 +2348,8 @@ /** * Creates a new function that, when called, invokes `func` with any additional - * `partial` arguments prepended to those passed to the partially applied - * function. This method is similar `bind`, except it does **not** alter the - * `this` binding. + * `partial` arguments prepended to those passed to the new function. This method + * is similar `bind`, except it does **not** alter the `this` binding. * * @static * @memberOf _ @@ -2433,14 +2432,14 @@ } /** - * Create a new function that passes `func` to the `wrapper` function as its + * Creates a new function that passes `value` to the `wrapper` function as its * first argument. Additional arguments passed to the new function are appended * to those passed to the `wrapper` function. * * @static * @memberOf _ * @category Functions - * @param {Function} func The function to wrap. + * @param {Mixed} value The value to wrap. * @param {Function} wrapper The wrapper function. * @returns {Function} Returns the new function. * @example @@ -2452,9 +2451,9 @@ * hello(); * // => 'before, hello: moe, after' */ - function wrap(func, wrapper) { + function wrap(value, wrapper) { return function() { - var args = [func]; + var args = [value]; if (arguments.length) { push.apply(args, arguments); } diff --git a/lodash.min.js b/lodash.min.js index fa01813d11..0eab8849c1 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,34 +2,34 @@ Lo-Dash 0.4.2 lodash.com/license Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE */ -;(function(e,t){"use strict";function s(e){return new o(e)}function o(e){if(e&&e._wrapped)return e;this._wrapped=e}function u(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||30),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="p='"+u.o[n]+"';if(","constructor"==u.o[n]&&(t+="!(k&&k.prototype===s)&&"),t+="n.call(s,p)){"+u.m.i+"}"}u.c&&(t+="}")}return t+=u.e+";return G",Function("c,d,e,i,j,l,n,o,q,u,A,x,F,I,J,M" -,"return function("+e+"){"+t+"}")(ut,H,C,f,G,lt,Y,L,E,p,St,ot,et,tt,pt,nt)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return Q[t]}function c(e){return"\\"+xt[e]}function h(e){return Et[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+__e("+t+")+'",K+n}function m(e,t,n,r){return e=Q.length,t?Q[e]="'+__e("+t+")+'":r?Q[e]="';"+r+";__p+='":n&&(Q[e]="'+((__t=("+ -n+"))==null?'':__t)+'"),K+e}function g(e,t){if(I.test(t))return"";var n=Q.length;return Q[n]="'+((__t=("+t+"))==null?'':__t)+'",K+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=yt&&nt.call(e)==pt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=nn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:tt.call(e,0,t)}function w(e,t){var n=[];if(!e) -return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e?tt.call(e,t==r|| -n?1:t):[]}function T(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=C(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]E(a,r))a.push(r),s.push(e[o]);return s}function C(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?G.apply(s,o) -:s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&St[typeof o]?o:u):e.apply(u,o)}var r,i=nt.call(e)==lt;if(i){if(bt||rt&&2++u&&(l=J[u],!Y.call(e,l)||!!(a=Y.call(t,l)&&k(e[l],t[l],s))););}return s.pop(),a}function L(e){return e}function A(e){Ft(Zt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Z.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,O,M,_,D -,P="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),H=Array.prototype,B=Object.prototype,j=0,F=e._,I=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,q=/\b__p\+='';/g,R=/\b(__p\+=)''\+/g,U=/(__e\(.*?\)|\b__t\))\+'';/g,z=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,W=RegExp("^"+(B.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),X=/__token__(\d+)/g,V=/[&<"']/g,$=/['\n\r\t\u2028\u2029\\]/g -,J="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),K="__token__",Q=[],G=H.concat,Y=B.hasOwnProperty,Z=H.push,et=B.propertyIsEnumerable,tt=H.slice,nt=B.toString,rt=W.test(rt=tt.bind)&&rt,it=W.test(it=Array.isArray)&&it,st=e.isFinite,ot=W.test(ot=Object.keys)&&ot,ut="[object Array]",at="[object Boolean]",ft="[object Date]",lt="[object Function]",ct="[object Number]",ht="[object RegExp]",pt="[object String]",dt=e.clearTimeout,vt=e.setTimeout -,mt=!et.call({valueOf:0},"valueOf"),gt="x"!=tt.call("x")[0],yt="xx"!="x"[0]+Object("x")[0],bt=rt&&/\n|Opera/.test(rt+nt.call(e.opera)),wt=ot&&/^.+$|true/.test(ot+!!e.attachEvent),Et={"&":"&","<":"<",'"':""","'":"'"},St={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},xt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj" -};var Tt={a:"h,f,L",j:"h",p:"if(!f){f=o}else if(L)f=u(f,L)",i:"f(s[p],p,h)"},Nt={j:"{}",p:"var B;if(typeof f!='function'){var O=f;f=function(N){return N[O]}}else if(L)f=u(f,L)",i:"B=f(s[p],p,h);(n.call(G,B)?G[B]++:G[B]=1)"},Ct={j:"true",i:"if(!f(s[p],p,h))return!G"},kt={q:i,r:i,a:"z",j:"z",p:"for(var t=1,v=arguments.length;t-1"},i:"if(s[p]===K)return true"}),Pt=a(Tt,Nt),Ht=a(Tt,Ct),Bt=a(Tt,Lt),jt=a(Tt,At,{j:"",i:"if(f(s[p],p,h))return s[p]"}),Ft=a(Tt,At),It=a(Tt,Nt,{i:"B=f(s[p],p,h);(n.call(G,B)?G[B]:G[B]=[]).push(s[p])"}),qt=a(Mt,{a:"h,w",p:"var b=I.call(arguments,2),r=typeof w=='function'" -,i:{b:"G[p]=(r?w:s[p][w]).apply(s[p],b)",l:"G"+(wt?"[C]=":".push")+"((r?w:s[p][w]).apply(s[p],b))"}}),Rt=a(Tt,Mt),Ut=a(Mt,{a:"h,E",i:{b:"G[p]=s[p][E]",l:"G"+(wt?"[C]=":".push")+"(s[p][E])"}}),zt=a({a:"h,f,a,L",j:"a",p:"var y=arguments.length<3;if(L)f=u(f,L)",d:{b:"if(y)G=h[++p]"},i:{b:"G=f(G,s[p],p,h)",l:"G=y?(y=false,s[p]):f(G,s[p],p,h)"}}),Wt=a(Tt,Lt,{i:"!"+Lt.i}),Xt=a(Tt,Ct,{j:"false",i:Ct.i.replace("!","")}),Vt=a(Tt,Nt,Mt,{i:{b:"G[p]={a:f(s[p],p,h),b:s[p]}",l:"G"+(wt?"[C]=":".push")+"({a:f(s[p],p,h),b:s[p]})" -},e:"G.sort(i);v=G.length;while(v--){G[v]=G[v].b}"}),$t=a({q:i,r:i,a:"z",j:"z",p:"var m=arguments,v=m.length;if(v>1){for(var p=1;pe?t():function(){ -if(1>--e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=$t,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&St[typeof e]?en(e)?e.slice():Qt({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&Ht(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=qt, -s.isArray=en,s.isBoolean=function(e){return e===n||e===i||nt.call(e)==at},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=tn,s.isEqual=k,s.isFinite=function(e){return st(e)&&nt.call(e)==ct},s.isNaN=function(e){return nt.call(e)==ct&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&St[typeof e]},s.isUndefined=function(e){return e===t},s.keys=nn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:tt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(! -e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Rt,s.max=S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Y.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0?e.length:nn(e).length},s.some=Xt,s.sortBy=Vt,s.sortedIndex=T, -s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,h=s.templateSettings,n=n.variable;o==r&&(o=h.escape),a==r&&(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,v)),f&&(e=e.replace(f,g)),a!=O&&(O=a,D=RegExp("|"+(a?"|"+a.source:""),"g")),o=Q.length,e=e.replace(D,m),o=o!=Q.length,e="__p += '"+e.replace($,c).replace(X,l)+"';",Q.length=0,n||(n=h.variable||M||"obj",o?e="with("+n+"){"+e+"}" -:(n!=M&&(M=n,_=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(z,"$&"+n+".").replace(_,"$1__d"))),e=(o?e.replace(q,""):e).replace(R,"$1").replace(U,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply -(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=vt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(gt?nt.call(e)==pt:"string"==typeof e)?e.split(""):tt.call(e):rn(e)},s.union=function(){for(var e=-1,t=[],n=G.apply(t,arguments),r=n.length;++eE(t,n[ -e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=j++;return e?e+t:t},s.values=rn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n=(n||30),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="p='"+u.o[n]+"';if(","constructor"==u.o[n]&&(t+="!(k&&k.prototype===t)&&"),t+="n.call(t,p)){"+u.m.i+"}"}u.c&&(t+="}")}return t+=u.e+";return H",Function("c,d,e,f,i,j,l,n,o,q,r,v,B,y,G,J,K,N" +,"return function("+e+"){"+t+"}")(ft,Tt,B,C,f,Y,ht,Z,A,E,k,p,Ct,ut,tt,nt,vt,rt)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return G[t]}function c(e){return"\\"+kt[e]}function h(e){return Nt[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(q.test(t))return"";var n=G.length;return G[n]="'+__e("+t+")+'",Q+n}function m(e,t,n,r){return e=G.length,t?G[e]="'+__e("+t+")+'":r?G[e]="';"+r+";__p+='":n&&(G[e]="'+((__t=("+ +n+"))==null?'':__t)+'"),Q+e}function g(e,t){if(q.test(t))return"";var n=G.length;return G[n]="'+((__t=("+t+"))==null?'':__t)+'",Q+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=Et&&rt.call(e)==vt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=un(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:nt.call(e,0,t)}function w(e,t){var n=[];if(!e) +return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e?nt.call(e,t==r|| +n?1:t):[]}function T(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=C(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]E(a,r))a.push(r),s.push(e[o]);return s}function C(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?Y.apply(s,o) +:s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&Ct[typeof o]?o:u):e.apply(u,o)}var r,i=rt.call(e)==ht;if(i){if(St||it&&2++u&&(l=K[u],!Z.call(e,l)||!!(a=Z.call(t,l)&&L(e[l],t[l],s))););}return s.pop(),a}function A(e){return e}function O(e){Ut(rn(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&et.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,M,_,D,P,H="object"==typeof exports&&exports&&("object"==typeof +global&&global&&global==global.global&&(e=global),exports),B=Array.prototype,j=Object.prototype,F=0,I=e._,q=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,R=/\b__p\+='';/g,U=/\b(__p\+=)''\+/g,z=/(__e\(.*?\)|\b__t\))\+'';/g,W=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,X=RegExp("^"+(j.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),V=/__token__(\d+)/g,$=/[&<"']/g,J=/['\n\r\t\u2028\u2029\\]/g,K="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf" +.split(" "),Q="__token__",G=[],Y=B.concat,Z=j.hasOwnProperty,et=B.push,tt=j.propertyIsEnumerable,nt=B.slice,rt=j.toString,it=X.test(it=nt.bind)&&it,st=X.test(st=Array.isArray)&&st,ot=e.isFinite,ut=X.test(ut=Object.keys)&&ut,at="[object Arguments]",ft="[object Array]",lt="[object Boolean]",ct="[object Date]",ht="[object Function]",pt="[object Number]",dt="[object RegExp]",vt="[object String]",mt=e.clearTimeout,gt=e.setTimeout,yt=!tt.call({valueOf:0},"valueOf"),bt=!k(arguments),wt="x"!=nt.call("x") +[0],Et="xx"!="x"[0]+Object("x")[0],St=it&&/\n|Opera/.test(it+rt.call(e.opera)),xt=ut&&/^.+$|true/.test(ut+!!e.attachEvent),Tt={"[object Arguments]":n,"[object Array]":n,"[object String]":n},Nt={"&":"&","<":"<",'"':""","'":"'"},Ct={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},kt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g +,variable:"obj"};var Lt={a:"h,g,M",j:"h",p:"if(!g){g=o}else if(M)g=v(g,M)",i:"g(t[p],p,h)"},At={j:"{}",p:"var C;if(typeof g!='function'){var P=g;g=function(O){return O[P]}}else if(M)g=v(g,M)",i:"C=g(t[p],p,h);(n.call(H,C)?H[C]++:H[C]=1)"},Ot={j:"true",i:"if(!g(t[p],p,h))return!H"},Mt={q:i,r:i,a:"A",j:"A",p:"for(var u=1,w=arguments.length;u-1"},i:"if(t[p]===L)return true"}),Ft=a(Lt,At),It=a(Lt,Ot),qt=a(Lt,_t),Rt=a(Lt,Dt,{j:"",i:"if(g(t[p],p,h))return t[p]"}),Ut=a(Lt,Dt),zt=a(Lt,At,{i:"C=g(t[p],p,h);(n.call(H,C)?H[C]:H[C]=[]).push(t[p])"}),Wt=a(Ht,{a:"h,x" +,p:"var b=J.call(arguments,2),s=typeof x=='function'",i:{b:"H[p]=(s?x:t[p][x]).apply(t[p],b)",l:"H"+(xt?"[D]=":".push")+"((s?x:t[p][x]).apply(t[p],b))"}}),Xt=a(Lt,Ht),Vt=a(Ht,{a:"h,F",i:{b:"H[p]=t[p][F]",l:"H"+(xt?"[D]=":".push")+"(t[p][F])"}}),$t=a({a:"h,g,a,M",j:"a",p:"var z=arguments.length<3;if(M)g=v(g,M)",d:{b:"if(z)H=h[++p]"},i:{b:"H=g(H,t[p],p,h)",l:"H=z?(z=false,t[p]):g(H,t[p],p,h)"}}),Jt=a(Lt,_t,{i:"!"+_t.i}),Kt=a(Lt,Ot,{j:"false",i:Ot.i.replace("!","")}),Qt=a(Lt,At,Ht,{i:{b:"H[p]={a:g(t[p],p,h),b:t[p]}" +,l:"H"+(xt?"[D]=":".push")+"({a:g(t[p],p,h),b:t[p]})"},e:"H.sort(i);w=H.length;while(w--){H[w]=H[w].b}"}),Gt=a({q:i,r:i,a:"A",j:"A",p:"var m=arguments,w=m.length;if(w>1){for(var p=1;pe?t():function(){if(1>-- +e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=Gt,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&Ct[typeof e]?sn(e)?e.slice():en({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&It(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=Wt,s.isArguments= +k,s.isArray=sn,s.isBoolean=function(e){return e===n||e===i||rt.call(e)==lt},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=on,s.isEqual=L,s.isFinite=function(e){return ot(e)&&rt.call(e)==pt},s.isNaN=function(e){return rt.call(e)==pt&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&Ct[typeof e]},s.isUndefined=function(e){return e===t},s.keys=un,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:nt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){ +if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Xt,s.max=S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Z.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s|"+(a?"|"+a.source:""),"g")),o=G.length,e=e.replace(P,m),o=o!=G.length,e="__p += '"+e.replace(J,c).replace(V,l)+"';",G.length=0,n||(n=h.variable||_||"obj",o?e="with("+n+"){"+e+"}":(n!=_&&(_= +n,D=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(W,"$&"+n+".").replace(D,"$1__d"))),e=(o?e.replace(R,""):e).replace(U,"$1").replace(z,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i +,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=gt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(wt?rt.call(e)==vt:"string"==typeof e)?e.split(""):nt.call(e):an(e)},s.union=function(){for(var e=-1,t=[],n=Y.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push +(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=F++;return e?e+t:t},s.values=an,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n Date: Tue, 24 Jul 2012 01:41:38 -0700 Subject: [PATCH 15/77] Add deep clone support via the `deep` argument to `_.clone`. Former-commit-id: d4fad45364489efb957d29e201846e8c1875b9ed --- build.js | 15 +++-- build/pre-compile.js | 7 +++ lodash.js | 134 ++++++++++++++++++++++++++++++++++++++++--- test/test.js | 96 +++++++++++++++++++++++++++++++ 4 files changed, 235 insertions(+), 17 deletions(-) diff --git a/build.js b/build.js index 156fd14a3f..0f8c7e4196 100755 --- a/build.js +++ b/build.js @@ -150,7 +150,7 @@ 'bind': [], 'bindAll': ['bind', 'functions'], 'chain': ['mixin'], - 'clone': ['extend', 'isArray'], + 'clone': ['extend', 'forOwn', 'isArguments'], 'compact': [], 'compose': [], 'contains': [], @@ -774,17 +774,12 @@ // build replacement code lodash.forOwn({ - 'Arguments': 'argsClass', 'Date': 'dateClass', 'Function': 'funcClass', 'Number': 'numberClass', 'RegExp': 'regexpClass', 'String': 'stringClass' }, function(value, key) { - // skip `isArguments` if not a mobile build - if (!isMobile && key == 'Arguments') { - return; - } var funcName = 'is' + key, funcCode = matchFunction(source, funcName); @@ -887,15 +882,19 @@ // remove IE `shift` and `splice` fix from mutator Array functions mixin source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, ''); - // remove `noCharByIndex` from `_.reduceRight` - source = source.replace(/noCharByIndex *&&[^:]+: *([^;]+)/g, '$1'); + // remove `noArgsClass` from `_.clone` and `_.size` + source = source.replace(/ *\|\| *\(noArgsClass *&[^)]+?\)\)/g, ''); // remove `noArraySliceOnStrings` from `_.toArray` source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1'); + // remove `noCharByIndex` from `_.reduceRight` + source = source.replace(/noCharByIndex *&&[^:]+: *([^;]+)/g, '$1'); + source = removeVar(source, 'extendIteratorOptions'); source = removeVar(source, 'hasDontEnumBug'); source = removeVar(source, 'iteratorTemplate'); + source = removeVar(source, 'noArgsClass'); source = removeVar(source, 'noArraySliceOnStrings'); source = removeVar(source, 'noCharByIndex'); source = removeIsArgumentsFallback(source); diff --git a/build/pre-compile.js b/build/pre-compile.js index d488c0dfea..fe6ee0f96a 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -220,6 +220,13 @@ // Closure Compiler errors trying to minify them source = source.replace(/(arrayLikeClasses =)[\s\S]+?= *true/g, "$1{'[object Arguments]': true, '[object Array]': true, '[object String]': true }"); + // manually convert `cloneableClasses` property assignments because + // Closure Compiler errors trying to minify them + source = source.replace(/(cloneableClasses =)[\s\S]+?= *true/g, + "$1{'[object Array]': true, '[object Boolean]': true, '[object Date]': true, " + + "'[object Number]': true, '[object Object]': true, '[object RegExp]': true, '[object String]': true }" + ); + // add brackets to whitelisted properties so Closure Compiler won't mung them // http://code.google.com/closure/compiler/docs/api-tutorial3.html#export source = source.replace(RegExp('\\.(' + propWhitelist.join('|') + ')\\b', 'g'), "['$1']"); diff --git a/lodash.js b/lodash.js index 104b2fa1a7..9f05ed000d 100644 --- a/lodash.js +++ b/lodash.js @@ -55,6 +55,9 @@ reEmptyStringMiddle = /\b(__p \+=) '' \+/g, reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; + /** Used to match regexp flags from their coerced string values */ + var reFlags = /\w*$/; + /** Used to insert the data object variable into compiled template source */ var reInsertVariable = /(?:__e|__t = )\(\s*(?![\d\s"']|this\.)/g; @@ -110,6 +113,7 @@ dateClass = '[object Date]', funcClass = '[object Function]', numberClass = '[object Number]', + objectClass = '[object Object]', regexpClass = '[object RegExp]', stringClass = '[object String]'; @@ -159,6 +163,12 @@ var arrayLikeClasses = {}; arrayLikeClasses[argsClass] = arrayLikeClasses[arrayClass] = arrayLikeClasses[stringClass] = true; + /** Used to identify object classifications that `_.clone` supports */ + var cloneableClasses = {}; + cloneableClasses[arrayClass] = cloneableClasses[boolClass] = cloneableClasses[dateClass] = + cloneableClasses[numberClass] = cloneableClasses[objectClass] = cloneableClasses[regexpClass] = + cloneableClasses[stringClass] = true; + /** * Used to escape characters for inclusion in HTML. * The `>` and `/` characters don't require escaping in HTML and have no @@ -2464,23 +2474,129 @@ /*--------------------------------------------------------------------------*/ /** - * Create a shallow clone of the `value`. Any nested objects or arrays will be - * assigned by reference and not cloned. + * Create a clone of `value`. If `deep` is `true`, all nested objects, excluding + * functons and `arguments` objects, will be cloned otherwise they will be + * assigned by reference. * * @static * @memberOf _ * @category Objects * @param {Mixed} value The value to clone. + * @param {Boolean} deep A flag to indicate a deep clone. + * @param {Object} [guard] Internally used to allow this method to work with + * others like `_.map` without using their callback `index` argument for `deep`. + * @param {Array} [stack=[]] Internally used to keep track of traversed objects + * to avoid circular references. * @returns {Mixed} Returns the cloned `value`. * @example * + * var stooges = [ + * { 'name': 'moe', 'age': 40 }, + * { 'name': 'larry', 'age': 50 }, + * { 'name': 'curly', 'age': 60 } + * ]; + * * _.clone({ 'name': 'moe' }); - * // => { 'name': 'moe' }; + * // => { 'name': 'moe' } + * + * var shallow = _.clone(stooges); + * shallow[0] === stooges[0]; + * // => true + * + * var deep = _.clone(stooges, true); + * shallow[0] === stooges[0]; + * // => false */ - function clone(value) { - return value && objectTypes[typeof value] - ? (isArray(value) ? value.slice() : extend({}, value)) - : value; + function clone(value, deep, guard, stack) { + if (!value) { + return value; + } + var isObj = typeof value == 'object'; + stack || (stack = []); + + if (guard) { + deep = false; + } + // use custom `clone` method if available + if (value.clone && toString.call(value.clone) == funcClass) { + return value.clone(deep); + } + // inspect [[Class]] + if (isObj) { + var className = toString.call(value); + + // don't clone `arguments` objects, functions, or non-object Objects + if (!cloneableClasses[className] || (noArgsClass && isArguments(value))) { + return value; + } + + var ctor = value.constructor, + isArr = className == arrayClass, + useCtor = toString.call(ctor) == funcClass; + + // IE < 9 presents nodes like `Object` objects: + // IE < 8 are missing the node's constructor property + // IE 8 node constructors are typeof "object" + // check if the constructor is `Object` as `Object instanceof Object` is `true` + if (className == objectClass && + (isObj = useCtor && ctor instanceof ctor)) { + // An object's own properties are iterated before inherited properties. + // If the last iterated key belongs to an object's own property then + // there are no inherited enumerable properties. + forIn(value, function(objValue, objKey) { isObj = objKey; }); + isObj = isObj == true || hasOwnProperty.call(value, isObj); + } + } + // shallow clone + if (!isObj || !deep) { + // don't clone functions + return isObj + ? (isArr ? slice.call(value) : extend({}, value)) + : value; + } + + switch (className) { + case boolClass: + return new ctor(value == true); + + case dateClass: + return new ctor(+value); + + case numberClass: + case stringClass: + return new ctor(value); + + case regexpClass: + return ctor(value.source, reFlags.exec(value)); + } + + // check for circular references and return corresponding clone + var length = stack.length; + while (length--) { + if (stack[length].value == value) { + return stack[length].clone; + } + } + + // init cloned object + length = value.length; + var result = isArr ? ctor(length) : (useCtor ? new ctor : {}); + + // add current clone and original value to the stack of traversed objects + stack.push({ 'clone': result, 'value': value }); + + // recursively populate clone (susceptible to call stack limits) + if (isArr) { + var index = -1; + while (++index < length) { + result[index] = clone(value[index], deep, null, stack); + } + } else { + forOwn(value, function(objValue, key) { + result[key] = clone(objValue, deep, null, stack); + }); + } + return result; } /** @@ -2780,8 +2896,8 @@ * @category Objects * @param {Mixed} a The value to compare. * @param {Mixed} b The other value to compare. - * @param {Array} [stack] Internally used to keep track of "seen" objects to - * avoid circular references. + * @param {Array} [stack=[]] Internally used to keep track of traversed objects + * to avoid circular references. * @returns {Boolean} Returns `true` if the values are equvalent, else `false`. * @example * diff --git a/test/test.js b/test/test.js index 6a143ddd7b..0d8d6b6d05 100644 --- a/test/test.js +++ b/test/test.js @@ -152,6 +152,102 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.clone'); + + (function() { + function Klass() { } + Klass.prototype = { 'a': 1 }; + + var nonCloneable = { + 'an arguments object': arguments, + 'an element': window.document && document.body, + 'a function': Klass, + 'a Klass instance': new Klass + }; + + var objects = { + 'an array': ['a', 'b', 'c', ''], + 'an array-like-object': { '0': 'a', '1': 'b', '2': 'c', '3': '', 'length': 5 }, + 'boolean': false, + 'boolean object': Object(false), + 'an object': { 'a': 0, 'b': 1, 'c': 3 }, + 'an object with object values': { 'a': /a/, 'b': ['B'], 'c': { 'C': 1 } }, + 'null': null, + 'a number': 3, + 'a number object': Object(3), + 'a regexp': /a/gim, + 'a string': 'a', + 'a string object': Object('a'), + 'undefined': undefined + }; + + objects['an array'].length = 5; + + _.forOwn(objects, function(object, key) { + test('should deep clone ' + key + ' correctly', function() { + var clone = _.clone(object, true); + + if (object == null) { + equal(clone, object); + } else { + deepEqual(clone.valueOf(), object.valueOf()); + } + if (_.isObject(object)) { + ok(clone !== object); + } else { + skipTest(); + } + }); + }); + + _.forOwn(nonCloneable, function(object, key) { + test('should not clone ' + key, function() { + ok(_.clone(object) === object); + ok(_.clone(object, true) === object); + }); + }); + + test('should shallow clone when used as `callback` for `_.map`', function() { + var expected = [{ 'a': [0] }, { 'b': [1] }], + actual = _.map(expected, _.clone); + + ok(actual != expected && actual.a == expected.a && actual.b == expected.b); + }); + + test('should deep clone objects with circular references', function() { + var object = { + 'foo': { 'b': { 'foo': { 'c': { } } } }, + 'bar': { } + }; + + object.foo.b.foo.c.foo = object; + object.bar.b = object.foo.b; + + var clone = _.clone(object, true); + ok(clone.bar.b === clone.foo.b && clone === clone.foo.b.foo.c.foo && clone !== object); + }); + + test('should clone using Klass#clone', function() { + var object = new Klass; + Klass.prototype.clone = function() { return new Klass; }; + + var clone = _.clone(object); + ok(clone !== object && clone instanceof Klass); + + clone = _.clone(object, true); + ok(clone !== object && clone instanceof Klass); + + delete Klass.prototype.clone; + }); + + test('should clone problem JScript properties (test in IE < 9)', function() { + deepEqual(_.clone(shadowed), shadowed); + deepEqual(_.clone(shadowed, true), shadowed); + }); + }(1, 2, 3)); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.contains'); (function() { From ed89a3e0f8524754f1f9c8650bda2c9200233f1b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 24 Jul 2012 01:45:34 -0700 Subject: [PATCH 16/77] Check for custom `isEqual` methods in `_.isEqual` before other comparisons and add cross-browser support for `arguments` objects. Former-commit-id: 56e40f670309aeb0dcda7868c8aa84b5909db1f1 --- lodash.js | 20 ++++++++++---------- test/test.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lodash.js b/lodash.js index 9f05ed000d..28cedea08d 100644 --- a/lodash.js +++ b/lodash.js @@ -2913,29 +2913,29 @@ function isEqual(a, b, stack) { stack || (stack = []); - // exit early for identical values - if (a === b) { - // treat `+0` vs. `-0` as not equal - return a !== 0 || (1 / a == 1 / b); - } // a strict comparison is necessary because `null == undefined` if (a == null || b == null) { return a === b; } - // unwrap any wrapped objects + // unwrap any LoDash wrapped values if (a._chain) { a = a._wrapped; } if (b._chain) { b = b._wrapped; } - // invoke a custom `isEqual` method if one is provided + // use custom `isEqual` method if available if (a.isEqual && toString.call(a.isEqual) == funcClass) { return a.isEqual(b); } if (b.isEqual && toString.call(b.isEqual) == funcClass) { return b.isEqual(a); } + // exit early for identical values + if (a === b) { + // treat `+0` vs. `-0` as not equal + return a !== 0 || (1 / a == 1 / b); + } // compare [[Class]] names var className = toString.call(a); if (className != toString.call(b)) { @@ -2979,12 +2979,12 @@ result = true, size = 0; - // add the first collection to the stack of traversed objects + // add `a` to the stack of traversed objects stack.push(a); // recursively compare objects and arrays (susceptible to call stack limits) - if (className == arrayClass) { - // compare array lengths to determine if a deep comparison is necessary + if (arrayLikeClasses[className] || (noArgsClass && isArguments(value))) { + // compare lengths to determine if a deep comparison is necessary size = a.length; result = size == b.length; diff --git a/test/test.js b/test/test.js index 0d8d6b6d05..fc40c42dd3 100644 --- a/test/test.js +++ b/test/test.js @@ -671,6 +671,20 @@ QUnit.module('lodash.isEqual'); (function() { + test('should work with `arguments` objects (test in IE < 9)', function() { + var args1 = (function() { return arguments; }(1, 2, 3)), + args2 = (function() { return arguments; }(1, 2, 3)), + args3 = (function() { return arguments; }(1, 2)); + + equal(_.isEqual(args1, args2), true); + equal(_.isEqual(args1, args3), false); + }); + + test('should respect custom `isEqual` result despite objects strict equaling each other', function() { + var object = { 'isEqual': function() { return false; } }; + equal(_.isEqual(object, object), false); + }); + test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { equal(_.isEqual(shadowed, {}), false); }); From 24035caadb9cce57897ce097d7d2d3e24c6c1ccc Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 24 Jul 2012 02:13:07 -0700 Subject: [PATCH 17/77] Keep objects in the `stack` array of `_.isEqual` in case a cyclical object is used in a sibling property. Former-commit-id: 33ffcec837322f4d479f64f9ec6b14184bf5f7a2 --- lodash.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lodash.js b/lodash.js index 28cedea08d..ba64214b3c 100644 --- a/lodash.js +++ b/lodash.js @@ -3038,8 +3038,6 @@ } } } - // remove the first collection from the stack of traversed objects - stack.pop(); return result; } From f1d0263ffa2063bc96ef565bec6481d166170caf Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 24 Jul 2012 02:13:31 -0700 Subject: [PATCH 18/77] Add `csp` Content Security Policy build. Former-commit-id: f922046de5150c098eb7f6d3b6901552117631e7 --- build.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.js b/build.js index 0f8c7e4196..c34e840ac8 100755 --- a/build.js +++ b/build.js @@ -14,11 +14,14 @@ /** Flag used to specify a Backbone build */ var isBackbone = process.argv.indexOf('backbone') > -1; + /** Flag used to specify a Content Security Policy build */ + var isCSP = process.argv.indexOf('csp') > -1 || process.argv.indexOf('CSP') > -1; + /** Flag used to specify a legacy build */ var isLegacy = process.argv.indexOf('legacy') > -1; /** Flag used to specify a mobile build */ - var isMobile = !isLegacy && process.argv.indexOf('mobile') > -1; + var isMobile = !isLegacy && (isCSP || process.argv.indexOf('mobile') > -1); /** * Flag used to specify `_.bindAll`, `_.extend`, and `_.defaults` are @@ -304,6 +307,7 @@ ' Commands:', '', ' lodash backbone Build containing all methods required by Backbone', + ' lodash csp Build supporting default Content Security Policy restrictions', ' lodash legacy Build tailored for older browsers without ES5 support', ' lodash mobile Build with IE < 9 bug fixes and method compilation removed', ' lodash strict Build with `_.bindAll`, `_.defaults`, and `_.extend` in strict mode', From 6d488b6a81ad579c5c52264724cacbc1260422f6 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 24 Jul 2012 02:15:20 -0700 Subject: [PATCH 19/77] Update minified build and rebuild documentation. Former-commit-id: 5f0ea311b51723c225774d735f67fc58f55a4d6e --- doc/README.md | 219 +++++++++++++++++++++++++++----------------------- lodash.min.js | 62 +++++++------- 2 files changed, 149 insertions(+), 132 deletions(-) diff --git a/doc/README.md b/doc/README.md index 929833ec64..c26b928329 100644 --- a/doc/README.md +++ b/doc/README.md @@ -12,7 +12,7 @@ * [`_.bind`](#_bindfunc--thisarg-arg1-arg2-) * [`_.bindAll`](#_bindallobject--methodname1-methodname2-) * [`_.chain`](#_chainvalue) -* [`_.clone`](#_clonevalue) +* [`_.clone`](#_clonevalue-deep--guard) * [`_.compact`](#_compactarray) * [`_.compose`](#_composefunc1-func2-) * [`_.contains`](#_containscollection-target) @@ -47,7 +47,7 @@ * [`_.isDate`](#_isdatevalue) * [`_.isElement`](#_iselementvalue) * [`_.isEmpty`](#_isemptyvalue) -* [`_.isEqual`](#_isequala-b--stack) +* [`_.isEqual`](#_isequala-b) * [`_.isFinite`](#_isfinitevalue) * [`_.isFunction`](#_isfunctionvalue) * [`_.isNaN`](#_isnanvalue) @@ -132,7 +132,7 @@ ### `_(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L206 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L216 "View in source") [Ⓣ][1] The `lodash` function. @@ -150,7 +150,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3676 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3790 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -162,7 +162,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2028 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2038 "View in source") [Ⓣ][1] Creates a new function that is restricted to executing only after it is called `n` times. @@ -190,7 +190,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2082 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2092 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. Lazy defined methods may be bound by passing the object they are bound to as `func` and the method name as `thisArg`. @@ -241,7 +241,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2152 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2162 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -272,7 +272,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3601 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3715 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -305,21 +305,37 @@ var youngest = _.chain(stooges) -### `_.clone(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2480 "View in source") [Ⓣ][1] +### `_.clone(value, deep [, guard])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2510 "View in source") [Ⓣ][1] -Create a shallow clone of the `value`. Any nested objects or arrays will be assigned by reference and not cloned. +Create a clone of `value`. If `deep` is `true`, all nested objects, excluding functons and `arguments` objects, will be cloned otherwise they will be assigned by reference. #### Arguments 1. `value` *(Mixed)*: The value to clone. +2. `deep` *(Boolean)*: A flag to indicate a deep clone. +3. `[guard]` *(Object)*: Internally used to allow this method to work with others like `_.map` without using their callback `index` argument for `deep`. #### Returns *(Mixed)*: Returns the cloned `value`. #### Example ~~~ js +var stooges = [ + { 'name': 'moe', 'age': 40 }, + { 'name': 'larry', 'age': 50 }, + { 'name': 'curly', 'age': 60 } +]; + _.clone({ 'name': 'moe' }); -// => { 'name': 'moe' }; +// => { 'name': 'moe' } + +var shallow = _.clone(stooges); +shallow[0] === stooges[0]; +// => true + +var deep = _.clone(stooges, true); +shallow[0] === stooges[0]; +// => false ~~~ * * * @@ -330,7 +346,7 @@ _.clone({ 'name': 'moe' }); ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1271 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1281 "View in source") [Ⓣ][1] Creates a new array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -354,7 +370,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2188 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2198 "View in source") [Ⓣ][1] Creates a new function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -381,7 +397,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L793 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L803 "View in source") [Ⓣ][1] Checks if a given `target` value is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -412,7 +428,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L829 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L839 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -444,7 +460,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2221 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2231 "View in source") [Ⓣ][1] Creates a new function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -470,7 +486,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2504 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2620 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -496,7 +512,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2286 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2296 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -521,7 +537,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2266 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2276 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -548,7 +564,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1303 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1313 "View in source") [Ⓣ][1] Creates a new array of `array` values not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -573,7 +589,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.drop(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2524 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2640 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -598,7 +614,7 @@ _.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3236 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3350 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -622,7 +638,7 @@ _.escape('Curly, Larry & Moe'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L849 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L859 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -648,7 +664,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2548 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2664 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -673,7 +689,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L869 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L879 "View in source") [Ⓣ][1] Examines each value in a `collection`, returning an array of all values the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -699,7 +715,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L890 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L900 "View in source") [Ⓣ][1] Examines each value in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -725,7 +741,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1340 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1350 "View in source") [Ⓣ][1] Gets the first value of the `array`. Pass `n` to return the first `n` values of the `array`. @@ -751,7 +767,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1364 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1374 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -779,7 +795,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L916 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L926 "View in source") [Ⓣ][1] Iterates over a `collection`, executing the `callback` for each value in the `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -808,7 +824,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2577 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2693 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -844,7 +860,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2600 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2716 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -872,7 +888,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2617 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2733 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -896,7 +912,7 @@ _.functions(_); ### `_.groupBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L944 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L954 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -928,7 +944,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2640 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2756 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -953,7 +969,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3255 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3369 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -978,7 +994,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1408 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1418 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1010,7 +1026,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1448 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1458 "View in source") [Ⓣ][1] Gets all but the last value of `array`. Pass `n` to exclude the last `n` values from the result. @@ -1036,7 +1052,7 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1469 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1479 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays. @@ -1060,7 +1076,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L972 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L982 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1089,7 +1105,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2660 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2776 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1116,7 +1132,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2686 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2802 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1143,7 +1159,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2703 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2819 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1167,7 +1183,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2720 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2836 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1191,7 +1207,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2737 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2853 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1215,7 +1231,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2762 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2878 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1244,15 +1260,14 @@ _.isEmpty(''); -### `_.isEqual(a, b [, stack])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2797 "View in source") [Ⓣ][1] +### `_.isEqual(a, b)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2913 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. #### Arguments 1. `a` *(Mixed)*: The value to compare. 2. `b` *(Mixed)*: The other value to compare. -3. `[stack]` *(Array)*: Internally used to keep track of "seen" objects to avoid circular references. #### Returns *(Boolean)*: Returns `true` if the values are equvalent, else `false`. @@ -1277,7 +1292,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2952 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3066 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1307,7 +1322,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2969 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3083 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1331,7 +1346,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3021 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3135 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1364,7 +1379,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3044 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3158 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1391,7 +1406,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3061 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3175 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1415,7 +1430,7 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2990 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3104 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1442,7 +1457,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3078 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1466,7 +1481,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3095 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3209 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1490,7 +1505,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3113 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3227 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1514,7 +1529,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3130 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3244 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1538,7 +1553,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1510 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1520 "View in source") [Ⓣ][1] Gets the last value of the `array`. Pass `n` to return the lasy `n` values of the `array`. @@ -1564,7 +1579,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1536 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1546 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1593,7 +1608,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1008 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1018 "View in source") [Ⓣ][1] Creates a new array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -1622,7 +1637,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1576 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1586 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1654,7 +1669,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2309 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2319 "View in source") [Ⓣ][1] Creates a new function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1680,7 +1695,7 @@ var fibonacci = _.memoize(function(n) { ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1626 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1636 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1706,7 +1721,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3281 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3395 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1736,7 +1751,7 @@ _('larry').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3312 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3426 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1756,7 +1771,7 @@ var lodash = _.noConflict(); ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2335 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2345 "View in source") [Ⓣ][1] Creates a new function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1782,7 +1797,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2367 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2377 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar `bind`, except it does **not** alter the `this` binding. @@ -1809,7 +1824,7 @@ hi('moe'); ### `_.pick(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3153 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3267 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -1834,7 +1849,7 @@ _.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1031 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1041 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -1865,7 +1880,7 @@ _.pluck(stooges, 'name'); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1687 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1697 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -1903,7 +1918,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1059 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1069 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -1930,7 +1945,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1096 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1106 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -1958,7 +1973,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1151 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1161 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -1984,7 +1999,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1724 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1734 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2010,7 +2025,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3344 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3458 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2045,7 +2060,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1745 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1755 "View in source") [Ⓣ][1] Creates a new array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2069,7 +2084,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3306 "View in source") [Ⓣ][1] Gets the size of `value` by returning `value.length` if `value` is an array, string, or `arguments` object. If `value` is an object, size is determined by returning the number of own enumerable properties it has. @@ -2099,7 +2114,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1174 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1184 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -2125,7 +2140,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1204 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1214 "View in source") [Ⓣ][1] Creates a new sorted array, sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2157,7 +2172,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1797 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1807 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with `1` argument; *(value)*. @@ -2198,7 +2213,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3628 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3742 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2228,7 +2243,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3404 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3518 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -2287,7 +2302,7 @@ _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' }); ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2403 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2413 "View in source") [Ⓣ][1] Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2312,7 +2327,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3544 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3658 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2338,7 +2353,7 @@ _.times(3, function() { this.grantWish(); }, genie); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1239 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1249 "View in source") [Ⓣ][1] Converts the `collection`, into an array. Useful for converting the `arguments` object. @@ -2362,7 +2377,7 @@ Converts the `collection`, into an array. Useful for converting the `arguments` ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1837 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1847 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays. @@ -2386,7 +2401,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1881 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1891 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -2422,7 +2437,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3571 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3685 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2446,7 +2461,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3214 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3328 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2470,7 +2485,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1930 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1940 "View in source") [Ⓣ][1] Creates a new array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2495,7 +2510,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2454 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2464 "View in source") [Ⓣ][1] Creates a new function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2524,7 +2539,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1963 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1973 "View in source") [Ⓣ][1] Merges the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2548,7 +2563,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.zipObject(keys)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1992 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2002 "View in source") [Ⓣ][1] Merges an array of `keys` and an array of `values` into a single object. @@ -2579,7 +2594,7 @@ _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3646 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3760 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2600,7 +2615,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3663 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3777 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -2628,7 +2643,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L234 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L244 "View in source") [Ⓣ][1] *(Object)*: By default, Lo-Dash uses embedded Ruby *(ERB)* style template delimiters, change the following template settings to use alternative delimiters. @@ -2640,7 +2655,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.escape` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L243 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L253 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to be HTML-escaped. @@ -2652,7 +2667,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.evaluate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L252 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L262 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect code to be evaluated. @@ -2664,7 +2679,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.interpolate` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L261 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L271 "View in source") [Ⓣ][1] *(RegExp)*: Used to detect `data` property values to inject. @@ -2676,7 +2691,7 @@ _([1, 2, 3]).value(); ### `_.templateSettings.variable` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L270 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L280 "View in source") [Ⓣ][1] *(String)*: Used to reference the data object in the template text. diff --git a/lodash.min.js b/lodash.min.js index 0eab8849c1..0996224718 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,34 +2,36 @@ Lo-Dash 0.4.2 lodash.com/license Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE */ -;(function(e,t){"use strict";function s(e){return new o(e)}function o(e){if(e&&e._wrapped)return e;this._wrapped=e}function u(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||30),s=i?{}:e;if(i)for(var o=t-1;++o=(n||30),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="p='"+u.o[n]+"';if(","constructor"==u.o[n]&&(t+="!(k&&k.prototype===t)&&"),t+="n.call(t,p)){"+u.m.i+"}"}u.c&&(t+="}")}return t+=u.e+";return H",Function("c,d,e,f,i,j,l,n,o,q,r,v,B,y,G,J,K,N" -,"return function("+e+"){"+t+"}")(ft,Tt,B,C,f,Y,ht,Z,A,E,k,p,Ct,ut,tt,nt,vt,rt)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return G[t]}function c(e){return"\\"+kt[e]}function h(e){return Nt[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(q.test(t))return"";var n=G.length;return G[n]="'+__e("+t+")+'",Q+n}function m(e,t,n,r){return e=G.length,t?G[e]="'+__e("+t+")+'":r?G[e]="';"+r+";__p+='":n&&(G[e]="'+((__t=("+ -n+"))==null?'':__t)+'"),Q+e}function g(e,t){if(q.test(t))return"";var n=G.length;return G[n]="'+((__t=("+t+"))==null?'':__t)+'",Q+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=Et&&rt.call(e)==vt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=un(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:nt.call(e,0,t)}function w(e,t){var n=[];if(!e) -return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e?nt.call(e,t==r|| -n?1:t):[]}function T(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=C(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]E(a,r))a.push(r),s.push(e[o]);return s}function C(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?Y.apply(s,o) -:s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&Ct[typeof o]?o:u):e.apply(u,o)}var r,i=rt.call(e)==ht;if(i){if(St||it&&2++u&&(l=K[u],!Z.call(e,l)||!!(a=Z.call(t,l)&&L(e[l],t[l],s))););}return s.pop(),a}function A(e){return e}function O(e){Ut(rn(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&et.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,M,_,D,P,H="object"==typeof exports&&exports&&("object"==typeof -global&&global&&global==global.global&&(e=global),exports),B=Array.prototype,j=Object.prototype,F=0,I=e._,q=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,R=/\b__p\+='';/g,U=/\b(__p\+=)''\+/g,z=/(__e\(.*?\)|\b__t\))\+'';/g,W=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,X=RegExp("^"+(j.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),V=/__token__(\d+)/g,$=/[&<"']/g,J=/['\n\r\t\u2028\u2029\\]/g,K="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf" -.split(" "),Q="__token__",G=[],Y=B.concat,Z=j.hasOwnProperty,et=B.push,tt=j.propertyIsEnumerable,nt=B.slice,rt=j.toString,it=X.test(it=nt.bind)&&it,st=X.test(st=Array.isArray)&&st,ot=e.isFinite,ut=X.test(ut=Object.keys)&&ut,at="[object Arguments]",ft="[object Array]",lt="[object Boolean]",ct="[object Date]",ht="[object Function]",pt="[object Number]",dt="[object RegExp]",vt="[object String]",mt=e.clearTimeout,gt=e.setTimeout,yt=!tt.call({valueOf:0},"valueOf"),bt=!k(arguments),wt="x"!=nt.call("x") -[0],Et="xx"!="x"[0]+Object("x")[0],St=it&&/\n|Opera/.test(it+rt.call(e.opera)),xt=ut&&/^.+$|true/.test(ut+!!e.attachEvent),Tt={"[object Arguments]":n,"[object Array]":n,"[object String]":n},Nt={"&":"&","<":"<",'"':""","'":"'"},Ct={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},kt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g -,variable:"obj"};var Lt={a:"h,g,M",j:"h",p:"if(!g){g=o}else if(M)g=v(g,M)",i:"g(t[p],p,h)"},At={j:"{}",p:"var C;if(typeof g!='function'){var P=g;g=function(O){return O[P]}}else if(M)g=v(g,M)",i:"C=g(t[p],p,h);(n.call(H,C)?H[C]++:H[C]=1)"},Ot={j:"true",i:"if(!g(t[p],p,h))return!H"},Mt={q:i,r:i,a:"A",j:"A",p:"for(var u=1,w=arguments.length;u-1"},i:"if(t[p]===L)return true"}),Ft=a(Lt,At),It=a(Lt,Ot),qt=a(Lt,_t),Rt=a(Lt,Dt,{j:"",i:"if(g(t[p],p,h))return t[p]"}),Ut=a(Lt,Dt),zt=a(Lt,At,{i:"C=g(t[p],p,h);(n.call(H,C)?H[C]:H[C]=[]).push(t[p])"}),Wt=a(Ht,{a:"h,x" -,p:"var b=J.call(arguments,2),s=typeof x=='function'",i:{b:"H[p]=(s?x:t[p][x]).apply(t[p],b)",l:"H"+(xt?"[D]=":".push")+"((s?x:t[p][x]).apply(t[p],b))"}}),Xt=a(Lt,Ht),Vt=a(Ht,{a:"h,F",i:{b:"H[p]=t[p][F]",l:"H"+(xt?"[D]=":".push")+"(t[p][F])"}}),$t=a({a:"h,g,a,M",j:"a",p:"var z=arguments.length<3;if(M)g=v(g,M)",d:{b:"if(z)H=h[++p]"},i:{b:"H=g(H,t[p],p,h)",l:"H=z?(z=false,t[p]):g(H,t[p],p,h)"}}),Jt=a(Lt,_t,{i:"!"+_t.i}),Kt=a(Lt,Ot,{j:"false",i:Ot.i.replace("!","")}),Qt=a(Lt,At,Ht,{i:{b:"H[p]={a:g(t[p],p,h),b:t[p]}" -,l:"H"+(xt?"[D]=":".push")+"({a:g(t[p],p,h),b:t[p]})"},e:"H.sort(i);w=H.length;while(w--){H[w]=H[w].b}"}),Gt=a({q:i,r:i,a:"A",j:"A",p:"var m=arguments,w=m.length;if(w>1){for(var p=1;pe?t():function(){if(1>-- -e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=Gt,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&Ct[typeof e]?sn(e)?e.slice():en({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&It(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=Wt,s.isArguments= -k,s.isArray=sn,s.isBoolean=function(e){return e===n||e===i||rt.call(e)==lt},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=on,s.isEqual=L,s.isFinite=function(e){return ot(e)&&rt.call(e)==pt},s.isNaN=function(e){return rt.call(e)==pt&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&Ct[typeof e]},s.isUndefined=function(e){return e===t},s.keys=un,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:nt.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){ -if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Xt,s.max=S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return Z.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s|"+(a?"|"+a.source:""),"g")),o=G.length,e=e.replace(P,m),o=o!=G.length,e="__p += '"+e.replace(J,c).replace(V,l)+"';",G.length=0,n||(n=h.variable||_||"obj",o?e="with("+n+"){"+e+"}":(n!=_&&(_= -n,D=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(W,"$&"+n+".").replace(D,"$1__d"))),e=(o?e.replace(R,""):e).replace(U,"$1").replace(z,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i -,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=gt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(wt?rt.call(e)==vt:"string"==typeof e)?e.split(""):nt.call(e):an(e)},s.union=function(){for(var e=-1,t=[],n=Y.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push -(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=F++;return e?e+t:t},s.values=an,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++nn?1:0}function l(e,t){return Z[t]}function c(e){return"\\"+Mt[e]}function h(e){return At[e]}function p(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function d(){}function v(e,t){if(R.test(t))return"";var n=Z.length;return Z[n]="'+__e("+t+")+'",Y+n}function m(e,t,n,r){return e=Z.length,t?Z[e]="'+__e("+t+")+'":r?Z[e]="';"+r+";__p+='":n&&(Z[ +e]="'+((__t=("+n+"))==null?'':__t)+'"),Y+e}function g(e,t){if(R.test(t))return"";var n=Z.length;return Z[n]="'+((__t=("+t+"))==null?'':__t)+'",Y+n}function y(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=p(t,r));if(i===i>>>0){var o=Tt&&st.call(e)==yt?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=cn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function b(e,t,n){if(e)return t==r||n?e[0]:it.call(e,0,t)}function w(e,t){ +var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=p(t,n));++sr&&(r=n,i=e[s]);return i}function x(e,t,n){return e? +it.call(e,t==r||n?1:t):[]}function T(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=C(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]E(a,r))a.push(r),s.push(e[o]);return s}function C(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length? +et.apply(s,o):s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&Ot[typeof o]?o:u):e.apply(u,o)}var r,i=st.call(e)==dt;if(i){if(Nt||ot&&2++u&&(l=G[u],!tt.call(e,l)||!!(a=tt.call(t,l)&&A(e[l],t[l],s))););}return a}function O(e){return e}function M(e){Vt(an(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped +];return arguments.length&&nt.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,_,D,P,H,B="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),j=Array.prototype,F=Object.prototype,I=0,q=e._,R=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,U=/\b__p\+='';/g,z=/\b(__p\+=)''\+/g,W=/(__e\(.*?\)|\b__t\))\+'';/g,X=/\w*$/,V=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,$=RegExp("^"+ +(F.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),J=/__token__(\d+)/g,K=/[&<"']/g,Q=/['\n\r\t\u2028\u2029\\]/g,G="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Y="__token__",Z=[],et=j.concat,tt=F.hasOwnProperty,nt=j.push,rt=F.propertyIsEnumerable,it=j.slice,st=F.toString,ot=$.test(ot=it.bind)&&ot,ut=$.test(ut=Array.isArray)&&ut,at=e.isFinite,ft=$.test(ft=Object.keys)&&ft,lt="[object Arguments]" +,ct="[object Array]",ht="[object Boolean]",pt="[object Date]",dt="[object Function]",vt="[object Number]",mt="[object Object]",gt="[object RegExp]",yt="[object String]",bt=e.clearTimeout,wt=e.setTimeout,Et=!rt.call({valueOf:0},"valueOf"),St=!L(arguments),xt="x"!=it.call("x")[0],Tt="xx"!="x"[0]+Object("x")[0],Nt=ot&&/\n|Opera/.test(ot+st.call(e.opera)),Ct=ft&&/^.+$|true/.test(ft+!!e.attachEvent),kt={"[object Arguments]":n,"[object Array]":n,"[object String]":n},Lt={"[object Array]":n,"[object Boolean]" +:n,"[object Date]":n,"[object Number]":n,"[object Object]":n,"[object RegExp]":n,"[object String]":n},At={"&":"&","<":"<",'"':""","'":"'"},Ot={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},Mt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj"};var _t={a:"h,g,M",j:"h",p:"if(!g){g=o}else if(M)g=v(g,M)",i:"g(t[p],p,h)" +},Dt={j:"{}",p:"var C;if(typeof g!='function'){var P=g;g=function(O){return O[P]}}else if(M)g=v(g,M)",i:"C=g(t[p],p,h);(n.call(H,C)?H[C]++:H[C]=1)"},Pt={j:"true",i:"if(!g(t[p],p,h))return!H"},Ht={q:i,r:i,a:"A",j:"A",p:"for(var u=1,w=arguments.length;u-1"},i:"if(t[p]===L)return true"}),Ut=a(_t,Dt),zt=a(_t,Pt),Wt=a(_t,Bt),Xt=a(_t,jt,{j:"",i:"if(g(t[p],p,h))return t[p]"}),Vt=a(_t,jt),$t=a(_t,Dt,{i:"C=g(t[p],p,h);(n.call(H,C)?H[C]:H[C]=[]).push(t[p])"}),Jt=a(It,{a:"h,x",p:"var b=J.call(arguments,2),s=typeof x=='function'",i:{b:"H[p]=(s?x:t[p][x]).apply(t[p],b)" +,l:"H"+(Ct?"[D]=":".push")+"((s?x:t[p][x]).apply(t[p],b))"}}),Kt=a(_t,It),Qt=a(It,{a:"h,F",i:{b:"H[p]=t[p][F]",l:"H"+(Ct?"[D]=":".push")+"(t[p][F])"}}),Gt=a({a:"h,g,a,M",j:"a",p:"var z=arguments.length<3;if(M)g=v(g,M)",d:{b:"if(z)H=h[++p]"},i:{b:"H=g(H,t[p],p,h)",l:"H=z?(z=false,t[p]):g(H,t[p],p,h)"}}),Yt=a(_t,Bt,{i:"!"+Bt.i}),Zt=a(_t,Pt,{j:"false",i:Pt.i.replace("!","")}),en=a(_t,Dt,It,{i:{b:"H[p]={a:g(t[p],p,h),b:t[p]}",l:"H"+(Ct?"[D]=":".push")+"({a:g(t[p],p,h),b:t[p]})"},e:"H.sort(i);w=H.length;while(w--){H[w]=H[w].b}" +}),tn=a({q:i,r:i,a:"A",j:"A",p:"var m=arguments,w=m.length;if(w>1){for(var p=1;pe?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=C,s.bindAll=tn,s.chain=function(e){return e=new o(e), +e._chain=n,e},s.clone=k,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nE(t,n)&&zt(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=Jt,s.isArguments=L,s.isArray=fn,s.isBoolean=function(e){return e===n||e===i||st.call(e)==ht},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=ln,s.isEqual= +A,s.isFinite=function(e){return at(e)&&st.call(e)==vt},s.isNaN=function(e){return st.call(e)==vt&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&Ot[typeof e]},s.isUndefined=function(e){return e===t},s.keys=cn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:it.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Kt,s.max= +S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return tt.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s|"+(a?"|"+a.source:""),"g")),o=Z.length,e=e.replace(H,m),o=o!=Z.length,e="__p += '"+e.replace(Q,c).replace(J,l)+"';",Z.length=0,n||(n=h.variable||D||"obj",o?e="with("+n+"){"+e+"}":(n!=D&&(D=n,P=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(V,"$&"+n+".").replace(P,"$1__d"))),e=(o?e.replace(U,""):e).replace(z,"$1").replace(W,"$1;" +),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=wt(n,f)),s}},s.times=function(e,t +,n){var r=-1;if(n)for(;++r>>0?(xt?st.call(e)==yt:"string"==typeof e)?e.split(""):it.call(e):hn(e)},s.union=function(){for(var e=-1,t=[],n=et.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=I++;return e?e+t:t},s.values=hn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1 +,r=e.length,i=u(arguments,1,20);++n Date: Wed, 25 Jul 2012 01:32:28 -0700 Subject: [PATCH 20/77] Make `_.range` coerce arguments to numbers. Former-commit-id: 5408800fef0bc8a418c298a112049232b6d85e78 --- lodash.js | 6 ++-- test/test.js | 91 ++++++++++++++++++++++++++++++++++------------------ 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/lodash.js b/lodash.js index ba64214b3c..2fba118c79 100644 --- a/lodash.js +++ b/lodash.js @@ -1695,9 +1695,11 @@ * // => [] */ function range(start, end, step) { - step || (step = 1); + start = +start || 0; + step = +step || 1; + if (end == null) { - end = start || 0; + end = start; start = 0; } // use `Array(length)` so V8 will avoid the slower "dictionary" mode diff --git a/test/test.js b/test/test.js index fc40c42dd3..0dda636537 100644 --- a/test/test.js +++ b/test/test.js @@ -27,6 +27,17 @@ _._ || _ ); + /** Used to pass falsey values to methods */ + var falsey = [ + , + '', + 0, + false, + NaN, + null, + undefined + ]; + /** Shortcut used to make object properties immutable */ var freeze = Object.freeze; @@ -829,6 +840,30 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.range'); + + (function() { + var func = _.range; + + test('should treat falsey `start` arguments as `0`', function() { + _.each(falsey, function(value, index) { + if (index) { + deepEqual(_.range(value), []); + deepEqual(_.range(value, 1), [0]); + } else { + deepEqual(_.range(), []); + } + }); + }); + + test('should coerce arguments to numbers', function() { + var actual = [func('0',1), func('1'), func(0, 1, '1')]; + deepEqual(actual, [[0], [0], [0]]); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.reduceRight'); (function() { @@ -896,12 +931,12 @@ }); test('should allow a falsey `object` argument', function() { - var func = _.size; - try { - var actual = [func(), func(undefined), func(null), func(false), func(0)]; - } catch(e) { } - - deepEqual(actual, [0, 0, 0, 0, 0]); + _.each(falsey, function(index, value) { + try { + var actual = index ? _.size(value) : _.size(); + } catch(e) { } + equal(actual, 0); + }) }); test('should work with an object that has a `length` property', function() { @@ -1217,15 +1252,14 @@ var func = _[methodName], pass = true; - try { - func(); - func(undefined); - func(null); - func(false); - func(0); - } catch(e) { - pass = false; - } + _.each(falsey, function(value, index) { + try { + index ? func() : func(value); + } catch(e) { + pass = false; + } + }); + ok(pass, methodName + ' allows a falsey `array` argument'); }); }); @@ -1256,23 +1290,18 @@ identity = _.identity, pass = true; - try { - if (/^(?:contains|toArray)$/.test(methodName)) { - func(); - func(undefined); - func(null); - func(false); - func(0); + _.each(falsey, function(value, index) { + try { + if (/^(?:contains|toArray)$/.test(methodName)) { + index ? func() : func(value); + } else if (index) { + func(value, identity); + } + } catch(e) { + pass = false; } - else { - func(undefined, identity); - func(null, identity); - func(false, identity); - func(0, identity); - } - } catch(e) { - pass = false; - } + }); + ok(pass, methodName + ' allows a falsey `collection` argument'); }); }); From 4ff12e04261bf2a2a42c5ae526d9d66a1e0f357a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 25 Jul 2012 01:33:16 -0700 Subject: [PATCH 21/77] Fix recent typo in `isEqual`. Former-commit-id: 84cdf90de59c8184a0ac1f78704f61dcc88c91f1 --- doc/README.md | 122 +++++++++++++++++++++++++------------------------- lodash.js | 2 +- lodash.min.js | 8 ++-- 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/doc/README.md b/doc/README.md index c26b928329..3356ad45f0 100644 --- a/doc/README.md +++ b/doc/README.md @@ -150,7 +150,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3790 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3792 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -162,7 +162,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2038 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2040 "View in source") [Ⓣ][1] Creates a new function that is restricted to executing only after it is called `n` times. @@ -190,7 +190,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2092 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2094 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. Lazy defined methods may be bound by passing the object they are bound to as `func` and the method name as `thisArg`. @@ -241,7 +241,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2162 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2164 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -272,7 +272,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3715 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3717 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -306,7 +306,7 @@ var youngest = _.chain(stooges) ### `_.clone(value, deep [, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2510 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2512 "View in source") [Ⓣ][1] Create a clone of `value`. If `deep` is `true`, all nested objects, excluding functons and `arguments` objects, will be cloned otherwise they will be assigned by reference. @@ -370,7 +370,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2198 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2200 "View in source") [Ⓣ][1] Creates a new function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -460,7 +460,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2231 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2233 "View in source") [Ⓣ][1] Creates a new function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -486,7 +486,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2620 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2622 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -512,7 +512,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2296 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2298 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -537,7 +537,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2276 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2278 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -589,7 +589,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.drop(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2640 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2642 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -614,7 +614,7 @@ _.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3350 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3352 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -664,7 +664,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2664 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2666 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -824,7 +824,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2693 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2695 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -860,7 +860,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2716 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2718 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -888,7 +888,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2733 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2735 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -944,7 +944,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2756 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2758 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -969,7 +969,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3369 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3371 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -1105,7 +1105,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2776 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2778 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1132,7 +1132,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2802 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2804 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1159,7 +1159,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2819 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2821 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1183,7 +1183,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2836 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2838 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1207,7 +1207,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2853 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2855 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1231,7 +1231,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2878 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2880 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1261,7 +1261,7 @@ _.isEmpty(''); ### `_.isEqual(a, b)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2913 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2915 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1292,7 +1292,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3066 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3068 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1322,7 +1322,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3083 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3085 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1346,7 +1346,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3135 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3137 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1379,7 +1379,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3158 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3160 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1406,7 +1406,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3175 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3177 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1430,7 +1430,7 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3104 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3106 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1457,7 +1457,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3194 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1481,7 +1481,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3209 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3211 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1505,7 +1505,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3227 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3229 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1529,7 +1529,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3244 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3246 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1669,7 +1669,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2319 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2321 "View in source") [Ⓣ][1] Creates a new function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1721,7 +1721,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3395 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3397 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1751,7 +1751,7 @@ _('larry').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3426 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3428 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1771,7 +1771,7 @@ var lodash = _.noConflict(); ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2345 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2347 "View in source") [Ⓣ][1] Creates a new function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1797,7 +1797,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2377 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2379 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar `bind`, except it does **not** alter the `this` binding. @@ -1824,7 +1824,7 @@ hi('moe'); ### `_.pick(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3267 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3269 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -1999,7 +1999,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1734 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1736 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2025,7 +2025,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3458 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3460 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2060,7 +2060,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1755 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1757 "View in source") [Ⓣ][1] Creates a new array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2084,7 +2084,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3306 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3308 "View in source") [Ⓣ][1] Gets the size of `value` by returning `value.length` if `value` is an array, string, or `arguments` object. If `value` is an object, size is determined by returning the number of own enumerable properties it has. @@ -2172,7 +2172,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1807 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1809 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with `1` argument; *(value)*. @@ -2213,7 +2213,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3742 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3744 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2243,7 +2243,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3518 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3520 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -2302,7 +2302,7 @@ _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' }); ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2413 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2415 "View in source") [Ⓣ][1] Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2327,7 +2327,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3658 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3660 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2377,7 +2377,7 @@ Converts the `collection`, into an array. Useful for converting the `arguments` ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1847 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1849 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays. @@ -2401,7 +2401,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1891 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1893 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -2437,7 +2437,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3685 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3687 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2461,7 +2461,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3328 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3330 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2485,7 +2485,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1940 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1942 "View in source") [Ⓣ][1] Creates a new array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2510,7 +2510,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2464 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2466 "View in source") [Ⓣ][1] Creates a new function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2539,7 +2539,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1973 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1975 "View in source") [Ⓣ][1] Merges the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2563,7 +2563,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.zipObject(keys)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2002 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2004 "View in source") [Ⓣ][1] Merges an array of `keys` and an array of `values` into a single object. @@ -2594,7 +2594,7 @@ _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3760 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3762 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2615,7 +2615,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3777 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3779 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index 2fba118c79..82d46800c4 100644 --- a/lodash.js +++ b/lodash.js @@ -2985,7 +2985,7 @@ stack.push(a); // recursively compare objects and arrays (susceptible to call stack limits) - if (arrayLikeClasses[className] || (noArgsClass && isArguments(value))) { + if (arrayLikeClasses[className] || (noArgsClass && isArguments(a))) { // compare lengths to determine if a deep comparison is necessary size = a.length; result = size == b.length; diff --git a/lodash.min.js b/lodash.min.js index 0996224718..530e3efee6 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -12,7 +12,7 @@ it.call(e,t==r||n?1:t):[]}function T(e,t,n,r){if(!e)return 0;var i=0,s=e.length; et.apply(s,o):s),this instanceof n?(d.prototype=e.prototype,u=new d,(o=e.apply(u,o))&&Ot[typeof o]?o:u):e.apply(u,o)}var r,i=st.call(e)==dt;if(i){if(Nt||ot&&2++u&&(l=G[u],!tt.call(e,l)||!!(a=tt.call(t,l)&&A(e[l],t[l],s))););}return a}function O(e){return e}function M(e){Vt(an(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped +kt[o]||St&&L(e)){if(f=e.length,a=f==t.length)for(;f--&&(a=A(e[f],t[f],s)););}else{if("constructor"in e!="constructor"in t||e.constructor!=t.constructor)return i;for(var l in e)if(tt.call(e,l)&&(f++,!(a=tt.call(t,l)&&A(e[l],t[l],s))))break;if(a){for(l in t)if(tt.call(t,l)&&!(f--))break;a=!f}if(a&&Et)for(;7>++u&&(l=G[u],!tt.call(e,l)||!!(a=tt.call(t,l)&&A(e[l],t[l],s))););}return a}function O(e){return e}function M(e){Vt(an(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped ];return arguments.length&&nt.apply(e,arguments),e=r.apply(s,e),this._chain&&(e=new o(e),e._chain=n),e}})}var n=!0,r=null,i=!1,_,D,P,H,B="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),j=Array.prototype,F=Object.prototype,I=0,q=e._,R=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,U=/\b__p\+='';/g,z=/\b(__p\+=)''\+/g,W=/(__e\(.*?\)|\b__t\))\+'';/g,X=/\w*$/,V=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,$=RegExp("^"+ (F.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),J=/__token__(\d+)/g,K=/[&<"']/g,Q=/['\n\r\t\u2028\u2029\\]/g,G="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),Y="__token__",Z=[],et=j.concat,tt=F.hasOwnProperty,nt=j.push,rt=F.propertyIsEnumerable,it=j.slice,st=F.toString,ot=$.test(ot=it.bind)&&ot,ut=$.test(ut=Array.isArray)&&ut,at=e.isFinite,ft=$.test(ft=Object.keys)&&ft,lt="[object Arguments]" ,ct="[object Array]",ht="[object Boolean]",pt="[object Date]",dt="[object Function]",vt="[object Number]",mt="[object Object]",gt="[object RegExp]",yt="[object String]",bt=e.clearTimeout,wt=e.setTimeout,Et=!rt.call({valueOf:0},"valueOf"),St=!L(arguments),xt="x"!=it.call("x")[0],Tt="xx"!="x"[0]+Object("x")[0],Nt=ot&&/\n|Opera/.test(ot+st.call(e.opera)),Ct=ft&&/^.+$|true/.test(ft+!!e.attachEvent),kt={"[object Arguments]":n,"[object Array]":n,"[object String]":n},Lt={"[object Array]":n,"[object Boolean]" @@ -27,9 +27,9 @@ arguments,1);return wt(function(){return e.apply(t,n)},1)},s.delay=function(e,n) function(e,t){return tt.call(e,t)},s.identity=O,s.indexOf=E,s.initial=function(e,t,n){return e?it.call(e,0,-(t==r||n?1:t)):[]},s.intersection=function(e){var t=[];if(!e)return t;for(var n,r=-1,i=e.length,s=it.call(arguments,1),o=[];++rE(t,n)&&zt(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=Jt,s.isArguments=L,s.isArray=fn,s.isBoolean=function(e){return e===n||e===i||st.call(e)==ht},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=ln,s.isEqual= A,s.isFinite=function(e){return at(e)&&st.call(e)==vt},s.isNaN=function(e){return st.call(e)==vt&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&Ot[typeof e]},s.isUndefined=function(e){return e===t},s.keys=cn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:it.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Kt,s.max= S,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return tt.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s|"+(a?"|"+a.source:""),"g")),o=Z.length,e=e.replace(H,m),o=o!=Z.length,e="__p += '"+e.replace(Q,c).replace(J,l)+"';",Z.length=0,n||(n=h.variable||D||"obj",o?e="with("+n+"){"+e+"}":(n!=D&&(D=n,P=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(V,"$&"+n+".").replace(P,"$1__d"))),e=(o?e.replace(U,""):e).replace(z,"$1").replace(W,"$1;" +e){var t=it.call(arguments,1),n=t.length;return function(){var r;return r=arguments,r.length&&(t.length=n,nt.apply(t,r)),r=1==t.length?e.call(this,t[0]):e.apply(this,t),t.length=n,r}},s.pick=function(e){for(var t,n=0,r=et.apply(j,arguments),i=r.length,s={};++n|"+(a?"|"+a.source:""),"g")),o=Z.length,e=e.replace(H,m),o=o!=Z.length,e="__p += '"+e.replace(Q,c).replace(J,l)+"';",Z.length=0,n||(n=h.variable||D||"obj",o?e="with("+n+"){"+e+"}":(n!=D&&(D=n,P=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(V,"$&"+n+".").replace(P,"$1__d"))),e=(o?e.replace(U,""):e).replace(z,"$1").replace(W,"$1;" ),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=wt(n,f)),s}},s.times=function(e,t ,n){var r=-1;if(n)for(;++r>>0?(xt?st.call(e)==yt:"string"==typeof e)?e.split(""):it.call(e):hn(e)},s.union=function(){for(var e=-1,t=[],n=et.apply(t,arguments),r=n.length;++eE(t,n[e])&&t.push(n[e]);return t},s.uniq=N,s.uniqueId=function(e){var t=I++;return e?e+t:t},s.values=hn,s.without=function(e){var t=[];if(!e)return t;for(var n=-1 ,r=e.length,i=u(arguments,1,20);++n Date: Thu, 26 Jul 2012 23:20:36 -0700 Subject: [PATCH 22/77] Ensure the `callback` of `_.filter` can't modify the resulting value. Former-commit-id: 6652dc5926390e8418b524c7ffd2347c2fa65c82 --- build/pre-compile.js | 16 +++++++++--- lodash.js | 59 ++++++++++++++++++++++++-------------------- test/test.js | 14 +++++++++++ 3 files changed, 59 insertions(+), 30 deletions(-) diff --git a/build/pre-compile.js b/build/pre-compile.js index fe6ee0f96a..724563a2d2 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -285,15 +285,25 @@ // minify properties properties.forEach(function(property, index) { + var reBracketProp = RegExp("\\['" + property + '\\b', 'g'), + reDotProp = RegExp('\\.' + property + '\\b', 'g'), + rePropColon = RegExp('\\b' + property + ' *:', 'g'); + // add quotes around properties in the inlined `_.sortBy` of the mobile // build so Closure Compiler won't mung them if (isSortBy && isInlined) { modified = modified - .replace(RegExp('\\.' + property + '\\b', 'g'), "['" + minNames[index] + "']") - .replace(RegExp('\\b' + property + ' *:', 'g'), "'" + minNames[index] + "':"); + .replace(reDotProp, "['" + minNames[index] + "']") + .replace(rePropColon, "'" + minNames[index] + "':"); + } + else { + modified = modified + .replace(reBracketProp, "['" + minNames[index]) + .replace(reDotProp, '.' + minNames[index]) + .replace(rePropColon, minNames[index] + ':'); } - modified = modified.replace(RegExp('\\b' + property + '\\b', 'g'), minNames[index]); }); + // replace with modified snippet source = source.replace(snippet, modified); }); diff --git a/lodash.js b/lodash.js index 82d46800c4..a5c684c76a 100644 --- a/lodash.js +++ b/lodash.js @@ -294,7 +294,7 @@ '<% if (useStrict) { %>\'use strict\';\n<% } %>' + // the `iteratee` may be reassigned by the `top` snippet - 'var index, iteratee = <%= firstArg %>, ' + + 'var index, value, iteratee = <%= firstArg %>, ' + // assign the `result` variable an initial value 'result<% if (init) { %> = <%= init %><% } %>;\n' + // add code to exit early or do so if the first argument is falsey @@ -316,6 +316,7 @@ ' <%= arrayBranch.beforeLoop %>;\n' + ' while (++index < length) {\n' + + ' value = iteratee[index];\n' + ' <%= arrayBranch.inLoop %>\n' + ' }' + ' <% if (objectBranch) { %>\n}<% } %>' + @@ -338,6 +339,7 @@ ' while (++propIndex < length) {\n' + ' index = props[propIndex];\n' + ' if (!(skipProto && index == \'prototype\')) {\n' + + ' value = iteratee[index];\n' + ' <%= objectBranch.inLoop %>\n' + ' }\n' + ' }' + @@ -348,6 +350,7 @@ ' for (index in iteratee) {' + ' <% if (hasDontEnumBug) { %>\n' + ' <% if (useHas) { %>if (hasOwnProperty.call(iteratee, index)) {\n <% } %>' + + ' value = iteratee[index];\n' + ' <%= objectBranch.inLoop %>;\n' + ' <% if (useHas) { %>}<% } %>' + ' <% } else { %>\n' + @@ -360,6 +363,7 @@ // [[Enumerable]] value. ' if (!(skipProto && index == \'prototype\')<% if (useHas) { %> &&\n' + ' hasOwnProperty.call(iteratee, index)<% } %>) {\n' + + ' value = iteratee[index];\n' + ' <%= objectBranch.inLoop %>\n' + ' }' + ' <% } %>\n' + @@ -378,6 +382,7 @@ ' if (shadowed[k] == \'constructor\') {' + ' %>!(ctor && ctor.prototype === iteratee) && <%' + ' } %>hasOwnProperty.call(iteratee, index)) {\n' + + ' value = iteratee[index];\n' + ' <%= objectBranch.inLoop %>\n' + ' }' + ' <% } %>' + @@ -406,7 +411,7 @@ 'else if (thisArg) {\n' + ' callback = iteratorBind(callback, thisArg)\n' + '}', - 'inLoop': 'callback(iteratee[index], index, collection)' + 'inLoop': 'callback(value, index, collection)' }; /** Reusable iterator options for `countBy`, `groupBy`, and `sortBy` */ @@ -422,14 +427,14 @@ ' callback = iteratorBind(callback, thisArg)\n' + '}', 'inLoop': - 'prop = callback(iteratee[index], index, collection);\n' + + 'prop = callback(value, index, collection);\n' + '(hasOwnProperty.call(result, prop) ? result[prop]++ : result[prop] = 1)' }; /** Reusable iterator options for `every` and `some` */ var everyIteratorOptions = { 'init': 'true', - 'inLoop': 'if (!callback(iteratee[index], index, collection)) return !result' + 'inLoop': 'if (!callback(value, index, collection)) return !result' }; /** Reusable iterator options for `defaults` and `extend` */ @@ -442,14 +447,14 @@ 'for (var iterateeIndex = 1, length = arguments.length; iterateeIndex < length; iterateeIndex++) {\n' + ' iteratee = arguments[iterateeIndex];\n' + (hasDontEnumBug ? ' if (iteratee) {' : ''), - 'inLoop': 'result[index] = iteratee[index]', + 'inLoop': 'result[index] = value', 'bottom': (hasDontEnumBug ? ' }\n' : '') + '}' }; /** Reusable iterator options for `filter` and `reject` */ var filterIteratorOptions = { 'init': '[]', - 'inLoop': 'callback(iteratee[index], index, collection) && result.push(iteratee[index])' + 'inLoop': 'callback(value, index, collection) && result.push(value)' }; /** Reusable iterator options for `find`, `forEach`, `forIn`, and `forOwn` */ @@ -473,8 +478,8 @@ 'object': 'result = ' + (isKeysFast ? 'Array(length)' : '[]') }, 'inLoop': { - 'array': 'result[index] = callback(iteratee[index], index, collection)', - 'object': 'result' + (isKeysFast ? '[propIndex] = ' : '.push') + '(callback(iteratee[index], index, collection))' + 'array': 'result[index] = callback(value, index, collection)', + 'object': 'result' + (isKeysFast ? '[propIndex] = ' : '.push') + '(callback(value, index, collection))' } }; @@ -807,7 +812,7 @@ 'beforeLoop': { 'array': 'if (toString.call(iteratee) == stringClass) return collection.indexOf(target) > -1' }, - 'inLoop': 'if (iteratee[index] === target) return true' + 'inLoop': 'if (value === target) return true' }); /** @@ -899,7 +904,7 @@ */ var find = createIterator(baseIteratorOptions, forEachIteratorOptions, { 'init': '', - 'inLoop': 'if (callback(iteratee[index], index, collection)) return iteratee[index]' + 'inLoop': 'if (callback(value, index, collection)) return value' }); /** @@ -953,8 +958,8 @@ */ var groupBy = createIterator(baseIteratorOptions, countByIteratorOptions, { 'inLoop': - 'prop = callback(iteratee[index], index, collection);\n' + - '(hasOwnProperty.call(result, prop) ? result[prop] : result[prop] = []).push(iteratee[index])' + 'prop = callback(value, index, collection);\n' + + '(hasOwnProperty.call(result, prop) ? result[prop] : result[prop] = []).push(value)' }); /** @@ -986,11 +991,11 @@ ' isFunc = typeof methodName == \'function\'', 'inLoop': { 'array': - 'result[index] = (isFunc ? methodName : iteratee[index][methodName])' + - '.apply(iteratee[index], args)', + 'result[index] = (isFunc ? methodName : value[methodName])' + + '.apply(value, args)', 'object': 'result' + (isKeysFast ? '[propIndex] = ' : '.push') + - '((isFunc ? methodName : iteratee[index][methodName]).apply(iteratee[index], args))' + '((isFunc ? methodName : value[methodName]).apply(value, args))' } }); @@ -1041,8 +1046,8 @@ var pluck = createIterator(mapIteratorOptions, { 'args': 'collection, property', 'inLoop': { - 'array': 'result[index] = iteratee[index][property]', - 'object': 'result' + (isKeysFast ? '[propIndex] = ' : '.push') + '(iteratee[index][property])' + 'array': 'result[index] = value[property]', + 'object': 'result' + (isKeysFast ? '[propIndex] = ' : '.push') + '(value[property])' } }); @@ -1077,11 +1082,11 @@ }, 'inLoop': { 'array': - 'result = callback(result, iteratee[index], index, collection)', + 'result = callback(result, value, index, collection)', 'object': 'result = noaccum\n' + - ' ? (noaccum = false, iteratee[index])\n' + - ' : callback(result, iteratee[index], index, collection)' + ' ? (noaccum = false, value)\n' + + ' : callback(result, value, index, collection)' } }); @@ -1215,13 +1220,13 @@ 'inLoop': { 'array': 'result[index] = {\n' + - ' criteria: callback(iteratee[index], index, collection),\n' + - ' value: iteratee[index]\n' + + ' criteria: callback(value, index, collection),\n' + + ' value: value\n' + '}', 'object': 'result' + (isKeysFast ? '[propIndex] = ' : '.push') + '({\n' + - ' criteria: callback(iteratee[index], index, collection),\n' + - ' value: iteratee[index]\n' + + ' criteria: callback(value, index, collection),\n' + + ' value: value\n' + '})' }, 'bottom': @@ -2644,7 +2649,7 @@ 'args': 'object', 'init': '{}', 'top': 'var props = concat.apply(ArrayProto, arguments)', - 'inLoop': 'if (indexOf(props, index) < 0) result[index] = iteratee[index]' + 'inLoop': 'if (indexOf(props, index) < 0) result[index] = value' }); /** @@ -2736,7 +2741,7 @@ 'useHas': false, 'args': 'object', 'init': '[]', - 'inLoop': 'if (toString.call(iteratee[index]) == funcClass) result.push(index)', + 'inLoop': 'if (toString.call(value) == funcClass) result.push(index)', 'bottom': 'result.sort()' }); @@ -3330,7 +3335,7 @@ var values = createIterator({ 'args': 'object', 'init': '[]', - 'inLoop': 'result.push(iteratee[index])' + 'inLoop': 'result.push(value)' }); /*--------------------------------------------------------------------------*/ diff --git a/test/test.js b/test/test.js index 0dda636537..249156dff7 100644 --- a/test/test.js +++ b/test/test.js @@ -427,6 +427,20 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.filter'); + + (function() { + test('should not modify the resulting value from within `callback`', function() { + var actual = _.filter([0], function(value, index, array) { + return (array[index] = 1); + }); + + deepEqual(actual, [0]); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.find'); (function() { From 86bd847bf9a6b22d6022f246c65661a1368c53ac Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 29 Jul 2012 00:58:23 -0700 Subject: [PATCH 23/77] Ensure `_.isEqual` works correctly for objects from another document and add `_.clone` benchmark. Former-commit-id: b1ef745ec6c24e8ea0c8fae304ead80c60dfd5aa --- build.js | 7 +- build/pre-compile.js | 11 ++- lodash.js | 191 ++++++++++++++++++++++++++----------------- perf/perf.js | 27 +++--- test/test.js | 26 ++++++ 5 files changed, 171 insertions(+), 91 deletions(-) diff --git a/build.js b/build.js index c34e840ac8..de0312d2dd 100755 --- a/build.js +++ b/build.js @@ -881,14 +881,17 @@ }); // remove JScript [[DontEnum]] fix from `_.isEqual` - source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(result *&& *hasDontEnumBug[\s\S]+?\n\1}/, ''); + source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(hasDontEnumBug[\s\S]+?\n\1}/, ''); // remove IE `shift` and `splice` fix from mutator Array functions mixin source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, ''); - // remove `noArgsClass` from `_.clone` and `_.size` + // remove `noArgsClass` from `_.clone`, `_.isEqual`, and `_.size` source = source.replace(/ *\|\| *\(noArgsClass *&[^)]+?\)\)/g, ''); + // remove `noArgsClass` from `_.isEqual` + source = source.replace(/if *\(noArgsClass[^}]+?}\n/, ''); + // remove `noArraySliceOnStrings` from `_.toArray` source = source.replace(/noArraySliceOnStrings *\?[^:]+: *([^)]+)/g, '$1'); diff --git a/build/pre-compile.js b/build/pre-compile.js index 724563a2d2..c35d3b8921 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -218,13 +218,18 @@ // manually convert `arrayLikeClasses` property assignments because // Closure Compiler errors trying to minify them - source = source.replace(/(arrayLikeClasses =)[\s\S]+?= *true/g, "$1{'[object Arguments]': true, '[object Array]': true, '[object String]': true }"); + source = source.replace(/(arrayLikeClasses =)[\s\S]+?= *true/g, + "$1{'[object Arguments]': true, '[object Array]': true, '[object Boolean]': false, " + + "'[object Date]': false, '[object Function]': false, '[object Number]': false, " + + "'[object Object]': false, '[object RegExp]': false, '[object String]': true }" + ); // manually convert `cloneableClasses` property assignments because // Closure Compiler errors trying to minify them source = source.replace(/(cloneableClasses =)[\s\S]+?= *true/g, - "$1{'[object Array]': true, '[object Boolean]': true, '[object Date]': true, " + - "'[object Number]': true, '[object Object]': true, '[object RegExp]': true, '[object String]': true }" + "$1{'[object Arguments]': false, '[object Array]': true, '[object Boolean]': true, " + + "'[object Date]': true, '[object Function]': false, '[object Number]': true, " + + "'[object Object]': true, '[object RegExp]': true, '[object String]': true }" ); // add brackets to whitelisted properties so Closure Compiler won't mung them diff --git a/lodash.js b/lodash.js index a5c684c76a..a7ddd5577e 100644 --- a/lodash.js +++ b/lodash.js @@ -39,7 +39,10 @@ /** Native prototype shortcuts */ var ArrayProto = Array.prototype, - ObjectProto = Object.prototype; + BoolProto = Boolean.prototype, + ObjectProto = Object.prototype, + NumberProto = Number.prototype, + StringProto = String.prototype; /** Used to generate unique IDs */ var idCounter = 0; @@ -141,6 +144,9 @@ */ var noCharByIndex = ('x'[0] + Object('x')[0]) != 'xx'; + /** Detect if a node's [[Class]] is unresolvable (IE < 9) */ + var noNodeClass = toString.call(window.document || {}) == objectClass; + /* Detect if `Function#bind` exists and is inferred to be fast (all but V8) */ var isBindFast = nativeBind && /\n|Opera/.test(nativeBind + toString.call(window.opera)); @@ -161,10 +167,13 @@ /** Used to identify object classifications that are array-like */ var arrayLikeClasses = {}; + arrayLikeClasses[boolClass] = arrayLikeClasses[dateClass] = arrayLikeClasses[funcClass] = + arrayLikeClasses[numberClass] = arrayLikeClasses[objectClass] = arrayLikeClasses[regexpClass] = false; arrayLikeClasses[argsClass] = arrayLikeClasses[arrayClass] = arrayLikeClasses[stringClass] = true; /** Used to identify object classifications that `_.clone` supports */ var cloneableClasses = {}; + cloneableClasses[argsClass] = cloneableClasses[funcClass] = false; cloneableClasses[arrayClass] = cloneableClasses[boolClass] = cloneableClasses[dateClass] = cloneableClasses[numberClass] = cloneableClasses[objectClass] = cloneableClasses[regexpClass] = cloneableClasses[stringClass] = true; @@ -189,7 +198,8 @@ 'object': true, 'number': false, 'string': false, - 'undefined': false + 'undefined': false, + 'unknown': true }; /** Used to escape characters for inclusion in compiled string literals */ @@ -2494,6 +2504,8 @@ * others like `_.map` without using their callback `index` argument for `deep`. * @param {Array} [stack=[]] Internally used to keep track of traversed objects * to avoid circular references. + * @param {Boolean} thorough Internally used to indicate whether or not to perform + * a more thorough clone of non-object values. * @returns {Mixed} Returns the cloned `value`. * @example * @@ -2514,8 +2526,8 @@ * shallow[0] === stooges[0]; * // => false */ - function clone(value, deep, guard, stack) { - if (!value) { + function clone(value, deep, guard, stack, thorough) { + if (value == null) { return value; } var isObj = typeof value == 'object'; @@ -2524,34 +2536,44 @@ if (guard) { deep = false; } + // avoid slower checks on non-objects + if (thorough == null) { + // primitives passed from iframes use the primary document's native prototypes + thorough = !!(BoolProto.clone || NumberProto.clone || StringProto.clone); + } // use custom `clone` method if available - if (value.clone && toString.call(value.clone) == funcClass) { + if ((isObj || thorough) && value.clone && toString.call(value.clone) == funcClass) { return value.clone(deep); } // inspect [[Class]] if (isObj) { - var className = toString.call(value); - // don't clone `arguments` objects, functions, or non-object Objects + var className = toString.call(value); if (!cloneableClasses[className] || (noArgsClass && isArguments(value))) { return value; } - var ctor = value.constructor, - isArr = className == arrayClass, - useCtor = toString.call(ctor) == funcClass; + var useCtor, + ctor = value.constructor, + isArr = className == arrayClass; + + if (className == objectClass) { + // IE < 9 presents DOM nodes as `Object` objects except they have `toString` + // methods that are `typeof` "string" and still can coerce nodes to strings + isObj = !noNodeClass || !(typeof value.toString != 'function' && typeof (value + '') == 'string'); - // IE < 9 presents nodes like `Object` objects: - // IE < 8 are missing the node's constructor property - // IE 8 node constructors are typeof "object" - // check if the constructor is `Object` as `Object instanceof Object` is `true` - if (className == objectClass && - (isObj = useCtor && ctor instanceof ctor)) { - // An object's own properties are iterated before inherited properties. - // If the last iterated key belongs to an object's own property then - // there are no inherited enumerable properties. - forIn(value, function(objValue, objKey) { isObj = objKey; }); - isObj = isObj == true || hasOwnProperty.call(value, isObj); + if (isObj) { + // check that the constructor is `Object` because `Object instanceof Object` is `true` + useCtor = toString.call(ctor) == funcClass; + isObj = !useCtor || ctor instanceof ctor; + } + if (isObj) { + // An object's own properties are iterated before inherited properties. + // If the last iterated key belongs to an object's own property then + // there are no inherited enumerable properties. + forIn(value, function(objValue, objKey) { isObj = objKey; }); + isObj = isObj == true || hasOwnProperty.call(value, isObj); + } } } // shallow clone @@ -2596,11 +2618,11 @@ if (isArr) { var index = -1; while (++index < length) { - result[index] = clone(value[index], deep, null, stack); + result[index] = clone(value[index], deep, null, stack, thorough); } } else { forOwn(value, function(objValue, key) { - result[key] = clone(objValue, deep, null, stack); + result[key] = clone(objValue, deep, null, stack, thorough); }); } return result; @@ -2905,6 +2927,8 @@ * @param {Mixed} b The other value to compare. * @param {Array} [stack=[]] Internally used to keep track of traversed objects * to avoid circular references. + * @param {Boolean} thorough Internally used to indicate whether or not to perform + * a more thorough comparison of non-object values. * @returns {Boolean} Returns `true` if the values are equvalent, else `false`. * @example * @@ -2917,26 +2941,33 @@ * _.isEqual(moe, clone); * // => true */ - function isEqual(a, b, stack) { + function isEqual(a, b, stack, thorough) { stack || (stack = []); // a strict comparison is necessary because `null == undefined` if (a == null || b == null) { return a === b; } - // unwrap any LoDash wrapped values - if (a._chain) { - a = a._wrapped; - } - if (b._chain) { - b = b._wrapped; - } - // use custom `isEqual` method if available - if (a.isEqual && toString.call(a.isEqual) == funcClass) { - return a.isEqual(b); + // avoid slower checks on non-objects + if (thorough == null) { + // primitives passed from iframes use the primary document's native prototypes + thorough = !!(BoolProto.isEqual || NumberProto.isEqual || StringProto.isEqual); } - if (b.isEqual && toString.call(b.isEqual) == funcClass) { - return b.isEqual(a); + if (objectTypes[typeof a] || objectTypes[typeof b] || thorough) { + // unwrap any LoDash wrapped values + if (a._chain) { + a = a._wrapped; + } + if (b._chain) { + b = b._wrapped; + } + // use custom `isEqual` method if available + if (a.isEqual && toString.call(a.isEqual) == funcClass) { + return a.isEqual(b); + } + if (b.isEqual && toString.call(b.isEqual) == funcClass) { + return b.isEqual(a); + } } // exit early for identical values if (a === b) { @@ -2968,10 +2999,18 @@ // treat string primitives and their corresponding object instances as equal return a == b + ''; } - if (typeof a != 'object' || typeof b != 'object') { - // for unequal function values + // exit early, in older browsers, if `a` is array-like but not `b` + var isArr = arrayLikeClasses[className]; + if (noArgsClass && !isArr && (isArr = isArguments(a)) && !isArguments(b)) { return false; } + // exit for functions and DOM nodes + if (!isArr && (className != objectClass || (noNodeClass && ( + (typeof a.toString != 'function' && typeof (a + '') == 'string') || + (typeof b.toString != 'function' && typeof (b + '') == 'string'))))) { + return false; + } + // assume cyclic structures are equal // the algorithm for detecting cyclic structures is adapted from ES 5.1 // section 15.12.3, abstract operation `JO` (http://es5.github.com/#x15.12.3) @@ -2990,7 +3029,7 @@ stack.push(a); // recursively compare objects and arrays (susceptible to call stack limits) - if (arrayLikeClasses[className] || (noArgsClass && isArguments(a))) { + if (isArr) { // compare lengths to determine if a deep comparison is necessary size = a.length; result = size == b.length; @@ -2998,54 +3037,56 @@ if (result) { // deep compare the contents, ignoring non-numeric properties while (size--) { - if (!(result = isEqual(a[size], b[size], stack))) { + if (!(result = isEqual(a[size], b[size], stack, thorough))) { break; } } } + return result; } - else { - // objects with different constructors are not equal - if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) { - return false; - } - // deep compare objects - for (var prop in a) { - if (hasOwnProperty.call(a, prop)) { - // count the number of properties. - size++; - // deep compare each property value. - if (!(result = hasOwnProperty.call(b, prop) && isEqual(a[prop], b[prop], stack))) { - break; - } + + var ctorA = a.constructor, + ctorB = b.constructor; + + // non `Object` object instances with different constructors are not equal + if (ctorA != ctorB && !( + toString.call(ctorA) == funcClass && ctorA instanceof ctorA && + toString.call(ctorB) == funcClass && ctorB instanceof ctorB + )) { + return false; + } + // deep compare objects + for (var prop in a) { + if (hasOwnProperty.call(a, prop)) { + // count the number of properties. + size++; + // deep compare each property value. + if (!(hasOwnProperty.call(b, prop) && isEqual(a[prop], b[prop], stack, thorough))) { + return false; } } - // ensure both objects have the same number of properties - if (result) { - for (prop in b) { - // The JS engine in Adobe products, like InDesign, has a bug that causes - // `!size--` to throw an error so it must be wrapped in parentheses. - // https://github.com/documentcloud/underscore/issues/355 - if (hasOwnProperty.call(b, prop) && !(size--)) { - break; - } - } + } + // ensure both objects have the same number of properties + for (prop in b) { + // The JS engine in Adobe products, like InDesign, has a bug that causes + // `!size--` to throw an error so it must be wrapped in parentheses. + // https://github.com/documentcloud/underscore/issues/355 + if (hasOwnProperty.call(b, prop) && !(size--)) { // `size` will be `-1` if `b` has more properties than `a` - result = !size; + return false; } - // handle JScript [[DontEnum]] bug - if (result && hasDontEnumBug) { - while (++index < 7) { - prop = shadowed[index]; - if (hasOwnProperty.call(a, prop)) { - if (!(result = hasOwnProperty.call(b, prop) && isEqual(a[prop], b[prop], stack))) { - break; - } - } + } + // handle JScript [[DontEnum]] bug + if (hasDontEnumBug) { + while (++index < 7) { + prop = shadowed[index]; + if (hasOwnProperty.call(a, prop) && + !(hasOwnProperty.call(b, prop) && isEqual(a[prop], b[prop], stack, thorough))) { + return false; } } } - return result; + return true; } /** diff --git a/perf/perf.js b/perf/perf.js index 1001d5e317..b30f776e8b 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -132,7 +132,10 @@ // potentially expensive for (index = 0; index < this.count; index++) { - bindAllObjects[index] = belt.clone(lodash); + bindAllObjects[index] = belt.reduce(funcNames, function(object, funcName) { + object[funcName] = lodash[funcName]; + return object; + }, {}); } } @@ -515,6 +518,18 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.clone` with an object') + .add('Lo-Dash', function() { + lodash.clone(object); + }) + .add('Underscore', function() { + _.clone(object); + }) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.countBy` with `callback` iterating an array') .add('Lo-Dash', function() { @@ -1145,16 +1160,6 @@ /*--------------------------------------------------------------------------*/ - suites.push( - Benchmark.Suite('`_.size` with an array') - .add('Lo-Dash', function() { - lodash.size(numbers); - }) - .add('Underscore', function() { - _.size(numbers); - }) - ); - suites.push( Benchmark.Suite('`_.size` with an object') .add('Lo-Dash', function() { diff --git a/test/test.js b/test/test.js index 249156dff7..5e78a26554 100644 --- a/test/test.js +++ b/test/test.js @@ -710,9 +710,35 @@ equal(_.isEqual(object, object), false); }); + test('should use custom `isEqual` method on primitives', function() { + Boolean.prototype.isEqual = function() { return true; }; + equal(_.isEqual(true, false), true); + delete Boolean.prototype.isEqual; + }); + test('fixes the JScript [[DontEnum]] bug (test in IE < 9)', function() { equal(_.isEqual(shadowed, {}), false); }); + + test('should return `true` for like-objects from different documents', function() { + if (window.document) { + var body = document.body, + iframe = document.createElement('iframe'), + object = { 'a': 1, 'b': 2, 'c': 3 }; + + body.appendChild(iframe); + var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc; + idoc.write(" - + diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js new file mode 100644 index 0000000000..f2ca264bae --- /dev/null +++ b/vendor/underscore/underscore-min.js @@ -0,0 +1,32 @@ +// Underscore.js 1.3.3 +// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. +// Underscore is freely distributable under the MIT license. +// Portions of Underscore are inspired or borrowed from Prototype, +// Oliver Steele's Functional, and John Resig's Micro-Templating. +// For all details and documentation: +// http://documentcloud.github.com/underscore +(function(){var s=this,L=s._,p={},k=Array.prototype,q=Object.prototype,M=k.push,i=k.slice,N=k.unshift,m=q.toString,O=q.hasOwnProperty,z=k.forEach,A=k.map,B=k.reduce,C=k.reduceRight,D=k.filter,E=k.every,F=k.some,r=k.indexOf,G=k.lastIndexOf,q=Array.isArray,P=Object.keys,t=Function.prototype.bind,b=function(a){return new l(a)};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._=b):s._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c, +d){if(a!=null)if(z&&a.forEach===z)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a==null&&(a=[]);if(B&&a.reduce===B){e&&(c=b.bind(c,e));return f?a.reduce(c, +d):a.reduce(c)}j(a,function(a,b,i){if(f)d=c.call(e,d,a,b,i);else{d=a;f=true}});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(C&&a.reduceRight===C){e&&(c=b.bind(c,e));return f?a.reduceRight(c,d):a.reduceRight(c)}var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect=function(a,c,b){var e;H(a,function(a,g,h){if(c.call(b,a,g,h)){e= +a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(D&&a.filter===D)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(E&&a.every===E)return a.every(c,b);j(a,function(a,g,h){if(!(e=e&&c.call(b,a,g,h)))return p});return!!e};var H=b.some=b.any= +function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(F&&a.some===F)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return p});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(r&&a.indexOf===r)return a.indexOf(c)!=-1;return b=H(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a,d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})}; +b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};var I=function(a,c){return b.isFunction(c)?c:function(a){return a[c]}},J=function(a,c,b){var e={},f=I(a,c);j(a,function(a,c){var i=f(a,c);b(e, +i,a)});return e};b.groupBy=function(a,c){return J(a,c,function(a,c,b){(a[c]||(a[c]=[])).push(b)})};b.countBy=function(a,c){return J(a,c,function(a,c){a[c]||(a[c]=0);a[c]++})};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var c=d(c),e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=n(i.call(arguments, +1),true,[]);return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=P||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a, +d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var b={};j(n(i.call(arguments,1),true,[]),function(d){d in a&&(b[d]=a[d])});return b};b.defaults=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)? +a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=m.call(a);if(e!=m.call(c))return false;switch(e){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a== ++c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){f=a.length;if(g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&u(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)){f++;if(!(g=b.has(c,h)&& +u(a[h],c[h],d)))break}if(g){for(h in c)if(b.has(c,h)&&!f--)break;g=!f}}d.pop();return g};b.isEqual=function(a,b){return u(a,b,[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=q||function(a){return m.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+ +a]=function(b){return m.call(b)=="[object "+a+"]"}});b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||m.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return O.call(a,b)};b.noConflict=function(){s._=L;return this};b.identity=function(a){return a}; +b.times=function(a,b,d){for(var e=0;e":">",'"':""","'":"'","/":"/"},R=/[&<>"'\/]/g;b.escape=function(a){return(""+a).replace(R,function(a){return Q[a]})};b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){S(c,b[c]=a[c])})};var T=0;b.uniqueId=function(a){var b=T++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g, +escape:/<%-([\s\S]+?)%>/g};var v=/.^/,o={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},w;for(w in o)o[o[w]]=w;var U=/\\|'|\r|\n|\t|\u2028|\u2029/g,V=/\\(\\|'|r|n|t|u2028|u2029)/g,x=function(a){return a.replace(V,function(a,b){return o[b]})};b.template=function(a,c,d){d=b.defaults(d||{},b.templateSettings);a="__p+='"+a.replace(U,function(a){return"\\"+o[a]}).replace(d.escape||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':_.escape(__t))+\n'"}).replace(d.interpolate|| +v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':__t)+\n'"}).replace(d.evaluate||v,function(a,b){return"';\n"+x(b)+"\n__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");var a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'')};\n"+a+"return __p;\n",e=new Function(d.variable||"obj","_",a);if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c};b.chain=function(a){return b(a).chain()}; +var l=function(a){this._wrapped=a};b.prototype=l.prototype;var y=function(a,c){return c?b(a).chain():a},S=function(a,c){l.prototype[a]=function(){var a=i.call(arguments);N.call(a,this._wrapped);return y(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];l.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return y(d,this._chain)}});j(["concat","join","slice"],function(a){var b= +k[a];l.prototype[a]=function(){return y(b.apply(this._wrapped,arguments),this._chain)}});l.prototype.chain=function(){this._chain=true;return this};l.prototype.value=function(){return this._wrapped}}).call(this); From 83d08e3aba7b44141c8dea009bcb28ddb5c35a7d Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 16 Aug 2012 22:22:08 -0700 Subject: [PATCH 66/77] Avoid false positives for `arguments` objects in IE < 9 when using `isPlainObject`. Former-commit-id: 19e5a6efed32f26d0c908771eec40e7fb2ecf265 --- lodash.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 5f2327b438..956985fe75 100644 --- a/lodash.js +++ b/lodash.js @@ -744,8 +744,9 @@ * @returns {Boolean} Returns `true` if the `value` is a plain `Object` object, else `false`. */ function isPlainObject(value) { + // avoid non-objects and false positives for `arguments` objects in IE < 9 var result = false; - if (!(value && typeof value == 'object')) { + if (!(value && typeof value == 'object') || (noArgumentsClass && isArguments(value))) { return result; } // IE < 9 presents DOM nodes as `Object` objects except they have `toString` From fab2d69fce5c5d7c99d5a8b69e59af5e4661a062 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 16 Aug 2012 23:24:59 -0700 Subject: [PATCH 67/77] Ensure `_.sortBy` performs a stable sort. [closes #59] Former-commit-id: 09c5ff85ef0f1d054579ec4260a7f76d9c0da281 --- build/pre-compile.js | 3 ++- lodash.js | 17 ++++++++++++----- test/test.js | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/build/pre-compile.js b/build/pre-compile.js index b1646a5ad1..069f770d22 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -151,6 +151,7 @@ 'head', 'identity', 'include', + 'index', 'indexOf', 'initial', 'inject', @@ -304,7 +305,7 @@ // minify internal properties used by 'compareAscending', `_.clone`, `_.merge`, and `_.sortBy` (function() { - var properties = ['criteria', 'source', 'value'], + var properties = ['criteria', 'index', 'source', 'value'], snippets = source.match(/( +)(?:function clone|function compareAscending|var merge|var sortBy)\b[\s\S]+?\n\1}/g); if (!snippets) { diff --git a/lodash.js b/lodash.js index 956985fe75..e3be19c513 100644 --- a/lodash.js +++ b/lodash.js @@ -678,15 +678,18 @@ } /** - * Used by `sortBy` to compare transformed values of `collection`, sorting - * them in ascending order. + * Used by `sortBy` to compare transformed `collection` values, sorting them + * stabily in ascending order. * * @private * @param {Object} a The object to compare to `b`. * @param {Object} b The object to compare to `a`. - * @returns {Number} Returns `-1` if `a` < `b`, `0` if `a` == `b`, or `1` if `a` > `b`. + * @returns {Number} Returns the sort order indicator of `1` or `-1`. */ function compareAscending(a, b) { + var ai = a.index, + bi = b.index; + a = a.criteria; b = b.criteria; @@ -696,7 +699,9 @@ if (b === undefined) { return -1; } - return a < b ? -1 : a > b ? 1 : 0; + // ensure a stable sort in V8 and other engines + // http://code.google.com/p/v8/issues/detail?id=90 + return a < b ? -1 : a > b ? 1 : ai < bi ? -1 : 1; } /** @@ -746,7 +751,7 @@ function isPlainObject(value) { // avoid non-objects and false positives for `arguments` objects in IE < 9 var result = false; - if (!(value && typeof value == 'object') || (noArgumentsClass && isArguments(value))) { + if (!(value && typeof value == 'object') || (noArgsClass && isArguments(value))) { return result; } // IE < 9 presents DOM nodes as `Object` objects except they have `toString` @@ -2272,11 +2277,13 @@ 'array': 'result[index] = {\n' + ' criteria: callback(value, index, collection),\n' + + ' index: index,\n' + ' value: value\n' + '}', 'object': 'result' + (isKeysFast ? '[ownIndex] = ' : '.push') + '({\n' + ' criteria: callback(value, index, collection),\n' + + ' index: index,\n' + ' value: value\n' + '})' }, diff --git a/test/test.js b/test/test.js index c3804c36ad..4c33bbdaea 100644 --- a/test/test.js +++ b/test/test.js @@ -1112,6 +1112,28 @@ QUnit.module('lodash.sortBy'); (function() { + test('should perform a stable sort', function() { + function Pair(x, y) { + this.x = x; + this.y = y; + } + + var collection = [ + new Pair(1, 1), new Pair(1, 2), + new Pair(1, 3), new Pair(1, 4), + new Pair(1, 5), new Pair(1, 6), + new Pair(2, 1), new Pair(2, 2), + new Pair(2, 3), new Pair(2, 4), + new Pair(2, 5), new Pair(2, 6) + ]; + + var actual = _.sortBy(collection, function(pair) { + return pair.x; + }); + + deepEqual(actual, collection); + }); + test('supports the `thisArg` argument', function() { var actual = _.sortBy([1, 2, 3], function(num) { return this.sin(num); From fd80e096ea50bc296bff42c11fb6cdc361c034e9 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 17 Aug 2012 00:10:03 -0700 Subject: [PATCH 68/77] Remove `noArgsClass` check from `isPlainObject`. Former-commit-id: bab7a68e8eaa21679b33b2ab70a9f8e47758ebc1 --- lodash.js | 4 ++-- test/test.js | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index e3be19c513..3bc9184cb5 100644 --- a/lodash.js +++ b/lodash.js @@ -749,9 +749,9 @@ * @returns {Boolean} Returns `true` if the `value` is a plain `Object` object, else `false`. */ function isPlainObject(value) { - // avoid non-objects and false positives for `arguments` objects in IE < 9 + // avoid non-objects and false positives for `arguments` objects var result = false; - if (!(value && typeof value == 'object') || (noArgsClass && isArguments(value))) { + if (!(value && typeof value == 'object') || isArguments(value)) { return result; } // IE < 9 presents DOM nodes as `Object` objects except they have `toString` diff --git a/test/test.js b/test/test.js index 4c33bbdaea..c47a34237c 100644 --- a/test/test.js +++ b/test/test.js @@ -859,6 +859,8 @@ QUnit.module('lodash.merge'); (function() { + var args = arguments; + test('should merge `source` into the destination object', function() { var stooges = [ { 'name': 'moe' }, @@ -918,7 +920,20 @@ deepEqual(_.merge(object, source), [shadowed]); }); - }()); + + test('should not treat `arguments` objects as plain objects', function() { + var object = { + 'args': args + }; + + var source = { + 'args': { '3': 4 } + }; + + var actual = _.merge(object, source); + equal(_.isArguments(actual.args), false); + }); + }(1, 2, 3)); /*--------------------------------------------------------------------------*/ @@ -1112,7 +1127,7 @@ QUnit.module('lodash.sortBy'); (function() { - test('should perform a stable sort', function() { + test('should perform a stable sort (test in IE > 8, Opera, and V8)', function() { function Pair(x, y) { this.x = x; this.y = y; From 2ddc3af5ffc9addd6faa451515b39d4f28cde54e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 17 Aug 2012 00:25:52 -0700 Subject: [PATCH 69/77] Fix jQuery/MooTools DOM collection unit tests in IE6. Former-commit-id: b9c3dbcffb28b0088018614e21fbe313b0d53713 --- test/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test.js b/test/test.js index c47a34237c..d5b03c7638 100644 --- a/test/test.js +++ b/test/test.js @@ -715,7 +715,7 @@ test('should work with jQuery/MooTools DOM query collections', function() { function Foo(elements) { Array.prototype.push.apply(this, elements); } - Foo.prototype = { 'splice': Array.prototype.splice }; + Foo.prototype = { 'length': 0, 'splice': Array.prototype.splice }; equal(_.isEmpty(new Foo([])), true); }); @@ -1108,7 +1108,7 @@ test('should work with jQuery/MooTools DOM query collections', function() { function Foo(elements) { Array.prototype.push.apply(this, elements); } - Foo.prototype = { 'splice': Array.prototype.splice }; + Foo.prototype = { 'length': 0, 'splice': Array.prototype.splice }; equal(_.size(new Foo([1, 2, 3])), 3); }); From 9fa0aebfe948573e2912b4e16e46e87837928407 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 17 Aug 2012 02:10:50 -0700 Subject: [PATCH 70/77] Add check for V8 bug #2291. Former-commit-id: 245f156a2ce1ee92c8f8f8f34b9891ba4eff0d23 --- test/test.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/test.js b/test/test.js index d5b03c7638..372895ae66 100644 --- a/test/test.js +++ b/test/test.js @@ -779,6 +779,26 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.isObject'); + + (function() { + test('should avoid V8 bug #2291', function() { + // trigger V8 bug + // http://code.google.com/p/v8/issues/detail?id=2291 + var obj = {}, + str = 'foo'; + + // 1: Useless comparison statement, this is half the trigger + obj == obj; + // 2: Initial check with object, this is the other half of the trigger + _.isObject(obj); + + equal(_.isObject(str), false); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.isNaN'); (function() { From 2d896f22d6d319d6c436868e853ded9c9be59b1c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 17 Aug 2012 02:28:42 -0700 Subject: [PATCH 71/77] Bump to v0.5.0. Former-commit-id: f30f4b99104c94fb52df4c90dcda24b8ac51432c --- README.md | 88 +++++++------ doc/README.md | 214 ++++++++++++++++--------------- doc/parse.php | 2 +- lodash.js | 6 +- lodash.min.js | 74 +++++------ package.json | 6 +- vendor/benchmark.js/benchmark.js | 2 +- 7 files changed, 203 insertions(+), 189 deletions(-) diff --git a/README.md b/README.md index 015e0ae181..d864f6cee7 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ -# Lo-Dash v0.5.0-rc.1 +# Lo-Dash v0.5.0 -A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) for Underscore.js, from the devs behind [jsPerf.com](http://jsperf.com), that delivers [performance improvements](http://lodash.com/benchmarks), [bug fixes](https://github.com/bestiejs/lodash#closed-underscorejs-issues), and [additional features](https://github.com/bestiejs/lodash#features). +A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) 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#closed-underscorejs-issues), and [additional features](https://github.com/bestiejs/lodash#features). 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. ## Download - * [Development source](https://raw.github.com/bestiejs/lodash/v0.5.0-rc.1/lodash.js) - * [Production source](https://raw.github.com/bestiejs/lodash/v0.5.0-rc.1/lodash.min.js) + * [Development source](https://raw.github.com/bestiejs/lodash/v0.5.0/lodash.js) + * [Production source](https://raw.github.com/bestiejs/lodash/v0.5.0/lodash.min.js) * CDN copies of ≤ [v0.4.2](http://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.4.2/lodash.min.js) are available on [cdnjs](http://cdnjs.com/) thanks to [CloudFlare](http://www.cloudflare.com/) * For optimal performance, [create a custom build](https://github.com/bestiejs/lodash#custom-builds) with only the features you need @@ -32,26 +32,26 @@ For more information check out these screencasts over Lo-Dash: * AMD loader support ([RequireJS](http://requirejs.org/), [curl.js](https://github.com/cujojs/curl), etc.) * [_.bind](http://lodash.com/docs#bind) supports *"lazy"* binding - * [_.clone](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_clonevalue-deep--guard-thorough) supports *"deep"* cloning - * [_.countBy](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_countbycollection-callback--thisarg) as a compainion function for [_.groupBy](http://lodash.com/docs#groupBy) and [_.sortBy](http://lodash.com/docs#sortBy) + * [_.clone](http://lodash.com/docs#clone) supports *"deep"* cloning + * [_.countBy](http://lodash.com/docs#countBy) as a compainion function for [_.groupBy](http://lodash.com/docs#groupBy) and [_.sortBy](http://lodash.com/docs#sortBy) * [_.debounce](http://lodash.com/docs#debounce)’ed functions match [_.throttle](http://lodash.com/docs#throttle)’ed functions’ return value behavior - * [_.drop](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_dropobject--prop1-prop2-) for the inverse functionality of [_.pick](http://lodash.com/docs#pick) + * [_.drop](http://lodash.com/docs#drop) for the inverse functionality of [_.pick](http://lodash.com/docs#pick) * [_.forEach](http://lodash.com/docs#forEach) is chainable and supports exiting iteration early * [_.forIn](http://lodash.com/docs#forIn) for iterating over an object’s own and inherited properties * [_.forOwn](http://lodash.com/docs#forOwn) for iterating over an object’s own properties * [_.groupBy](http://lodash.com/docs#groupBy), [_.sortedIndex](http://lodash.com/docs#sortedIndex), and [_.uniq](http://lodash.com/docs#uniq) accept a `thisArg` argument * [_.indexOf](http://lodash.com/docs#indexOf) and [_.lastIndexOf](http://lodash.com/docs#lastIndexOf) accept a `fromIndex` argument - * [_.merge](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_mergeobject--source1-source2--indicator) for a *"deep"* [_.extend](http://lodash.com/docs#extend) + * [_.merge](http://lodash.com/docs#merge) for a *"deep"* [_.extend](http://lodash.com/docs#extend) * [_.partial](http://lodash.com/docs#partial) for partial application without `this` binding * [_.template](http://lodash.com/docs#template) utilizes [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) for easier debugging - * [_.where](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_wherecollection-properties) for filtering collections by contained properties + * [_.where](http://lodash.com/docs#where) for filtering collections by contained properties * [_.zipObject](http://lodash.com/docs#zipObject) for composing objects * [_.contains](http://lodash.com/docs#contains), [_.size](http://lodash.com/docs#size), [_.toArray](http://lodash.com/docs#toArray), [and more…](http://lodash.com/docs "_.every, _.filter, _.find, _.forEach, _.groupBy, _.invoke, _.map, _.pluck, _.reduce, _.reduceRight, _.reject, _.some, _sortBy") accept strings ## Support -Lo-Dash has been tested in at least Chrome 5-21, Firefox 1.5-13, IE 6-9, Opera 9.25-12.01, Safari 3.0.4-6, Node.js 0.4.8-0.8.5, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC3. +Lo-Dash has been tested in at least Chrome 5-21, Firefox 1.5-13, IE 6-9, Opera 9.25-12.01, Safari 3-6, Node.js 0.4.8-0.8.6, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC3. ## Custom builds @@ -166,36 +166,39 @@ require({ }); ~~~ -## Closed Underscore.js issues (20+) +## Resolved Underscore.js issues (20+) - * 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.5.0-rc.1/test/test.js#L540-546)] - * Ensure array-like objects with invalid `length` properties are treated like regular objects [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L491-497)] - * Ensure *"Arrays"* methods allow falsey `array` arguments [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1412-1450)] - * 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.5.0-rc.1/test/test.js#L499-517)] - * Ensure templates compiled with errors are inspectable [[#666](https://github.com/documentcloud/underscore/issues/666), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1157-1160)] - * 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.5.0-rc.1/test/test.js#L551-576)] + * 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.5.0/test/test.js#L544-550)] + * Ensure array-like objects with invalid `length` properties are treated like regular objects [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L491-501)] + * Ensure *"Arrays"* methods allow falsey `array` arguments [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1487-1525)] + * 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.5.0/test/test.js#L503-521)] + * Ensure templates compiled with errors are inspectable [[#666](https://github.com/documentcloud/underscore/issues/666), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1232-1235)] + * 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.5.0/test/test.js#L555-580)] * Handle arrays with `undefined` values correctly in IE < 9 [[#601](https://github.com/documentcloud/underscore/issues/601)] - * Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L117-123)] - * 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.5.0-rc.1/test/test.js#L101-115)] - * `_(…)` should return passed wrapper instances [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L135-138)] - * `_.clone` should allow `deep` cloning [[#595](https://github.com/documentcloud/underscore/pull/595), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L197-212)] - * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L267-276)] - * `_.escape` should return an empty string when passed `null` or `undefined` [[#407](https://github.com/documentcloud/underscore/issues/427), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L367-370)] - * `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L851-873)] - * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L486-489)] - * `_.forEach` should exit iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L578-597)] - * `_.groupBy` should add values to own, not inherited, properties [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L612-619)] - * `_.isEqual` should return `true` for like-objects from different documents [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L746-766)] - * `_.isNaN(new Number(NaN))` should return `true` [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L774-776)] - * `_.keys` and `_.size` should work with `arguments` objects cross-browser [[#396](https://github.com/documentcloud/underscore/issues/396), [#653](https://github.com/documentcloud/underscore/issues/653), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L786-788), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1083-1085)] - * `_.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.5.0-rc.1/test/test.js#L996-999)] - * `_.reduceRight` should pass correct callback arguments when iterating objects [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1007-1021)] - * `_.size` should return the `length` of string values [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1066-1068)] - * `_.size` shouldn’t error on falsey values [[#650](https://github.com/documentcloud/underscore/pull/650), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1070-1077)] - * `_.sortedIndex` should support arrays with high `length` values [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1127-1136)] - * `_.template` should not augment the `options` object [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1151-1155)] - * `_.throttle` should work when called in a loop [[#502](https://github.com/documentcloud/underscore/issues/502), [test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1247-1257)] - * `_.zipObject` should accept less than two arguments [[test](https://github.com/bestiejs/lodash/blob/v0.5.0-rc.1/test/test.js#L1374-1376)] + * Methods should work on pages with incorrectly shimmed native methods [[#7](https://github.com/documentcloud/underscore/issues/7), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L117-123)] + * 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.5.0/test/test.js#L101-115)] + * `_(…)` should return passed wrapper instances [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L135-138)] + * `_.clone` should allow `deep` cloning [[#595](https://github.com/documentcloud/underscore/pull/595), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L197-212)] + * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L267-276)] + * `_.escape` should return an empty string when passed `null` or `undefined` [[#407](https://github.com/documentcloud/underscore/issues/427), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L367-370)] + * `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L862-920)] + * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L486-489)] + * `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L582-601)] + * `_.groupBy` should add values to own, not inherited, properties [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L616-623)] + * `_.isEmpty` and `_.size` should support jQuery/MooTools DOM query collections [[#690](https://github.com/documentcloud/underscore/pull/690), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L716-721)] + * `_.isEqual` should return `true` for like-objects from different documents [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L757-777)] + * `_.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.5.0/test/test.js#L785-797)] + * `_.isNaN(new Number(NaN))` should return `true` [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L805-807)] + * `_.keys` and `_.size` should work with `arguments` objects cross-browser [[#396](https://github.com/documentcloud/underscore/issues/396), [#653](https://github.com/documentcloud/underscore/issues/653), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L817-819)] + * `_.once` should free the given function for garbage collection [[#693](https://github.com/documentcloud/underscore/pull/693)] + * `_.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.5.0/test/test.js#L1042-1045)] + * `_.reduceRight` should pass correct callback arguments when iterating objects [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1053-1067)] + * `_.size` should return the `length` of string values [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1112-1114)] + * `_.size` shouldn’t error on falsey values [[#650](https://github.com/documentcloud/underscore/pull/650), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1116-1123)] + * `_.sortedIndex` should support arrays with high `length` values [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1202-1211)] + * `_.template` should not augment the `options` object [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1226-1230)] + * `_.throttle` should work when called in a loop [[#502](https://github.com/documentcloud/underscore/issues/502), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1322-1332)] + * `_.zipObject` should accept less than two arguments [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L1449-1451)] ## Optimized methods (50+) @@ -259,19 +262,24 @@ require({ ## Release Notes -### v0.5.0-rc.1 +### v0.5.0 - * Added [_.countBy](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_countbycollection-callback--thisarg), [_.drop](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_dropobject--prop1-prop2-), [_.merge](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_mergeobject--source1-source2--indicator), and [_.where](https://github.com/bestiejs/lodash/tree/v0.5.0-rc.1/doc#_wherecollection-properties) + * Added [_.countBy](http://lodash.com/docs#countBy), [_.drop](http://lodash.com/docs#drop), [_.merge](http://lodash.com/docs#merge), and [_.where](http://lodash.com/docs#where) * Added `csp` *(Content Security Policy)* and `underscore` build options * Added `deep` cloning support to `_.clone` + * Added [Jam](http://jamjs.org/) package support * Added support for exiting `_.forEach`, `_.forIn`, and `_.forOwn` early by returning `false` in the `callback` + * Added support for jQuery/MooTools DOM query collections to `_.isEmpty` and `_.size` * Ensured development build works with IE conditional compilation enabled * Ensured `_.clone` doesn't clone functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` * Ensured `_.filter`’s `callback` can't modify result values * Ensured `_.isEmpty`, `_.isEquals`, and `_.size` support `arguments` objects * Ensured `_.isEqual` doesn't inspect DOM nodes, works with objects from other documents, and calls custom `isEqual` methods before checking strict equality + * Ensured `_.once` frees the given function for garbage collection + * Ensured `_.sortBy` performs a stable sort * Ensured `reEvaluateDelimiter` is assigned when `_.templateSettings.evaluate` is undefined * Made `_.range` coerce arguments to numbers + * Optimized `_.isFunction` The full changelog is available [here](https://github.com/bestiejs/lodash/wiki/Changelog). diff --git a/doc/README.md b/doc/README.md index 162bac9d8c..649f5aed7a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,18 +1,18 @@ -# Lo-Dash v0.5.0-rc.1 +# Lo-Dash v0.5.0 -## `_` +## `_` * [`_`](#_value) * [`_.VERSION`](#_version) * [`_.after`](#_aftern-func) * [`_.bind`](#_bindfunc--thisarg-arg1-arg2-) * [`_.bindAll`](#_bindallobject--methodname1-methodname2-) * [`_.chain`](#_chainvalue) -* [`_.clone`](#_clonevalue-deep--guard-thorough) +* [`_.clone`](#_clonevalue-deep--guard-stack-thorough) * [`_.compact`](#_compactarray) * [`_.compose`](#_composefunc1-func2-) * [`_.contains`](#_containscollection-target) @@ -47,7 +47,7 @@ * [`_.isDate`](#_isdatevalue) * [`_.isElement`](#_iselementvalue) * [`_.isEmpty`](#_isemptyvalue) -* [`_.isEqual`](#_isequala-b-thorough) +* [`_.isEqual`](#_isequala-b--stack-thorough) * [`_.isFinite`](#_isfinitevalue) * [`_.isFunction`](#_isfunctionvalue) * [`_.isNaN`](#_isnanvalue) @@ -63,7 +63,7 @@ * [`_.map`](#_mapcollection--callbackidentity-thisarg) * [`_.max`](#_maxarray--callback-thisarg) * [`_.memoize`](#_memoizefunc--resolver) -* [`_.merge`](#_mergeobject--source1-source2--indicator) +* [`_.merge`](#_mergeobject--source1-source2--indicator-stack) * [`_.min`](#_minarray--callback-thisarg) * [`_.mixin`](#_mixinobject) * [`_.noConflict`](#_noconflict) @@ -95,7 +95,7 @@ * [`_.without`](#_withoutarray--value1-value2-) * [`_.wrap`](#_wrapvalue-wrapper) * [`_.zip`](#_ziparray1-array2-) -* [`_.zipObject`](#_zipobjectkeys) +* [`_.zipObject`](#_zipobjectkeys--values) @@ -152,7 +152,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4003 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4043 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -164,7 +164,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3107 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3142 "View in source") [Ⓣ][1] Creates a new function that is restricted to executing only after it is called `n` times. @@ -192,7 +192,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3161 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3196 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. Lazy defined methods may be bound by passing the object they are bound to as `func` and the method name as `thisArg`. @@ -243,7 +243,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3231 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3266 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -274,7 +274,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3928 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3968 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -307,8 +307,8 @@ var youngest = _.chain(stooges) -### `_.clone(value, deep [, guard], thorough)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L897 "View in source") [Ⓣ][1] +### `_.clone(value, deep [, guard, stack=[]], thorough)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L991 "View in source") [Ⓣ][1] Creates a clone of `value`. If `deep` is `true`, all nested objects will also be cloned otherwise they will be assigned by reference. If a value has a `clone` method it will be used to perform the clone. Functions, DOM nodes, `arguments` objects, and objects created by constructors other than `Object` are **not** cloned unless they have a custom `clone` method. @@ -316,7 +316,8 @@ Creates a clone of `value`. If `deep` is `true`, all nested objects will also be 1. `value` *(Mixed)*: The value to clone. 2. `deep` *(Boolean)*: A flag to indicate a deep clone. 3. `[guard]` *(Object)*: Internally used to allow this method to work with others like `_.map` without using their callback `index` argument for `deep`. -4. `thorough` *(Object)*: Internally used to indicate whether or not to perform a more thorough clone of non-object values. +4. `[stack=[]]` *(Array)*: Internally used to keep track of traversed objects to avoid circular references. +5. `thorough` *(Object)*: Internally used to indicate whether or not to perform a more thorough clone of non-object values. #### Returns *(Mixed)*: Returns the cloned `value`. @@ -349,7 +350,7 @@ shallow[0] === stooges[0]; ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2348 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2381 "View in source") [Ⓣ][1] Creates a new array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -373,7 +374,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3267 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3304 "View in source") [Ⓣ][1] Creates a new function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -400,7 +401,7 @@ welcome('moe'); ### `_.contains(collection, target)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1777 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1808 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. @@ -431,7 +432,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1813 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1844 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -463,7 +464,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3300 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3337 "View in source") [Ⓣ][1] Creates a new function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -489,7 +490,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, default1, default2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L998 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1092 "View in source") [Ⓣ][1] Assigns enumerable properties of the default object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -515,7 +516,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3365 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3402 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -540,7 +541,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3345 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3382 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -567,7 +568,7 @@ _.delay(log, 1000, 'logged later'); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2380 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2413 "View in source") [Ⓣ][1] Creates a new array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -592,7 +593,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.drop(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1018 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1112 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -617,7 +618,7 @@ _.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3559 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3599 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -641,7 +642,7 @@ _.escape('Moe, Larry & Curly'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1833 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1864 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -667,7 +668,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1042 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1136 "View in source") [Ⓣ][1] Assigns enumerable properties of the source object(s) to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -692,7 +693,7 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1853 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1884 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -718,7 +719,7 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1874 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1905 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -744,7 +745,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.first(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2417 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2450 "View in source") [Ⓣ][1] Gets the first element of the `array`. Pass `n` to return the first `n` elements of the `array`. @@ -770,7 +771,7 @@ _.first([5, 4, 3, 2, 1]); ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2441 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2474 "View in source") [Ⓣ][1] Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level. @@ -798,7 +799,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1901 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1932 "View in source") [Ⓣ][1] Iterates over a `collection`, executing the `callback` for each element in the `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -827,7 +828,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1072 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1166 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -863,7 +864,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1096 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1190 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -891,7 +892,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1113 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1207 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -915,7 +916,7 @@ _.functions(_); ### `_.groupBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1929 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1960 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -947,7 +948,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1136 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1230 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -972,7 +973,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3579 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -997,7 +998,7 @@ moe === _.identity(moe); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2485 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2518 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster binary search. @@ -1029,7 +1030,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2525 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2558 "View in source") [Ⓣ][1] Gets all but the last element of `array`. Pass `n` to exclude the last `n` elements from the result. @@ -1055,9 +1056,9 @@ _.initial([3, 2, 1]); ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2546 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2580 "View in source") [Ⓣ][1] -Computes the intersection of all the passed-in arrays. +Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. #### Arguments 1. `[array1, array2, ...]` *(Array)*: Arrays to process. @@ -1079,7 +1080,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1957 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1988 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`. Additional arguments will be passed to each invoked method. If `methodName` is a function it will be invoked for, and `this` bound to, each element in the `collection`. @@ -1108,7 +1109,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1156 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L883 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1135,7 +1136,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1182 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L909 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1162,7 +1163,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1199 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1247 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1186,7 +1187,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1216 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1264 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1210,7 +1211,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1233 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1281 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1234,7 +1235,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1258 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1306 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1263,15 +1264,16 @@ _.isEmpty(''); -### `_.isEqual(a, b, thorough)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1296 "View in source") [Ⓣ][1] +### `_.isEqual(a, b [, stack=[]], thorough)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1348 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. If a value has an `isEqual` method it will be used to perform the comparison. #### Arguments 1. `a` *(Mixed)*: The value to compare. 2. `b` *(Mixed)*: The other value to compare. -3. `thorough` *(Object)*: Internally used to indicate whether or not to perform a more thorough comparison of non-object values. +3. `[stack=[]]` *(Array)*: Internally used to keep track of traversed objects to avoid circular references. +4. `thorough` *(Object)*: Internally used to indicate whether or not to perform a more thorough comparison of non-object values. #### Returns *(Boolean)*: Returns `true` if the values are equvalent, else `false`. @@ -1296,7 +1298,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1469 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1521 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1326,7 +1328,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1486 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L926 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1350,7 +1352,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1539 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1576 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1383,7 +1385,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1562 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1599 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1410,7 +1412,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1579 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1616 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1434,7 +1436,7 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1507 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1542 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -1461,7 +1463,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1596 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1633 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1485,7 +1487,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1613 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1650 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1509,7 +1511,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1631 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1668 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1533,7 +1535,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1663 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1685 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property names of `object`. @@ -1557,7 +1559,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.last(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2587 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2621 "View in source") [Ⓣ][1] Gets the last element of the `array`. Pass `n` to return the lasy `n` elementsvof the `array`. @@ -1583,7 +1585,7 @@ _.last([3, 2, 1]); ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2613 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2647 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1612,7 +1614,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1993 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2023 "View in source") [Ⓣ][1] Creates a new array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -1641,7 +1643,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2653 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2687 "View in source") [Ⓣ][1] Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1673,7 +1675,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3388 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3425 "View in source") [Ⓣ][1] Creates a new function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1698,8 +1700,8 @@ var fibonacci = _.memoize(function(n) { -### `_.merge(object [, source1, source2, ..., indicator])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2025 "View in source") [Ⓣ][1] +### `_.merge(object [, source1, source2, ..., indicator, stack=[]])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2055 "View in source") [Ⓣ][1] Merges enumerable properties of the source object(s) into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -1707,6 +1709,7 @@ Merges enumerable properties of the source object(s) into the `destination` obje 1. `object` *(Object)*: The destination object. 2. `[source1, source2, ...]` *(Object)*: The source objects. 3. `[indicator]` *(Object)*: Internally used to indicate that the `stack` argument is an array of traversed objects instead of another source object. +4. `[stack=[]]` *(Array)*: Internally used to keep track of traversed objects to avoid circular references. #### Returns *(Object)*: Returns the destination object. @@ -1735,7 +1738,7 @@ _.merge(stooges, ages); ### `_.min(array [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2703 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2737 "View in source") [Ⓣ][1] Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -1761,7 +1764,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3605 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3645 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1791,7 +1794,7 @@ _('curly').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3636 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3676 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1811,7 +1814,7 @@ var lodash = _.noConflict(); ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3414 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3451 "View in source") [Ⓣ][1] Creates a new function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1837,7 +1840,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3446 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3486 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar `bind`, except it does **not** alter the `this` binding. @@ -1864,7 +1867,7 @@ hi('moe'); ### `_.pick(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1686 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1708 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -1889,7 +1892,7 @@ _.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2073 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2103 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -1920,7 +1923,7 @@ _.pluck(stooges, 'name'); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2764 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2798 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `stop`. This method is a port of Python's `range()` function. See http://docs.python.org/library/functions.html#range. @@ -1958,7 +1961,7 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2101 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2131 "View in source") [Ⓣ][1] Boils down a `collection` to a single value. The initial state of the reduction is `accumulator` and each successive step of it should be returned by the `callback`. The `callback` is bound to `thisArg` and invoked with `4` arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -1985,7 +1988,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2138 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2168 "View in source") [Ⓣ][1] The right-associative version of `_.reduce`. @@ -2013,7 +2016,7 @@ var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); ### `_.reject(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2193 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2224 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the values of a `collection` that `callback` does **not** return truthy for. @@ -2039,7 +2042,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.rest(array [, n, guard])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2803 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2837 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. Pass `n` to exclude the first `n` values from the result. @@ -2065,7 +2068,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3668 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3708 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2100,7 +2103,7 @@ _.result(object, 'stuff'); ### `_.shuffle(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2824 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2858 "View in source") [Ⓣ][1] Creates a new array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -2124,7 +2127,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1725 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1747 "View in source") [Ⓣ][1] Gets the size of `value` by returning `value.length` if `value` is an array, string, or `arguments` object. If `value` is an object, size is determined by returning the number of own enumerable properties it has. @@ -2154,7 +2157,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2216 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2247 "View in source") [Ⓣ][1] Checks if the `callback` returns a truthy value for **any** element of a `collection`. The function returns as soon as it finds passing value, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. @@ -2180,7 +2183,7 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2246 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2277 "View in source") [Ⓣ][1] Creates a new sorted array, sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -2212,7 +2215,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2876 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2910 "View in source") [Ⓣ][1] Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with `1` argument; *(value)*. @@ -2253,7 +2256,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3955 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3995 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2283,7 +2286,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3731 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3771 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. Note: For Chrome extensions use the `lodash csp` build and see http://code.google.com/chrome/extensions/trunk/sandboxingEval.html @@ -2342,7 +2345,7 @@ _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' }); ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3482 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3522 "View in source") [Ⓣ][1] Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2367,7 +2370,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3871 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3911 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2393,7 +2396,7 @@ _.times(3, function() { this.grantWish(); }, genie); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2281 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2314 "View in source") [Ⓣ][1] Converts the `collection`, into an array. Useful for converting the `arguments` object. @@ -2417,9 +2420,9 @@ Converts the `collection`, into an array. Useful for converting the `arguments` ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2916 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2951 "View in source") [Ⓣ][1] -Computes the union of the passed-in arrays. +Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. #### Arguments 1. `[array1, array2, ...]` *(Array)*: Arrays to process. @@ -2441,7 +2444,7 @@ _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.uniq(array [, isSorted=false, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2960 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2995 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, index, array)*. @@ -2477,7 +2480,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3898 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3938 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2501,7 +2504,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1747 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1778 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2525,7 +2528,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2318 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2351 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that contain the given `properties`. @@ -2556,7 +2559,7 @@ _.where(stooges, { 'age': 40 }); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3009 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3044 "View in source") [Ⓣ][1] Creates a new array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -2581,7 +2584,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3533 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3573 "View in source") [Ⓣ][1] Creates a new function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the new function are appended to those passed to the `wrapper` function. @@ -2610,7 +2613,7 @@ hello(); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3042 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3077 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -2633,13 +2636,14 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); -### `_.zipObject(keys)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3071 "View in source") [Ⓣ][1] +### `_.zipObject(keys [, values=[]])` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3106 "View in source") [Ⓣ][1] Creates an object composed from an array of `keys` and an array of `values`. #### Arguments 1. `keys` *(Array)*: The array of keys. +2. `[values=[]]` *(Array)*: The array of values. #### Returns *(Object)*: Returns an object composed of the given keys and corresponding values. @@ -2665,7 +2669,7 @@ _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3973 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4013 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2686,7 +2690,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3990 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4030 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/doc/parse.php b/doc/parse.php index 3fcd36cd7c..b059ce7e95 100644 --- a/doc/parse.php +++ b/doc/parse.php @@ -21,7 +21,7 @@ // generate Markdown $markdown = docdown(array( 'path' => '../' . $file, - 'title' => 'Lo-Dash v0.5.0-rc.1', + 'title' => 'Lo-Dash v0.5.0', 'url' => 'https://github.com/bestiejs/lodash/blob/master/lodash.js' )); diff --git a/lodash.js b/lodash.js index 3bc9184cb5..b1de0d6517 100644 --- a/lodash.js +++ b/lodash.js @@ -1,5 +1,5 @@ /*! - * Lo-Dash v0.5.0-rc.1 + * Lo-Dash v0.5.0 * Copyright 2012 John-David Dalton * Based on Underscore.js 1.3.3, copyright 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. * @@ -1542,6 +1542,8 @@ function isObject(value) { // check if the value is the ECMAScript language type of Object // http://es5.github.com/#x8 + // and avoid a V8 bug + // http://code.google.com/p/v8/issues/detail?id=2291 return value && objectTypes[typeof value]; } @@ -4038,7 +4040,7 @@ * @memberOf _ * @type String */ - lodash.VERSION = '0.5.0-rc.1'; + lodash.VERSION = '0.5.0'; // assign static methods lodash.after = after; diff --git a/lodash.min.js b/lodash.min.js index 1a56c05a2f..e9c791d906 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -1,40 +1,40 @@ /*! - Lo-Dash 0.5.0-rc.1 lodash.com/license + Lo-Dash 0.5.0 lodash.com/license Underscore.js 1.3.3 github.com/documentcloud/underscore/blob/master/LICENSE */ -;(function(e,t){"use strict";function s(e){return new o(e)}function o(e){if(e&&e._wrapped)return e;this._wrapped=e}function u(e,t,n){t||(t=0);var r=e.length,i=r-t>=(n||30),s=i?{}:e;if(i)for(var o=t-1;++on;n++ -)t+="h='"+u.p[n]+"';if(","constructor"==u.p[n]&&(t+="!(d&&d.prototype===i)&&"),t+="f.call(i,h)){z=i[h];"+u.m.i+"}"}if(u.c||u.n)t+="}"}return t+=u.e+";return t",Function("E,F,G,I,c,K,e,f,g,N,P,R,T,j,W,l,q,v,w,y","var H=function("+e+"){"+t+"};return H")(Ht,F,O,f,it,Gt,yt,st,M,N,w,en,p,d,Ft,pt,ut,at,St,ft)}function f(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function l(e,t){return rt[t]}function c(e){return"\\"+It[e]}function h(e){return jt[e]}function p(e){var t=i;if(!e||"object"!=typeof -e)return t;var n=e.constructor;return(!Mt||"function"==typeof e.toString||"string"!=typeof (e+""))&&(ft.call(n)!=yt||n instanceof n)?Ct?(Gt(e,function(n,r){return t=!st.call(e,r),i}),t===i):(Gt(e,function(e,n){t=n}),t===i||st.call(e,t)):t}function d(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function v(){}function m(e,t){if(X.test(t))return"";var n=rt.length;return rt[n]="'+__e("+t+")+'",nt+n}function g(e,t,n,r){return e=rt.length,t?rt[e]="'+__e("+t+")+'":r?rt[e]="';"+r+";__p+='" -:n&&(rt[e]="'+((__t=("+n+"))==null?'':__t)+'"),nt+e}function y(e,t){if(X.test(t))return"";var n=rt.length;return rt[n]="'+((__t=("+t+"))==null?'':__t)+'",nt+n}function b(e,t,s,o,u){if(e==r)return e;s&&(t=i),u||(u={c:r}),u.c==r&&(u.c=!(!I.clone&&!R.clone&&!U.clone));if(((s=Ft[typeof e])||u.c)&&e.clone&&ft.call(e.clone)==yt)return u.c=r,e.clone(t);if(s){var a=ft.call(e);if(!Bt[a]||Lt&&w(e))return e;var f=a==vt,s=f||(a==wt?p(e):s)}if(!s||!t)return s?f?at.call(e):Qt({},e):e;s=e.constructor -;switch(a){case mt:return new s(e==n);case gt:return new s(+e);case bt:case St:return new s(e);case Et:return s(e.source,K.exec(e))}o||(o=[]);for(a=o.length;a--;)if(o[a].b==e)return o[a].c;var a=e.length,l=f?s(a):{};o.push({c:l,b:e});if(f)for(f=-1;++f++u;)if(c=tt[u],st.call(e,c)&&(! -st.call(t,c)||!E(e[c],t[c],s,o)))return i;return n}return i}function S(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=d(t,r));if(i===i>>>0){var o=Ot&&ft.call(e)==St?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=rn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function x(e,t,n){if(e)return t==r||n?e[0]:at.call(e,0,t)}function T(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=d(t,n));++sr&&(r=n,i=e[s]);return i}function k(e,t,n){return e?at.call(e,t==r||n?1:t):[]}function L(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=O(n,r -));for(t=n(t);i>>1,n(e[r])>>1,e[r]N(a,r))a.push(r),s.push(e[o]);return s}function O(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?it.apply(s,o):s),this instanceof n?(v.prototype=e.prototype,u=new v,(o=e.apply(u,o))&&Ft[typeof -o]?o:u):e.apply(u,o)}var r,i=ft.call(e)==yt;if(i){if(Dt||lt&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,V=/\b__p\+='';/g,$=/\b(__p\+=)''\+/g,J=/(__e\(.*?\)|\b__t\))\+'';/g,K=/\w*$/,Q=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,G=RegExp("^"+(q.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),Y=/__token__(\d+)/g,Z=/[&<"']/g,et=/['\n\r\t\u2028\u2029\\]/g, -tt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),nt="__token__",rt=[],it=F.concat,st=q.hasOwnProperty,ot=F.push,ut=q.propertyIsEnumerable,at=F.slice,ft=q.toString,lt=G.test(lt=at.bind)&<,ct=G.test(ct=Array.isArray)&&ct,ht=e.isFinite,pt=G.test(pt=Object.keys)&&pt,dt="[object Arguments]",vt="[object Array]",mt="[object Boolean]",gt="[object Date]",yt="[object Function]",bt="[object Number]",wt="[object Object]",Et="[object RegExp]",St="[object String]" -,xt=e.clearTimeout,Tt=e.setTimeout,Nt,Ct,kt=n;(function(){function e(){this.x=1}var t=[];e.prototype={valueOf:1,y:1};for(var n in new e)t.push(n);for(n in arguments)kt=!n;Nt=4>(t+"").length,Ct="x"!=t[0]})(1);var Lt=!w(arguments),At="x"!=at.call("x")[0],Ot="xx"!="x"[0]+Object("x")[0];try{var Mt=("[object Object]",ft.call(e.document||0)==wt)}catch(_t){}var Dt=lt&&/\n|Opera/.test(lt+ft.call(e.opera)),Pt=pt&&/^.+$|true/.test(pt+!!e.attachEvent),Ht={"[object Arguments]":n,"[object Array]":n,"[object Boolean]" -:i,"[object Date]":i,"[object Function]":i,"[object Number]":i,"[object Object]":i,"[object RegExp]":i,"[object String]":n},Bt={"[object Arguments]":i,"[object Array]":n,"[object Boolean]":n,"[object Date]":n,"[object Function]":i,"[object Number]":n,"[object Object]":n,"[object RegExp]":n,"[object String]":n},jt={"&":"&","<":"<",'"':""","'":"'"},Ft={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},It={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028" -:"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj"};var qt={a:"b,a,x",j:"b",q:"if(!a){a=g}else if(x)a=j(a,x)",i:"if(a(z,h,b)===false)return t"},Rt={j:"{}",q:"var p;if(typeof a!='function'){var gg=a;a=function(z){return z[gg]}}else if(x)a=j(a,x)",i:"p=a(z,h,b);(f.call(t,p)?t[p]++:t[p]=1)"},Ut={j:"true",i:"if(!a(z,h,b))return!t"},zt={r:i,s:i,a:"m",j:"m",q:"for(var C=1,D=arguments.length;C-1"},i:"if(z===ff)return true"}),un=a(qt,Rt),an=a(qt,Ut),fn=a(qt,Wt),ln=a(qt,Xt,{ -j:"",i:"if(a(z,h,b))return z"}),cn=a(qt,Xt),hn=a(qt,Rt,{i:"p=a(z,h,b);(f.call(t,p)?t[p]:t[p]=[]).push(z)"}),pn=a($t,{a:"b,U",q:"var B=v.call(arguments,2),S=typeof U=='function'",i:{b:"t[h]=(S?U:z[U]).apply(z,B)",l:"t"+(Pt?"[n]=":".push")+"((S?U:z[U]).apply(z,B))"}}),dn=a(qt,$t),vn=a(zt,{a:"m,cc,O,dd",q:"var J,L,Q,ee,bb=O==T;if(!bb)dd=[];for(var C=1,D=bb?2:arguments.length;C1){for(var h=1;he?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=O,s.bindAll=Sn,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=b,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length -;++nN(t,n)&&an(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=pn,s.isArguments=w,s.isArray=en,s.isBoolean=function(e){return e===n||e===i||ft.call(e)==mt},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=tn,s.isEqual=E,s.isFinite=function(e){return ht(e)&&ft.call(e)==bt},s.isNaN=function(e){return ft.call(e)== -bt&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&Ft[typeof e]},s.isUndefined=function(e){return e===t},s.keys=rn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:at.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=dn,s.max=C,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments -[0];return st.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=vn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s|"+(a?"|"+a.source:""),"g")),o=rt.length,e=e.replace(B,g),o=o!=rt.length,e="__p += '"+e.replace(et,c).replace(Y,l)+"';",rt.length=0,n||(n=h.variable||P||"obj",o?e="with("+n+"){"+e+"}":(n!=P&&(P=n,H=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(Q,"$&"+n+".").replace(H,"$1__d"))),e=(o?e.replace(V,""):e).replace($,"$1").replace(J,"$1;"),e="function("+n+"){"+n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}" -:",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=Tt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(At?ft.call(e)==St:"string"==typeof e)?e.split(""):at.call(e):sn(e)},s.union=function(){for(var e=-1,t=[],n=it.apply(t,arguments),r=n.length;++eN(t,n[e])&&t.push(n[e]);return t},s.uniq=A,s.uniqueId=function(e){var t=z++;return e?e+t:t},s.values=sn,s.where=En,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n=(n||30),s=i?{}:e;if(i)for(var o=t-1;++on;n++)t+="g='"+u.p[n]+"';if(","constructor"==u.p[n]&&(t+="!(d&&d.prototype===h)&&"),t+="e.call(h,g)){y=h[g];"+u.m.i+"}"}if(u.c||u.n)t+="}"}return t+=u.e+";return s",Function("D,E,F,I,c,K,e,f,N,P,R,T,U,i,X,Y,k,p,u,v,x","var G=function("+e+"){"+t+"};return G")(Ht,I,M,f,st,Zt,ot,_,C,b,Jt,w,p,d,wt,Ft,dt,at,ft,St,lt)}function f(e,n){var r=e.b,i=n.b,e=e.a,n=n.a;return e===t?1:n===t?-1:en?1:r";var n=it.length;return it[n]="'+__e("+t+")+'",rt+n}function g(e,t,n,r){return e=it.length,t?it[e]="'+__e("+ +t+")+'":r?it[e]="';"+r+";__p+='":n&&(it[e]="'+((__t=("+n+"))==null?'':__t)+'"),rt+e}function y(e,t){if(V.test(t))return"";var n=it.length;return it[n]="'+((__t=("+t+"))==null?'':__t)+'",rt+n}function b(e){return lt.call(e)==vt}function w(e){return"function"==typeof e}function E(e,t,s,o,u){if(e==r)return e;s&&(t=i),u||(u={d:r}),u.d==r&&(u.d=!(!q.clone&&!U.clone&&!z.clone));if(((s=Ft[typeof e])||u.d)&&e.clone&&w(e.clone))return u.d=r,e.clone(t);if(s){var a=lt.call(e);if(!Bt[a]||Lt&&b(e)) +return e;var f=a==mt,s=f||(a==wt?p(e):s)}if(!s||!t)return s?f?ft.call(e):Yt({},e):e;s=e.constructor;switch(a){case gt:return new s(e==n);case yt:return new s(+e);case bt:case St:return new s(e);case Et:return s(e.source,Q.exec(e))}o||(o=[]);for(a=o.length;a--;)if(o[a].c==e)return o[a].d;var a=e.length,l=f?s(a):{};o.push({d:l,c:e});if(f)for(f=-1;++f++u;)if(c=nt[u],ot.call(e,c)&&(!ot.call(t,c)||!S(e[c],t[c],s,o)))return i;return n}function x(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=d(t,r));if(-1>>0){var o=Ot&<.call(e)==St?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=rn(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function T(e,t,n){if(e)return t==r||n?e[0]:ft.call(e,0,t)}function N(e,t){var n=[];if(!e)return n;for(var r,i=-1,s=e.length;++in?Math.max(0,i+n):n)-1}for(;++ri&&(i=e[s]);return i}for(n&&(t=d(t,n));++sr&&(r=n,i=e[s]);return i}function L(e,t,n){return e?ft.call(e,t==r||n?1:t):[]}function A(e,t,n,r){if(!e)return 0 +;var i=0,s=e.length;if(n){r&&(n=M(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]C(a,r))a.push(r),s.push(e[o]);return s}function M(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?st.apply(s,o):s),this instanceof n?(v.prototype=e.prototype +,u=new v,(o=e.apply(u,o))&&Ft[typeof o]?o:u):e.apply(u,o)}var r,i=w(e);if(i){if(Dt||ct&&2|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/,$=/\b__p\+='';/g,J=/\b(__p\+=)''\+/g,K=/(__e\(.*?\)|\b__t\))\+'';/g,Q=/\w*$/,G=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,Y=RegExp("^"+(R.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),Z=/__token__(\d+)/g,et=/[&<"']/g +,tt=/['\n\r\t\u2028\u2029\\]/g,nt="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),rt="__token__",it=[],st=I.concat,ot=R.hasOwnProperty,ut=I.push,at=R.propertyIsEnumerable,ft=I.slice,lt=R.toString,ct=Y.test(ct=ft.bind)&&ct,ht=Y.test(ht=Array.isArray)&&ht,pt=e.isFinite,dt=Y.test(dt=Object.keys)&&dt,vt="[object Arguments]",mt="[object Array]",gt="[object Boolean]",yt="[object Date]",bt="[object Number]",wt="[object Object]",Et="[object RegExp]" +,St="[object String]",xt=e.clearTimeout,Tt=e.setTimeout,Nt,Ct,kt=n;(function(){function e(){this.x=1}var t=[];e.prototype={valueOf:1,y:1};for(var n in new e)t.push(n);for(n in arguments)kt=!n;Nt=4>(t+"").length,Ct="x"!=t[0]})(1);var Lt=!b(arguments),At="x"!=ft.call("x")[0],Ot="xx"!="x"[0]+Object("x")[0];try{var Mt=("[object Object]",lt.call(e.document||0)==wt)}catch(_t){}var Dt=ct&&/\n|Opera/.test(ct+lt.call(e.opera)),Pt=dt&&/^.+$|true/.test(dt+!!e.attachEvent),Ht={"[object Arguments]":n,"[object Array]" +:n,"[object Boolean]":i,"[object Date]":i,"[object Function]":i,"[object Number]":i,"[object Object]":i,"[object RegExp]":i,"[object String]":n},Bt={"[object Arguments]":i,"[object Array]":n,"[object Boolean]":n,"[object Date]":n,"[object Function]":i,"[object Number]":n,"[object Object]":n,"[object RegExp]":n,"[object String]":n},jt={"&":"&","<":"<",'"':""","'":"'"},Ft={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i,unknown:n},It={"\\":"\\","'":"'","\n":"n","\r" +:"r"," ":"t","\u2028":"u2028","\u2029":"u2029"};s.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj"};var qt={a:"b,a,w",j:"b",q:"if(!a)a=f;else if(w)a=i(a,w)",i:"if(a(y,g,b)===false)return s"},Rt={j:"{}",q:"var o;if(typeof a!='function'){var ii=a;a=function(y){return y[ii]}}else if(w)a=i(a,w)",i:"o=a(y,g,b);(e.call(s,o)?s[o]++:s[o]=1)"},Ut={j:"true",i:"if(!a(y,g,b))return!s"},zt={r:i,s:i,a:"l",j:"l",q:"for(var B=1,C=arguments.length;B-1&&j===j>>>0&&T(y.splice)))return!j",i:{l:"return false"}}),rn=dt?function(e){return"function"==typeof e&&at.call(e,"prototype")?Kt(e):dt(e)}:Kt,sn=a({a:"l",j:"[]",i:"s.push(y)"}),on=a({a:"b,hh",j:"false",o:i,d:{b:"if(x.call(h)==v)return b.indexOf(hh)>-1" +},i:"if(y===hh)return true"}),un=a(qt,Rt),an=a(qt,Ut),fn=a(qt,Wt),ln=a(qt,Xt,{j:"",i:"if(a(y,g,b))return y"}),cn=a(qt,Xt),hn=a(qt,Rt,{i:"o=a(y,g,b);(e.call(s,o)?s[o]:s[o]=[]).push(y)"}),pn=a($t,{a:"b,V",q:"var A=u.call(arguments,2),S=typeof V=='function'",i:{b:"s[g]=(S?V:y[V]).apply(y,A)",l:"s"+(Pt?"[m]=":".push")+"((S?V:y[V]).apply(y,A))"}}),dn=a(qt,$t),vn=a(zt,{a:"l,ee,O,ff",q:"var J,L,Q,gg,dd=O==U;if(!dd)ff=[];for(var B=1,C=dd?2:arguments.length;B1){for(var g=1;ge?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=M,s.bindAll=Sn,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=E,s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nC(t,n)&&an(s,function(e,t){return(o[t]||(o[t]=u(e)))(n)})&&t.push(n);return t},s.invoke=pn,s.isArguments=b,s.isArray=Jt,s.isBoolean=function(e){return e===n||e===i||lt.call(e)==gt},s.isElement=function(e){return!!e&&1==e.nodeType},s.isEmpty=nn,s.isEqual=S,s.isFinite=function(e){return pt(e)&<.call(e)==bt},s.isFunction=w,s.isNaN=function(e){return lt.call +(e)==bt&&e!=+e},s.isNull=function(e){return e===r},s.isObject=function(e){return e&&Ft[typeof e]},s.isUndefined=function(e){return e===t},s.keys=rn,s.last=function(e,t,n){if(e){var i=e.length;return t==r||n?e[i-1]:ft.call(e,-t||i)}},s.lastIndexOf=function(e,t,n){if(!e)return-1;var r=e.length;for(n&&"number"==typeof n&&(r=(0>n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=dn,s.max=k,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments +[0];return ot.call(n,r)?n[r]:n[r]=e.apply(this,arguments)}},s.merge=vn,s.min=function(e,t,n){var r=Infinity,i=r;if(!e)return i;var s=-1,o=e.length;if(!t){for(;++s>>0&&w(e.splice)?n:rn(e).length},s.some=bn,s.sortBy=wn,s.sortedIndex=A,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var o,u;o=n.escape;var a=n.evaluate,f=n.interpolate,h=s.templateSettings,n=n.variable;o==r&&(o=h.escape),a==r&& +(a=h.evaluate||i),f==r&&(f=h.interpolate),o&&(e=e.replace(o,m)),f&&(e=e.replace(f,y)),a!=P&&(P=a,j=RegExp("|"+(a?"|"+a.source:""),"g")),o=it.length,e=e.replace(j,g),o=o!=it.length,e="__p += '"+e.replace(tt,c).replace(Z,l)+"';",it.length=0,n||(n=h.variable||H||"obj",o?e="with("+n+"){"+e+"}":(n!=H&&(H=n,B=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(G,"$&"+n+".").replace(B,"$1__d"))),e=(o?e.replace($,""):e).replace(J,"$1").replace(K,"$1;"),e="function("+n+"){"+ +n+"||("+n+"={});var __t,__p='',__e=_.escape"+(o?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":",__d="+n+"."+n+"||"+n+";")+e+"return __p}";try{u=Function("_","return "+e)(s)}catch(p){u=function(){throw p}}return t?u(t):(u.source=e,u)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=Tt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++ +r>>0?(At?lt.call(e)==St:"string"==typeof e)?e.split(""):ft.call(e):sn(e)},s.union=function(){for(var e=-1,t=[],n=st.apply(t,arguments),r=n.length;++eC(t,n[e])&&t.push(n[e]);return t},s.uniq=O,s.uniqueId=function(e){var t=W++;return e?e+t:t},s.values=sn,s.where=En,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments +,1,20);++n Date: Fri, 17 Aug 2012 02:54:19 -0700 Subject: [PATCH 72/77] Fix typos in README.md. Former-commit-id: fb31a291a3afe799d2e9809f17420eda10888250 --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d864f6cee7..6c545563e8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Lo-Dash v0.5.0 -A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) 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#closed-underscorejs-issues), and [additional features](https://github.com/bestiejs/lodash#features). +A drop-in replacement[*](https://github.com/bestiejs/lodash/wiki/Drop-in-Disclaimer) 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). 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. @@ -51,7 +51,7 @@ For more information check out these screencasts over Lo-Dash: ## Support -Lo-Dash has been tested in at least Chrome 5-21, Firefox 1.5-13, IE 6-9, Opera 9.25-12.01, Safari 3-6, Node.js 0.4.8-0.8.6, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC3. +Lo-Dash has been tested in at least Chrome 5-21, Firefox 1.5-13, IE 6-9, Opera 9.25-12.01, Safari 3-6, Node.js 0.4.8-0.8.7, Narwhal 0.3.2, RingoJS 0.8, and Rhino 1.7RC5. ## Custom builds @@ -180,8 +180,8 @@ require({ * `_(…)` should return passed wrapper instances [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L135-138)] * `_.clone` should allow `deep` cloning [[#595](https://github.com/documentcloud/underscore/pull/595), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L197-212)] * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L267-276)] - * `_.escape` should return an empty string when passed `null` or `undefined` [[#407](https://github.com/documentcloud/underscore/issues/427), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L367-370)] - * `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L862-920)] + * `_.escape` should return an empty string when passed `null` or `undefined` [[#427](https://github.com/documentcloud/underscore/issues/427), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L367-370)] + * `_.extend` should recursively extend objects [[#379](https://github.com/documentcloud/underscore/pull/379), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L882-955)] * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L486-489)] * `_.forEach` should allow exiting iteration early [[#211](https://github.com/documentcloud/underscore/issues/211), [test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L582-601)] * `_.groupBy` should add values to own, not inherited, properties [[test](https://github.com/bestiejs/lodash/blob/v0.5.0/test/test.js#L616-623)] From b43684262f17c02086b5edc1aac7c5fcb2829f26 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 17 Aug 2012 04:05:50 -0700 Subject: [PATCH 73/77] Cleanup `_.template` documentation. Former-commit-id: 7b45705bd8a4661dbf824912798ccba15e5ed989 --- lodash.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lodash.js b/lodash.js index b1de0d6517..988141a951 100644 --- a/lodash.js +++ b/lodash.js @@ -3759,9 +3759,9 @@ * template({ 'name': 'Mustache' }); * // => 'Hello Mustache!' * - * // using the `variable` option - * _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' }); - * // => 'no' + * // specify the `variable` option to avoid using a with-statement during compilation + * _.template('Using a with-statement: <%= data.answer %>', { 'answer': 'no' }, { 'variable': 'data' }); + * // => 'Using a with-statement: no' * * // using the `source` property * -~~~ +``` Using [npm](http://npmjs.org/): -~~~ bash +```bash npm install lodash npm install -g lodash -~~~ +``` In [Node.js](http://nodejs.org/) and [RingoJS v0.8.0+](http://ringojs.org/): -~~~ js +```js var _ = require('lodash'); -~~~ +``` In [RingoJS v0.7.0-](http://ringojs.org/): -~~~ js +```js var _ = require('lodash')._; -~~~ +``` In [Rhino](http://www.mozilla.org/rhino/): -~~~ js +```js load('lodash.js'); -~~~ +``` In an AMD loader like [RequireJS](http://requirejs.org/): -~~~ js +```js require({ 'paths': { 'underscore': 'path/to/lodash' @@ -164,7 +164,7 @@ require({ ['underscore'], function(_) { console.log(_.VERSION); }); -~~~ +``` ## Resolved Underscore.js issues (20+) diff --git a/doc/README.md b/doc/README.md index 00fab307b1..7b84aea648 100644 --- a/doc/README.md +++ b/doc/README.md @@ -176,13 +176,13 @@ Creates a new function that is restricted to executing only after it is called ` *(Function)*: Returns the new restricted function. #### Example -~~~ js +```js var renderNotes = _.after(notes.length, render); _.forEach(notes, function(note) { note.asyncSave({ 'success': renderNotes }); }); // `renderNotes` is run once, after all notes have saved -~~~ +``` * * * @@ -205,7 +205,7 @@ Creates a new function that, when called, invokes `func` with the `this` binding *(Function)*: Returns the new bound function. #### Example -~~~ js +```js // basic bind var func = function(greeting) { return greeting + ' ' + this.name; @@ -233,7 +233,7 @@ object.greet = function(greeting) { func(); // => 'hi, moe!' -~~~ +``` * * * @@ -255,7 +255,7 @@ Binds methods on `object` to `object`, overwriting the existing method. If no me *(Object)*: Returns `object`. #### Example -~~~ js +```js var buttonView = { 'label': 'lodash', 'onClick': function() { alert('clicked: ' + this.label); } @@ -264,7 +264,7 @@ var buttonView = { _.bindAll(buttonView); jQuery('#lodash_button').on('click', buttonView.onClick); // => When the button is clicked, `this.label` will have the correct value -~~~ +``` * * * @@ -285,7 +285,7 @@ Wraps the value in a `lodash` wrapper object. *(Object)*: Returns the wrapper object. #### Example -~~~ js +```js var stooges = [ { 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }, @@ -298,7 +298,7 @@ var youngest = _.chain(stooges) .first() .value(); // => 'moe is 40' -~~~ +``` * * * @@ -323,7 +323,7 @@ Creates a clone of `value`. If `deep` is `true`, all nested objects will also be *(Mixed)*: Returns the cloned `value`. #### Example -~~~ js +```js var stooges = [ { 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }, @@ -340,7 +340,7 @@ shallow[0] === stooges[0]; var deep = _.clone(stooges, true); shallow[0] === stooges[0]; // => false -~~~ +``` * * * @@ -361,10 +361,10 @@ Creates a new array with all falsey values of `array` removed. The values `false *(Array)*: Returns a new filtered array. #### Example -~~~ js +```js _.compact([0, 1, false, 2, '', 3]); // => [1, 2, 3] -~~~ +``` * * * @@ -385,13 +385,13 @@ Creates a new function that is the composition of the passed functions, where ea *(Function)*: Returns the new composed function. #### Example -~~~ js +```js var greet = function(name) { return 'hi: ' + name; }; var exclaim = function(statement) { return statement + '!'; }; var welcome = _.compose(exclaim, greet); welcome('moe'); // => 'hi: moe!' -~~~ +``` * * * @@ -413,7 +413,7 @@ Checks if a given `target` element is present in a `collection` using strict equ *(Boolean)*: Returns `true` if the `target` element is found, else `false`. #### Example -~~~ js +```js _.contains([1, 2, 3], 3); // => true @@ -422,7 +422,7 @@ _.contains({ 'name': 'moe', 'age': 40 }, 'moe'); _.contains('curly', 'ur'); // => true -~~~ +``` * * * @@ -445,7 +445,7 @@ Creates an object composed of keys returned from running each element of `collec *(Object)*: Returns the composed aggregate object. #### Example -~~~ js +```js _.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); }); // => { '4': 1, '6': 2 } @@ -454,7 +454,7 @@ _.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math); _.countBy(['one', 'two', 'three'], 'length'); // => { '3': 2, '5': 1 } -~~~ +``` * * * @@ -477,10 +477,10 @@ Creates a new function that will delay the execution of `func` until after `wait *(Function)*: Returns the new debounced function. #### Example -~~~ js +```js var lazyLayout = _.debounce(calculateLayout, 300); jQuery(window).on('resize', lazyLayout); -~~~ +``` * * * @@ -502,11 +502,11 @@ Assigns enumerable properties of the default object(s) to the `destination` obje *(Object)*: Returns the destination object. #### Example -~~~ js +```js var iceCream = { 'flavor': 'chocolate' }; _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); // => { 'flavor': 'chocolate', 'sprinkles': 'rainbow' } -~~~ +``` * * * @@ -528,10 +528,10 @@ Defers executing the `func` function until the current call stack has cleared. A *(Number)*: Returns the `setTimeout` timeout id. #### Example -~~~ js +```js _.defer(function() { alert('deferred'); }); // returns from the function before `alert` is called -~~~ +``` * * * @@ -554,11 +554,11 @@ Executes the `func` function after `wait` milliseconds. Additional arguments wil *(Number)*: Returns the `setTimeout` timeout id. #### Example -~~~ js +```js var log = _.bind(console.log, console); _.delay(log, 1000, 'logged later'); // => 'logged later' (Appears after one second.) -~~~ +``` * * * @@ -580,10 +580,10 @@ Creates a new array of `array` elements not present in the other arrays using st *(Array)*: Returns a new array of `array` elements not present in the other arrays. #### Example -~~~ js +```js _.difference([1, 2, 3, 4, 5], [5, 2, 10]); // => [1, 3, 4] -~~~ +``` * * * @@ -605,10 +605,10 @@ Creates a shallow clone of `object` excluding the specified properties. Property *(Object)*: Returns an object without the dropped properties. #### Example -~~~ js +```js _.drop({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'userid'); // => { 'name': 'moe', 'age': 40 } -~~~ +``` * * * @@ -629,10 +629,10 @@ Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` charact *(String)*: Returns the escaped string. #### Example -~~~ js +```js _.escape('Moe, Larry & Curly'); // => "Moe, Larry & Curly" -~~~ +``` * * * @@ -655,10 +655,10 @@ Checks if the `callback` returns a truthy value for **all** elements of a `colle *(Boolean)*: Returns `true` if all elements pass the callback check, else `false`. #### Example -~~~ js +```js _.every([true, 1, null, 'yes'], Boolean); // => false -~~~ +``` * * * @@ -680,10 +680,10 @@ Assigns enumerable properties of the source object(s) to the `destination` objec *(Object)*: Returns the destination object. #### Example -~~~ js +```js _.extend({ 'name': 'moe' }, { 'age': 40 }); // => { 'name': 'moe', 'age': 40 } -~~~ +``` * * * @@ -706,10 +706,10 @@ Examines each element in a `collection`, returning an array of all elements the *(Array)*: Returns a new array of elements that passed callback check. #### Example -~~~ js +```js var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); // => [2, 4, 6] -~~~ +``` * * * @@ -732,10 +732,10 @@ Examines each element in a `collection`, returning the first one the `callback` *(Mixed)*: Returns the element that passed the callback check, else `undefined`. #### Example -~~~ js +```js var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); // => 2 -~~~ +``` * * * @@ -758,10 +758,10 @@ Gets the first element of the `array`. Pass `n` to return the first `n` elements *(Mixed)*: Returns the first element or an array of the first `n` elements of `array`. #### Example -~~~ js +```js _.first([5, 4, 3, 2, 1]); // => 5 -~~~ +``` * * * @@ -783,13 +783,13 @@ Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is tru *(Array)*: Returns a new flattened array. #### Example -~~~ js +```js _.flatten([1, [2], [3, [[4]]]]); // => [1, 2, 3, 4]; _.flatten([1, [2], [3, [[4]]]], true); // => [1, 2, 3, [[4]]]; -~~~ +``` * * * @@ -812,13 +812,13 @@ Iterates over a `collection`, executing the `callback` for each element in the ` *(Array, Object)*: Returns `collection`. #### Example -~~~ js +```js _([1, 2, 3]).forEach(alert).join(','); // => alerts each number and returns '1,2,3' _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); // => alerts each number (order is not guaranteed) -~~~ +``` * * * @@ -841,7 +841,7 @@ Iterates over `object`'s own and inherited enumerable properties, executing the *(Object)*: Returns `object`. #### Example -~~~ js +```js function Dog(name) { this.name = name; } @@ -854,7 +854,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { alert(key); }); // => alerts 'name' and 'bark' (order is not guaranteed) -~~~ +``` * * * @@ -877,12 +877,12 @@ Iterates over `object`'s own enumerable properties, executing the `callback` for *(Object)*: Returns `object`. #### Example -~~~ js +```js _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { alert(key); }); // => alerts '0', '1', and 'length' (order is not guaranteed) -~~~ +``` * * * @@ -903,10 +903,10 @@ Creates a sorted array of all enumerable properties, own and inherited, of `obje *(Array)*: Returns a new array of property names that have function values. #### Example -~~~ js +```js _.functions(_); // => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] -~~~ +``` * * * @@ -929,7 +929,7 @@ Creates an object composed of keys returned from running each element of `collec *(Object)*: Returns the composed aggregate object. #### Example -~~~ js +```js _.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); }); // => { '4': [4.2], '6': [6.1, 6.4] } @@ -938,7 +938,7 @@ _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math); _.groupBy(['one', 'two', 'three'], 'length'); // => { '3': ['one', 'two'], '5': ['three'] } -~~~ +``` * * * @@ -960,10 +960,10 @@ Checks if the specified object `property` exists and is a direct property, inste *(Boolean)*: Returns `true` if key is a direct property, else `false`. #### Example -~~~ js +```js _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); // => true -~~~ +``` * * * @@ -984,11 +984,11 @@ This function returns the first argument passed to it. Note: It is used through *(Mixed)*: Returns `value`. #### Example -~~~ js +```js var moe = { 'name': 'moe' }; moe === _.identity(moe); // => true -~~~ +``` * * * @@ -1011,7 +1011,7 @@ Gets the index at which the first occurrence of `value` is found using strict eq *(Number)*: Returns the index of the matched value or `-1`. #### Example -~~~ js +```js _.indexOf([1, 2, 3, 1, 2, 3], 2); // => 1 @@ -1020,7 +1020,7 @@ _.indexOf([1, 2, 3, 1, 2, 3], 2, 3); _.indexOf([1, 1, 2, 2, 3, 3], 2, true); // => 2 -~~~ +``` * * * @@ -1043,10 +1043,10 @@ Gets all but the last element of `array`. Pass `n` to exclude the last `n` eleme *(Array)*: Returns all but the last element or `n` elements of `array`. #### Example -~~~ js +```js _.initial([3, 2, 1]); // => [3, 2] -~~~ +``` * * * @@ -1067,10 +1067,10 @@ Computes the intersection of all the passed-in arrays using strict equality for *(Array)*: Returns a new array of unique elements, in order, that are present in **all** of the arrays. #### Example -~~~ js +```js _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); // => [1, 2] -~~~ +``` * * * @@ -1093,13 +1093,13 @@ Invokes the method named by `methodName` on each element in the `collection`. Ad *(Array)*: Returns a new array of values returned from each invoked method. #### Example -~~~ js +```js _.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); // => [[1, 5, 7], [1, 2, 3]] _.invoke([123, 456], String.prototype.split, ''); // => [['1', '2', '3'], ['4', '5', '6']] -~~~ +``` * * * @@ -1120,13 +1120,13 @@ Checks if `value` is an `arguments` object. *(Boolean)*: Returns `true` if the `value` is an `arguments` object, else `false`. #### Example -~~~ js +```js (function() { return _.isArguments(arguments); })(1, 2, 3); // => true _.isArguments([1, 2, 3]); // => false -~~~ +``` * * * @@ -1147,13 +1147,13 @@ Checks if `value` is an array. *(Boolean)*: Returns `true` if the `value` is an array, else `false`. #### Example -~~~ js +```js (function() { return _.isArray(arguments); })(); // => false _.isArray([1, 2, 3]); // => true -~~~ +``` * * * @@ -1174,10 +1174,10 @@ Checks if `value` is a boolean *(`true` or `false`)* value. *(Boolean)*: Returns `true` if the `value` is a boolean value, else `false`. #### Example -~~~ js +```js _.isBoolean(null); // => false -~~~ +``` * * * @@ -1198,10 +1198,10 @@ Checks if `value` is a date. *(Boolean)*: Returns `true` if the `value` is a date, else `false`. #### Example -~~~ js +```js _.isDate(new Date); // => true -~~~ +``` * * * @@ -1222,10 +1222,10 @@ Checks if `value` is a DOM element. *(Boolean)*: Returns `true` if the `value` is a DOM element, else `false`. #### Example -~~~ js +```js _.isElement(document.body); // => true -~~~ +``` * * * @@ -1246,7 +1246,7 @@ Checks if `value` is empty. Arrays, strings, or `arguments` objects with a lengt *(Boolean)*: Returns `true` if the `value` is empty, else `false`. #### Example -~~~ js +```js _.isEmpty([1, 2, 3]); // => false @@ -1255,7 +1255,7 @@ _.isEmpty({}); _.isEmpty(''); // => true -~~~ +``` * * * @@ -1279,7 +1279,7 @@ Performs a deep comparison between two values to determine if they are equivalen *(Boolean)*: Returns `true` if the values are equvalent, else `false`. #### Example -~~~ js +```js var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; @@ -1288,7 +1288,7 @@ moe == clone; _.isEqual(moe, clone); // => true -~~~ +``` * * * @@ -1309,7 +1309,7 @@ Checks if `value` is a finite number. Note: This is not the same as native `isF *(Boolean)*: Returns `true` if the `value` is a finite number, else `false`. #### Example -~~~ js +```js _.isFinite(-101); // => true @@ -1318,7 +1318,7 @@ _.isFinite('10'); _.isFinite(Infinity); // => false -~~~ +``` * * * @@ -1339,10 +1339,10 @@ Checks if `value` is a function. *(Boolean)*: Returns `true` if the `value` is a function, else `false`. #### Example -~~~ js +```js _.isFunction(''.concat); // => true -~~~ +``` * * * @@ -1363,7 +1363,7 @@ Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which *(Boolean)*: Returns `true` if the `value` is `NaN`, else `false`. #### Example -~~~ js +```js _.isNaN(NaN); // => true @@ -1375,7 +1375,7 @@ isNaN(undefined); _.isNaN(undefined); // => false -~~~ +``` * * * @@ -1396,13 +1396,13 @@ Checks if `value` is `null`. *(Boolean)*: Returns `true` if the `value` is `null`, else `false`. #### Example -~~~ js +```js _.isNull(null); // => true _.isNull(undefined); // => false -~~~ +``` * * * @@ -1423,10 +1423,10 @@ Checks if `value` is a number. *(Boolean)*: Returns `true` if the `value` is a number, else `false`. #### Example -~~~ js +```js _.isNumber(8.4 * 5; // => true -~~~ +``` * * * @@ -1447,13 +1447,13 @@ Checks if `value` is the language type of Object. *(e.g. arrays, functions, obje *(Boolean)*: Returns `true` if the `value` is an object, else `false`. #### Example -~~~ js +```js _.isObject({}); // => true _.isObject(1); // => false -~~~ +``` * * * @@ -1474,10 +1474,10 @@ Checks if `value` is a regular expression. *(Boolean)*: Returns `true` if the `value` is a regular expression, else `false`. #### Example -~~~ js +```js _.isRegExp(/moe/); // => true -~~~ +``` * * * @@ -1498,10 +1498,10 @@ Checks if `value` is a string. *(Boolean)*: Returns `true` if the `value` is a string, else `false`. #### Example -~~~ js +```js _.isString('moe'); // => true -~~~ +``` * * * @@ -1522,10 +1522,10 @@ Checks if `value` is `undefined`. *(Boolean)*: Returns `true` if the `value` is `undefined`, else `false`. #### Example -~~~ js +```js _.isUndefined(void 0); // => true -~~~ +``` * * * @@ -1546,10 +1546,10 @@ Creates an array composed of the own enumerable property names of `object`. *(Array)*: Returns a new array of property names. #### Example -~~~ js +```js _.keys({ 'one': 1, 'two': 2, 'three': 3 }); // => ['one', 'two', 'three'] (order is not guaranteed) -~~~ +``` * * * @@ -1572,10 +1572,10 @@ Gets the last element of the `array`. Pass `n` to return the lasy `n` elementsvo *(Mixed)*: Returns the last element or an array of the last `n` elements of `array`. #### Example -~~~ js +```js _.last([3, 2, 1]); // => 1 -~~~ +``` * * * @@ -1598,13 +1598,13 @@ Gets the index at which the last occurrence of `value` is found using strict equ *(Number)*: Returns the index of the matched value or `-1`. #### Example -~~~ js +```js _.lastIndexOf([1, 2, 3, 1, 2, 3], 2); // => 4 _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); // => 1 -~~~ +``` * * * @@ -1627,13 +1627,13 @@ Creates a new array of values by running each element in the `collection` throug *(Array)*: Returns a new array of elements returned by the callback. #### Example -~~~ js +```js _.map([1, 2, 3], function(num) { return num * 3; }); // => [3, 6, 9] _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); // => [3, 6, 9] (order is not guaranteed) -~~~ +``` * * * @@ -1656,7 +1656,7 @@ Retrieves the maximum value of an `array`. If `callback` is passed, it will be e *(Mixed)*: Returns the maximum value. #### Example -~~~ js +```js var stooges = [ { 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }, @@ -1665,7 +1665,7 @@ var stooges = [ _.max(stooges, function(stooge) { return stooge.age; }); // => { 'name': 'curly', 'age': 60 }; -~~~ +``` * * * @@ -1687,11 +1687,11 @@ Creates a new function that memoizes the result of `func`. If `resolver` is pass *(Function)*: Returns the new memoizing function. #### Example -~~~ js +```js var fibonacci = _.memoize(function(n) { return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); }); -~~~ +``` * * * @@ -1715,7 +1715,7 @@ Merges enumerable properties of the source object(s) into the `destination` obje *(Object)*: Returns the destination object. #### Example -~~~ js +```js var stooges = [ { 'name': 'moe' }, { 'name': 'larry' } @@ -1728,7 +1728,7 @@ var ages = [ _.merge(stooges, ages); // => [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] -~~~ +``` * * * @@ -1751,10 +1751,10 @@ Retrieves the minimum value of an `array`. If `callback` is passed, it will be e *(Mixed)*: Returns the minimum value. #### Example -~~~ js +```js _.min([10, 5, 100, 2, 1000]); // => 2 -~~~ +``` * * * @@ -1772,7 +1772,7 @@ Adds functions properties of `object` to the `lodash` function and chainable wra 1. `object` *(Object)*: The object of function properties to add to `lodash`. #### Example -~~~ js +```js _.mixin({ 'capitalize': function(string) { return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); @@ -1784,7 +1784,7 @@ _.capitalize('larry'); _('curly').capitalize(); // => 'Curly' -~~~ +``` * * * @@ -1802,9 +1802,9 @@ Reverts the '_' variable to its previous value and returns a reference to the `l *(Function)*: Returns the `lodash` function. #### Example -~~~ js +```js var lodash = _.noConflict(); -~~~ +``` * * * @@ -1825,12 +1825,12 @@ Creates a new function that is restricted to one execution. Repeat calls to the *(Function)*: Returns the new restricted function. #### Example -~~~ js +```js var initialize = _.once(createApplication); initialize(); initialize(); // Application is only created once. -~~~ +``` * * * @@ -1852,12 +1852,12 @@ Creates a new function that, when called, invokes `func` with any additional `pa *(Function)*: Returns the new partially applied function. #### Example -~~~ js +```js var greet = function(greeting, name) { return greeting + ': ' + name; }; var hi = _.partial(greet, 'hi'); hi('moe'); // => 'hi: moe' -~~~ +``` * * * @@ -1879,10 +1879,10 @@ Creates a shallow clone of `object` composed of the specified properties. Proper *(Object)*: Returns an object composed of the picked properties. #### Example -~~~ js +```js _.pick({ 'name': 'moe', 'age': 40, 'userid': 'moe1' }, 'name', 'age'); // => { 'name': 'moe', 'age': 40 } -~~~ +``` * * * @@ -1904,7 +1904,7 @@ Retrieves the value of a specified property from all elements in the `collection *(Array)*: Returns a new array of property values. #### Example -~~~ js +```js var stooges = [ { 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }, @@ -1913,7 +1913,7 @@ var stooges = [ _.pluck(stooges, 'name'); // => ['moe', 'larry', 'curly'] -~~~ +``` * * * @@ -1936,7 +1936,7 @@ Creates an array of numbers *(positive and/or negative)* progressing from `start *(Array)*: Returns a new range array. #### Example -~~~ js +```js _.range(10); // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] @@ -1951,7 +1951,7 @@ _.range(0, -10, -1); _.range(0); // => [] -~~~ +``` * * * @@ -1975,10 +1975,10 @@ Boils down a `collection` to a single value. The initial state of the reduction *(Mixed)*: Returns the accumulated value. #### Example -~~~ js +```js var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); // => 6 -~~~ +``` * * * @@ -2002,11 +2002,11 @@ The right-associative version of `_.reduce`. *(Mixed)*: Returns the accumulated value. #### Example -~~~ js +```js var list = [[0, 1], [2, 3], [4, 5]]; var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []); // => [4, 5, 2, 3, 0, 1] -~~~ +``` * * * @@ -2029,10 +2029,10 @@ The opposite of `_.filter`, this method returns the values of a `collection` tha *(Array)*: Returns a new array of elements that did **not** pass the callback check. #### Example -~~~ js +```js var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); // => [1, 3, 5] -~~~ +``` * * * @@ -2055,10 +2055,10 @@ The opposite of `_.initial`, this method gets all but the first value of `array` *(Array)*: Returns all but the first value or `n` values of `array`. #### Example -~~~ js +```js _.rest([3, 2, 1]); // => [2, 1] -~~~ +``` * * * @@ -2080,7 +2080,7 @@ Resolves the value of `property` on `object`. If `property` is a function it wil *(Mixed)*: Returns the resolved value. #### Example -~~~ js +```js var object = { 'cheese': 'crumpets', 'stuff': function() { @@ -2093,7 +2093,7 @@ _.result(object, 'cheese'); _.result(object, 'stuff'); // => 'nonsense' -~~~ +``` * * * @@ -2114,10 +2114,10 @@ Creates a new array of shuffled `array` values, using a version of the Fisher-Ya *(Array)*: Returns a new shuffled array. #### Example -~~~ js +```js _.shuffle([1, 2, 3, 4, 5, 6]); // => [4, 1, 6, 3, 5, 2] -~~~ +``` * * * @@ -2138,7 +2138,7 @@ Gets the size of `value` by returning `value.length` if `value` is an array, str *(Number)*: Returns `value.length` or number of own enumerable properties. #### Example -~~~ js +```js _.size([1, 2]); // => 2 @@ -2147,7 +2147,7 @@ _.size({ 'one': 1, 'two': 2, 'three': 3 }); _.size('curly'); // => 5 -~~~ +``` * * * @@ -2170,10 +2170,10 @@ Checks if the `callback` returns a truthy value for **any** element of a `collec *(Boolean)*: Returns `true` if any element passes the callback check, else `false`. #### Example -~~~ js +```js _.some([null, 0, 'yes', false]); // => true -~~~ +``` * * * @@ -2196,7 +2196,7 @@ Creates a new sorted array, sorted in ascending order by the results of running *(Array)*: Returns a new array of sorted elements. #### Example -~~~ js +```js _.sortBy([1, 2, 3], function(num) { return Math.sin(num); }); // => [3, 1, 2] @@ -2205,7 +2205,7 @@ _.sortBy([1, 2, 3], function(num) { return this.sin(num); }, Math); _.sortBy(['larry', 'brendan', 'moe'], 'length'); // => ['moe', 'larry', 'brendan'] -~~~ +``` * * * @@ -2229,7 +2229,7 @@ Uses a binary search to determine the smallest index at which the `value` should *(Number)*: Returns the index at which the value should be inserted into `array`. #### Example -~~~ js +```js _.sortedIndex([20, 30, 40], 35); // => 2 @@ -2246,7 +2246,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { return this.wordToNumber[word]; }, dict); // => 2 -~~~ +``` * * * @@ -2268,7 +2268,7 @@ Invokes `interceptor` with the `value` as the first argument, and then returns ` *(Mixed)*: Returns `value`. #### Example -~~~ js +```js _.chain([1,2,3,200]) .filter(function(num) { return num % 2 == 0; }) .tap(alert) @@ -2276,7 +2276,7 @@ _.chain([1,2,3,200]) .value(); // => // [2, 200] (alerted) // => [4, 40000] -~~~ +``` * * * @@ -2299,7 +2299,7 @@ A micro-templating method that handles arbitrary delimiters, preserves whitespac *(Function, String)*: Returns a compiled function when no `data` object is given, else it returns the interpolated text. #### Example -~~~ js +```js // using compiled template var compiled = _.template('hello: <%= name %>'); compiled({ 'name': 'moe' }); @@ -2335,7 +2335,7 @@ _.template('Using a with-statement: <%= data.answer %>', { 'answer': 'no' }, { ' -~~~ +``` * * * @@ -2357,10 +2357,10 @@ Creates a new function that, when executed, will only call the `func` function a *(Function)*: Returns the new throttled function. #### Example -~~~ js +```js var throttled = _.throttle(updatePosition, 100); jQuery(window).on('scroll', throttled); -~~~ +``` * * * @@ -2380,13 +2380,13 @@ Executes the `callback` function `n` times. The `callback` is bound to `thisArg` 3. `[thisArg]` *(Mixed)*: The `this` binding for the callback. #### Example -~~~ js +```js _.times(3, function() { genie.grantWish(); }); // => calls `genie.grantWish()` 3 times _.times(3, function() { this.grantWish(); }, genie); // => also calls `genie.grantWish()` 3 times -~~~ +``` * * * @@ -2407,10 +2407,10 @@ Converts the `collection`, into an array. Useful for converting the `arguments` *(Array)*: Returns the new converted array. #### Example -~~~ js +```js (function() { return _.toArray(arguments).slice(1); })(1, 2, 3, 4); // => [2, 3, 4] -~~~ +``` * * * @@ -2431,10 +2431,10 @@ Computes the union of the passed-in arrays using strict equality for comparisons *(Array)*: Returns a new array of unique values, in order, that are present in one or more of the arrays. #### Example -~~~ js +```js _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]); // => [1, 2, 3, 101, 10] -~~~ +``` * * * @@ -2458,7 +2458,7 @@ Creates a duplicate-value-free version of the `array` using strict equality for *(Array)*: Returns a duplicate-value-free array. #### Example -~~~ js +```js _.uniq([1, 2, 1, 3, 1]); // => [1, 2, 3] @@ -2470,7 +2470,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return Math.floor(num); }); _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); // => [1, 2, 3] -~~~ +``` * * * @@ -2491,10 +2491,10 @@ Generates a unique id. If `prefix` is passed, the id will be appended to it. *(Number, String)*: Returns a numeric id if no prefix is passed, else a string id may be returned. #### Example -~~~ js +```js _.uniqueId('contact_'); // => 'contact_104' -~~~ +``` * * * @@ -2515,10 +2515,10 @@ Creates an array composed of the own enumerable property values of `object`. *(Array)*: Returns a new array of property values. #### Example -~~~ js +```js _.values({ 'one': 1, 'two': 2, 'three': 3 }); // => [1, 2, 3] -~~~ +``` * * * @@ -2540,7 +2540,7 @@ Examines each element in a `collection`, returning an array of all elements that *(Array)*: Returns a new array of elements that contain the given `properties`. #### Example -~~~ js +```js var stooges = [ { 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }, @@ -2549,7 +2549,7 @@ var stooges = [ _.where(stooges, { 'age': 40 }); // => [{ 'name': 'moe', 'age': 40 }] -~~~ +``` * * * @@ -2571,10 +2571,10 @@ Creates a new array with all occurrences of the passed values removed using stri *(Array)*: Returns a new filtered array. #### Example -~~~ js +```js _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); // => [2, 3, 4] -~~~ +``` * * * @@ -2596,14 +2596,14 @@ Creates a new function that passes `value` to the `wrapper` function as its firs *(Function)*: Returns the new function. #### Example -~~~ js +```js var hello = function(name) { return 'hello: ' + name; }; hello = _.wrap(hello, function(func) { return 'before, ' + func('moe') + ', after'; }); hello(); // => 'before, hello: moe, after' -~~~ +``` * * * @@ -2624,10 +2624,10 @@ Groups the elements of each array at their corresponding indexes. Useful for sep *(Array)*: Returns a new array of grouped elements. #### Example -~~~ js +```js _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); // => [['moe', 30, true], ['larry', 40, false], ['curly', 50, false]] -~~~ +``` * * * @@ -2649,10 +2649,10 @@ Creates an object composed from an array of `keys` and an array of `values`. *(Object)*: Returns an object composed of the given keys and corresponding values. #### Example -~~~ js +```js _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); // => { 'moe': 30, 'larry': 40, 'curly': 50 } -~~~ +``` * * * @@ -2677,10 +2677,10 @@ Enables method chaining on the wrapper object. *(Mixed)*: Returns the wrapper object. #### Example -~~~ js +```js _([1, 2, 3]).value(); // => [1, 2, 3] -~~~ +``` * * * @@ -2698,10 +2698,10 @@ Extracts the wrapped value. *(Mixed)*: Returns the wrapped value. #### Example -~~~ js +```js _([1, 2, 3]).value(); // => [1, 2, 3] -~~~ +``` * * * From 15b14e12e2398f429497bd15a0c12ae5b81aa6ed Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 17 Aug 2012 13:04:32 -0700 Subject: [PATCH 77/77] Change to triple-backtick code fences. Former-commit-id: 81d38ed0155734a72d98b2e16425635da907aa01 --- vendor/benchmark.js/README.md | 36 ++++++++++++++-------------- vendor/docdown/README.md | 4 ++-- vendor/docdown/src/DocDown/Entry.php | 2 +- vendor/platform.js/README.md | 24 +++++++++---------- vendor/qunit-clib/README.md | 4 ++-- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/vendor/benchmark.js/README.md b/vendor/benchmark.js/README.md index 1578b4f593..603d1a336b 100644 --- a/vendor/benchmark.js/README.md +++ b/vendor/benchmark.js/README.md @@ -20,15 +20,15 @@ Benchmark.js has been tested in at least Adobe AIR 3.1, Chrome 5-21, Firefox 1.5 In a browser or Adobe AIR: -~~~ html +```html -~~~ +``` Optionally, expose Java’s nanosecond timer by adding the `nano` applet to the ``: -~~~ html +```html -~~~ +``` Or enable Chrome’s microsecond timer by using the [command line switch](http://peter.sh/experiments/chromium-command-line-switches/#enable-benchmarking): @@ -36,37 +36,37 @@ Or enable Chrome’s microsecond timer by using the [command line switch](http:/ Via [npm](http://npmjs.org/): -~~~ bash +```bash npm install benchmark -~~~ +``` In [Node.js](http://nodejs.org/) and [RingoJS v0.8.0+](http://ringojs.org/): -~~~ js +```js var Benchmark = require('benchmark'); -~~~ +``` Optionally, use the [microtime module](https://github.com/wadey/node-microtime) by Wade Simmons: -~~~ bash +```bash npm install microtime -~~~ +``` In [RingoJS v0.7.0-](http://ringojs.org/): -~~~ js +```js var Benchmark = require('benchmark').Benchmark; -~~~ +``` In [Rhino](http://www.mozilla.org/rhino/): -~~~ js +```js load('benchmark.js'); -~~~ +``` In an AMD loader like [RequireJS](http://requirejs.org/): -~~~ js +```js require({ 'paths': { 'benchmark': 'path/to/benchmark' @@ -88,11 +88,11 @@ require({ Benchmark.platform = platform; console.log(Benchmark.platform.name); }); -~~~ +``` Usage example: -~~~ js +```js var suite = new Benchmark.Suite; // add tests @@ -116,7 +116,7 @@ suite.add('RegExp#test', function() { // > RegExp#test x 4,161,532 +-0.99% (59 cycles) // > String#indexOf x 6,139,623 +-1.00% (131 cycles) // > Fastest is String#indexOf -~~~ +``` ## BestieJS diff --git a/vendor/docdown/README.md b/vendor/docdown/README.md index 7581efc720..7e2665e38d 100644 --- a/vendor/docdown/README.md +++ b/vendor/docdown/README.md @@ -12,7 +12,7 @@ For a list of upcoming features, check out our [roadmap](https://github.com/jdal Usage example: -~~~ php +```php require("docdown.php"); // generate Markdown @@ -20,7 +20,7 @@ $markdown = docdown(array( "path" => $filepath, "url" => "https://github.com/username/project/blob/master/my.js" )); -~~~ +``` ## Author diff --git a/vendor/docdown/src/DocDown/Entry.php b/vendor/docdown/src/DocDown/Entry.php index 87a8c19af3..e7924c0ebd 100644 --- a/vendor/docdown/src/DocDown/Entry.php +++ b/vendor/docdown/src/DocDown/Entry.php @@ -140,7 +140,7 @@ public function getExample() { preg_match('#\*\s*@example\s+([\s\S]*?)(?=\*\s\@[a-z]|\*/)#', $this->entry, $result); if (count($result)) { $result = trim(preg_replace('/(?:^|\n)\s*\* ?/', "\n", $result[1])); - $result = '~~~ ' . $this->lang . "\n" . $result . "\n~~~"; + $result = '```' . $this->lang . "\n" . $result . "\n```"; } return $result; } diff --git a/vendor/platform.js/README.md b/vendor/platform.js/README.md index e83e43fb7a..b9133118ed 100644 --- a/vendor/platform.js/README.md +++ b/vendor/platform.js/README.md @@ -24,31 +24,31 @@ Platform.js has been tested in at least Adobe AIR 3.1, Chrome 5-21, Firefox 1.5- In a browser or Adobe AIR: -~~~ html +```html -~~~ +``` Via [npm](http://npmjs.org/): -~~~ bash +```bash npm install platform -~~~ +``` In [Node.js](http://nodejs.org/) and [RingoJS](http://ringojs.org/): -~~~ js +```js var platform = require('platform'); -~~~ +``` In [Rhino](http://www.mozilla.org/rhino/): -~~~ js +```js load('platform.js'); -~~~ +``` In an AMD loader like [RequireJS](http://requirejs.org/): -~~~ js +```js require({ 'paths': { 'platform': 'path/to/platform' @@ -57,11 +57,11 @@ require({ ['platform'], function(platform) { console.log(platform.name); }); -~~~ +``` Usage example: -~~~ js +```js // on IE10 x86 platform preview running in IE7 compatibility mode on Windows 7 64 bit edition platform.name; // 'IE' platform.version; // '10.0' @@ -85,7 +85,7 @@ info.version; // '11.52' info.layout; // 'Presto' info.os; // 'Mac OS X 10.7.2' info.description; // 'Opera 11.52 (identifying as Firefox 4.0) on Mac OS X 10.7.2' -~~~ +``` ## Author diff --git a/vendor/qunit-clib/README.md b/vendor/qunit-clib/README.md index 8c4259b460..b84a21c98f 100644 --- a/vendor/qunit-clib/README.md +++ b/vendor/qunit-clib/README.md @@ -13,7 +13,7 @@ QUnit CLIB has been tested in at least Node.js 0.4.8-0.8.6, Narwhal v0.3.2, Ring ## Usage -~~~ js +```js (function(window) { // use a single load function @@ -43,7 +43,7 @@ QUnit CLIB has been tested in at least Node.js 0.4.8-0.8.6, Narwhal v0.3.2, Ring QUnit.start(); } }(typeof global == 'object' && global || this)); -~~~ +``` ## Footnotes