From 79a289c7e2e7f0dd70eef17f886ab7e4ec977b5c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 02:06:55 -0400 Subject: [PATCH 01/21] Update CDN copy link. Former-commit-id: 4d0d26292eef227f343f6b482856482f8f554a43 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 88ce31ece5..052d4839b9 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.1/lodash.js) * [Production source](https://raw.github.com/bestiejs/lodash/v0.4.1/lodash.min.js) - * CDN copies of ≤ [v0.3.2](http://cdnjs.cloudflare.com/ajax/libs/lodash.js/0.3.2/lodash.min.js) are available on [cdnjs](http://cdnjs.com/) thanks to [CloudFlare](http://www.cloudflare.com/) + * 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/) * For optimal performance, [create a custom build](https://github.com/bestiejs/lodash#custom-builds) with only the features you need ## Dive in From 61105e0679a729a0736651eff6e95fa8d53a7a82 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 03:27:15 -0400 Subject: [PATCH 02/21] Cleanup inline documentation. Former-commit-id: 1fa95d45c2c3d1fe50f5827f4743aad3c8b75f95 --- doc/README.md | 190 +++++++++++++++++++++++++------------------------- lodash.js | 45 +++++------- 2 files changed, 113 insertions(+), 122 deletions(-) diff --git a/doc/README.md b/doc/README.md index b01d7a65af..5a8204a94d 100644 --- a/doc/README.md +++ b/doc/README.md @@ -148,7 +148,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3563 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3554 "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#L1946 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1937 "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#L2000 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1991 "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#L2070 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2061 "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#L3488 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3479 "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#L2396 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2387 "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#L1193 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1184 "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#L2102 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2093 "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()))`. @@ -410,7 +410,7 @@ _.contains('curly', 'ur'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2135 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2126 "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#L2419 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2410 "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#L2200 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2191 "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#L2180 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2171 "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#L1225 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1216 "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#L3128 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3119 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -563,9 +563,9 @@ _.escape('Curly, Larry & Moe'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L748 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L747 "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; for arrays they are *(value, index, array)* and for objects they are *(value, key, object)*. +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)*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -589,7 +589,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2438 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2429 "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,9 +614,9 @@ _.extend({ 'name': 'moe' }, { 'age': 40 }); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L769 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L767 "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; for arrays they are *(value, index, array)* and for objects they are *(value, key, object)*. +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)*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -640,9 +640,9 @@ 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#L791 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L788 "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; for arrays they are *(value, index, array)* and for objects they are *(value, key, object)*. +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)*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -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#L1261 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1252 "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#L1285 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1276 "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,9 +720,9 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.forEach(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L818 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L814 "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; for arrays they are *(value, index, array)* and for objects they are *(value, key, object)*. +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)*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -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#L2467 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2458 "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#L2490 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2481 "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#L2507 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2498 "View in source") [Ⓣ][1] Produces a sorted array of the enumerable properties, own and inherited, of `object` that have function values. @@ -837,9 +837,9 @@ _.functions(_); ### `_.groupBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L846 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L841 "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; for arrays they are *(value, index, array)* and for objects they are *(value, key, object)*. The `callback` argument may also be the name of a property to group by. +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. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -869,7 +869,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2530 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2521 "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#L3147 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3138 "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#L1329 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1320 "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#L1369 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1360 "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#L1390 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1381 "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#L880 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L875 "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#L2550 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2541 "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#L2576 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2567 "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#L2593 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2584 "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#L2610 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2601 "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#L2627 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2618 "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#L2651 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2642 "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#L2685 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2676 "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#L2846 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2837 "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#L2863 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2854 "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#L2915 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2906 "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#L2938 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2929 "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#L2955 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2946 "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#L2884 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2875 "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#L2972 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2963 "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#L2989 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2980 "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#L3007 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2998 "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#L3024 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3015 "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#L1428 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1419 "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#L1454 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1445 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. @@ -1534,9 +1534,9 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L917 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L911 "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; for arrays they are *(value, index, array)* and for objects they are *(value, key, object)*. +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)*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -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#L1494 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1485 "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#L2223 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2214 "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#L1544 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1535 "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#L3173 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3164 "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#L3204 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3195 "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#L2249 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2240 "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#L2282 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2273 "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#L3046 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3037 "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#L940 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L934 "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#L1605 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1596 "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,9 +1844,9 @@ _.range(0); ### `_.reduce(collection, callback [, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L969 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L962 "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, array)* and for objects they are *(accumulator, value, key, object)*. +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)*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -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#L1006 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L999 "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#L1061 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1054 "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#L1642 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1633 "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#L3236 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3227 "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#L1663 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1654 "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#L3085 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3076 "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,9 +2040,9 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1085 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1077 "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; for arrays they are *(value, index, array)* and for objects they are *(value, key, object)*. +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)*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -2066,9 +2066,9 @@ _.some([null, 0, 'yes', false]); ### `_.sortBy(collection, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1118 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1109 "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; for arrays they are *(value, index, array)* and for objects they are *(value, key, object)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. +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')*. #### Arguments 1. `collection` *(Array|Object|String)*: The collection to iterate over. @@ -2098,7 +2098,7 @@ _.sortBy(['larry', 'brendan', 'moe'], 'length'); ### `_.sortedIndex(array, value [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1715 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1706 "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#L3515 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3506 "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#L3296 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3287 "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#L2318 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2309 "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#L3431 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3422 "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#L1161 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1152 "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#L1755 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1746 "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#L1800 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1791 "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#L3458 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3449 "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#L3106 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3097 "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#L1849 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1840 "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#L2370 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2361 "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#L1881 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1872 "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#L1910 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1901 "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#L3533 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3524 "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#L3550 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3541 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index 432956722a..332ee65ae2 100644 --- a/lodash.js +++ b/lodash.js @@ -123,7 +123,7 @@ */ var hasDontEnumBug = !propertyIsEnumerable.call({ 'valueOf': 0 }, 'valueOf'); - /** Detect if `Array#slice` cannot be used to convert strings to arrays (e.g. Opera < 10.52) */ + /** Detect if `Array#slice` cannot be used to convert strings to arrays (Opera < 10.52) */ var noArraySliceOnStrings = slice.call('x')[0] != 'x'; /** @@ -133,10 +133,10 @@ */ var noCharByIndex = ('x'[0] + Object('x')[0]) != 'xx'; - /* Detect if `Function#bind` exists and is inferred to be fast (i.e. all but V8) */ + /* 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 (i.e. V8, Opera, IE) */ + /* Detect if `Object.keys` exists and is inferred to be fast (V8, Opera, IE) */ var isKeysFast = nativeKeys && /^.+$|true/.test(nativeKeys + !!window.attachEvent); /** Detect if sourceURL syntax is usable without erroring */ @@ -729,8 +729,7 @@ /** * 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; for arrays they are (value, index, array) and for objects they - * are (value, key, object). + * arguments; (value, index|key, collection). * * @static * @memberOf _ @@ -750,8 +749,7 @@ /** * 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; for arrays they are (value, index, array) and for - * objects they are (value, key, object). + * invoked with 3 arguments; (value, index|key, collection). * * @static * @memberOf _ @@ -772,8 +770,7 @@ * 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; for arrays they are - * (value, index, array) and for objects they are (value, key, object). + * bound to `thisArg` and invoked with 3 arguments; (value, index|key, collection). * * @static * @memberOf _ @@ -796,8 +793,7 @@ /** * Iterates over a `collection`, executing the `callback` for each value in the * `collection`. The `callback` is bound to `thisArg` and invoked with 3 - * arguments; for arrays they are (value, index, array) and for objects they - * are (value, key, object). + * arguments; (value, index|key, collection). * * @static * @memberOf _ @@ -820,9 +816,8 @@ /** * 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; for arrays they are (value, index, array) and for objects they - * are (value, key, object). The `callback` argument may also be the name of a - * property to group by. + * 3 arguments; (value, index|key, collection). The `callback` argument may + * also be the name of a property to group by. * * @static * @memberOf _ @@ -895,8 +890,7 @@ /** * 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; for arrays they are (value, index, array) - * and for objects they are (value, key, object). + * and invoked with 3 arguments; (value, index|key, collection). * * @static * @memberOf _ @@ -949,8 +943,7 @@ * 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, array) and for - * objects they are (accumulator, value, key, object). + * arguments; for arrays they are (accumulator, value, index|key, collection). * * @static * @memberOf _ @@ -1043,8 +1036,8 @@ } /** - * The opposite of `_.filter`, this method returns the values of a `collection` - * that `callback` does **not** return truthy for. + * The opposite of `_.filter`, this method returns the values of a + * `collection` that `callback` does **not** return truthy for. * * @static * @memberOf _ @@ -1066,8 +1059,7 @@ * 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; for arrays they are - * (value, index, array) and for objects they are (value, key, object). + * `thisArg` and invoked with 3 arguments; (value, index|key, collection). * * @static * @memberOf _ @@ -1092,9 +1084,8 @@ * 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; - * for arrays they are (value, index, array) and for objects they are - * (value, key, object). The `callback` argument may also be the name of a - * property to sort by (e.g. 'length'). + * (value, index|key, collection). The `callback` argument may also be the + * name of a property to sort by (e.g. 'length'). * * @static * @memberOf _ @@ -2729,8 +2720,8 @@ 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 + // 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 From 4293515b3d9d527d9cf96a92c2663325f04c10a0 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 13:26:14 -0400 Subject: [PATCH 03/21] Add `help` and `version` options to build.js. Former-commit-id: 95a9fdaa7a00550922e71ce01a3f742b845d082c --- README.md | 16 ++++++++-------- build.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 052d4839b9..66e7deb119 100644 --- a/README.md +++ b/README.md @@ -75,23 +75,23 @@ lodash category=collections,functions lodash category="collections, functions" ~~~ - 2. Use the `include` argument to pass the names of methods to include in the build. + 2. Use the `exclude` argument to pass the names of methods to exclude from the build. ~~~ bash -lodash include=each,filter,map -lodash include="each, filter, map" +lodash exclude=union,uniq,zip +lodash exclude="union, uniq, zip" ~~~ - 3. Use the `exclude` argument to pass the names of methods to exclude from the build. + 3. Use the `include` argument to pass the names of methods to include in the build. ~~~ bash -lodash exclude=union,uniq,zip -lodash exclude="union, uniq, zip" +lodash include=each,filter,map +lodash include="each, filter, map" ~~~ -All arguments, except `include` with `exclude` and `mobile` with `legacy`, may be combined. +All arguments, except `exclude` with `include` and `legacy` with `mobile`, may be combined. ~~~ bash -lodash backbone mobile category=functions include=pick,uniq lodash backbone legacy category=utilities exclude=first,last +lodash backbone mobile category=functions include=pick,uniq ~~~ The `lodash` command-line utility is available when Lo-Dash is installed as a global package (i.e. `npm install -g lodash`). diff --git a/build.js b/build.js index 26ba3eea9a..2a57c6a833 100755 --- a/build.js +++ b/build.js @@ -29,7 +29,6 @@ /** Load customized Lo-Dash module */ var lodash = (function() { var sandbox = {}; - if (isLegacy) { ['isBindFast', 'isKeysFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) { source = replaceVar(source, varName, 'false'); @@ -261,6 +260,33 @@ /*--------------------------------------------------------------------------*/ + /** + * Logs the help message to the console. + * + * @private + */ + function displayHelp() { + console.log([ + '', + ' Commands:', + '', + ' 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 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.', + '', + ' Options:', + '', + ' -h, --help Display help information', + ' -V, --version Output current version of Lo-Dash', + '' + ].join('\n')); + } + /** * Gets the aliases associated with a given function name. * @@ -537,6 +563,24 @@ /*--------------------------------------------------------------------------*/ + // display help message + if (lodash.find(process.argv, function(arg) { + return /^(?:-h|--help)$/.test(arg); + })) { + displayHelp(); + process.exit(); + } + + // display `lodash.VERSION` + if (lodash.find(process.argv, function(arg) { + return /^(?:-V|--version)$/.test(arg); + })) { + console.log(lodash.VERSION); + process.exit(); + } + + /*--------------------------------------------------------------------------*/ + // Backbone build if (isBackbone) { // add any additional sub-dependencies From 9530efb4d429bd43dc5dcc57557b805120558063 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 13:32:48 -0400 Subject: [PATCH 04/21] Update vendor folder. Former-commit-id: 363508c8d79afa1ec8c1aba48b5be58a8a572367 --- test/test.js | 2 +- vendor/qunit-clib/qunit-clib.js | 78 ++++++++++++---------- vendor/qunit/README.md | 9 +-- vendor/qunit/qunit/qunit.css | 41 +++++------- vendor/qunit/qunit/qunit.js | 113 +++++++++++++++++++++++++------- 5 files changed, 157 insertions(+), 86 deletions(-) diff --git a/test/test.js b/test/test.js index a916c2d109..8771e0c08c 100644 --- a/test/test.js +++ b/test/test.js @@ -740,7 +740,7 @@ }); test('should raise an error if a template, compiled with errors, is executed', function() { - raises(_.template('<% if x %>')); + throws(_.template('<% if x %>')); }); test('should work with complex "interpolate" delimiters', function() { diff --git a/vendor/qunit-clib/qunit-clib.js b/vendor/qunit-clib/qunit-clib.js index 236785e4e6..c5ff65324b 100644 --- a/vendor/qunit-clib/qunit-clib.js +++ b/vendor/qunit-clib/qunit-clib.js @@ -5,6 +5,7 @@ * Available under MIT license */ ;(function(global) { + 'use strict'; /** Add `console.log()` support for Narwhal, Rhino, and RingoJS */ global.console || (global.console = { 'log': global.print }); @@ -24,7 +25,8 @@ var toString = {}.toString; /** Used by timer methods */ - var timer, + var doneCalled, + timer, counter = 0, ids = {}; @@ -149,26 +151,26 @@ * `runtime`, and `total`. */ function done(details) { - // stop `asyncTest()` from erroneously calling `done()` twice in environments w/o timeouts - if (!QUnit.doneCalled) { - console.log(hr); - console.log(' PASS: ' + details.passed + ' FAIL: ' + details.failed + ' TOTAL: ' + details.total); - console.log(' Finished in ' + details.runtime + ' milliseconds.'); - console.log(hr); - - // exit out of Rhino - try { - quit(); - } catch(e) { } - - // exit out of Node.js - try { - process.exit(); - } catch(e) { } - - // prevent multiple calls to `done()` - QUnit.doneCalled = true; + // stop `asyncTest()` from erroneously calling `done()` twice in + // environments w/o timeouts + if (doneCalled) { + return; } + doneCalled = true; + console.log(hr); + console.log(' PASS: ' + details.passed + ' FAIL: ' + details.failed + ' TOTAL: ' + details.total); + console.log(' Finished in ' + details.runtime + ' milliseconds.'); + console.log(hr); + + // exit out of Rhino + try { + quit(); + } catch(e) { } + + // exit out of Node.js + try { + process.exit(); + } catch(e) { } } /** @@ -181,12 +183,13 @@ function log(details) { var expected = details.expected, result = details.result, - type = typeof expected != 'undefined' ? 'EQ' : 'OK', - assertion = [ - result ? 'PASS' : 'FAIL', - type, - details.message || 'ok' - ]; + type = typeof expected != 'undefined' ? 'EQ' : 'OK'; + + var assertion = [ + result ? 'PASS' : 'FAIL', + type, + details.message || 'ok' + ]; if (!result && type == 'EQ') { assertion.push('Expected: ' + expected + ', Actual: ' + details.actual); @@ -215,7 +218,7 @@ * @returns {String} The result string. */ var parseObject = (function() { - var _parseObject = QUnit.jsDump.parsers.object; + var func = QUnit.jsDump.parsers.object; return function(object) { // fork to support Rhino's error objects if (typeof object.rhinoException == 'object') { @@ -224,7 +227,7 @@ '", fileName: "' + object.fileName + '", lineNumber: ' + object.lineNumber + ' }'; } - return _parseObject(object); + return func(object); }; }()); @@ -237,16 +240,16 @@ */ function testDone(details) { var assertions = QUnit.config.testStats.assertions, - name = details.name; + testName = details.name; if (details.failed > 0) { - console.log(' FAIL - '+ name); + console.log(' FAIL - '+ testName); each(assertions, function(value) { console.log(' ' + value); }); } else { - console.log(' PASS - ' + name); + console.log(' PASS - ' + testName); } assertions.length = 0; } @@ -274,8 +277,11 @@ // exclude `module` because some environments have it as a built-in object each(['asyncTest', 'deepEqual', 'equal', 'equals', 'expect', 'notDeepEqual', 'notEqual', 'notStrictEqual', 'ok', 'raises', 'same', 'start', 'stop', - 'strictEqual', 'test'], function(name) { - global[name] = QUnit[name]; + 'strictEqual', 'test', 'throws'], function(funcName) { + var func = QUnit[funcName]; + if (func) { + global[funcName] = func; + } }); // expose timer methods to global @@ -301,11 +307,11 @@ QUnit.moduleStart(moduleStart); QUnit.testDone(testDone); - // wrap `parseObject` + // add wrapped function QUnit.jsDump.parsers.object = parseObject; - // must call `QUnit.start()` in the test file if using QUnit < 1.3.0 with Node.js - // or any version of QUnit with Narwhal, Rhino, or RingoJS + // must call `QUnit.start()` in the test file if using QUnit < 1.3.0 with + // Node.js or any version of QUnit with Narwhal, Rhino, or RingoJS QUnit.init(); }(typeof global == 'object' && global || this)); diff --git a/vendor/qunit/README.md b/vendor/qunit/README.md index f51d74caf7..3778a27b4a 100644 --- a/vendor/qunit/README.md +++ b/vendor/qunit/README.md @@ -41,8 +41,9 @@ Releases -------- Install git-extras and run `git changelog` to update History.md. -Update qunit/qunit.js|css to the release version, commit and tag, update them -again to the next version, commit and push commits and tags. +Update qunit/qunit.js|css and package.json to the release version, commit and +tag, update them again to the next version, commit and push commits and tags +(`git push --tags origin master`). -Put the 'v' in front of the tag (unlike the 1.1.0 release). Clean up the changelog, -removing merge commits or whitespace cleanups. +Put the 'v' in front of the tag, e.g. `v1.8.0`. Clean up the changelog, removing merge commits +or whitespace cleanups. diff --git a/vendor/qunit/qunit/qunit.css b/vendor/qunit/qunit/qunit.css index 5684a44859..257b224ff4 100644 --- a/vendor/qunit/qunit/qunit.css +++ b/vendor/qunit/qunit/qunit.css @@ -1,5 +1,5 @@ /** - * QUnit v1.8.0 - A JavaScript Unit Testing Framework + * QUnit v1.9.0 - A JavaScript Unit Testing Framework * * http://docs.jquery.com/QUnit * @@ -38,10 +38,10 @@ line-height: 1em; font-weight: normal; - border-radius: 15px 15px 0 0; - -moz-border-radius: 15px 15px 0 0; - -webkit-border-top-right-radius: 15px; - -webkit-border-top-left-radius: 15px; + border-radius: 5px 5px 0 0; + -moz-border-radius: 5px 5px 0 0; + -webkit-border-top-right-radius: 5px; + -webkit-border-top-left-radius: 5px; } #qunit-header a { @@ -54,9 +54,9 @@ color: #fff; } -#qunit-header label { +#qunit-testrunner-toolbar label { display: inline-block; - padding-left: 0.5em; + padding: 0 .5em 0 .1em; } #qunit-banner { @@ -113,13 +113,9 @@ background-color: #fff; - border-radius: 15px; - -moz-border-radius: 15px; - -webkit-border-radius: 15px; - - box-shadow: inset 0px 2px 13px #999; - -moz-box-shadow: inset 0px 2px 13px #999; - -webkit-box-shadow: inset 0px 2px 13px #999; + border-radius: 5px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; } #qunit-tests table { @@ -162,8 +158,7 @@ #qunit-tests b.failed { color: #710909; } #qunit-tests li li { - margin: 0.5em; - padding: 0.4em 0.5em 0.4em 0.5em; + padding: 5px; background-color: #fff; border-bottom: none; list-style-position: inside; @@ -172,9 +167,9 @@ /*** Passing Styles */ #qunit-tests li li.pass { - color: #5E740B; + color: #3c510c; background-color: #fff; - border-left: 26px solid #C6E746; + border-left: 10px solid #C6E746; } #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } @@ -190,15 +185,15 @@ #qunit-tests li li.fail { color: #710909; background-color: #fff; - border-left: 26px solid #EE5757; + border-left: 10px solid #EE5757; white-space: pre; } #qunit-tests > li:last-child { - border-radius: 0 0 15px 15px; - -moz-border-radius: 0 0 15px 15px; - -webkit-border-bottom-right-radius: 15px; - -webkit-border-bottom-left-radius: 15px; + border-radius: 0 0 5px 5px; + -moz-border-radius: 0 0 5px 5px; + -webkit-border-bottom-right-radius: 5px; + -webkit-border-bottom-left-radius: 5px; } #qunit-tests .fail { color: #000000; background-color: #EE5757; } diff --git a/vendor/qunit/qunit/qunit.js b/vendor/qunit/qunit/qunit.js index c1570c2520..9efedcb442 100644 --- a/vendor/qunit/qunit/qunit.js +++ b/vendor/qunit/qunit/qunit.js @@ -1,5 +1,5 @@ /** - * QUnit v1.8.0 - A JavaScript Unit Testing Framework + * QUnit v1.9.0 - A JavaScript Unit Testing Framework * * http://docs.jquery.com/QUnit * @@ -403,6 +403,8 @@ QUnit = { QUnit.assert = { /** * Asserts rough true-ish result. + * @name ok + * @function * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); */ ok: function( result, msg ) { @@ -437,36 +439,59 @@ QUnit.assert = { /** * Assert that the first two arguments are equal, with an optional message. * Prints out both actual and expected values. + * @name equal + * @function * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" ); */ equal: function( actual, expected, message ) { QUnit.push( expected == actual, actual, expected, message ); }, + /** + * @name notEqual + * @function + */ notEqual: function( actual, expected, message ) { QUnit.push( expected != actual, actual, expected, message ); }, + /** + * @name deepEqual + * @function + */ deepEqual: function( actual, expected, message ) { QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); }, + /** + * @name notDeepEqual + * @function + */ notDeepEqual: function( actual, expected, message ) { QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); }, + /** + * @name strictEqual + * @function + */ strictEqual: function( actual, expected, message ) { QUnit.push( expected === actual, actual, expected, message ); }, + /** + * @name notStrictEqual + * @function + */ notStrictEqual: function( actual, expected, message ) { QUnit.push( expected !== actual, actual, expected, message ); }, - raises: function( block, expected, message ) { + throws: function( block, expected, message ) { var actual, ok = false; + // 'expected' is optional if ( typeof expected === "string" ) { message = expected; expected = null; @@ -494,18 +519,29 @@ QUnit.assert = { } else if ( expected.call( {}, actual ) === true ) { ok = true; } - } - QUnit.push( ok, actual, null, message ); + QUnit.push( ok, actual, null, message ); + } else { + QUnit.pushFailure( message, null, 'No exception was thrown.' ); + } } }; -// @deprecated: Kept assertion helpers in root for backwards compatibility +/** + * @deprecate since 1.8.0 + * Kept assertion helpers in root for backwards compatibility + */ extend( QUnit, QUnit.assert ); /** - * @deprecated: Kept for backwards compatibility - * next step: remove entirely + * @deprecated since 1.9.0 + * Kept global "raises()" for backwards compatibility + */ +QUnit.raises = QUnit.assert.throws; + +/** + * @deprecated since 1.0.0, replaced with error pushes since 1.3.0 + * Kept to avoid TypeErrors for undefined methods. */ QUnit.equals = function() { QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ); @@ -549,7 +585,20 @@ config = { // when enabled, all tests must call expect() requireExpects: false, - urlConfig: [ "noglobals", "notrycatch" ], + // add checkboxes that are persisted in the query-string + // when enabled, the id is set to `true` as a `QUnit.config` property + urlConfig: [ + { + id: "noglobals", + label: "Check for Globals", + tooltip: "Enabling this will test if any test introduces new properties on the `window` object. Stored as query-strings." + }, + { + id: "notrycatch", + label: "No try-catch", + tooltip: "Enabling this will run tests outside of a try-catch block. Makes debugging exceptions in IE reasonable. Stored as query-strings." + } + ], // logging callback queues begin: [], @@ -770,7 +819,7 @@ extend( QUnit, { }); }, - pushFailure: function( message, source ) { + pushFailure: function( message, source, actual ) { if ( !config.current ) { throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) ); } @@ -781,15 +830,23 @@ extend( QUnit, { message: message }; - message = escapeInnerText(message ) || "error"; + message = escapeInnerText( message ) || "error"; message = "" + message + ""; output = message; + output += ""; + + if ( actual ) { + output += ""; + } + if ( source ) { details.source = source; - output += "
Result:
" + escapeInnerText( actual ) + "
Source:
" + escapeInnerText( source ) + "
"; + output += "Source:
" + escapeInnerText( source ) + "
"; } + output += ""; + runLoggingCallbacks( "log", QUnit, details ); config.current.assertions.push({ @@ -859,7 +916,7 @@ QUnit.load = function() { runLoggingCallbacks( "begin", QUnit, {} ); // Initialize the config, saving the execution queue - var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, + var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, urlConfigCheckboxes, urlConfigHtml = "", oldconfig = extend( {}, config ); @@ -872,8 +929,15 @@ QUnit.load = function() { for ( i = 0; i < len; i++ ) { val = config.urlConfig[i]; - config[val] = QUnit.urlParams[val]; - urlConfigHtml += ""; + if ( typeof val === "string" ) { + val = { + id: val, + label: val, + tooltip: "[no tooltip available]" + }; + } + config[ val.id ] = QUnit.urlParams[ val.id ]; + urlConfigHtml += ""; } // `userAgent` initialized at top of scope @@ -885,12 +949,7 @@ QUnit.load = function() { // `banner` initialized at top of scope banner = id( "qunit-header" ); if ( banner ) { - banner.innerHTML = "" + banner.innerHTML + " " + urlConfigHtml; - addEvent( banner, "change", function( event ) { - var params = {}; - params[ event.target.name ] = event.target.checked ? true : undefined; - window.location = QUnit.url( params ); - }); + banner.innerHTML = "" + banner.innerHTML + " "; } // `toolbar` initialized at top of scope @@ -931,8 +990,18 @@ QUnit.load = function() { // `label` initialized at top of scope label = document.createElement( "label" ); label.setAttribute( "for", "qunit-filter-pass" ); + label.setAttribute( "title", "Only show tests and assertons that fail. Stored in sessionStorage." ); label.innerHTML = "Hide passed tests"; toolbar.appendChild( label ); + + urlConfigCheckboxes = document.createElement( 'span' ); + urlConfigCheckboxes.innerHTML = urlConfigHtml; + addEvent( urlConfigCheckboxes, "change", function( event ) { + var params = {}; + params[ event.target.name ] = event.target.checked ? true : undefined; + window.location = QUnit.url( params ); + }); + toolbar.appendChild( urlConfigCheckboxes ); } // `main` initialized at top of scope @@ -1051,14 +1120,14 @@ function done() { function validTest( test ) { var include, filter = config.filter && config.filter.toLowerCase(), - module = config.module, + module = config.module && config.module.toLowerCase(), fullName = (test.module + ": " + test.testName).toLowerCase(); if ( config.testNumber ) { return test.testNumber === config.testNumber; } - if ( module && test.module !== module ) { + if ( module && ( !test.module || test.module.toLowerCase() !== module ) ) { return false; } From 3386c2a7a5b04ee895974878314bcf1f77c3cb9f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 15:25:18 -0400 Subject: [PATCH 05/21] Avoid enforcing strict mode in `_.defaults`, `_.extend`, and `_.bindAll` and add benchmarks for `_.bindAll` and `_.functions`. [closes #45] Former-commit-id: 1bb0b5155d3ae46052b4a06cb538dff307e8ec5e --- build.js | 12 ++----- build/post-compile.js | 3 -- build/pre-compile.js | 9 ++--- lodash.js | 76 ++++++++++++++++++++++++------------------- perf/perf.js | 59 ++++++++++++++++++++++++++++----- test/test.js | 41 ++++++++++++++++++++--- 6 files changed, 137 insertions(+), 63 deletions(-) diff --git a/build.js b/build.js index 2a57c6a833..92a597fd05 100755 --- a/build.js +++ b/build.js @@ -223,13 +223,13 @@ 'inLoop', 'init', 'isKeysFast', - 'iteratee', 'object', 'objectBranch', 'noCharByIndex', 'shadowed', 'top', - 'useHas' + 'useHas', + 'useStrict' ]; /** Collections of method names */ @@ -840,13 +840,7 @@ // prepend data object references to property names to avoid having to // use a with-statement iteratorOptions.forEach(function(property) { - if (property == 'iteratee') { - // use a more fine-grained regexp for the `iteratee` property because - // it's a compiled variable as well as a data property - snippet = snippet.replace(/(__t *= *\( *)(iteratee)/, '$1obj.$2'); - } else { - snippet = snippet.replace(RegExp('([^\\w.])\\b' + property + '\\b', 'g'), '$1obj.' + property); - } + snippet = snippet.replace(RegExp('([^\\w.])\\b' + property + '\\b', 'g'), '$1obj.' + property); }); // remove unnecessary code diff --git a/build/post-compile.js b/build/post-compile.js index 915d39f7da..2db1732277 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -34,9 +34,6 @@ // move vars exposed by Closure Compiler into the IIFE source = source.replace(/^([^(\n]+)\s*(\(function[^)]+\){)/, '$2$1'); - // use double quotes consistently - source = source.replace(/'use strict'/, '"use strict"'); - // unescape properties (i.e. foo["bar"] => foo.bar) source = source.replace(/(\w)\["([^."]+)"\]/g, '$1.$2'); diff --git a/build/pre-compile.js b/build/pre-compile.js index 759625b049..7e0c049447 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -10,17 +10,20 @@ 'accumulator', 'args', 'arrayClass', + 'bind', 'callback', 'className', 'collection', 'compareAscending', 'ctor', 'funcClass', + 'funcs', 'hasOwnProperty', 'identity', 'index', 'isFunc', 'iteratee', + 'iterateeIndex', 'iteratorBind', 'length', 'methodName', @@ -36,8 +39,6 @@ 'result', 'skipProto', 'slice', - 'source', - 'sourceIndex', 'stringClass', 'target', 'thisArg', @@ -58,13 +59,13 @@ 'inLoop', 'init', 'isKeysFast', - 'iteratee', 'object', 'objectBranch', 'noCharByIndex', 'shadowed', 'top', - 'useHas' + 'useHas', + 'useStrict' ]; /** Used to minify variables and string values to a single character */ diff --git a/lodash.js b/lodash.js index 332ee65ae2..bc96d53fb9 100644 --- a/lodash.js +++ b/lodash.js @@ -266,13 +266,17 @@ * @returns {String} Returns the interpolated text. */ var iteratorTemplate = template( + // conditional strict mode + '<% if (useStrict) { %>\'use strict\';\n<% } %>' + + + // the `iteratee` may be reassigned by the `top` snippet + 'var index, iteratee = <%= firstArg %>, ' + // assign the `result` variable an initial value - 'var result<% if (init) { %> = <%= init %><% } %>;\n' + + 'result<% if (init) { %> = <%= init %><% } %>;\n' + // add code to exit early or do so if the first argument is falsey '<%= exit %>;\n' + // add code after the exit snippet but before the iteration branches '<%= top %>;\n' + - 'var index, iteratee = <%= iteratee %>;\n' + // the following branch is for iterating arrays and array-like objects '<% if (arrayBranch) { %>' + @@ -389,14 +393,14 @@ /** Reusable iterator options for `defaults` and `extend` */ var extendIteratorOptions = { + 'useHas': false, + 'useStrict': false, 'args': 'object', 'init': 'object', 'top': - 'for (var source, sourceIndex = 1, length = arguments.length; sourceIndex < length; sourceIndex++) {\n' + - ' source = arguments[sourceIndex];\n' + - (hasDontEnumBug ? ' if (source) {' : ''), - 'iteratee': 'source', - 'useHas': false, + 'for (var iterateeIndex = 1, length = arguments.length; iterateeIndex < length; iterateeIndex++) {\n' + + ' iteratee = arguments[iterateeIndex];\n' + + (hasDontEnumBug ? ' if (iteratee) {' : ''), 'inLoop': 'result[index] = iteratee[index]', 'bottom': (hasDontEnumBug ? ' }\n' : '') + '}' }; @@ -443,6 +447,12 @@ * @private * @param {Object} [options1, options2, ...] The compile options objects. * + * useHas - A boolean to specify whether or not to use `hasOwnProperty` checks + * in the object loop. + * + * useStrict - A boolean to specify whether or not to include the ES5 + * "use strict" directive. + * * args - A string of comma separated arguments the iteration function will * accept. * @@ -457,12 +467,6 @@ * beforeLoop - A string or object containing an "array" or "object" property * of code to execute before the array or object loops. * - * iteratee - A string or object containing an "array" or "object" property - * of the variable to be iterated in the loop expression. - * - * useHas - A boolean to specify whether or not to use `hasOwnProperty` checks - * in the object loop. - * * inLoop - A string or object containing an "array" or "object" property * of code to execute in the array or object loops. * @@ -506,14 +510,14 @@ } // set additional template `data` values var args = data.args, - firstArg = /^[^,]+/.exec(args)[0], - iteratee = (data.iteratee = data.iteratee || firstArg); + firstArg = /^[^,]+/.exec(args)[0]; data.firstArg = firstArg; data.hasDontEnumBug = hasDontEnumBug; data.isKeysFast = isKeysFast; data.shadowed = shadowed; data.useHas = data.useHas !== false; + data.useStrict = data.useStrict !== false; if (!('noCharByIndex' in data)) { data.noCharByIndex = noCharByIndex; @@ -526,14 +530,14 @@ } // create the function factory var factory = Function( - 'arrayClass, compareAscending, funcClass, hasOwnProperty, identity, ' + - 'iteratorBind, objectTypes, nativeKeys, propertyIsEnumerable, ' + - 'slice, stringClass, toString', - '"use strict"; return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}' + 'arrayClass, bind, compareAscending, funcClass, hasOwnProperty, identity, ' + + 'iteratorBind, objectTypes, nativeKeys, propertyIsEnumerable, slice, ' + + 'stringClass, toString', + 'return function(' + args + ') {\n' + iteratorTemplate(data) + '\n}' ); // return the compiled function return factory( - arrayClass, compareAscending, funcClass, hasOwnProperty, identity, + arrayClass, bind, compareAscending, funcClass, hasOwnProperty, identity, iteratorBind, objectTypes, nativeKeys, propertyIsEnumerable, slice, stringClass, toString ); @@ -2058,19 +2062,23 @@ * jQuery('#lodash_button').on('click', buttonView.onClick); * // => When the button is clicked, `this.label` will have the correct value */ - function bindAll(object) { - var funcs = arguments, - index = 1; - - if (funcs.length == 1) { - index = 0; - funcs = functions(object); - } - for (var length = funcs.length; index < length; index++) { - object[funcs[index]] = bind(object[funcs[index]], object); - } - return object; - } + var bindAll = createIterator({ + 'useHas': false, + 'useStrict': false, + 'args': 'object', + 'init': 'object', + 'top': + 'var funcs = arguments,\n' + + ' length = funcs.length;\n' + + 'if (length > 1) {\n' + + ' for (var index = 1; index < length; index++)\n' + + ' result[funcs[index]] = bind(result[funcs[index]], result);\n' + + ' return result\n' + + '}', + 'inLoop': + 'if (toString.call(result[index]) == funcClass)' + + ' result[index] = bind(result[index], result)' + }); /** * Creates a new function that is the composition of the passed functions, @@ -2496,9 +2504,9 @@ * // => ['all', 'any', 'bind', 'bindAll', 'clone', 'compact', 'compose', ...] */ var functions = createIterator({ + 'useHas': false, 'args': 'object', 'init': '[]', - 'useHas': false, 'inLoop': 'if (toString.call(iteratee[index]) == funcClass) result.push(index)', 'bottom': 'result.sort()' }); diff --git a/perf/perf.js b/perf/perf.js index 20a6bf1680..cffb3176ff 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -82,12 +82,28 @@ lodash = window.lodash; var length = 20, + funcNames = lodash.functions(lodash), numbers = [], object = {}, fourNumbers = [5, 25, 10, 30], nestedNumbers = [1, [2], [3, [[4]]]], twoNumbers = [12, 21]; + var bindAllObjects = []; + + var objects = lodash.map(numbers, function(num) { + return { 'num': num }; + }); + + lodash.times(this.count, function(index) { + bindAllObjects[index] = lodash.clone(lodash); + }); + + lodash.times(length, function(index) { + numbers[index] = index; + object['key' + index] = index; + }); + var ctor = function() { }; var func = function(greeting, punctuation) { @@ -219,15 +235,6 @@ }; var words = _.keys(wordToNumber).slice(0, length); - - for (var index = 0; index < length; index++) { - numbers[index] = index; - object['key' + index] = index; - } - - var objects = lodash.map(numbers, function(num) { - return { 'num': num }; - }); } }); @@ -352,6 +359,28 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.bindAll` iterating arguments') + .add('Lo-Dash', function() { + lodash.bindAll.apply(lodash, [bindAllObjects.pop()].concat(funcNames)); + }) + .add('Underscore', function() { + _.bindAll.apply(_, [bindAllObjects.pop()].concat(funcNames)); + }) + ); + + suites.push( + Benchmark.Suite('`_.bindAll` iterating the `object`') + .add('Lo-Dash', function() { + lodash.bindAll(bindAllObjects.pop()); + }) + .add('Underscore', function() { + _.bindAll(bindAllObjects.pop()); + }) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.each` iterating an array') .add('Lo-Dash', function() { @@ -498,6 +527,18 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.functions`') + .add('Lo-Dash', function() { + lodash.functions(lodash); + }) + .add('Underscore', function() { + _.functions(lodash); + }) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.difference`') .add('Lo-Dash', function() { diff --git a/test/test.js b/test/test.js index 8771e0c08c..bcd82c6d2f 100644 --- a/test/test.js +++ b/test/test.js @@ -21,6 +21,9 @@ _._ || _ ); + /** Shortcut used to make object properties immutable */ + var freeze = Object.freeze; + /** Shortcut used to convert array-like objects to arrays */ var slice = [].slice; @@ -52,9 +55,10 @@ * Skips a given number of tests with a passing result. * * @private - * @param {Number} count The number of tests to skip. + * @param {Number} [count=1] The number of tests to skip. */ function skipTest(count) { + count || (count = 1); while (count--) { ok(true, 'test skipped'); } @@ -71,7 +75,7 @@ if (window.document && window.require) { equal((lodashModule || {}).moduleName, 'lodash'); } else { - skipTest(1) + skipTest() } }); @@ -79,7 +83,7 @@ if (window.document && window.require) { equal((underscoreModule || {}).moduleName, 'underscore'); } else { - skipTest(1) + skipTest() } }); @@ -87,7 +91,7 @@ if (window.document) { notDeepEqual(lodashBadShim.keys({ 'a': 1 }), []); } else { - skipTest(1); + skipTest(); } }); }()); @@ -209,6 +213,35 @@ /*--------------------------------------------------------------------------*/ + _.each(['bindAll', 'defaults', 'extend'], function(methodName) { + var func = _[methodName]; + QUnit.module('lodash.' + methodName + ' strict mode checks'); + + test('should not throw strict mode errors', function() { + var object = { 'a': null, 'b': function(){} }, + pass = true; + + if (freeze) { + freeze(object); + try { + if (methodName == 'bindAll') { + func(object); + } else { + func(object, { 'a': 1 }); + } + } catch(e) { + pass = false; + } + ok(pass); + } + else { + skipTest(); + } + }); + }); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.find'); (function() { From 660a6e9e4ce4a83717a31dd90b5de91a7749a0c6 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 15:27:25 -0400 Subject: [PATCH 06/21] Update minified build and rebuild documentation. Former-commit-id: 6e747961d3d756d016a27b530bf961841a93bd00 --- doc/README.md | 174 +++++++++++++++++++++++++------------------------- lodash.min.js | 58 ++++++++--------- 2 files changed, 116 insertions(+), 116 deletions(-) diff --git a/doc/README.md b/doc/README.md index 5a8204a94d..53ae8b4ce5 100644 --- a/doc/README.md +++ b/doc/README.md @@ -148,7 +148,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3554 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3562 "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#L1937 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1941 "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#L1991 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1995 "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#L2061 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2065 "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#L3479 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3487 "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#L2387 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2395 "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#L1184 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1188 "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#L2093 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2101 "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#L719 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L723 "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#L2126 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2134 "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#L2410 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2418 "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#L2191 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2199 "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#L2171 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2179 "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#L1216 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1220 "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#L3119 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3127 "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#L747 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L751 "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#L2429 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2437 "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#L767 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L771 "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#L788 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L792 "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#L1252 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1256 "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#L1276 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1280 "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#L814 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L818 "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#L2458 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2466 "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#L2481 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2489 "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#L2498 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2506 "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#L841 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L845 "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#L2521 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2529 "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#L3138 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3146 "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#L1320 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1324 "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#L1360 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1364 "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#L1381 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1385 "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#L875 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L879 "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#L2541 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2549 "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#L2567 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2575 "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#L2584 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2592 "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#L2601 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2609 "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#L2618 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2626 "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#L2642 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2650 "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#L2676 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2684 "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#L2837 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2845 "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#L2854 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2862 "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#L2906 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2914 "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#L2929 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2937 "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#L2946 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2954 "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#L2875 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2883 "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#L2963 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2971 "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#L2980 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2988 "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#L2998 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3006 "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#L3015 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3023 "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#L1419 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1423 "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#L1445 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1449 "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#L911 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L915 "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#L1485 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1489 "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#L2214 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2222 "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#L1535 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1539 "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#L3164 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3172 "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#L3195 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3203 "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#L2240 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2248 "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#L2273 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2281 "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#L3037 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3045 "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#L934 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L938 "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#L1596 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1600 "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#L962 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L966 "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#L999 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1003 "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#L1054 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1058 "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#L1633 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1637 "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#L3227 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3235 "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#L1654 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1658 "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#L3076 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3084 "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#L1077 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1081 "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#L1109 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1113 "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#L1706 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1710 "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#L3506 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3514 "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#L3287 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3295 "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#L2309 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2317 "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#L3422 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3430 "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#L1152 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1156 "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#L1746 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1750 "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#L1791 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1795 "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#L3449 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3457 "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#L3097 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3105 "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#L1840 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1844 "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#L2361 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2369 "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#L1872 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1876 "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#L1901 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1905 "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#L3524 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3532 "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#L3541 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3549 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.min.js b/lodash.min.js index 32316688f6..33980c1558 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,34 +2,34 @@ Lo-Dash 0.4.1 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(){for(var e,t,n,s=-1,o=arguments.length,u={e:"",f:"",j:"",q:"",c:{d:""},n:{d:""}};++sn;n++)t+="l='"+u.p[n]+"';if(","constructor"==u.p[n]&&(t+="!(h&&h.prototype===n)&&"),t+="j.call(n,l)){"+u.n.i+"}"}u.c&&(t+="}")}return t+=u.e+";return A",Function("c,g,i,j,k,o,u,r,z,C,F,I",'"use strict";return function('+e+"){"+t+"}")(ot,a,ft,G,k,h,Et,st,Z,et,ht,tt)}function a(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function f(e,t){return K[t]}function l(e){return"\\"+St[e]}function c( -e){return wt[e]}function h(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function p(){}function d(e,t){if(F.test(t))return"";var n=K.length;return K[n]="'+__e("+t+")+'",J+n}function v(e,t,n,r){return e=K.length,t?K[e]="';"+t+";__p+='":n?K[e]="'+__e("+n+")+'":r&&(K[e]="'+((__t=("+r+"))==null?'':__t)+'"),J+e}function m(e,t){if(F.test(t))return"";var n=K.length;return K[n]="'+((__t=("+t+"))==null?'':__t)+'",J+n}function g(e,t,n,r){if(!e)return n;var i=e.length,s=3>arguments -.length;r&&(t=h(t,r));if(i===i>>>0){var o=gt&&tt.call(e)==ht?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=Gt(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function y(e,t,n){if(e)return t==r||n?e[0]:et.call(e,0,t)}function b(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=h(t,n));++sr&&(r=n,i=e[s]);return i}function S(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function x(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=N(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]w(a,r))a.push(r),s.push(e[o]);return s}function N(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?Q.apply(s,o):s),this instanceof n?(p.prototype=e.prototype,u=new p,(o=e.apply(u,o))&&Et[typeof o]?o:u):e.apply(u,o)}var r,i=tt.call(e)==ft;if(i){if(yt||nt&&2++u&&(l=$[u],!G.call(e,l)||!!(a=G.call(t,l -)&&C(e[l],t[l],s))););}return s.pop(),a}function k(e){return e}function L(e){Ht(Jt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Y.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,A,O,M,_,D="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),P=Array.prototype,H=Object.prototype,B=0,j=e._,F=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ +;(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(){for(var e,t,n,s=-1,o=arguments.length,u={e:"",f:"",j:"",p:"",c:{d:""},m:{d:""}};++sn;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+"}")(ot,N,a,ft,G,k,h,Et,st,Z,et,ht,tt)}function a(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function f(e,t){return K[t]} +function l(e){return"\\"+St[e]}function c(e){return wt[e]}function h(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function p(){}function d(e,t){if(F.test(t))return"";var n=K.length;return K[n]="'+__e("+t+")+'",J+n}function v(e,t,n,r){return e=K.length,t?K[e]="';"+t+";__p+='":n?K[e]="'+__e("+n+")+'":r&&(K[e]="'+((__t=("+r+"))==null?'':__t)+'"),J+e}function m(e,t){if(F.test(t))return"";var n=K.length;return K[n]="'+((__t=("+t+"))==null?'':__t)+'",J+n}function g(e,t,n,r) +{if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=h(t,r));if(i===i>>>0){var o=gt&&tt.call(e)==ht?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=Yt(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function y(e,t,n){if(e)return t==r||n?e[0]:et.call(e,0,t)}function b(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=h(t,n));++sr&&(r=n,i=e[s]);return i}function S(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function x(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=N(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]w(a,r))a.push(r),s.push(e[o]);return s}function N(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?Q.apply(s,o):s),this instanceof n?(p.prototype=e.prototype,u=new p,(o=e.apply(u,o))&&Et[typeof o]?o:u):e.apply(u,o)}var r,i=tt.call(e)==ft;if(i){if(yt||nt&&2++ +u&&(l=$[u],!G.call(e,l)||!!(a=G.call(t,l)&&C(e[l],t[l],s))););}return s.pop(),a}function k(e){return e}function L(e){Ht(Kt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Y.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,A,O,M,_,D="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),P=Array.prototype,H=Object.prototype,B=0,j=e._,F=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ ,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g,R=/(__e\(.*?\)|\b__t\))\+'';/g,U=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,z=RegExp("^"+(H.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),W=/__token__(\d+)/g,X=/[&<"']/g,V=/['\n\r\t\u2028\u2029\\]/g,$="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="__token__",K=[],Q=P.concat,G=H.hasOwnProperty,Y=P.push,Z=H.propertyIsEnumerable,et=P.slice,tt=H.toString ,nt=z.test(nt=et.bind)&&nt,rt=z.test(rt=Array.isArray)&&rt,it=e.isFinite,st=z.test(st=Object.keys)&&st,ot="[object Array]",ut="[object Boolean]",at="[object Date]",ft="[object Function]",lt="[object Number]",ct="[object RegExp]",ht="[object String]",pt=e.clearTimeout,dt=e.setTimeout,vt=!Z.call({valueOf:0},"valueOf"),mt="x"!=et.call("x")[0],gt="xx"!="x"[0]+Object("x")[0],yt=nt&&/\n|Opera/.test(nt+tt.call(e.opera)),bt=st&&/^.+$|true/.test(st+!!e.attachEvent),wt={"&":"&","<":"<",'"':""","'" -:"'"},Et={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},St={"\\":"\\","'":"'","\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 xt={a:"f,d,H",j:"f",q:"if(!d){d=k}else if(H)d=o(d,H)",i:"d(n[l],l,f)"},Tt={j:"true",i:"if(!d(n[l],l,f))return!A"},Nt={a:"t",j:"t",q:"for(var D,E=1,p=arguments.length;E-1"},i:"if(n[l]===G)return true"}),_t=u(xt,Tt),Dt=u(xt,Ct),Pt=u(xt,kt,{j:"",i:"if(d(n[l],l,f))return n[l]" -}),Ht=u(xt,kt),Bt=u(xt,{j:"{}",q:"var v,m=typeof d=='function';if(m&&H)d=o(d,H)",i:"v=m?d(n[l],l,f):n[l][d];(j.call(A,v)?A[v]:A[v]=[]).push(n[l])"}),jt=u(At,{a:"f,q",q:"var b=C.call(arguments,2),m=typeof q=='function'",i:{b:"A[l]=(m?q:n[l][q]).apply(n[l],b)",m:"A"+(bt?"[w]=":".push")+"((m?q:n[l][q]).apply(n[l],b))"}}),Ft=u(xt,At),It=u(At,{a:"f,y",i:{b:"A[l]=n[l][y]",m:"A"+(bt?"[w]=":".push")+"(n[l][y])"}}),qt=u({a:"f,d,a,H",j:"a",q:"var s=arguments.length<3;if(H)d=o(d,H)",d:{b:"if(s)A=f[++l]"},i: -{b:"A=d(A,n[l],l,f)",m:"A=s?(s=false,n[l]):d(A,n[l],l,f)"}}),Rt=u(xt,Ct,{i:"!"+Ct.i}),Ut=u(xt,Tt,{j:"false",i:Tt.i.replace("!","")}),zt=u(xt,At,{q:"if(typeof d=='string'){var v=d;d=function(f){return f[v]}}else if(H)d=o(d,H)",i:{b:"A[l]={a:d(n[l],l,f),b:n[l]}",m:"A"+(bt?"[w]=":".push")+"({a:d(n[l],l,f),b:n[l]})"},e:"A.sort(g);p=A.length;while(p--){A[p]=A[p].b}"}),Wt=u(Nt,{i:"if(A[l]==null)"+Nt.i}),Xt=u(Nt),Vt=u(xt,kt,Lt,{r:i}),$t=u(xt,kt,Lt),Jt=u({a:"t",j:"[]",r:i,i:"if(I.call(n[l])==i)A.push(l)" -,e:"A.sort()"});Ht({Arguments:"[object Arguments]",Date:at,Function:ft,Number:lt,RegExp:ct,String:ht},function(e,t){s["is"+t]=function(t){return tt.call(t)==e}}),s.isArguments(arguments)||(s.isArguments=function(e){return!!e&&!!G.call(e,"callee")});var Kt=rt||function(e){return tt.call(e)==ot},Qt=u({a:"J",j:"true",q:"var e=I.call(J);if(e==c||e==F)return!J.length",i:{m:"return false"}}),Gt=st?function(e){return"function"==typeof e&&Z.call(e,"prototype")?Ot(e):st(e)}:Ot,Yt=u({a:"t",j:"[]",i:"A.push(n[l])" -});s.VERSION="0.4.1",s.after=function(e,t){return 1>e?t():function(){if(1>--e)return t.apply(this,arguments)}},s.bind=N,s.bindAll=function(e){var t=arguments,n=1;1==t.length&&(n=0,t=Jt(e));for(var r=t.length;nw(i,e[n],r)&&t.push(e[n]);return t},s.escape=function(e){return e==r?"":(e+"").replace(X,c)},s.every=_t,s.extend=Xt,s.filter=Dt,s.find=Pt,s.first=y,s.flatten=b,s.forEach=Ht,s.forIn=Vt,s.forOwn=$t,s.functions=Jt,s.groupBy=Bt,s.has=function(e,t){return G.call(e,t)},s.identity=k,s.indexOf=w,s.initial=function(e,t,n){return e?et.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=et.call(arguments,1);++rw(t,n)&&_t(s,function(e){return-1n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Ft,s.max=E,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return G.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:Gt(e).length},s.some=Ut,s.sortBy=zt,s.sortedIndex=x,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,c=s.templateSettings,n=n.variable;i==r&&(i=c.escape),u==r&&(u=c.evaluate),a==r&&(a=c.interpolate),i&&(e=e.replace(i,d)),a&&(e=e.replace(a,m)),u!=A&&(A=u,_=RegExp((u?u.source:"($^)")+"||","g")),i=K.length,e=e.replace(_,v), -i=i!=K.length,e="__p += '"+e.replace(V,l).replace(W,f)+"';",K.length=0,n||(n=c.variable||O||"obj",i?e="with("+n+"){"+e+"}":(n!=O&&(O=n,M=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(U,"$&"+n+".").replace(M,"$1__d"))),e=(i?e.replace(I,""):e).replace(q,"$1").replace(R,"$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=dt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(mt?tt.call(e)==ht:"string"==typeof -e)?e.split(""):et.call(e):Yt(e)},s.union=function(){for(var e=-1,t=[],n=Q.apply(t,arguments),r=n.length;++ew(t,n[e])&&t.push(n[e]);return t},s.uniq=T,s.uniqueId=function(e){var t=B++;return e?e+t:t},s.values=Yt,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nw(arguments,e[n],1)&&t.push(e[n]);return t},s.wrap=function(e,t){return function(){var n=[e];return arguments.length&&Y.apply(n,arguments),t.apply(this,n)}},s.zip=function(e){if(!e)return[];for(var t=-1,n= -E(It(arguments,"length")),r=Array(n);++t/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:"obj"};var xt={a:"g,e,I",j:"g",p:"if(!e){e=m}else if(I)e=r(e,I)",i:"e(p[n],n,g)"},Tt={j:"true",i:"if(!e(p[n],n,g))return!D"},Nt={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"}),_t=u(xt,Tt),Dt=u(xt,Ct),Pt=u(xt,kt,{j:"",i:"if(e(p[n],n,g))return p[n]" +}),Ht=u(xt,kt),Bt=u(xt,{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])"}),jt=u(At,{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"+(bt?"[z]=":".push")+"((o?t:p[n][t]).apply(p[n],b))"}}),Ft=u(xt,At),It=u(At,{a:"g,B",i:{b:"D[n]=p[n][B]",l:"D"+(bt?"[z]=":".push")+"(p[n][B])"}}),qt=u({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)"}}),Rt=u(xt,Ct,{i:"!"+Ct.i}),Ut=u(xt,Tt,{j:"false",i:Tt.i.replace("!","")}),zt=u(xt,At,{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"+(bt?"[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}"}),Wt=u({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=N,s.bindAll=Wt,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&Et[typeof e]?Qt(e)?e.slice():Vt({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nw(i,e[n],r)&&t.push(e[n]);return t},s.escape=function(e){return e==r?"":(e+"").replace(X,c)},s.every=_t,s.extend=Vt,s.filter=Dt,s.find=Pt,s.first=y,s.flatten=b,s.forEach=Ht,s.forIn=$t,s.forOwn=Jt,s.functions=Kt,s.groupBy=Bt,s.has=function(e,t){return G.call(e,t)},s.identity=k,s.indexOf=w,s.initial=function(e,t,n){return e?et.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=et.call(arguments,1);++rw(t,n)&&_t(s,function(e){return-1n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Ft,s.max=E,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return G.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:Yt(e).length},s.some=Ut,s.sortBy=zt,s.sortedIndex=x,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,c=s.templateSettings,n=n.variable;i==r&&(i=c.escape),u==r&&(u=c.evaluate),a==r&&(a=c.interpolate),i&&(e=e.replace(i,d)),a&&(e=e.replace(a,m)),u!=A&&(A=u,_=RegExp((u?u.source:"($^)")+"||","g") +),i=K.length,e=e.replace(_,v),i=i!=K.length,e="__p += '"+e.replace(V,l).replace(W,f)+"';",K.length=0,n||(n=c.variable||O||"obj",i?e="with("+n+"){"+e+"}":(n!=O&&(O=n,M=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(U,"$&"+n+".").replace(M,"$1__d"))),e=(i?e.replace(I,""):e).replace(q,"$1").replace(R,"$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=dt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(mt? +tt.call(e)==ht:"string"==typeof e)?e.split(""):et.call(e):Zt(e)},s.union=function(){for(var e=-1,t=[],n=Q.apply(t,arguments),r=n.length;++ew(t,n[e])&&t.push(n[e]);return t},s.uniq=T,s.uniqueId=function(e){var t=B++;return e?e+t:t},s.values=Zt,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nw(arguments,e[n],1)&&t.push(e[n]);return t},s.wrap=function(e,t){return function(){var n=[e];return arguments.length&&Y.apply(n,arguments),t.apply(this,n)}},s.zip=function(e +){if(!e)return[];for(var t=-1,n=E(It(arguments,"length")),r=Array(n);++t Date: Thu, 12 Jul 2012 15:48:52 -0400 Subject: [PATCH 07/21] Update test-ui.js to better integrate with QUnit 1.9.0. Former-commit-id: 7e6083ebb54fde0ebaa9f4f4551bb190e602a370 --- test/test-ui.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/test-ui.js b/test/test-ui.js index 74409a9134..fee5647e8b 100644 --- a/test/test-ui.js +++ b/test/test-ui.js @@ -45,10 +45,10 @@ } function init() { - var header = document.getElementById('qunit-header'); - if (header) { - header.appendChild(label1); - header.appendChild(label2); + var toolbar = document.getElementById('qunit-testrunner-toolbar'); + if (toolbar) { + toolbar.appendChild(label1); + toolbar.appendChild(label2); dropdown.selectedIndex = (function() { switch (build) { @@ -70,16 +70,16 @@ var label1 = document.createElement('label'); label1.innerHTML = - 'norequire'; + 'No RequireJS'; var label2 = document.createElement('label'); label2.innerHTML = 'build'; + '' + + '' + + '' + + '' + + ' Build'; var checkbox = label1.firstChild, dropdown = label2.firstChild; From cc620205d678e6f859b008b80c2c065ce00b7e3d Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 16:25:30 -0400 Subject: [PATCH 08/21] Control "use strict" directive use in builds. Former-commit-id: 66a9bdee5cc61710d7d42d685feba616ec855322 --- build.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/build.js b/build.js index 92a597fd05..4a1e739aa0 100755 --- a/build.js +++ b/build.js @@ -20,6 +20,9 @@ /** Flag used to specify a mobile build */ var isMobile = !isLegacy && process.argv.indexOf('mobile') > -1; + /** Flag used to specify if the source should be in strict mode */ + var isStrict = !(isLegacy || isMobile); + /** Shortcut used to convert array-like objects to arrays */ var slice = [].slice; @@ -33,6 +36,15 @@ ['isBindFast', 'isKeysFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) { source = replaceVar(source, varName, 'false'); }); + + // remove `useStrict` branch from `iteratorTemplate` + source = source.replace(/(?: *\/\/.*\n)*\s*' *<% *if *\(useStrict\).+\n/, ''); + + // remove `useStrict` from iterator options + source = source.replace(/ *'useStrict': *false,\n/g, ''); + + // remove `useStrict` data object property assignment in `createIterator` + source = source.replace(/\s*.+?\.useStrict *=.+/, ''); } else if (isMobile) { source = replaceVar(source, 'isKeysFast', 'false'); @@ -505,6 +517,17 @@ .replace(/(?: *\/\/.*\n)*\s*'( *)<% *if *\(isKeysFast[\s\S]+?'\1<% *} *else *\{ *%>.+\n([\s\S]+?) *'\1<% *} *%>.+/, '$2'); } + /** + * Removes the "use strict" directive from `source`. + * + * @private + * @param {String} source The source to process. + * @returns {String} Returns the modified source. + */ + function removeUseStrict(source) { + return source.replace(/(["'])use strict\1;( *\n)?/, ''); + } + /** * Removes a given variable from `source`. * @@ -938,10 +961,19 @@ // cleanup code source = source.replace(/^ *;\n/gm, ''); + if (!isStrict) { + source = removeUseStrict(source); + } + // begin the minification process if (filterType || isBackbone || isLegacy || isMobile) { fs.writeFileSync(path.join(cwd, 'lodash.custom.js'), source); + minify(source, 'lodash.custom.min', function(result) { + // re-remove "use strict" added by the minifier + if (!isStrict) { + result = removeUseStrict(result); + } fs.writeFileSync(path.join(cwd, 'lodash.custom.min.js'), result); }); } From 268fe34238c2260f22cc74aeeb49bdfd0a90b01b Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 16:54:17 -0400 Subject: [PATCH 09/21] Update Closure Compiler. Former-commit-id: bfdbe43546f3861cbeaaa99644af68e95f2175d5 --- lodash.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lodash.min.js b/lodash.min.js index 33980c1558..a0dbd3fc1d 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -9,7 +9,7 @@ function l(e){return"\\"+St[e]}function c(e){return wt[e]}function h(e,t){return {if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=h(t,r));if(i===i>>>0){var o=gt&&tt.call(e)==ht?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=Yt(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function y(e,t,n){if(e)return t==r||n?e[0]:et.call(e,0,t)}function b(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=h(t,n));++sr&&(r=n,i=e[s]);return i}function S(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function x(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=N(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]w(a,r))a.push(r),s.push(e[o]);return s}function N(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?Q.apply(s,o):s),this instanceof n?(p.prototype=e.prototype,u=new p,(o=e.apply(u,o))&&Et[typeof o]?o:u):e.apply(u,o)}var r,i=tt.call(e)==ft;if(i){if(yt||nt&&2++ u&&(l=$[u],!G.call(e,l)||!!(a=G.call(t,l)&&C(e[l],t[l],s))););}return s.pop(),a}function k(e){return e}function L(e){Ht(Kt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Y.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,A,O,M,_,D="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),P=Array.prototype,H=Object.prototype,B=0,j=e._,F=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ ,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g,R=/(__e\(.*?\)|\b__t\))\+'';/g,U=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,z=RegExp("^"+(H.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),W=/__token__(\d+)/g,X=/[&<"']/g,V=/['\n\r\t\u2028\u2029\\]/g,$="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="__token__",K=[],Q=P.concat,G=H.hasOwnProperty,Y=P.push,Z=H.propertyIsEnumerable,et=P.slice,tt=H.toString From 6c4b4b392bf51eb8035a72072d4ea499e0ebd551 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 12 Jul 2012 17:32:55 -0400 Subject: [PATCH 10/21] Avoid expensive test setup in perf.js. Former-commit-id: f1c1ed41cb86c83aba2c3f7da1dedf6a280221ad --- perf/perf.js | 66 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/perf/perf.js b/perf/perf.js index cffb3176ff..0f4b375ece 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -81,28 +81,32 @@ _ = window._, lodash = window.lodash; - var length = 20, - funcNames = lodash.functions(lodash), - numbers = [], + var index, + length, + belt = /Lo-Dash/.test(this.name) ? lodash : _, + limit = 20, + numbers = Array(limit), object = {}, + objects = Array(limit), fourNumbers = [5, 25, 10, 30], nestedNumbers = [1, [2], [3, [[4]]]], twoNumbers = [12, 21]; - var bindAllObjects = []; - - var objects = lodash.map(numbers, function(num) { - return { 'num': num }; - }); - - lodash.times(this.count, function(index) { - bindAllObjects[index] = lodash.clone(lodash); - }); - - lodash.times(length, function(index) { + for (index = 0, length = limit; index < length; index++) { numbers[index] = index; object['key' + index] = index; - }); + objects[index] = { 'num': index }; + } + + if (typeof isBindAll != 'undefined') { + var bindAllObjects = Array(this.count), + funcNames = belt.functions(lodash); + + // potentially expensive + for (index = 0, length = this.count; index < length; index++) { + bindAllObjects[index] = belt.clone(lodash); + } + } var ctor = function() { }; @@ -234,7 +238,7 @@ 'twenty-five': 25 }; - var words = _.keys(wordToNumber).slice(0, length); + var words = belt.keys(wordToNumber).slice(0, limit); } }); @@ -361,21 +365,33 @@ suites.push( Benchmark.Suite('`_.bindAll` iterating arguments') - .add('Lo-Dash', function() { - lodash.bindAll.apply(lodash, [bindAllObjects.pop()].concat(funcNames)); + .add('Lo-Dash', { + 'fn': function() { + lodash.bindAll.apply(lodash, [bindAllObjects.pop()].concat(funcNames)); + }, + 'teardown': 'function isBindAll(){}' }) - .add('Underscore', function() { - _.bindAll.apply(_, [bindAllObjects.pop()].concat(funcNames)); + .add('Underscore', { + 'fn': function() { + _.bindAll.apply(_, [bindAllObjects.pop()].concat(funcNames)); + }, + 'teardown': 'function isBindAll(){}' }) ); suites.push( Benchmark.Suite('`_.bindAll` iterating the `object`') - .add('Lo-Dash', function() { - lodash.bindAll(bindAllObjects.pop()); - }) - .add('Underscore', function() { - _.bindAll(bindAllObjects.pop()); + .add('Lo-Dash', { + 'fn': function() { + lodash.bindAll(bindAllObjects.pop()); + }, + 'teardown': 'function isBindAll(){}' + }) + .add('Underscore', { + 'fn': function() { + _.bindAll(bindAllObjects.pop()); + }, + 'teardown': 'function isBindAll(){}' }) ); From 4f78a06993806f5d2a375e85d668fd53658817f5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 13 Jul 2012 04:17:38 -0400 Subject: [PATCH 11/21] Add `_.isEqual` benchmarks. Former-commit-id: 5b3ee06ea3f31f10e8fac96da8766cc1c4c2d3bb --- perf/perf.js | 130 +++++++++++++++++++++++++------ vendor/benchmark.js/benchmark.js | 28 ++++--- 2 files changed, 118 insertions(+), 40 deletions(-) diff --git a/perf/perf.js b/perf/perf.js index 0f4b375ece..4588f94555 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -76,6 +76,8 @@ lodash.extend(Benchmark.options, { 'async': true, + 'maxTime': 1, + 'minSamples': 30, 'setup': function() { var window = Function('return this || global')(), _ = window._, @@ -83,19 +85,29 @@ var index, length, - belt = /Lo-Dash/.test(this.name) ? lodash : _, + belt = this.name == 'Lo-Dash' ? lodash : _, limit = 20, - numbers = Array(limit), object = {}, objects = Array(limit), + numbers = Array(limit), fourNumbers = [5, 25, 10, 30], nestedNumbers = [1, [2], [3, [[4]]]], twoNumbers = [12, 21]; + var object2 = {}, + objects2 = Array(limit), + numbers2 = Array(limit), + nestedNumbers2 = [1, [2], [3, [[4]]]]; + for (index = 0, length = limit; index < length; index++) { numbers[index] = index; + numbers2[index] = index; + object['key' + index] = index; + object2['key' + index] = index; + objects[index] = { 'num': index }; + objects2[index] = { 'num': index }; } if (typeof isBindAll != 'undefined') { @@ -108,19 +120,33 @@ } } - var ctor = function() { }; + var ctor = function() {}; var func = function(greeting, punctuation) { return greeting + ', ' + this.name + (punctuation || '.'); }; - var lodashBoundNormal = lodash.bind(func, { 'name': 'moe' }), - lodashBoundCtor = lodash.bind(ctor, { 'name': 'moe' }), - lodashBoundPartial = lodash.bind(func, { 'name': 'moe' }, 'hi'); + var objectOfPrimitives = { + 'boolean': true, + 'number': 1, + 'string': 'a' + }; + + var objectOfObjects = { + 'boolean': new Boolean(true), + 'number': new Number(1), + 'string': new String('a') + }; + + var contextObject = { 'name': 'moe' }; - var _boundNormal = _.bind(func, { 'name': 'moe' }), - _boundCtor = _.bind(ctor, { 'name': 'moe' }), - _boundPartial = _.bind(func, { 'name': 'moe' }, 'hi'); + var lodashBoundNormal = lodash.bind(func, contextObject), + lodashBoundCtor = lodash.bind(ctor, contextObject), + lodashBoundPartial = lodash.bind(func, contextObject, 'hi'); + + var _boundNormal = _.bind(func, contextObject), + _boundCtor = _.bind(ctor, contextObject), + _boundPartial = _.bind(func, contextObject, 'hi'); var tplData = { 'header1': 'Header1', @@ -200,15 +226,17 @@ '' + ''; + var settingsObject = { 'variable': 'data' }; + var lodashTpl = lodash.template(tpl), lodashTplWithEvaluate = lodash.template(tplWithEvaluate), - lodashTplVerbose = lodash.template(tplVerbose, null, { 'variable': 'data' }), - lodashTplVerboseWithEvaluate = lodash.template(tplVerboseWithEvaluate, null, { 'variable': 'data' }); + lodashTplVerbose = lodash.template(tplVerbose, null, settingsObject), + lodashTplVerboseWithEvaluate = lodash.template(tplVerboseWithEvaluate, null, settingsObject); var _tpl = _.template(tpl), _tplWithEvaluate = _.template(tplWithEvaluate), - _tplVerbose = _.template(tplVerbose, null, { 'variable': 'data' }), - _tplVerboseWithEvaluate = _.template(tplVerboseWithEvaluate, null, { 'variable': 'data' }); + _tplVerbose = _.template(tplVerbose, null, settingsObject), + _tplVerboseWithEvaluate = _.template(tplVerboseWithEvaluate, null, settingsObject); var wordToNumber = { 'one': 1, @@ -397,6 +425,18 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.difference`') + .add('Lo-Dash', function() { + lodash.difference(numbers, fourNumbers, twoNumbers); + }) + .add('Underscore', function() { + _.difference(numbers, fourNumbers, twoNumbers); + }) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.each` iterating an array') .add('Lo-Dash', function() { @@ -555,18 +595,6 @@ /*--------------------------------------------------------------------------*/ - suites.push( - Benchmark.Suite('`_.difference`') - .add('Lo-Dash', function() { - lodash.difference(numbers, fourNumbers, twoNumbers); - }) - .add('Underscore', function() { - _.difference(numbers, fourNumbers, twoNumbers); - }) - ); - - /*--------------------------------------------------------------------------*/ - suites.push( Benchmark.Suite('`_.groupBy` with `callback` iterating an array') .add('Lo-Dash', function() { @@ -633,6 +661,58 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.isEqual` comparing primitives and objects (edge case)') + .add('Lo-Dash', function() { + lodash.isEqual(objectOfPrimitives, objectOfObjects); + }) + .add('Underscore', function() { + _.isEqual(objectOfPrimitives, objectOfObjects); + }) + ); + + suites.push( + Benchmark.Suite('`_.isEqual` comparing arrays') + .add('Lo-Dash', function() { + lodash.isEqual(numbers, numbers2); + }) + .add('Underscore', function() { + _.isEqual(numbers, numbers2); + }) + ); + + suites.push( + Benchmark.Suite('`_.isEqual` comparing nested arrays') + .add('Lo-Dash', function() { + lodash.isEqual(nestedNumbers, nestedNumbers2); + }) + .add('Underscore', function() { + _.isEqual(nestedNumbers, nestedNumbers2); + }) + ); + + suites.push( + Benchmark.Suite('`_.isEqual` comparing arrays of objects') + .add('Lo-Dash', function() { + lodash.isEqual(objects, objects2); + }) + .add('Underscore', function() { + _.isEqual(objects, objects2); + }) + ); + + suites.push( + Benchmark.Suite('`_.isEqual` comparing objects') + .add('Lo-Dash', function() { + lodash.isEqual(object, object2); + }) + .add('Underscore', function() { + _.isEqual(object, object2); + }) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.keys` (uses native `Object.keys` if available)') .add('Lo-Dash', function() { diff --git a/vendor/benchmark.js/benchmark.js b/vendor/benchmark.js/benchmark.js index 42d00a8272..7d2ec9ff9c 100644 --- a/vendor/benchmark.js/benchmark.js +++ b/vendor/benchmark.js/benchmark.js @@ -2698,20 +2698,18 @@ sample = bench.stats.sample; /** - * Adds a number of clones to the queue. + * Adds a clone to the queue. */ - function enqueue(count) { - while (count--) { - queue.push(bench.clone({ - '_original': bench, - 'events': { - 'abort': [update], - 'cycle': [update], - 'error': [update], - 'start': [update] - } - })); - } + function enqueue() { + queue.push(bench.clone({ + '_original': bench, + 'events': { + 'abort': [update], + 'cycle': [update], + 'error': [update], + 'start': [update] + } + })); } /** @@ -2817,14 +2815,14 @@ } // if time permits, increase sample size to reduce the margin of error if (queue.length < 2 && !maxedOut) { - enqueue(1); + enqueue(); } // abort the invoke cycle when done event.aborted = done; } // init queue and begin - enqueue(minSamples); + enqueue(); invoke(queue, { 'name': 'run', 'args': { 'async': async }, From 8052f1ac9dba0576f2f62060e1f1e55605def832 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 13 Jul 2012 04:33:50 -0400 Subject: [PATCH 12/21] Revert unstable Closure Compiler. Former-commit-id: 81716f0c269ac8a5befbf584c0dc964777cc1e1a --- lodash.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lodash.min.js b/lodash.min.js index a0dbd3fc1d..33980c1558 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -9,7 +9,7 @@ function l(e){return"\\"+St[e]}function c(e){return wt[e]}function h(e,t){return {if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=h(t,r));if(i===i>>>0){var o=gt&&tt.call(e)==ht?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=Yt(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function y(e,t,n){if(e)return t==r||n?e[0]:et.call(e,0,t)}function b(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=h(t,n));++sr&&(r=n,i=e[s]);return i}function S(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function x(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=N(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]w(a,r))a.push(r),s.push(e[o]);return s}function N(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?Q.apply(s,o):s),this instanceof n?(p.prototype=e.prototype,u=new p,(o=e.apply(u,o))&&Et[typeof o]?o:u):e.apply(u,o)}var r,i=tt.call(e)==ft;if(i){if(yt||nt&&2++ u&&(l=$[u],!G.call(e,l)||!!(a=G.call(t,l)&&C(e[l],t[l],s))););}return s.pop(),a}function k(e){return e}function L(e){Ht(Kt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Y.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,A,O,M,_,D="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),P=Array.prototype,H=Object.prototype,B=0,j=e._,F=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ ,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g,R=/(__e\(.*?\)|\b__t\))\+'';/g,U=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,z=RegExp("^"+(H.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),W=/__token__(\d+)/g,X=/[&<"']/g,V=/['\n\r\t\u2028\u2029\\]/g,$="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="__token__",K=[],Q=P.concat,G=H.hasOwnProperty,Y=P.push,Z=H.propertyIsEnumerable,et=P.slice,tt=H.toString From f98193d822f6555fd26406c7886eaa5112e11fe4 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 13 Jul 2012 14:41:21 -0400 Subject: [PATCH 13/21] Poll until Firebug-lite is loaded. Former-commit-id: c568ed963fc5716c2c84d63aba45a8ef258c1e7b --- perf/index.html | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/perf/index.html b/perf/index.html index a51c348230..1fa6110b00 100644 --- a/perf/index.html +++ b/perf/index.html @@ -34,14 +34,22 @@ }()); window.onload = function() { - var fbUI = document.getElementById('FirebugUI'), - fbDoc = (fbDoc = fbUI.contentWindow || fbUI.contentDocument).document || fbDoc, - sibling = document.getElementsByTagName('script')[0], - script = document.createElement('script'); + function init() { + var fbUI = document.getElementById('FirebugUI'), + fbDoc = fbUI && (fbDoc = fbUI.contentWindow || fbUI.contentDocument).document || fbDoc; - fbUI.style.height = fbDoc.body.style.height = fbDoc.documentElement.style.height = '100%'; - script.src = 'perf.js?t=' + (+new Date); - sibling.parentNode.insertBefore(script, sibling); + if (!fbDoc || !fbDoc.body) { + return setTimeout(init, 15); + } + var sibling = document.getElementsByTagName('script')[0], + script = document.createElement('script'); + + fbUI.style.height = fbDoc.body.style.height = fbDoc.documentElement.style.height = '100%'; + script.src = 'perf.js?t=' + (+new Date); + sibling.parentNode.insertBefore(script, sibling); + + } + init(); }; From 139693dce6865e28a90ce67ff28ed136dd1a0179 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 14 Jul 2012 04:51:50 -0400 Subject: [PATCH 14/21] Optimize benchmark setups, cleanup perf/index.html, and add platform.js. Former-commit-id: 228b7b6fd230638f9ec8c79eafa56506fc84b79a --- perf/index.html | 35 +- perf/perf.js | 669 ++++++++++++++---------- vendor/platform.js/LICENSE.txt | 20 + vendor/platform.js/README.md | 99 ++++ vendor/platform.js/platform.js | 922 +++++++++++++++++++++++++++++++++ 5 files changed, 1467 insertions(+), 278 deletions(-) create mode 100644 vendor/platform.js/LICENSE.txt create mode 100644 vendor/platform.js/README.md create mode 100644 vendor/platform.js/platform.js diff --git a/perf/index.html b/perf/index.html index 1fa6110b00..2fc310deb6 100644 --- a/perf/index.html +++ b/perf/index.html @@ -21,36 +21,37 @@ var lodash = _.noConflict(); + + diff --git a/perf/perf.js b/perf/perf.js index 4588f94555..5a696456ba 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -25,10 +25,8 @@ _._ || _ ); - /** Used to access the Firebug Lite panel */ - var fbPanel = (fbPanel = window.document && document.getElementById('FirebugUI')) && - (fbPanel = (fbPanel = fbPanel.contentWindow || fbPanel.contentDocument).document || fbPanel) && - fbPanel.getElementById('fbPanel1'); + /** Used to access the Firebug Lite panel (set by `run`) */ + var fbPanel; /** Used to score Lo-Dash and Underscore performance */ var score = { 'lodash': 0, 'underscore': 0 }; @@ -72,20 +70,32 @@ } } + /** + * Runs all benchmark suites. + * + * @private (@public in the browser) + */ + function run() { + fbPanel = (fbPanel = window.document && document.getElementById('FirebugUI')) && + (fbPanel = (fbPanel = fbPanel.contentWindow || fbPanel.contentDocument).document || fbPanel) && + fbPanel.getElementById('fbPanel1'); + + log('\nSit back and relax, this may take a while.'); + suites[0].run(); + } + /*--------------------------------------------------------------------------*/ lodash.extend(Benchmark.options, { 'async': true, - 'maxTime': 1, - 'minSamples': 30, 'setup': function() { var window = Function('return this || global')(), _ = window._, - lodash = window.lodash; + lodash = window.lodash, + belt = this.name == 'Lo-Dash' ? lodash : _; var index, length, - belt = this.name == 'Lo-Dash' ? lodash : _, limit = 20, object = {}, objects = Array(limit), @@ -94,23 +104,30 @@ nestedNumbers = [1, [2], [3, [[4]]]], twoNumbers = [12, 21]; - var object2 = {}, - objects2 = Array(limit), - numbers2 = Array(limit), - nestedNumbers2 = [1, [2], [3, [[4]]]]; - for (index = 0, length = limit; index < length; index++) { numbers[index] = index; - numbers2[index] = index; - object['key' + index] = index; - object2['key' + index] = index; - objects[index] = { 'num': index }; - objects2[index] = { 'num': index }; } - if (typeof isBindAll != 'undefined') { + if (typeof bind != 'undefined') { + var contextObject = { 'name': 'moe' }, + ctor = function() {}; + + var func = function(greeting, punctuation) { + return greeting + ', ' + this.name + (punctuation || '.'); + }; + + var lodashBoundNormal = lodash.bind(func, contextObject), + lodashBoundCtor = lodash.bind(ctor, contextObject), + lodashBoundPartial = lodash.bind(func, contextObject, 'hi'); + + var _boundNormal = _.bind(func, contextObject), + _boundCtor = _.bind(ctor, contextObject), + _boundPartial = _.bind(func, contextObject, 'hi'); + } + + if (typeof bindAll != 'undefined') { var bindAllObjects = Array(this.count), funcNames = belt.functions(lodash); @@ -120,153 +137,154 @@ } } - var ctor = function() {}; - - var func = function(greeting, punctuation) { - return greeting + ', ' + this.name + (punctuation || '.'); - }; - - var objectOfPrimitives = { - 'boolean': true, - 'number': 1, - 'string': 'a' - }; - - var objectOfObjects = { - 'boolean': new Boolean(true), - 'number': new Number(1), - 'string': new String('a') - }; - - var contextObject = { 'name': 'moe' }; - - var lodashBoundNormal = lodash.bind(func, contextObject), - lodashBoundCtor = lodash.bind(ctor, contextObject), - lodashBoundPartial = lodash.bind(func, contextObject, 'hi'); - - var _boundNormal = _.bind(func, contextObject), - _boundCtor = _.bind(ctor, contextObject), - _boundPartial = _.bind(func, contextObject, 'hi'); - - var tplData = { - 'header1': 'Header1', - 'header2': 'Header2', - 'header3': 'Header3', - 'header4': 'Header4', - 'header5': 'Header5', - 'header6': 'Header6', - 'list': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] - }; - - var tplBase = - '
' + - "

<%= header1 %>

" + - "

<%= header2 %>

" + - "

<%= header3 %>

" + - "

<%= header4 %>

" + - "
<%= header5 %>
" + - "
<%= header6 %>
"; - - var tpl = - tplBase + - "
    " + - "
  • <%= list[0] %>
  • " + - "
  • <%= list[1] %>
  • " + - "
  • <%= list[2] %>
  • " + - "
  • <%= list[3] %>
  • " + - "
  • <%= list[4] %>
  • " + - "
  • <%= list[5] %>
  • " + - "
  • <%= list[6] %>
  • " + - "
  • <%= list[7] %>
  • " + - "
  • <%= list[8] %>
  • " + - "
  • <%= list[9] %>
  • " + - '
' + - '
'; - - var tplWithEvaluate = - tplBase + - "
    " + - '<% for (var index = 0, length = list.length; index < length; index++) { %>' + - "
  • <%= list[index] %>
  • " + - '<% } %>' + - '
' + - ''; - - var tplBaseVerbose = - '
' + - "

<%= data.header1 %>

" + - "

<%= data.header2 %>

" + - "

<%= data.header3 %>

" + - "

<%= data.header4 %>

" + - "
<%= data.header5 %>
" + - "
<%= data.header6 %>
"; - - var tplVerbose = - tplBaseVerbose + - "
    " + - "
  • <%= data.list[0] %>
  • " + - "
  • <%= data.list[1] %>
  • " + - "
  • <%= data.list[2] %>
  • " + - "
  • <%= data.list[3] %>
  • " + - "
  • <%= data.list[4] %>
  • " + - "
  • <%= data.list[5] %>
  • " + - "
  • <%= data.list[6] %>
  • " + - "
  • <%= data.list[7] %>
  • " + - "
  • <%= data.list[8] %>
  • " + - "
  • <%= data.list[9] %>
  • " + - '
' + - '
'; - - var tplVerboseWithEvaluate = - tplBaseVerbose + - "
    " + - '<% for (var index = 0, length = data.list.length; index < length; index++) { %>' + - "
  • <%= data.list[index] %>
  • " + - '<% } %>' + - '
' + - ''; - - var settingsObject = { 'variable': 'data' }; - - var lodashTpl = lodash.template(tpl), - lodashTplWithEvaluate = lodash.template(tplWithEvaluate), - lodashTplVerbose = lodash.template(tplVerbose, null, settingsObject), - lodashTplVerboseWithEvaluate = lodash.template(tplVerboseWithEvaluate, null, settingsObject); - - var _tpl = _.template(tpl), - _tplWithEvaluate = _.template(tplWithEvaluate), - _tplVerbose = _.template(tplVerbose, null, settingsObject), - _tplVerboseWithEvaluate = _.template(tplVerboseWithEvaluate, null, settingsObject); - - var wordToNumber = { - 'one': 1, - 'two': 2, - 'three': 3, - 'four': 4, - 'five': 5, - 'six': 6, - 'seven': 7, - 'eight': 8, - 'nine': 9, - 'ten': 10, - 'eleven': 11, - 'twelve': 12, - 'thirteen': 13, - 'fourteen': 14, - 'fifteen': 15, - 'sixteen': 16, - 'seventeen': 17, - 'eighteen': 18, - 'nineteen': 19, - 'twenty': 20, - 'twenty-one': 21, - 'twenty-two': 22, - 'twenty-three': 23, - 'twenty-four': 24, - 'twenty-five': 25 - }; - - var words = belt.keys(wordToNumber).slice(0, limit); + if (typeof groupBy != 'undefined') { + var wordToNumber = { + 'one': 1, + 'two': 2, + 'three': 3, + 'four': 4, + 'five': 5, + 'six': 6, + 'seven': 7, + 'eight': 8, + 'nine': 9, + 'ten': 10, + 'eleven': 11, + 'twelve': 12, + 'thirteen': 13, + 'fourteen': 14, + 'fifteen': 15, + 'sixteen': 16, + 'seventeen': 17, + 'eighteen': 18, + 'nineteen': 19, + 'twenty': 20, + 'twenty-one': 21, + 'twenty-two': 22, + 'twenty-three': 23, + 'twenty-four': 24, + 'twenty-five': 25 + }; + + var words = belt.keys(wordToNumber).slice(0, limit); + } + + if (typeof isEqual != 'undefined') { + var objectOfPrimitives = { + 'boolean': true, + 'number': 1, + 'string': 'a' + }; + + var objectOfObjects = { + 'boolean': new Boolean(true), + 'number': new Number(1), + 'string': new String('a') + }; + + var object2 = {}, + objects2 = Array(limit), + numbers2 = Array(limit), + nestedNumbers2 = [1, [2], [3, [[4]]]]; + + for (index = 0, length = limit; index < length; index++) { + numbers2[index] = index; + object2['key' + index] = index; + objects2[index] = { 'num': index }; + } + } + + if (typeof template != 'undefined') { + var tplData = { + 'header1': 'Header1', + 'header2': 'Header2', + 'header3': 'Header3', + 'header4': 'Header4', + 'header5': 'Header5', + 'header6': 'Header6', + 'list': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] + }; + + var tplBase = + '
' + + "

<%= header1 %>

" + + "

<%= header2 %>

" + + "

<%= header3 %>

" + + "

<%= header4 %>

" + + "
<%= header5 %>
" + + "
<%= header6 %>
"; + + var tpl = + tplBase + + "
    " + + "
  • <%= list[0] %>
  • " + + "
  • <%= list[1] %>
  • " + + "
  • <%= list[2] %>
  • " + + "
  • <%= list[3] %>
  • " + + "
  • <%= list[4] %>
  • " + + "
  • <%= list[5] %>
  • " + + "
  • <%= list[6] %>
  • " + + "
  • <%= list[7] %>
  • " + + "
  • <%= list[8] %>
  • " + + "
  • <%= list[9] %>
  • " + + '
' + + '
'; + + var tplWithEvaluate = + tplBase + + "
    " + + '<% for (var index = 0, length = list.length; index < length; index++) { %>' + + "
  • <%= list[index] %>
  • " + + '<% } %>' + + '
' + + ''; + + var tplBaseVerbose = + '
' + + "

<%= data.header1 %>

" + + "

<%= data.header2 %>

" + + "

<%= data.header3 %>

" + + "

<%= data.header4 %>

" + + "
<%= data.header5 %>
" + + "
<%= data.header6 %>
"; + + var tplVerbose = + tplBaseVerbose + + "
    " + + "
  • <%= data.list[0] %>
  • " + + "
  • <%= data.list[1] %>
  • " + + "
  • <%= data.list[2] %>
  • " + + "
  • <%= data.list[3] %>
  • " + + "
  • <%= data.list[4] %>
  • " + + "
  • <%= data.list[5] %>
  • " + + "
  • <%= data.list[6] %>
  • " + + "
  • <%= data.list[7] %>
  • " + + "
  • <%= data.list[8] %>
  • " + + "
  • <%= data.list[9] %>
  • " + + '
' + + '
'; + + var tplVerboseWithEvaluate = + tplBaseVerbose + + "
    " + + '<% for (var index = 0, length = data.list.length; index < length; index++) { %>' + + "
  • <%= data.list[index] %>
  • " + + '<% } %>' + + '
' + + ''; + + var settingsObject = { 'variable': 'data' }; + + var lodashTpl = lodash.template(tpl), + lodashTplWithEvaluate = lodash.template(tplWithEvaluate), + lodashTplVerbose = lodash.template(tplVerbose, null, settingsObject), + lodashTplVerboseWithEvaluate = lodash.template(tplVerboseWithEvaluate, null, settingsObject); + + var _tpl = _.template(tpl), + _tplWithEvaluate = _.template(tplWithEvaluate), + _tplVerbose = _.template(tplVerbose, null, settingsObject), + _tplVerboseWithEvaluate = _.template(tplVerboseWithEvaluate, null, settingsObject); + } } }); @@ -331,61 +349,97 @@ suites.push( Benchmark.Suite('`_.bind` (uses native `Function#bind` if available and inferred fast)') - .add('Lo-Dash', function() { - lodash.bind(func, { 'name': 'moe' }, 'hi'); + .add('Lo-Dash', { + 'fn': function() { + lodash.bind(func, { 'name': 'moe' }, 'hi'); + }, + 'teardown': 'function bind(){}' }) - .add('Underscore', function() { - _.bind(func, { 'name': 'moe' }, 'hi'); + .add('Underscore', { + 'fn': function() { + _.bind(func, { 'name': 'moe' }, 'hi'); + }, + 'teardown': 'function bind(){}' }) ); suites.push( Benchmark.Suite('bound call') - .add('Lo-Dash', function() { - lodashBoundNormal(); + .add('Lo-Dash', { + 'fn': function() { + lodashBoundNormal(); + }, + 'teardown': 'function bind(){}' }) - .add('Underscore', function() { - _boundNormal(); + .add('Underscore', { + 'fn': function() { + _boundNormal(); + }, + 'teardown': 'function bind(){}' }) ); suites.push( Benchmark.Suite('bound call with arguments') - .add('Lo-Dash', function() { - lodashBoundNormal('hi', '!'); + .add('Lo-Dash', { + 'fn': function() { + lodashBoundNormal('hi', '!'); + }, + 'teardown': 'function bind(){}' }) - .add('Underscore', function() { - _boundNormal('hi', '!'); + .add('Underscore', { + 'fn': function() { + _boundNormal('hi', '!'); + }, + 'teardown': 'function bind(){}' }) ); suites.push( Benchmark.Suite('bound and partially applied call (uses native `Function#bind` if available)') - .add('Lo-Dash', function() { - lodashBoundPartial(); + .add('Lo-Dash', { + 'fn': function() { + lodashBoundPartial(); + }, + 'teardown': 'function bind(){}' }) - .add('Underscore', function() { - _boundPartial(); + .add('Underscore', { + 'fn': function() { + _boundPartial(); + }, + 'teardown': 'function bind(){}' }) ); suites.push( Benchmark.Suite('bound and partially applied call with arguments (uses native `Function#bind` if available)') - .add('Lo-Dash', function() { - lodashBoundPartial('!'); + .add('Lo-Dash', { + 'fn': function() { + lodashBoundPartial('!'); + }, + 'teardown': 'function bind(){}' }) - .add('Underscore', function() { - _boundPartial('!'); + .add('Underscore', { + 'fn': function() { + _boundPartial('!'); + }, + 'teardown': 'function bind(){}' }) ); suites.push( Benchmark.Suite('bound and called in a `new` expression, i.e. `new bound` (edge case)') - .add('Lo-Dash', function() { - new lodashBoundCtor(); + .add('Lo-Dash', { + 'fn': function() { + new lodashBoundCtor(); + }, + 'teardown': 'function bind(){}' }) - .add('Underscore', function() { - new _boundCtor(); + .add('Underscore', { + 'fn': function() { + new _boundCtor(); + }, + 'teardown': 'function bind(){}' }) ); @@ -397,13 +451,13 @@ 'fn': function() { lodash.bindAll.apply(lodash, [bindAllObjects.pop()].concat(funcNames)); }, - 'teardown': 'function isBindAll(){}' + 'teardown': 'function bindAll(){}' }) .add('Underscore', { 'fn': function() { _.bindAll.apply(_, [bindAllObjects.pop()].concat(funcNames)); }, - 'teardown': 'function isBindAll(){}' + 'teardown': 'function bindAll(){}' }) ); @@ -413,13 +467,13 @@ 'fn': function() { lodash.bindAll(bindAllObjects.pop()); }, - 'teardown': 'function isBindAll(){}' + 'teardown': 'function bindAll(){}' }) .add('Underscore', { 'fn': function() { _.bindAll(bindAllObjects.pop()); }, - 'teardown': 'function isBindAll(){}' + 'teardown': 'function bindAll(){}' }) ); @@ -607,21 +661,33 @@ suites.push( Benchmark.Suite('`_.groupBy` with `property` name iterating an array') - .add('Lo-Dash', function() { - lodash.groupBy(words, 'length'); + .add('Lo-Dash', { + 'fn': function() { + lodash.groupBy(words, 'length'); + }, + 'teardown': 'function groupBy(){}' }) - .add('Underscore', function() { - _.groupBy(words, 'length'); + .add('Underscore', { + 'fn': function() { + _.groupBy(words, 'length'); + }, + 'teardown': 'function groupBy(){}' }) ); suites.push( Benchmark.Suite('`_.groupBy` with `callback` iterating an object') - .add('Lo-Dash', function() { - lodash.groupBy(wordToNumber, function(num) { return num >> 1; }); + .add('Lo-Dash', { + 'fn': function() { + lodash.groupBy(wordToNumber, function(num) { return num >> 1; }); + }, + 'teardown': 'function groupBy(){}' }) - .add('Underscore', function() { - _.groupBy(wordToNumber, function(num) { return num >> 1; }); + .add('Underscore', { + 'fn': function() { + _.groupBy(wordToNumber, function(num) { return num >> 1; }); + }, + 'teardown': 'function groupBy(){}' }) ); @@ -663,51 +729,81 @@ suites.push( Benchmark.Suite('`_.isEqual` comparing primitives and objects (edge case)') - .add('Lo-Dash', function() { - lodash.isEqual(objectOfPrimitives, objectOfObjects); + .add('Lo-Dash', { + 'fn': function() { + lodash.isEqual(objectOfPrimitives, objectOfObjects); + }, + 'teardown': 'function isEqual(){}' }) - .add('Underscore', function() { - _.isEqual(objectOfPrimitives, objectOfObjects); + .add('Underscore', { + 'fn': function() { + _.isEqual(objectOfPrimitives, objectOfObjects); + }, + 'teardown': 'function isEqual(){}' }) ); suites.push( Benchmark.Suite('`_.isEqual` comparing arrays') - .add('Lo-Dash', function() { - lodash.isEqual(numbers, numbers2); + .add('Lo-Dash', { + 'fn': function() { + lodash.isEqual(numbers, numbers2); + }, + 'teardown': 'function isEqual(){}' }) - .add('Underscore', function() { - _.isEqual(numbers, numbers2); + .add('Underscore', { + 'fn': function() { + _.isEqual(numbers, numbers2); + }, + 'teardown': 'function isEqual(){}' }) ); suites.push( Benchmark.Suite('`_.isEqual` comparing nested arrays') - .add('Lo-Dash', function() { - lodash.isEqual(nestedNumbers, nestedNumbers2); + .add('Lo-Dash', { + 'fn': function() { + lodash.isEqual(nestedNumbers, nestedNumbers2); + }, + 'teardown': 'function isEqual(){}' }) - .add('Underscore', function() { - _.isEqual(nestedNumbers, nestedNumbers2); + .add('Underscore', { + 'fn': function() { + _.isEqual(nestedNumbers, nestedNumbers2); + }, + 'teardown': 'function isEqual(){}' }) ); suites.push( Benchmark.Suite('`_.isEqual` comparing arrays of objects') - .add('Lo-Dash', function() { - lodash.isEqual(objects, objects2); + .add('Lo-Dash', { + 'fn': function() { + lodash.isEqual(objects, objects2); + }, + 'teardown': 'function isEqual(){}' }) - .add('Underscore', function() { - _.isEqual(objects, objects2); + .add('Underscore', { + 'fn': function() { + _.isEqual(objects, objects2); + }, + 'teardown': 'function isEqual(){}' }) ); suites.push( Benchmark.Suite('`_.isEqual` comparing objects') - .add('Lo-Dash', function() { - lodash.isEqual(object, object2); + .add('Lo-Dash', { + 'fn': function() { + lodash.isEqual(object, object2); + }, + 'teardown': 'function isEqual(){}' }) - .add('Underscore', function() { - _.isEqual(object, object2); + .add('Underscore', { + 'fn': function() { + _.isEqual(object, object2); + }, + 'teardown': 'function isEqual(){}' }) ); @@ -885,11 +981,17 @@ suites.push( Benchmark.Suite('`_.sortBy` with `property` name') - .add('Lo-Dash', function() { - lodash.sortBy(words, 'length'); + .add('Lo-Dash', { + 'fn': function() { + lodash.sortBy(words, 'length'); + }, + 'teardown': 'function groupBy(){}' }) - .add('Underscore', function() { - _.sortBy(words, 'length'); + .add('Underscore', { + 'fn': function() { + _.sortBy(words, 'length'); + }, + 'teardown': 'function groupBy(){}' }) ); @@ -907,15 +1009,21 @@ suites.push( Benchmark.Suite('`_.sortedIndex` with `callback`') - .add('Lo-Dash', function() { - lodash.sortedIndex(words, 'twenty-five', function(value) { - return wordToNumber[value]; - }); + .add('Lo-Dash', { + 'fn': function() { + lodash.sortedIndex(words, 'twenty-five', function(value) { + return wordToNumber[value]; + }); + }, + 'teardown': 'function groupBy(){}' }) - .add('Underscore', function() { - _.sortedIndex(words, 'twenty-five', function(value) { - return wordToNumber[value]; - }); + .add('Underscore', { + 'fn': function() { + _.sortedIndex(words, 'twenty-five', function(value) { + return wordToNumber[value]; + }); + }, + 'teardown': 'function groupBy(){}' }) ); @@ -923,61 +1031,97 @@ suites.push( Benchmark.Suite('`_.template` without "evaluate" delimiters (slow path)') - .add('Lo-Dash', function() { - lodash.template(tpl, tplData); + .add('Lo-Dash', { + 'fn': function() { + lodash.template(tpl, tplData); + }, + 'teardown': 'function template(){}' }) - .add('Underscore', function() { - _.template(tpl, tplData); + .add('Underscore', { + 'fn': function() { + _.template(tpl, tplData); + }, + 'teardown': 'function template(){}' }) ); suites.push( Benchmark.Suite('`_.template` with "evaluate" delimiters (slow path)') - .add('Lo-Dash', function() { - lodash.template(tplWithEvaluate, tplData); + .add('Lo-Dash', { + 'fn': function() { + lodash.template(tplWithEvaluate, tplData); + }, + 'teardown': 'function template(){}' }) - .add('Underscore', function() { - _.template(tplWithEvaluate, tplData); + .add('Underscore', { + 'fn': function() { + _.template(tplWithEvaluate, tplData); + }, + 'teardown': 'function template(){}' }) ); suites.push( Benchmark.Suite('compiled template without "evaluate" delimiters') - .add('Lo-Dash', function() { - lodashTpl(tplData); + .add('Lo-Dash', { + 'fn': function() { + lodashTpl(tplData); + }, + 'teardown': 'function template(){}' }) - .add('Underscore', function() { - _tpl(tplData); + .add('Underscore', { + 'fn': function() { + _tpl(tplData); + }, + 'teardown': 'function template(){}' }) ); suites.push( Benchmark.Suite('compiled template with "evaluate" delimiters') - .add('Lo-Dash', function() { - lodashTplWithEvaluate(tplData); + .add('Lo-Dash', { + 'fn': function() { + lodashTplWithEvaluate(tplData); + }, + 'teardown': 'function template(){}' }) - .add('Underscore', function() { - _tplWithEvaluate(tplData); + .add('Underscore', { + 'fn': function() { + _tplWithEvaluate(tplData); + }, + 'teardown': 'function template(){}' }) ); suites.push( Benchmark.Suite('compiled template without a with-statement or "evaluate" delimiters') - .add('Lo-Dash', function() { - lodashTplVerbose(tplData); + .add('Lo-Dash', { + 'fn': function() { + lodashTplVerbose(tplData); + }, + 'teardown': 'function template(){}' }) - .add('Underscore', function() { - _tplVerbose(tplData); + .add('Underscore', { + 'fn': function() { + _tplVerbose(tplData); + }, + 'teardown': 'function template(){}' }) ); suites.push( Benchmark.Suite('compiled template without a with-statement using "evaluate" delimiters') - .add('Lo-Dash', function() { - lodashTplVerboseWithEvaluate(tplData); + .add('Lo-Dash', { + 'fn': function() { + lodashTplVerboseWithEvaluate(tplData); + }, + 'teardown': 'function template(){}' }) - .add('Underscore', function() { - _tplVerboseWithEvaluate(tplData); + .add('Underscore', { + 'fn': function() { + _tplVerboseWithEvaluate(tplData); + }, + 'teardown': 'function template(){}' }) ); @@ -1084,8 +1228,11 @@ if (Benchmark.platform + '') { log(Benchmark.platform + ''); } - // start suites - log('\nSit back and relax, this may take a while.'); - suites[0].run(); + // in the browser, expose `run` to be called later + if (window.document) { + window.run = run; + } else { + run(); + } }(typeof global == 'object' && global || this)); diff --git a/vendor/platform.js/LICENSE.txt b/vendor/platform.js/LICENSE.txt new file mode 100644 index 0000000000..dadad22fa7 --- /dev/null +++ b/vendor/platform.js/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright 2011-2012 John-David Dalton + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vendor/platform.js/README.md b/vendor/platform.js/README.md new file mode 100644 index 0000000000..4e5c08a90c --- /dev/null +++ b/vendor/platform.js/README.md @@ -0,0 +1,99 @@ +# Platform.js v1.0.0-pre + +A platform detection library that works on nearly all JavaScript platforms1. + +## Disclaimer + +Platform.js is for informational purposes only and **not** intended as a substitution for [feature detection/inference](http://allyoucanleet.com/post/18087210413/feature-testing-costs#screencast2) checks. + +## BestieJS + +Platform.js is part of the BestieJS *"Best in Class"* module collection. This means we promote solid browser/environment support, ES5 precedents, unit testing, and plenty of documentation. + +## Documentation + +The documentation for Platform.js can be viewed here: [/doc/README.md](https://github.com/bestiejs/platform.js/blob/master/doc/README.md#readme) + +For a list of upcoming features, check out our [roadmap](https://github.com/bestiejs/platform.js/wiki/Roadmap). + +## Installation and usage + +In a browser or Adobe AIR: + +~~~ html + +~~~ + +Via [npm](http://npmjs.org/): + +~~~ bash +npm install platform +~~~ + +In [Narwhal](http://narwhaljs.org/), [Node.js](http://nodejs.org/), and [RingoJS](http://ringojs.org/): + +~~~ js +var platform = require('platform'); +~~~ + +In [Rhino](http://www.mozilla.org/rhino/): + +~~~ js +load('platform.js'); +~~~ + +In an AMD loader like [RequireJS](http://requirejs.org/): + +~~~ js +require({ + 'paths': { + 'platform': 'path/to/platform' + } +}, +['platform'], function(platform) { + console.log(platform.name); +}); +~~~ + +Usage example: + +~~~ js +// on IE10 x86 platform preview running in IE7 compatibility mode on Windows 7 64 bit edition +platform.name; // 'IE' +platform.version; // '10.0' +platform.layout; // 'Trident' +platform.os; // 'Windows Server 2008 R2 / 7 x64' +platform.description; // 'IE 10.0 x86 (platform preview; running in IE 7 mode) on Windows Server 2008 R2 / 7 x64' + +// or on an iPad +platform.name; // 'Safari' +platform.version; // '5.1' +platform.product; // 'iPad' +platform.manufacturer; // 'Apple' +platform.layout; // 'WebKit' +platform.os; // 'iOS 5.0' +platform.description; // 'Safari 5.1 on Apple iPad (iOS 5.0)' + +// or parsing a given UA string +var info = platform.parse('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7.2; en; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 11.52'); +info.name; // 'Opera' +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' +~~~ + +## Footnotes + + 1. Platform.js has been tested in at least Adobe AIR 2.6, Chrome 5-15, Firefox 1.5-8, IE 6-10, Opera 9.25-11.52, Safari 2-5.1.1, Node.js 0.4.8-0.6.1, Narwhal 0.3.2, RingoJS 0.7-0.8, and Rhino 1.7RC3. + + +## Author + +* [John-David Dalton](http://allyoucanleet.com/) + [![twitter/jdalton](http://gravatar.com/avatar/299a3d891ff1920b69c364d061007043?s=70)](https://twitter.com/jdalton "Follow @jdalton on Twitter") + +## Contributors + +* [Mathias Bynens](http://mathiasbynens.be/) + [![twitter/mathias](http://gravatar.com/avatar/24e08a9ea84deb17ae121074d0f17125?s=70)](https://twitter.com/mathias "Follow @mathias on Twitter") diff --git a/vendor/platform.js/platform.js b/vendor/platform.js/platform.js new file mode 100644 index 0000000000..722fd3f126 --- /dev/null +++ b/vendor/platform.js/platform.js @@ -0,0 +1,922 @@ +/*! + * Platform.js v1.0.0-pre + * Copyright 2010-2012 John-David Dalton + * Available under MIT license + */ +;(function(window) { + 'use strict'; + + /** Backup possible window/global object */ + var oldWin = window; + + /** Detect free variable `exports` */ + var freeExports = typeof exports == 'object' && exports; + + /** Detect free variable `global` */ + var freeGlobal = typeof global == 'object' && global && + (global == global.global ? (window = global) : global); + + /** Opera regexp */ + var reOpera = /Opera/; + + /** Used to resolve a value's internal [[Class]] */ + var toString = {}.toString; + + /** Detect Java environment */ + var java = /Java/.test(getClassOf(window.java)) && window.java; + + /** A character to represent alpha */ + var alpha = java ? 'a' : '\u03b1'; + + /** A character to represent beta */ + var beta = java ? 'b' : '\u03b2'; + + /** Browser document object */ + var doc = window.document || {}; + + /** Used to check for own properties of an object */ + var hasOwnProperty = {}.hasOwnProperty; + + /** Browser navigator object */ + var nav = window.navigator || {}; + + /** + * Detect Opera browser + * http://www.howtocreate.co.uk/operaStuff/operaObject.html + * http://dev.opera.com/articles/view/opera-mini-web-content-authoring-guidelines/#operamini + */ + var opera = window.operamini || window.opera; + + /** Opera [[Class]] */ + var operaClass = reOpera.test(operaClass = getClassOf(opera)) ? operaClass : (opera = null); + + /** Possible global object */ + var thisBinding = this; + + /** Browser user agent string */ + var userAgent = nav.userAgent || ''; + + /*--------------------------------------------------------------------------*/ + + /** + * Capitalizes a string value. + * + * @private + * @param {String} string The string to capitalize. + * @returns {String} The capitalized string. + */ + function capitalize(string) { + string = String(string); + return string.charAt(0).toUpperCase() + string.slice(1); + } + + /** + * An iteration utility for arrays and objects. + * + * @private + * @param {Array|Object} object The object to iterate over. + * @param {Function} callback The function called per iteration. + */ + function each(object, callback) { + var index = -1, + length = object.length; + + if (length == length >>> 0) { + while (++index < length) { + callback(object[index], index, object); + } + } else { + forOwn(object, callback); + } + } + + /** + * Trim and conditionally capitalize string values. + * + * @private + * @param {String} string The string to format. + * @returns {String} The formatted string. + */ + function format(string) { + string = trim(string); + return /^(?:webOS|i(?:OS|P))/.test(string) + ? string + : capitalize(string); + } + + /** + * Iterates over an object's own properties, executing the `callback` for each. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} callback The function executed per own property. + */ + function forOwn(object, callback) { + for (var key in object) { + hasKey(object, key) && callback(object[key], key, object); + } + } + + /** + * Gets the internal [[Class]] of a value. + * + * @private + * @param {Mixed} value The value. + * @returns {String} The [[Class]]. + */ + function getClassOf(value) { + return value == null + ? capitalize(value) + : toString.call(value).slice(8, -1); + } + + /** + * Checks if an object has the specified key as a direct property. + * + * @private + * @param {Object} object The object to check. + * @param {String} key The key to check for. + * @returns {Boolean} Returns `true` if key is a direct property, else `false`. + */ + function hasKey() { + // lazy define for others (not as accurate) + hasKey = function(object, key) { + var parent = object != null && (object.constructor || Object).prototype; + return !!parent && key in Object(object) && !(key in parent && object[key] === parent[key]); + }; + // for modern browsers + if (getClassOf(hasOwnProperty) == 'Function') { + hasKey = function(object, key) { + return object != null && hasOwnProperty.call(object, key); + }; + } + // for Safari 2 + else if ({}.__proto__ == Object.prototype) { + hasKey = function(object, key) { + var result = false; + if (object != null) { + object = Object(object); + object.__proto__ = [object.__proto__, object.__proto__ = null, result = key in object][0]; + } + return result; + }; + } + return hasKey.apply(this, arguments); + } + + /** + * Host objects can return type values that are different from their actual + * data type. The objects we are concerned with usually return non-primitive + * types of object, function, or unknown. + * + * @private + * @param {Mixed} object The owner of the property. + * @param {String} property The property to check. + * @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`. + */ + function isHostType(object, property) { + var type = object != null ? typeof object[property] : 'number'; + return !/^(?:boolean|number|string|undefined)$/.test(type) && + (type == 'object' ? !!object[property] : true); + } + + /** + * Prepares a string for use in a RegExp constructor by making hyphens and + * spaces optional. + * + * @private + * @param {String} string The string to qualify. + * @returns {String} The qualified string. + */ + function qualify(string) { + return String(string).replace(/([ -])(?!$)/g, '$1?'); + } + + /** + * A bare-bones` Array#reduce` like utility function. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} callback The function called per iteration. + * @param {Mixed} accumulator Initial value of the accumulator. + * @returns {Mixed} The accumulator. + */ + function reduce(array, callback) { + var accumulator = null; + each(array, function(value, index) { + accumulator = callback(accumulator, value, index, array); + }); + return accumulator; + } + + /** + * Removes leading and trailing whitespace from a string. + * + * @private + * @param {String} string The string to trim. + * @returns {String} The trimmed string. + */ + function trim(string) { + return String(string).replace(/^ +| +$/g, ''); + } + + /*--------------------------------------------------------------------------*/ + + /** + * Creates a new platform object. + * + * @memberOf platform + * @param {String} [ua = navigator.userAgent] The user agent string. + * @returns {Object} A platform object. + */ + function parse(ua) { + + ua || (ua = userAgent); + + /** Temporary variable used over the script's lifetime */ + var data; + + /** The CPU architecture */ + var arch = ua; + + /** Platform description array */ + var description = []; + + /** Platform alpha/beta indicator */ + var prerelease = null; + + /** A flag to indicate that environment features should be used to resolve the platform */ + var useFeatures = ua == userAgent; + + /** The browser/environment version */ + var version = useFeatures && opera && typeof opera.version == 'function' && opera.version(); + + /* Detectable layout engines (order is important) */ + var layout = getLayout([ + { 'label': 'WebKit', 'pattern': 'AppleWebKit' }, + 'iCab', + 'Presto', + 'NetFront', + 'Tasman', + 'Trident', + 'KHTML', + 'Gecko' + ]); + + /* Detectable browser names (order is important) */ + var name = getName([ + 'Adobe AIR', + 'Arora', + 'Avant Browser', + 'Camino', + 'Epiphany', + 'Fennec', + 'Flock', + 'Galeon', + 'GreenBrowser', + 'iCab', + 'Iceweasel', + 'Iron', + 'K-Meleon', + 'Konqueror', + 'Lunascape', + 'Maxthon', + 'Midori', + 'Nook Browser', + 'PhantomJS', + 'Raven', + 'Rekonq', + 'RockMelt', + 'SeaMonkey', + { 'label': 'Silk', 'pattern': '(?:Cloud9|Silk-Accelerated)' }, + 'Sleipnir', + 'SlimBrowser', + 'Sunrise', + 'Swiftfox', + 'WebPositive', + 'Opera Mini', + 'Opera', + 'Chrome', + { 'label': 'Chrome Mobile', 'pattern': 'CrMo' }, + { 'label': 'Firefox', 'pattern': '(?:Firefox|Minefield)' }, + { 'label': 'IE', 'pattern': 'MSIE' }, + 'Safari' + ]); + + /* Detectable products (order is important) */ + var product = getProduct([ + 'BlackBerry', + { 'label': 'Galaxy S', 'pattern': 'GT-I9000' }, + { 'label': 'Galaxy S2', 'pattern': 'GT-I9100' }, + 'Google TV', + 'iPad', + 'iPod', + 'iPhone', + 'Kindle', + { 'label': 'Kindle Fire', 'pattern': '(?:Cloud9|Silk-Accelerated)' }, + 'Nook', + 'PlayBook', + 'PlayStation Vita', + 'TouchPad', + 'Transformer', + 'Xoom' + ]); + + /* Detectable manufacturers */ + var manufacturer = getManufacturer({ + 'Apple': { 'iPad': 1, 'iPhone': 1, 'iPod': 1 }, + 'Amazon': { 'Kindle': 1, 'Kindle Fire': 1 }, + 'Asus': { 'Transformer': 1 }, + 'Barnes & Noble': { 'Nook': 1 }, + 'BlackBerry': { 'PlayBook': 1 }, + 'Google': { 'Google TV': 1 }, + 'HP': { 'TouchPad': 1 }, + 'LG': { }, + 'Motorola': { 'Xoom': 1 }, + 'Nokia': { }, + 'Samsung': { 'Galaxy S': 1, 'Galaxy S2': 1 }, + 'Sony': { 'PlayStation Vita': 1 } + }); + + /* Detectable OSes (order is important) */ + var os = getOS([ + 'Android', + 'CentOS', + 'Debian', + 'Fedora', + 'FreeBSD', + 'Gentoo', + 'Haiku', + 'Kubuntu', + 'Linux Mint', + 'Red Hat', + 'SuSE', + 'Ubuntu', + 'Xubuntu', + 'Cygwin', + 'Symbian OS', + 'hpwOS', + 'webOS ', + 'webOS', + 'Tablet OS', + 'Linux', + 'Mac OS X', + 'Macintosh', + 'Mac', + 'Windows 98;', + 'Windows ' + ]); + + /*------------------------------------------------------------------------*/ + + /** + * Picks the layout engine from an array of guesses. + * + * @private + * @param {Array} guesses An array of guesses. + * @returns {String|Null} The detected layout engine. + */ + function getLayout(guesses) { + return reduce(guesses, function(result, guess) { + return result || RegExp('\\b' + ( + guess.pattern || qualify(guess) + ) + '\\b', 'i').exec(ua) && (guess.label || guess); + }); + } + + /** + * Picks the manufacturer from an array of guesses. + * + * @private + * @param {Array} guesses An array of guesses. + * @returns {String|Null} The detected manufacturer. + */ + function getManufacturer(guesses) { + return reduce(guesses, function(result, value, key) { + // lookup the manufacturer by product or scan the UA for the manufacturer + return result || ( + value[product] || + value[0/*Opera 9.25 fix*/, /^[a-z]+(?: +[a-z]+\b)*/i.exec(product)] || + RegExp('\\b' + (key.pattern || qualify(key)) + '(?:\\b|\\w*\\d)', 'i').exec(ua) + ) && (key.label || key); + }); + } + + /** + * Picks the browser name from an array of guesses. + * + * @private + * @param {Array} guesses An array of guesses. + * @returns {String|Null} The detected browser name. + */ + function getName(guesses) { + return reduce(guesses, function(result, guess) { + return result || RegExp('\\b' + ( + guess.pattern || qualify(guess) + ) + '\\b', 'i').exec(ua) && (guess.label || guess); + }); + } + + /** + * Picks the OS name from an array of guesses. + * + * @private + * @param {Array} guesses An array of guesses. + * @returns {String|Null} The detected OS name. + */ + function getOS(guesses) { + return reduce(guesses, function(result, guess) { + var pattern = guess.pattern || qualify(guess); + if (!result && (result = + RegExp('\\b' + pattern + '(?:/[\\d.]+|[ \\w.]*)', 'i').exec(ua))) { + // platform tokens defined at + // http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx + // http://web.archive.org/web/20081122053950/http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx + data = { + '6.2': '8', + '6.1': 'Server 2008 R2 / 7', + '6.0': 'Server 2008 / Vista', + '5.2': 'Server 2003 / XP 64-bit', + '5.1': 'XP', + '5.01': '2000 SP1', + '5.0': '2000', + '4.0': 'NT', + '4.90': 'ME' + }; + // detect Windows version from platform tokens + if (/^Win/i.test(result) && + (data = data[0/*Opera 9.25 fix*/, /[\d.]+$/.exec(result)])) { + result = 'Windows ' + data; + } + // correct character case and cleanup + result = format(String(result) + .replace(RegExp(pattern, 'i'), guess.label || guess) + .replace(/ ce$/i, ' CE') + .replace(/hpw/i, 'web') + .replace(/Macintosh/, 'Mac OS') + .replace(/_PowerPC/i, ' OS') + .replace(/(OS X) [^ \d]+/i, '$1') + .replace(/\/(\d)/, ' $1') + .replace(/_/g, '.') + .replace(/(?: BePC|[ .]*fc[ \d.]+)$/i, '') + .replace(/x86\.64/gi, 'x86_64') + .split(' on ')[0]); + } + return result; + }); + } + + /** + * Picks the product name from an array of guesses. + * + * @private + * @param {Array} guesses An array of guesses. + * @returns {String|Null} The detected product name. + */ + function getProduct(guesses) { + return reduce(guesses, function(result, guess) { + var pattern = guess.pattern || qualify(guess); + if (!result && (result = + RegExp('\\b' + pattern + ' *\\d+[.\\w_]*', 'i').exec(ua) || + RegExp('\\b' + pattern + '(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)', 'i').exec(ua) + )) { + // split by forward slash and append product version if needed + if ((result = String(guess.label || result).split('/'))[1] && !/[\d.]+/.test(result[0])) { + result[0] += ' ' + result[1]; + } + // correct character case and cleanup + guess = guess.label || guess; + result = format(result[0] + .replace(RegExp(pattern, 'i'), guess) + .replace(RegExp('; *(?:' + guess + '[_-])?', 'i'), ' ') + .replace(RegExp('(' + guess + ')(\\w)', 'i'), '$1 $2')); + } + return result; + }); + } + + /** + * Resolves the version using an array of UA patterns. + * + * @private + * @param {Array} patterns An array of UA patterns. + * @returns {String|Null} The detected version. + */ + function getVersion(patterns) { + return reduce(patterns, function(result, pattern) { + return result || (RegExp(pattern + + '(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)', 'i').exec(ua) || 0)[1] || null; + }); + } + + /*------------------------------------------------------------------------*/ + + /** + * Return platform description when the platform object is coerced to a string. + * + * @name toString + * @memberOf platform + * @type Function + * @returns {String} The platform description. + */ + function toStringPlatform() { + return this.description || ''; + } + + /*------------------------------------------------------------------------*/ + + // convert layout to an array so we can add extra details + layout && (layout = [layout]); + + // detect product names that contain their manufacturer's name + if (manufacturer && !product) { + product = getProduct([manufacturer]); + } + // clean up Google TV + if ((data = /Google TV/.exec(product))) { + product = data[0]; + } + // detect simulators + if (/\bSimulator\b/i.test(ua)) { + product = (product ? product + ' ' : '') + 'Simulator'; + } + // detect iOS + if (/^iP/.test(product)) { + name || (name = 'Safari'); + os = 'iOS' + ((data = / OS ([\d_]+)/i.exec(ua)) + ? ' ' + data[1].replace(/_/g, '.') + : ''); + } + // detect Kubuntu + else if (name == 'Konqueror' && !/buntu/i.test(os)) { + os = 'Kubuntu'; + } + // detect Android browsers + else if (manufacturer && manufacturer != 'Google' && + /Chrome|Vita/.test(name + ';' + product)) { + name = 'Android Browser'; + os = /Android/.test(os) ? os : 'Android'; + } + // detect false positives for Firefox/Safari + else if (!name || (data = !/\bMinefield\b/i.test(ua) && /Firefox|Safari/.exec(name))) { + // escape the `/` for Firefox 1 + if (name && !product && /[\/,]|^[^(]+?\)/.test(ua.slice(ua.indexOf(data + '/') + 8))) { + // clear name of false positives + name = null; + } + // reassign a generic name + if ((data = product || manufacturer || os) && + (product || manufacturer || /Android|Symbian OS|Tablet OS|webOS/.test(os))) { + name = /[a-z]+(?: Hat)?/i.exec(/Android/.test(os) ? os : data) + ' Browser'; + } + } + // detect non-Opera versions (order is important) + if (!version) { + version = getVersion([ + '(?:Cloud9|CrMo|Opera ?Mini|Raven|Silk(?!/[\\d.]+$))', + 'Version', + qualify(name), + '(?:Firefox|Minefield|NetFront)' + ]); + } + // detect stubborn layout engines + if (layout == 'iCab' && parseFloat(version) > 3) { + layout = ['WebKit']; + } else if (data = + /Opera/.test(name) && 'Presto' || + /\b(?:Midori|Nook|Safari)\b/i.test(ua) && 'WebKit' || + !layout && /\bMSIE\b/i.test(ua) && (/^Mac/.test(os) ? 'Tasman' : 'Trident')) { + layout = [data]; + } + // leverage environment features + if (useFeatures) { + // detect server-side environments + // Rhino has a global function while others have a global object + if (isHostType(window, 'global')) { + if (java) { + data = java.lang.System; + arch = data.getProperty('os.arch'); + os = os || data.getProperty('os.name') + ' ' + data.getProperty('os.version'); + } + if (typeof exports == 'object' && exports) { + // if `thisBinding` is the [ModuleScope] + if (thisBinding == oldWin && typeof system == 'object' && (data = [system])[0]) { + os || (os = data[0].os || null); + try { + data[1] = require('ringo/engine').version; + version = data[1].join('.'); + name = 'RingoJS'; + } catch(e) { + if (data[0].global == freeGlobal) { + name = 'Narwhal'; + } + } + } else if (typeof process == 'object' && (data = process)) { + name = 'Node.js'; + arch = data.arch; + os = data.platform; + version = /[\d.]+/.exec(data.version)[0]; + } + } else if (getClassOf(window.environment) == 'Environment') { + name = 'Rhino'; + } + } + // detect Adobe AIR + else if (getClassOf(data = window.runtime) == 'ScriptBridgingProxyObject') { + name = 'Adobe AIR'; + os = data.flash.system.Capabilities.os; + } + // detect PhantomJS + else if (getClassOf(data = window.phantom) == 'RuntimeObject') { + name = 'PhantomJS'; + version = (data = data.version || null) && (data.major + '.' + data.minor + '.' + data.patch); + } + // detect IE compatibility modes + else if (typeof doc.documentMode == 'number' && (data = /\bTrident\/(\d+)/i.exec(ua))) { + // we're in compatibility mode when the Trident version + 4 doesn't + // equal the document mode + version = [version, doc.documentMode]; + if ((data = +data[1] + 4) != version[1]) { + description.push('IE ' + version[1] + ' mode'); + layout[1] = ''; + version[1] = data; + } + version = name == 'IE' ? String(version[1].toFixed(1)) : version[0]; + } + os = os && format(os); + } + // detect prerelease phases + if (version && (data = + /(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(version) || + /(?:alpha|beta)(?: ?\d)?/i.exec(ua + ';' + (useFeatures && nav.appMinorVersion)) || + /\bMinefield\b/i.test(ua) && 'a')) { + prerelease = /b/i.test(data) ? 'beta' : 'alpha'; + version = version.replace(RegExp(data + '\\+?$'), '') + + (prerelease == 'beta' ? beta : alpha) + (/\d+\+?/.exec(data) || ''); + } + // rename code name "Fennec" + if (name == 'Fennec') { + name = 'Firefox Mobile'; + } + // obscure Maxthon's unreliable version + else if (name == 'Maxthon' && version) { + version = version.replace(/\.[\d.]+/, '.x'); + } + // detect Silk desktop/accelerated modes + else if (name == 'Silk') { + if (!/Mobi/i.test(ua)) { + os = 'Android'; + description.unshift('desktop mode'); + } + if (/Accelerated *= *true/i.test(ua)) { + description.unshift('accelerated'); + } + } + // detect Windows Phone desktop mode + else if (name == 'IE' && (data = (/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(ua) || 0)[1])) { + name += ' Mobile'; + os = 'Windows Phone OS ' + data + '.x'; + description.unshift('desktop mode'); + } + // add mobile postfix + else if ((name == 'IE' || name && !product && !/Browser|Mobi/.test(name)) && + (os == 'Windows CE' || /Mobi/i.test(ua))) { + name += ' Mobile'; + } + // detect IE platform preview + else if (name == 'IE' && useFeatures && typeof external == 'object' && !external) { + description.unshift('platform preview'); + } + // detect BlackBerry OS version + // http://docs.blackberry.com/en/developers/deliverables/18169/HTTP_headers_sent_by_BB_Browser_1234911_11.jsp + else if (/BlackBerry/.test(product) && (data = + (RegExp(product.replace(/ +/g, ' *') + '/([.\\d]+)', 'i').exec(ua) || 0)[1] || + version)) { + os = 'Device Software ' + data; + version = null; + } + // detect Opera identifying/masking itself as another browser + // http://www.opera.com/support/kb/view/843/ + else if (this != forOwn && ( + (useFeatures && opera) || + (/Opera/.test(name) && /\b(?:MSIE|Firefox)\b/i.test(ua)) || + (name == 'Firefox' && /OS X (?:\d+\.){2,}/.test(os)) || + (name == 'IE' && ( + (os && !/^Win/.test(os) && version > 5.5) || + /Windows XP/.test(os) && version > 8 || + version == 8 && !/Trident/.test(ua) + )) + ) && !reOpera.test(data = parse.call(forOwn, ua.replace(reOpera, '') + ';')) && data.name) { + + // when "indentifying" the UA contains both Opera and the other browser's name + data = 'ing as ' + data.name + ((data = data.version) ? ' ' + data : ''); + if (reOpera.test(name)) { + if (/IE/.test(data) && os == 'Mac OS') { + os = null; + } + data = 'identify' + data; + } + // when "masking" the UA contains only the other browser's name + else { + data = 'mask' + data; + if (operaClass) { + name = format(operaClass.replace(/([a-z])([A-Z])/g, '$1 $2')); + } else { + name = 'Opera'; + } + if (/IE/.test(data)) { + os = null; + } + if (!useFeatures) { + version = null; + } + } + layout = ['Presto']; + description.push(data); + } + // detect WebKit Nightly and approximate Chrome/Safari versions + if ((data = (/\bAppleWebKit\/([\d.]+\+?)/i.exec(ua) || 0)[1])) { + // correct build for numeric comparison + // (e.g. "532.5" becomes "532.05") + data = [parseFloat(data.replace(/\.(\d)$/, '.0$1')), data]; + // nightly builds are postfixed with a `+` + if (name == 'Safari' && data[1].slice(-1) == '+') { + name = 'WebKit Nightly'; + prerelease = 'alpha'; + version = data[1].slice(0, -1); + } + // clear incorrect browser versions + else if (version == data[1] || + version == (/\bSafari\/([\d.]+\+?)/i.exec(ua) || 0)[1]) { + version = null; + } + // use the full Chrome version when available + data = [data[0], (/\bChrome\/([\d.]+)/i.exec(ua) || 0)[1]]; + + // detect JavaScriptCore + // http://stackoverflow.com/questions/6768474/how-can-i-detect-which-javascript-engine-v8-or-jsc-is-used-at-runtime-in-androi + if (!useFeatures || (/internal|\n/i.test(toString.toString()) && !data[1])) { + layout[1] = 'like Safari'; + data = (data = data[0], data < 400 ? 1 : data < 500 ? 2 : data < 526 ? 3 : data < 533 ? 4 : data < 534 ? '4+' : data < 535 ? 5 : '5'); + } else { + layout[1] = 'like Chrome'; + data = data[1] || (data = data[0], data < 530 ? 1 : data < 532 ? 2 : data < 532.05 ? 3 : data < 533 ? 4 : data < 534.03 ? 5 : data < 534.07 ? 6 : data < 534.10 ? 7 : data < 534.13 ? 8 : data < 534.16 ? 9 : data < 534.24 ? 10 : data < 534.30 ? 11 : data < 535.01 ? 12 : data < 535.02 ? '13+' : data < 535.07 ? 15 : data < 535.11 ? 16 : data < 535.19 ? 17 : data < 535.21 ? 18 : '19'); + } + // add the postfix of ".x" or "+" for approximate versions + layout[1] += ' ' + (data += typeof data == 'number' ? '.x' : /[.+]/.test(data) ? '' : '+'); + // obscure version for some Safari 1-2 releases + if (name == 'Safari' && (!version || parseInt(version) > 45)) { + version = data; + } + } + // strip incorrect OS versions + if (version && version.indexOf(data = /[\d.]+$/.exec(os)) == 0 && + ua.indexOf('/' + data + '-') > -1) { + os = trim(os.replace(data, '')); + } + // add layout engine + if (layout && !/Avant|Nook/.test(name) && ( + /Browser|Lunascape|Maxthon/.test(name) || + /^(?:Adobe|Arora|Midori|Phantom|Rekonq|Rock|Sleipnir|Web)/.test(name) && layout[1])) { + // don't add layout details to description if they are falsey + (data = layout[layout.length - 1]) && description.push(data); + } + // combine contextual information + if (description.length) { + description = ['(' + description.join('; ') + ')']; + } + // append manufacturer + if (manufacturer && product && product.indexOf(manufacturer) < 0) { + description.push('on ' + manufacturer); + } + // append product + if (product) { + description.push((/^on /.test(description[description.length -1]) ? '' : 'on ') + product); + } + // add browser/OS architecture + if ((data = /\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i).test(arch) && !/\bi686\b/i.test(arch)) { + os = os && os + (data.test(os) ? '' : ' 64-bit'); + if (name && (/WOW64/i.test(ua) || + (useFeatures && /\w(?:86|32)$/.test(nav.cpuClass || nav.platform)))) { + description.unshift('32-bit'); + } + } + + ua || (ua = null); + + /*------------------------------------------------------------------------*/ + + /** + * The platform object. + * + * @name platform + * @type Object + */ + return { + + /** + * The browser/environment version. + * + * @memberOf platform + * @type String|Null + */ + 'version': name && version && (description.unshift(version), version), + + /** + * The name of the browser/environment. + * + * @memberOf platform + * @type String|Null + */ + 'name': name && (description.unshift(name), name), + + /** + * The name of the operating system. + * + * @memberOf platform + * @type String|Null + */ + 'os': os && (name && + !(os == os.split(' ')[0] && (os == name.split(' ')[0] || product)) && + description.push(product ? '(' + os + ')' : 'on ' + os), os), + + /** + * The platform description. + * + * @memberOf platform + * @type String|Null + */ + 'description': description.length ? description.join(' ') : ua, + + /** + * The name of the browser layout engine. + * + * @memberOf platform + * @type String|Null + */ + 'layout': layout && layout[0], + + /** + * The name of the product's manufacturer. + * + * @memberOf platform + * @type String|Null + */ + 'manufacturer': manufacturer, + + /** + * The alpha/beta release indicator. + * + * @memberOf platform + * @type String|Null + */ + 'prerelease': prerelease, + + /** + * The name of the product hosting the browser. + * + * @memberOf platform + * @type String|Null + */ + 'product': product, + + /** + * The browser's user agent string. + * + * @memberOf platform + * @type String|Null + */ + 'ua': ua, + + // parses a user agent string into a platform object + 'parse': parse, + + // returns the platform description + 'toString': toStringPlatform + }; + } + + /*--------------------------------------------------------------------------*/ + + // expose platform + // some AMD build optimizers, like r.js, check for specific condition patterns like the following: + if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) { + // define as an anonymous module so, through path mapping, it can be aliased + define(function() { + return parse(); + }); + } + // check for `exports` after `define` in case a build optimizer adds an `exports` object + else if (freeExports) { + // in Narwhal, Node.js, or RingoJS + forOwn(parse(), function(value, key) { + freeExports[key] = value; + }); + } + // in a browser or Rhino + else { + // use square bracket notation so Closure Compiler won't munge `platform` + // http://code.google.com/closure/compiler/docs/api-tutorial3.html#export + window['platform'] = parse(); + } +}(this)); From c9c83ee7e6ef9a11cdd85e05050ee579aa18a0ae Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 14 Jul 2012 06:21:59 -0400 Subject: [PATCH 15/21] Add `_.invoke` benchmark to perf.js and a link to the compatibility changes wiki entry in README.md. Former-commit-id: 51296709ea8d9dd6e951530b9874b90af3c764a2 --- README.md | 2 +- perf/perf.js | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 66e7deb119..afa72ca320 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Lo-Dash v0.4.1 -A drop-in replacement 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), 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). 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. diff --git a/perf/perf.js b/perf/perf.js index 5a696456ba..3b7c18becc 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -602,12 +602,12 @@ suites.push( Benchmark.Suite('`_.find` iterating an object') .add('Lo-Dash', function() { - lodash.find(numbers, function(value, key) { + lodash.find(object, function(value, key) { return /\D9$/.test(key); }); }) .add('Underscore', function() { - _.find(numbers, function(value, key) { + _.find(object, function(value, key) { return /\D9$/.test(key); }); }) @@ -727,6 +727,39 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.invoke` iterating an array') + .add('Lo-Dash', function() { + lodash.invoke(numbers, 'toFixed', '2'); + }) + .add('Underscore', function() { + _.invoke(numbers, 'toFixed', '2'); + }) + ); + + suites.push( + Benchmark.Suite('`_.invoke` with a function for `methodName` iterating an array') + .add('Lo-Dash', function() { + lodash.invoke(numbers, String.prototype.split, ''); + }) + .add('Underscore', function() { + _.invoke(numbers, String.prototype.split, ''); + }) + ); + + suites.push( + Benchmark.Suite('`_.invoke` iterating an object') + .add('Lo-Dash', function() { + lodash.invoke(object, 'toFixed', '2'); + }) + .add('Underscore', function() { + _.invoke(object, 'toFixed', '2'); + }) + ); + + /*--------------------------------------------------------------------------*/ + + suites.push( Benchmark.Suite('`_.isEqual` comparing primitives and objects (edge case)') .add('Lo-Dash', { From e58d47a3b27d813d5be63445dadc1f6f8c288da2 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 14 Jul 2012 08:59:50 -0400 Subject: [PATCH 16/21] Add "strict" build. Former-commit-id: fcdd8d36c9e0c6d698059541b97915ae1b28650e --- build.js | 65 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/build.js b/build.js index 4a1e739aa0..44a62c5693 100755 --- a/build.js +++ b/build.js @@ -20,8 +20,14 @@ /** Flag used to specify a mobile build */ var isMobile = !isLegacy && process.argv.indexOf('mobile') > -1; - /** Flag used to specify if the source should be in strict mode */ - var isStrict = !(isLegacy || isMobile); + /** + * Flag used to specify `_.bindAll`, `_.extend`, and `_.defaults` are + * constructed using the "use strict" directive. + */ + var isStrict = process.argv.indexOf('strict') > -1; + + /** Flag used to specify if the build should include the "use strict" directive */ + var useStrict = isStrict || !(isLegacy || isMobile); /** Shortcut used to convert array-like objects to arrays */ var slice = [].slice; @@ -32,19 +38,19 @@ /** Load customized Lo-Dash module */ var lodash = (function() { var sandbox = {}; + + if (isStrict) { + source = setUseStrictOption(source, true); + } + else if (!useStrict) { + source = removeUseStrictDirective(source); + source = setUseStrictOption(source, false); + } + if (isLegacy) { ['isBindFast', 'isKeysFast', 'nativeBind', 'nativeIsArray', 'nativeKeys'].forEach(function(varName) { source = replaceVar(source, varName, 'false'); }); - - // remove `useStrict` branch from `iteratorTemplate` - source = source.replace(/(?: *\/\/.*\n)*\s*' *<% *if *\(useStrict\).+\n/, ''); - - // remove `useStrict` from iterator options - source = source.replace(/ *'useStrict': *false,\n/g, ''); - - // remove `useStrict` data object property assignment in `createIterator` - source = source.replace(/\s*.+?\.useStrict *=.+/, ''); } else if (isMobile) { source = replaceVar(source, 'isKeysFast', 'false'); @@ -285,6 +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 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', @@ -507,14 +514,14 @@ */ function removeKeysOptimization(source) { return removeVar(source, 'isKeysFast') + // remove optimized branch in `iteratorTemplate` + .replace(/(?: *\/\/.*\n)*\s*'( *)<% *if *\(isKeysFast[\s\S]+?'\1<% *} *else *\{ *%>.+\n([\s\S]+?) *'\1<% *} *%>.+/, '$2') // remove `isKeysFast` from `beforeLoop.object` of `mapIteratorOptions` .replace(/=\s*'\s*\+\s*\(isKeysFast.+/, "= []'") // remove `isKeysFast` from `inLoop.object` of `mapIteratorOptions`, `invoke`, `pluck`, and `sortBy` .replace(/'\s*\+\s*\(isKeysFast[^)]+?\)\s*\+\s*'/g, '.push') // remove data object property assignment in `createIterator` - .replace(/\s*.+?\.isKeysFast *=.+/, '') - // remove optimized branch in `iteratorTemplate` - .replace(/(?: *\/\/.*\n)*\s*'( *)<% *if *\(isKeysFast[\s\S]+?'\1<% *} *else *\{ *%>.+\n([\s\S]+?) *'\1<% *} *%>.+/, '$2'); + .replace(/\s*.+?\.isKeysFast *=.+/, ''); } /** @@ -524,7 +531,7 @@ * @param {String} source The source to process. * @returns {String} Returns the modified source. */ - function removeUseStrict(source) { + function removeUseStrictDirective(source) { return source.replace(/(["'])use strict\1;( *\n)?/, ''); } @@ -584,6 +591,24 @@ return source; } + /** + * Hard-codes the `useStrict` template option value for `iteratorTemplate`. + * + * @private + * @param {String} source The source to process. + * @param {Boolean} value The value to set. + * @returns {String} Returns the modified source. + */ + function setUseStrictOption(source, value) { + return source + // replace `useStrict` branch in `value` with hard-coded option + .replace(/(?: *\/\/.*\n)*(\s*)' *<% *if *\(useStrict\).+/, value ? "$1'\\'use strict\\';\\n' +" : '') + // remove `useStrict` from iterator options + .replace(/ *'useStrict': *false,\n/g, '') + // remove `useStrict` data object property assignment in `createIterator` + .replace(/\s*.+?\.useStrict *=.+/, ''); + } + /*--------------------------------------------------------------------------*/ // display help message @@ -961,18 +986,14 @@ // cleanup code source = source.replace(/^ *;\n/gm, ''); - if (!isStrict) { - source = removeUseStrict(source); - } - // begin the minification process - if (filterType || isBackbone || isLegacy || isMobile) { + if (filterType || isBackbone || isLegacy || isMobile || isStrict) { fs.writeFileSync(path.join(cwd, 'lodash.custom.js'), source); minify(source, 'lodash.custom.min', function(result) { // re-remove "use strict" added by the minifier - if (!isStrict) { - result = removeUseStrict(result); + if (!useStrict) { + result = removeUseStrictDirective(result); } fs.writeFileSync(path.join(cwd, 'lodash.custom.min.js'), result); }); From 8577816234ac1d908eed8382c32b79db30884316 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 15 Jul 2012 03:51:28 -0400 Subject: [PATCH 17/21] Add optimizations for large arrays to `_.difference`, `_.intersection`, and `_.without`. Former-commit-id: 26d55a6a3340e77b5269b2003d20def3fe77bca9 --- lodash.js | 55 ++++++++++-- perf/perf.js | 249 +++++++++++++++++++++++++++++++++++++++++++++++++-- test/test.js | 19 ++++ 3 files changed, 311 insertions(+), 12 deletions(-) diff --git a/lodash.js b/lodash.js index bc96d53fb9..6d39dafc08 100644 --- a/lodash.js +++ b/lodash.js @@ -439,6 +439,41 @@ /*--------------------------------------------------------------------------*/ + /** + * Creates a new function optimized for searching large arrays for a given `value`, + * starting at `fromIndex`, using strict equality for comparisons, i.e. `===`. + * + * @private + * @param {Array} array The array to search. + * @param {Mixed} value The value to search for. + * @param {Number} [fromIndex=0] The index to start searching from. + * @param {Number} [largeSize=30] The length at which an array is considered large. + * @returns {Boolean} Returns `true` if `value` is found, else `false`. + */ + function cachedContains(array, fromIndex, largeSize) { + fromIndex || (fromIndex = 0); + + var length = array.length, + isLarge = (length - fromIndex) >= (largeSize || 30), + cache = isLarge ? {} : array; + + if (isLarge) { + // init value cache + var value, + index = fromIndex - 1; + + while (++index < length) { + value = array[index]; + (hasOwnProperty.call(cache, value) ? cache[value] : (cache[value] = [])).push(value); + } + } + return function(value) { + return isLarge + ? hasOwnProperty.call(cache, value) && indexOf(cache[value], value) > -1 + : indexOf(cache, value, fromIndex) > -1; + } + } + /** * Creates compiled iteration functions. The iteration function will be created * to iterate over only objects if the first argument of `options.args` is @@ -1224,10 +1259,11 @@ } var index = -1, length = array.length, - flattened = concat.apply(result, arguments); + flattened = concat.apply(result, arguments), + contains = cachedContains(flattened, length); while (++index < length) { - if (indexOf(flattened, array[index], length) < 0) { + if (!contains(array[index])) { result.push(array[index]); } } @@ -1390,12 +1426,15 @@ var value, index = -1, length = array.length, - others = slice.call(arguments, 1); + others = slice.call(arguments, 1), + cache = []; while (++index < length) { value = array[index]; if (indexOf(result, value) < 0 && - every(others, function(other) { return indexOf(other, value) > -1; })) { + every(others, function(other, index) { + return (cache[index] || (cache[index] = cachedContains(other)))(value); + })) { result.push(value); } } @@ -1847,10 +1886,11 @@ return result; } var index = -1, - length = array.length; + length = array.length, + contains = cachedContains(arguments, 1, 20); while (++index < length) { - if (indexOf(arguments, array[index], 1) < 0) { + if (!contains(array[index])) { result.push(array[index]); } } @@ -2774,7 +2814,8 @@ } } } - } else { + } + else { // objects with different constructors are not equivalent if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) { return false; diff --git a/perf/perf.js b/perf/perf.js index 3b7c18becc..f945ba866f 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -95,7 +95,6 @@ belt = this.name == 'Lo-Dash' ? lodash : _; var index, - length, limit = 20, object = {}, objects = Array(limit), @@ -104,7 +103,7 @@ nestedNumbers = [1, [2], [3, [[4]]]], twoNumbers = [12, 21]; - for (index = 0, length = limit; index < length; index++) { + for (index = 0; index < limit; index++) { numbers[index] = index; object['key' + index] = index; objects[index] = { 'num': index }; @@ -132,7 +131,7 @@ funcNames = belt.functions(lodash); // potentially expensive - for (index = 0, length = this.count; index < length; index++) { + for (index = 0; index < this.count; index++) { bindAllObjects[index] = belt.clone(lodash); } } @@ -187,13 +186,50 @@ numbers2 = Array(limit), nestedNumbers2 = [1, [2], [3, [[4]]]]; - for (index = 0, length = limit; index < length; index++) { + for (index = 0; index < limit; index++) { numbers2[index] = index; object2['key' + index] = index; objects2[index] = { 'num': index }; } } + if (typeof multiArrays != 'undefined') { + var twentyFiveValues = Array(25), + twentyFiveValues2 = Array(25), + fiftyValues = Array(50), + fiftyValues2 = Array(50), + seventyFiveValues = Array(75), + seventyFiveValues2 = Array(75), + lowerChars = 'abcdefghijklmnopqrstuvwxyz'.split(''), + upperChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(''); + + for (index = 0; index < 75; index++) { + if (index < 26) { + if (index < 20) { + twentyFiveValues[index] = lowerChars[index]; + twentyFiveValues2[index] = upperChars[index]; + } + else if (index < 25) { + twentyFiveValues[index] = + twentyFiveValues2[index] = index; + } + fiftyValues[index] = + seventyFiveValues[index] = lowerChars[index]; + + fiftyValues2[index] = + seventyFiveValues2[index] = upperChars[index]; + } + else { + if (index < 50) { + fiftyValues[index] = index; + fiftyValues2[index] = index + (index < 40 ? 75 : 0); + } + seventyFiveValues[index] = index; + seventyFiveValues2[index] = index + (index < 60 ? 75 : 0); + } + } + } + if (typeof template != 'undefined') { var tplData = { 'header1': 'Header1', @@ -489,6 +525,54 @@ }) ); + suites.push( + Benchmark.Suite('`_.difference` iterating 25 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.difference(twentyFiveValues, twentyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.difference(twentyFiveValues, twentyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.difference` iterating 50 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.difference(fiftyValues, fiftyValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.difference(fiftyValues, fiftyValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.difference` iterating 75 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.difference(seventyFiveValues, seventyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.difference(seventyFiveValues, seventyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + /*--------------------------------------------------------------------------*/ suites.push( @@ -725,6 +809,54 @@ }) ); + suites.push( + Benchmark.Suite('`_.intersection` iterating 25 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.intersection(twentyFiveValues, twentyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.intersection(twentyFiveValues, twentyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.intersection` iterating 50 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.intersection(fiftyValues, fiftyValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.intersection(fiftyValues, fiftyValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.intersection` iterating 75 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.intersection(seventyFiveValues, seventyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.intersection(seventyFiveValues, seventyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + /*--------------------------------------------------------------------------*/ suites.push( @@ -759,7 +891,6 @@ /*--------------------------------------------------------------------------*/ - suites.push( Benchmark.Suite('`_.isEqual` comparing primitives and objects (edge case)') .add('Lo-Dash', { @@ -1218,6 +1349,54 @@ }) ); + suites.push( + Benchmark.Suite('`_.union` iterating an array of 25 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.union(twentyFiveValues, twentyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.union(twentyFiveValues, twentyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.union` iterating an array of 50 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.union(fiftyValues, fiftyValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.union(fiftyValues, fiftyValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.union` iterating an array of 75 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.union(seventyFiveValues, seventyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.union(seventyFiveValues, seventyFiveValues2); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + /*--------------------------------------------------------------------------*/ suites.push( @@ -1258,6 +1437,66 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.without`') + .add('Lo-Dash', function() { + lodash.without(numbers, 9, 12, 14, 15); + }) + .add('Underscore', function() { + _.without(numbers, 9, 12, 14, 15); + }) + ); + + suites.push( + Benchmark.Suite('`_.without` iterating an array of 25 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.without.apply(lodash, [twentyFiveValues].concat(twentyFiveValues2)); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.without.apply(_, [twentyFiveValues].concat(twentyFiveValues2)); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.without` iterating an array of 50 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.without.apply(lodash, [fiftyValues].concat(fiftyValues2)); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.without.apply(_, [fiftyValues].concat(fiftyValues2)); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + suites.push( + Benchmark.Suite('`_.without` iterating an array of 75 elements') + .add('Lo-Dash', { + 'fn': function() { + lodash.without.apply(lodash, [seventyFiveValues].concat(seventyFiveValues2)); + }, + 'teardown': 'function multiArrays(){}' + }) + .add('Underscore', { + 'fn': function() { + _.without.apply(_, [seventyFiveValues].concat(seventyFiveValues2)); + }, + 'teardown': 'function multiArrays(){}' + }) + ); + + /*--------------------------------------------------------------------------*/ + if (Benchmark.platform + '') { log(Benchmark.platform + ''); } diff --git a/test/test.js b/test/test.js index bcd82c6d2f..2139f8e518 100644 --- a/test/test.js +++ b/test/test.js @@ -166,6 +166,25 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.difference'); + + (function() { + test('should work correctly when using `cachedContains`', function() { + var array1 = _.range(27), + array2 = array1.slice(), + a = {}, + b = {}, + c = {}; + + array1.push(a, b, c); + array2.push(b, c, a); + + deepEqual(_.difference(array1, array2), []); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.escape'); (function() { From 2629f85e739e6203553a9aff4cc09f8e2ed2f65f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 15 Jul 2012 03:52:22 -0400 Subject: [PATCH 18/21] Update minified build and rebuild documentation. Former-commit-id: 5b434ca8c22a44d1603dcc1e92bf4caea6fe00a1 --- doc/README.md | 174 +++++++++++++++++++++++++------------------------- lodash.min.js | 62 +++++++++--------- 2 files changed, 118 insertions(+), 118 deletions(-) diff --git a/doc/README.md b/doc/README.md index 53ae8b4ce5..135f7cc3a8 100644 --- a/doc/README.md +++ b/doc/README.md @@ -148,7 +148,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3562 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3603 "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#L1941 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1981 "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#L1995 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2035 "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#L2065 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2105 "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#L3487 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3528 "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#L2395 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2435 "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#L1188 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1223 "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#L2101 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2141 "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#L723 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L758 "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#L2134 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2174 "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#L2418 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2458 "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#L2199 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2239 "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#L2179 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2219 "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#L1220 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1255 "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#L3127 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3168 "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#L751 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L786 "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#L2437 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2477 "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#L771 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L806 "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#L792 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L827 "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#L1256 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1292 "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#L1280 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1316 "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#L818 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L853 "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#L2466 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2506 "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#L2489 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2529 "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#L2506 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2546 "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#L845 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L880 "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#L2529 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2569 "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#L3146 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3187 "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#L1324 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1360 "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#L1364 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1400 "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#L1385 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1421 "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#L879 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L914 "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#L2549 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2589 "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#L2575 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2615 "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#L2592 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2632 "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#L2609 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2649 "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#L2626 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2666 "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#L2650 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2690 "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#L2684 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2724 "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#L2845 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2886 "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#L2862 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2903 "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#L2914 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2955 "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#L2937 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2978 "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#L2954 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2995 "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#L2883 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2924 "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#L2971 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3012 "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#L2988 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3029 "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#L3006 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3047 "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#L3023 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3064 "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#L1423 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1462 "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#L1449 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1488 "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#L915 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L950 "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#L1489 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1528 "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#L2222 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2262 "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#L1539 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1578 "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#L3172 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3213 "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#L3203 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3244 "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#L2248 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2288 "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#L2281 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2321 "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#L3045 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3086 "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#L938 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L973 "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#L1600 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1639 "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#L966 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1001 "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#L1003 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1038 "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#L1058 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1093 "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#L1637 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1676 "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#L3235 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3276 "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#L1658 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1697 "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#L3084 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3125 "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#L1081 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1116 "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#L1113 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1148 "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#L1710 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1749 "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#L3514 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3555 "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#L3295 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3336 "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#L2317 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2357 "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#L3430 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3471 "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#L1156 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1191 "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#L1750 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1789 "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#L1795 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1834 "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#L3457 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3498 "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#L3105 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3146 "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#L1844 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1883 "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#L2369 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2409 "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#L1876 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1916 "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#L1905 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1945 "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#L3532 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3573 "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#L3549 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3590 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.min.js b/lodash.min.js index 33980c1558..2b3b34e874 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -2,34 +2,34 @@ Lo-Dash 0.4.1 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(){for(var e,t,n,s=-1,o=arguments.length,u={e:"",f:"",j:"",p:"",c:{d:""},m:{d:""}};++sn;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+"}")(ot,N,a,ft,G,k,h,Et,st,Z,et,ht,tt)}function a(e,n){return e=e.a,n=n.a,e===t?1:n===t?-1:en?1:0}function f(e,t){return K[t]} -function l(e){return"\\"+St[e]}function c(e){return wt[e]}function h(e,t){return function(n,r,i){return e.call(t,n,r,i)}}function p(){}function d(e,t){if(F.test(t))return"";var n=K.length;return K[n]="'+__e("+t+")+'",J+n}function v(e,t,n,r){return e=K.length,t?K[e]="';"+t+";__p+='":n?K[e]="'+__e("+n+")+'":r&&(K[e]="'+((__t=("+r+"))==null?'':__t)+'"),J+e}function m(e,t){if(F.test(t))return"";var n=K.length;return K[n]="'+((__t=("+t+"))==null?'':__t)+'",J+n}function g(e,t,n,r) -{if(!e)return n;var i=e.length,s=3>arguments.length;r&&(t=h(t,r));if(i===i>>>0){var o=gt&&tt.call(e)==ht?e.split(""):e;for(i&&s&&(n=o[--i]);i--;)n=t(n,o[i],i,e);return n}o=Yt(e);for((i=o.length)&&s&&(n=e[o[--i]]);i--;)s=o[i],n=t(n,e[s],s,e);return n}function y(e,t,n){if(e)return t==r||n?e[0]:et.call(e,0,t)}function b(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=h(t,n));++sr&&(r=n,i=e[s]);return i}function S(e,t,n){return e?et.call(e,t==r||n?1:t):[]}function x(e,t,n,r){if(!e)return 0;var i=0,s=e.length;if(n){r&&(n=N(n,r));for(t=n(t);i>>1,n(e[r])>>1,e[r]w(a,r))a.push(r),s.push(e[o]);return s}function N(e,t){function n(){var o=arguments,u=t;return i||(e=t[r]),s.length&&(o=o.length?Q.apply(s,o):s),this instanceof n?(p.prototype=e.prototype,u=new p,(o=e.apply(u,o))&&Et[typeof o]?o:u):e.apply(u,o)}var r,i=tt.call(e)==ft;if(i){if(yt||nt&&2++ -u&&(l=$[u],!G.call(e,l)||!!(a=G.call(t,l)&&C(e[l],t[l],s))););}return s.pop(),a}function k(e){return e}function L(e){Ht(Kt(e),function(t){var r=s[t]=e[t];o.prototype[t]=function(){var e=[this._wrapped];return arguments.length&&Y.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,A,O,M,_,D="object"==typeof exports&&exports&&("object"==typeof global&&global&&global==global.global&&(e=global),exports),P=Array.prototype,H=Object.prototype,B=0,j=e._,F=/[-+=!~*%&^<>|{(\/]|\[\D|\b(?:delete|in|instanceof|new|typeof|void)\b/ -,I=/\b__p\+='';/g,q=/\b(__p\+=)''\+/g,R=/(__e\(.*?\)|\b__t\))\+'';/g,U=/(?:__e|__t=)\(\s*(?![\d\s"']|this\.)/g,z=RegExp("^"+(H.valueOf+"").replace(/[.*+?^=!:${}()|[\]\/\\]/g,"\\$&").replace(/valueOf|for [^\]]+/g,".+?")+"$"),W=/__token__(\d+)/g,X=/[&<"']/g,V=/['\n\r\t\u2028\u2029\\]/g,$="constructor hasOwnProperty isPrototypeOf propertyIsEnumerable toLocaleString toString valueOf".split(" "),J="__token__",K=[],Q=P.concat,G=H.hasOwnProperty,Y=P.push,Z=H.propertyIsEnumerable,et=P.slice,tt=H.toString -,nt=z.test(nt=et.bind)&&nt,rt=z.test(rt=Array.isArray)&&rt,it=e.isFinite,st=z.test(st=Object.keys)&&st,ot="[object Array]",ut="[object Boolean]",at="[object Date]",ft="[object Function]",lt="[object Number]",ct="[object RegExp]",ht="[object String]",pt=e.clearTimeout,dt=e.setTimeout,vt=!Z.call({valueOf:0},"valueOf"),mt="x"!=et.call("x")[0],gt="xx"!="x"[0]+Object("x")[0],yt=nt&&/\n|Opera/.test(nt+tt.call(e.opera)),bt=st&&/^.+$|true/.test(st+!!e.attachEvent),wt={"&":"&","<":"<",'"':""","'" -:"'"},Et={"boolean":i,"function":n,object:n,number:i,string:i,"undefined":i},St={"\\":"\\","'":"'","\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 xt={a:"g,e,I",j:"g",p:"if(!e){e=m}else if(I)e=r(e,I)",i:"e(p[n],n,g)"},Tt={j:"true",i:"if(!e(p[n],n,g))return!D"},Nt={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"}),_t=u(xt,Tt),Dt=u(xt,Ct),Pt=u(xt,kt,{j:"",i:"if(e(p[n],n,g))return p[n]" -}),Ht=u(xt,kt),Bt=u(xt,{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])"}),jt=u(At,{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"+(bt?"[z]=":".push")+"((o?t:p[n][t]).apply(p[n],b))"}}),Ft=u(xt,At),It=u(At,{a:"g,B",i:{b:"D[n]=p[n][B]",l:"D"+(bt?"[z]=":".push")+"(p[n][B])"}}),qt=u({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)"}}),Rt=u(xt,Ct,{i:"!"+Ct.i}),Ut=u(xt,Tt,{j:"false",i:Tt.i.replace("!","")}),zt=u(xt,At,{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"+(bt?"[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}"}),Wt=u({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=N,s.bindAll=Wt,s.chain=function(e){return e=new o(e),e._chain=n,e},s.clone=function(e){return e&&Et[typeof e]?Qt(e)?e.slice():Vt({},e):e},s.compact=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nw(i,e[n],r)&&t.push(e[n]);return t},s.escape=function(e){return e==r?"":(e+"").replace(X,c)},s.every=_t,s.extend=Vt,s.filter=Dt,s.find=Pt,s.first=y,s.flatten=b,s.forEach=Ht,s.forIn=$t,s.forOwn=Jt,s.functions=Kt,s.groupBy=Bt,s.has=function(e,t){return G.call(e,t)},s.identity=k,s.indexOf=w,s.initial=function(e,t,n){return e?et.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=et.call(arguments,1);++rw(t,n)&&_t(s,function(e){return-1n?Math.max(0,r+n):Math.min(n,r-1))+1);r--;)if(e[r]===t)return r;return-1},s.map=Ft,s.max=E,s.memoize=function(e,t){var n={};return function(){var r=t?t.apply(this,arguments):arguments[0];return G.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:Yt(e).length},s.some=Ut,s.sortBy=zt,s.sortedIndex=x,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,c=s.templateSettings,n=n.variable;i==r&&(i=c.escape),u==r&&(u=c.evaluate),a==r&&(a=c.interpolate),i&&(e=e.replace(i,d)),a&&(e=e.replace(a,m)),u!=A&&(A=u,_=RegExp((u?u.source:"($^)")+"||","g") -),i=K.length,e=e.replace(_,v),i=i!=K.length,e="__p += '"+e.replace(V,l).replace(W,f)+"';",K.length=0,n||(n=c.variable||O||"obj",i?e="with("+n+"){"+e+"}":(n!=O&&(O=n,M=RegExp("(\\(\\s*)"+n+"\\."+n+"\\b","g")),e=e.replace(U,"$&"+n+".").replace(M,"$1__d"))),e=(i?e.replace(I,""):e).replace(q,"$1").replace(R,"$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=dt(n,f)),s}},s.times=function(e,t,n){var r=-1;if(n)for(;++r>>0?(mt? -tt.call(e)==ht:"string"==typeof e)?e.split(""):et.call(e):Zt(e)},s.union=function(){for(var e=-1,t=[],n=Q.apply(t,arguments),r=n.length;++ew(t,n[e])&&t.push(n[e]);return t},s.uniq=T,s.uniqueId=function(e){var t=B++;return e?e+t:t},s.values=Zt,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nw(arguments,e[n],1)&&t.push(e[n]);return t},s.wrap=function(e,t){return function(){var n=[e];return arguments.length&&Y.apply(n,arguments),t.apply(this,n)}},s.zip=function(e -){if(!e)return[];for(var t=-1,n=E(It(arguments,"length")),r=Array(n);++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) +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 +,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:"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) +{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= +function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length,i=u(arguments,1,20);++n Date: Sun, 15 Jul 2012 07:01:44 -0400 Subject: [PATCH 19/21] Ensure `stringClass` isn't stripped out when needed for certain builds and update dependencies for `arrayClass`, `funcClass`, `objectTypes`, and `reNative`. Former-commit-id: 334973dcab4660733e1d081efe3602a167c452d9 --- build.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/build.js b/build.js index 44a62c5693..9b34b18369 100755 --- a/build.js +++ b/build.js @@ -919,6 +919,16 @@ /*--------------------------------------------------------------------------*/ // remove associated functions, variables, and code snippets that the minifier may miss + if (isRemoved(source, 'bind')) { + source = removeVar(source, 'nativeBind'); + source = removeVar(source, 'isBindFast'); + } + if (isRemoved(source, 'isArray')) { + source = removeVar(source, 'nativeIsArray'); + } + if (isRemoved(source, 'keys')) { + source = removeFunction(source, 'shimKeys'); + } if (isRemoved(source, 'mixin')) { // remove `LoDash` constructor source = removeFunction(source, 'LoDash'); @@ -937,37 +947,27 @@ if (isRemoved(source, 'toArray')) { source = removeVar(source, 'noArraySliceOnStrings'); } - if (isRemoved(source, 'isArray', 'isEmpty', 'isEqual', 'size')) { + if (isRemoved(source, 'isArray', 'isEmpty', 'isEqual')) { source = removeVar(source, 'arrayClass'); } - if (isRemoved(source, 'bind', 'functions', 'groupBy', 'invoke', 'isEqual', 'isFunction', 'result', 'sortBy', 'toArray')) { + if (isRemoved(source, 'bind', 'bindAll', 'functions', 'isEqual', 'isFunction', 'result', 'toArray')) { source = removeVar(source, 'funcClass'); } - if (isRemoved(source, 'bind')) { - source = removeVar(source, 'nativeBind'); - source = removeVar(source, 'isBindFast'); - } - if (isRemoved(source, 'isArray')) { - source = removeVar(source, 'nativeIsArray'); - } - if (isRemoved(source, 'keys')) { - source = removeFunction(source, 'shimKeys'); - } - if (isRemoved(source, 'clone', 'isObject', 'keys')) { + if (isRemoved(source, 'bind', 'clone', 'isObject', 'keys')) { source = removeVar(source, 'objectTypes'); } - if (isRemoved(source, 'bind', 'isArray', 'keys')) { - source = removeVar(source, 'reNative'); - } - if (isRemoved(source, 'isEmpty', 'isEqual', 'isString', 'size')) { - source = removeVar(source, 'stringClass'); - } if ((source.match(/\bcreateIterator\b/g) || []).length < 2) { source = removeFunction(source, 'createIterator'); } + if (isRemoved(source, 'createIterator', 'bind', 'isArray', 'keys')) { + source = removeVar(source, 'reNative'); + } if (isRemoved(source, 'createIterator', 'extend', 'isEqual')) { source = removeVar(source, 'hasDontEnumBug'); } + if (isRemoved(source, 'createIterator', 'contains', 'isEmpty', 'isEqual', 'isString')) { + source = removeVar(source, 'stringClass'); + } if (isRemoved(source, 'createIterator', 'keys')) { source = removeVar(source, 'nativeKeys'); } From 7e79903fe893338640a1b88fb3573174dca2812e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 16 Jul 2012 13:21:11 -0400 Subject: [PATCH 20/21] Update tests to work around QUnit 1.9.0 bug in Narwhal/older-Firefox and add platform.js to test/index.html. Former-commit-id: eed8246c795735558ba9f499b86f08ed3970ccaf --- test/index.html | 20 +- test/test-ui.js | 4 +- test/test.js | 10 +- vendor/qunit/qunit/qunit-1.8.0.js | 1863 +++++++++++++++++++++++++++++ 4 files changed, 1892 insertions(+), 5 deletions(-) create mode 100644 vendor/qunit/qunit/qunit-1.8.0.js diff --git a/test/index.html b/test/index.html index a5c378be36..102e0c700e 100644 --- a/test/index.html +++ b/test/index.html @@ -7,7 +7,14 @@
- + + diff --git a/test/test-ui.js b/test/test-ui.js index fee5647e8b..b4142ae94f 100644 --- a/test/test-ui.js +++ b/test/test-ui.js @@ -73,7 +73,7 @@ 'No RequireJS'; var label2 = document.createElement('label'); - label2.innerHTML = + label2.innerHTML = ' ' + ' Build'; var checkbox = label1.firstChild, - dropdown = label2.firstChild; + dropdown = label2.getElementsByTagName('select')[0]; init(); }); diff --git a/test/test.js b/test/test.js index 2139f8e518..05f40104fe 100644 --- a/test/test.js +++ b/test/test.js @@ -4,11 +4,17 @@ /** Use a single load function */ var load = typeof require == 'function' ? require : window.load; + /** The `platform` object to check */ + var platform = + window.platform || + load('../vendor/platform.js/platform.js') || + window.platform; + /** The unit testing framework */ var QUnit = window.QUnit || ( window.setTimeout || (window.addEventListener = window.setTimeout = / /), - window.QUnit = load('../vendor/qunit/qunit/qunit.js') || window.QUnit, + window.QUnit = load('../vendor/qunit/qunit/qunit' + (platform.name == 'Narwhal' ? '-1.8.0' : '') + '.js') || window.QUnit, load('../vendor/qunit-clib/qunit-clib.js'), (window.addEventListener || 0).test && delete window.addEventListener, window.QUnit @@ -792,7 +798,7 @@ }); test('should raise an error if a template, compiled with errors, is executed', function() { - throws(_.template('<% if x %>')); + raises(_.template('<% if x %>')); }); test('should work with complex "interpolate" delimiters', function() { diff --git a/vendor/qunit/qunit/qunit-1.8.0.js b/vendor/qunit/qunit/qunit-1.8.0.js new file mode 100644 index 0000000000..c1570c2520 --- /dev/null +++ b/vendor/qunit/qunit/qunit-1.8.0.js @@ -0,0 +1,1863 @@ +/** + * QUnit v1.8.0 - A JavaScript Unit Testing Framework + * + * http://docs.jquery.com/QUnit + * + * Copyright (c) 2012 John Resig, Jörn Zaefferer + * Dual licensed under the MIT (MIT-LICENSE.txt) + * or GPL (GPL-LICENSE.txt) licenses. + */ + +(function( window ) { + +var QUnit, + config, + onErrorFnPrev, + testId = 0, + fileName = (sourceFromStacktrace( 0 ) || "" ).replace(/(:\d+)+\)?/, "").replace(/.+\//, ""), + toString = Object.prototype.toString, + hasOwn = Object.prototype.hasOwnProperty, + defined = { + setTimeout: typeof window.setTimeout !== "undefined", + sessionStorage: (function() { + var x = "qunit-test-string"; + try { + sessionStorage.setItem( x, x ); + sessionStorage.removeItem( x ); + return true; + } catch( e ) { + return false; + } + }()) +}; + +function Test( settings ) { + extend( this, settings ); + this.assertions = []; + this.testNumber = ++Test.count; +} + +Test.count = 0; + +Test.prototype = { + init: function() { + var a, b, li, + tests = id( "qunit-tests" ); + + if ( tests ) { + b = document.createElement( "strong" ); + b.innerHTML = this.name; + + // `a` initialized at top of scope + a = document.createElement( "a" ); + a.innerHTML = "Rerun"; + a.href = QUnit.url({ testNumber: this.testNumber }); + + li = document.createElement( "li" ); + li.appendChild( b ); + li.appendChild( a ); + li.className = "running"; + li.id = this.id = "qunit-test-output" + testId++; + + tests.appendChild( li ); + } + }, + setup: function() { + if ( this.module !== config.previousModule ) { + if ( config.previousModule ) { + runLoggingCallbacks( "moduleDone", QUnit, { + name: config.previousModule, + failed: config.moduleStats.bad, + passed: config.moduleStats.all - config.moduleStats.bad, + total: config.moduleStats.all + }); + } + config.previousModule = this.module; + config.moduleStats = { all: 0, bad: 0 }; + runLoggingCallbacks( "moduleStart", QUnit, { + name: this.module + }); + } else if ( config.autorun ) { + runLoggingCallbacks( "moduleStart", QUnit, { + name: this.module + }); + } + + config.current = this; + + this.testEnvironment = extend({ + setup: function() {}, + teardown: function() {} + }, this.moduleTestEnvironment ); + + runLoggingCallbacks( "testStart", QUnit, { + name: this.testName, + module: this.module + }); + + // allow utility functions to access the current test environment + // TODO why?? + QUnit.current_testEnvironment = this.testEnvironment; + + if ( !config.pollution ) { + saveGlobal(); + } + if ( config.notrycatch ) { + this.testEnvironment.setup.call( this.testEnvironment ); + return; + } + try { + this.testEnvironment.setup.call( this.testEnvironment ); + } catch( e ) { + QUnit.pushFailure( "Setup failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) ); + } + }, + run: function() { + config.current = this; + + var running = id( "qunit-testresult" ); + + if ( running ) { + running.innerHTML = "Running:
" + this.name; + } + + if ( this.async ) { + QUnit.stop(); + } + + if ( config.notrycatch ) { + this.callback.call( this.testEnvironment, QUnit.assert ); + return; + } + + try { + this.callback.call( this.testEnvironment, QUnit.assert ); + } catch( e ) { + QUnit.pushFailure( "Died on test #" + (this.assertions.length + 1) + " " + this.stack + ": " + e.message, extractStacktrace( e, 0 ) ); + // else next test will carry the responsibility + saveGlobal(); + + // Restart the tests if they're blocking + if ( config.blocking ) { + QUnit.start(); + } + } + }, + teardown: function() { + config.current = this; + if ( config.notrycatch ) { + this.testEnvironment.teardown.call( this.testEnvironment ); + return; + } else { + try { + this.testEnvironment.teardown.call( this.testEnvironment ); + } catch( e ) { + QUnit.pushFailure( "Teardown failed on " + this.testName + ": " + e.message, extractStacktrace( e, 1 ) ); + } + } + checkPollution(); + }, + finish: function() { + config.current = this; + if ( config.requireExpects && this.expected == null ) { + QUnit.pushFailure( "Expected number of assertions to be defined, but expect() was not called.", this.stack ); + } else if ( this.expected != null && this.expected != this.assertions.length ) { + QUnit.pushFailure( "Expected " + this.expected + " assertions, but " + this.assertions.length + " were run", this.stack ); + } else if ( this.expected == null && !this.assertions.length ) { + QUnit.pushFailure( "Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.", this.stack ); + } + + var assertion, a, b, i, li, ol, + test = this, + good = 0, + bad = 0, + tests = id( "qunit-tests" ); + + config.stats.all += this.assertions.length; + config.moduleStats.all += this.assertions.length; + + if ( tests ) { + ol = document.createElement( "ol" ); + + for ( i = 0; i < this.assertions.length; i++ ) { + assertion = this.assertions[i]; + + li = document.createElement( "li" ); + li.className = assertion.result ? "pass" : "fail"; + li.innerHTML = assertion.message || ( assertion.result ? "okay" : "failed" ); + ol.appendChild( li ); + + if ( assertion.result ) { + good++; + } else { + bad++; + config.stats.bad++; + config.moduleStats.bad++; + } + } + + // store result when possible + if ( QUnit.config.reorder && defined.sessionStorage ) { + if ( bad ) { + sessionStorage.setItem( "qunit-test-" + this.module + "-" + this.testName, bad ); + } else { + sessionStorage.removeItem( "qunit-test-" + this.module + "-" + this.testName ); + } + } + + if ( bad === 0 ) { + ol.style.display = "none"; + } + + // `b` initialized at top of scope + b = document.createElement( "strong" ); + b.innerHTML = this.name + " (" + bad + ", " + good + ", " + this.assertions.length + ")"; + + addEvent(b, "click", function() { + var next = b.nextSibling.nextSibling, + display = next.style.display; + next.style.display = display === "none" ? "block" : "none"; + }); + + addEvent(b, "dblclick", function( e ) { + var target = e && e.target ? e.target : window.event.srcElement; + if ( target.nodeName.toLowerCase() == "span" || target.nodeName.toLowerCase() == "b" ) { + target = target.parentNode; + } + if ( window.location && target.nodeName.toLowerCase() === "strong" ) { + window.location = QUnit.url({ testNumber: test.testNumber }); + } + }); + + // `li` initialized at top of scope + li = id( this.id ); + li.className = bad ? "fail" : "pass"; + li.removeChild( li.firstChild ); + a = li.firstChild; + li.appendChild( b ); + li.appendChild ( a ); + li.appendChild( ol ); + + } else { + for ( i = 0; i < this.assertions.length; i++ ) { + if ( !this.assertions[i].result ) { + bad++; + config.stats.bad++; + config.moduleStats.bad++; + } + } + } + + runLoggingCallbacks( "testDone", QUnit, { + name: this.testName, + module: this.module, + failed: bad, + passed: this.assertions.length - bad, + total: this.assertions.length + }); + + QUnit.reset(); + + config.current = undefined; + }, + + queue: function() { + var bad, + test = this; + + synchronize(function() { + test.init(); + }); + function run() { + // each of these can by async + synchronize(function() { + test.setup(); + }); + synchronize(function() { + test.run(); + }); + synchronize(function() { + test.teardown(); + }); + synchronize(function() { + test.finish(); + }); + } + + // `bad` initialized at top of scope + // defer when previous test run passed, if storage is available + bad = QUnit.config.reorder && defined.sessionStorage && + +sessionStorage.getItem( "qunit-test-" + this.module + "-" + this.testName ); + + if ( bad ) { + run(); + } else { + synchronize( run, true ); + } + } +}; + +// Root QUnit object. +// `QUnit` initialized at top of scope +QUnit = { + + // call on start of module test to prepend name to all tests + module: function( name, testEnvironment ) { + config.currentModule = name; + config.currentModuleTestEnviroment = testEnvironment; + }, + + asyncTest: function( testName, expected, callback ) { + if ( arguments.length === 2 ) { + callback = expected; + expected = null; + } + + QUnit.test( testName, expected, callback, true ); + }, + + test: function( testName, expected, callback, async ) { + var test, + name = "" + escapeInnerText( testName ) + ""; + + if ( arguments.length === 2 ) { + callback = expected; + expected = null; + } + + if ( config.currentModule ) { + name = "" + config.currentModule + ": " + name; + } + + test = new Test({ + name: name, + testName: testName, + expected: expected, + async: async, + callback: callback, + module: config.currentModule, + moduleTestEnvironment: config.currentModuleTestEnviroment, + stack: sourceFromStacktrace( 2 ) + }); + + if ( !validTest( test ) ) { + return; + } + + test.queue(); + }, + + // Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. + expect: function( asserts ) { + config.current.expected = asserts; + }, + + start: function( count ) { + config.semaphore -= count || 1; + // don't start until equal number of stop-calls + if ( config.semaphore > 0 ) { + return; + } + // ignore if start is called more often then stop + if ( config.semaphore < 0 ) { + config.semaphore = 0; + } + // A slight delay, to avoid any current callbacks + if ( defined.setTimeout ) { + window.setTimeout(function() { + if ( config.semaphore > 0 ) { + return; + } + if ( config.timeout ) { + clearTimeout( config.timeout ); + } + + config.blocking = false; + process( true ); + }, 13); + } else { + config.blocking = false; + process( true ); + } + }, + + stop: function( count ) { + config.semaphore += count || 1; + config.blocking = true; + + if ( config.testTimeout && defined.setTimeout ) { + clearTimeout( config.timeout ); + config.timeout = window.setTimeout(function() { + QUnit.ok( false, "Test timed out" ); + config.semaphore = 1; + QUnit.start(); + }, config.testTimeout ); + } + } +}; + +// Asssert helpers +// All of these must call either QUnit.push() or manually do: +// - runLoggingCallbacks( "log", .. ); +// - config.current.assertions.push({ .. }); +QUnit.assert = { + /** + * Asserts rough true-ish result. + * @example ok( "asdfasdf".length > 5, "There must be at least 5 chars" ); + */ + ok: function( result, msg ) { + if ( !config.current ) { + throw new Error( "ok() assertion outside test context, was " + sourceFromStacktrace(2) ); + } + result = !!result; + + var source, + details = { + result: result, + message: msg + }; + + msg = escapeInnerText( msg || (result ? "okay" : "failed" ) ); + msg = "" + msg + ""; + + if ( !result ) { + source = sourceFromStacktrace( 2 ); + if ( source ) { + details.source = source; + msg += "
Source:
" + escapeInnerText( source ) + "
"; + } + } + runLoggingCallbacks( "log", QUnit, details ); + config.current.assertions.push({ + result: result, + message: msg + }); + }, + + /** + * Assert that the first two arguments are equal, with an optional message. + * Prints out both actual and expected values. + * @example equal( format( "Received {0} bytes.", 2), "Received 2 bytes.", "format() replaces {0} with next argument" ); + */ + equal: function( actual, expected, message ) { + QUnit.push( expected == actual, actual, expected, message ); + }, + + notEqual: function( actual, expected, message ) { + QUnit.push( expected != actual, actual, expected, message ); + }, + + deepEqual: function( actual, expected, message ) { + QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); + }, + + notDeepEqual: function( actual, expected, message ) { + QUnit.push( !QUnit.equiv(actual, expected), actual, expected, message ); + }, + + strictEqual: function( actual, expected, message ) { + QUnit.push( expected === actual, actual, expected, message ); + }, + + notStrictEqual: function( actual, expected, message ) { + QUnit.push( expected !== actual, actual, expected, message ); + }, + + raises: function( block, expected, message ) { + var actual, + ok = false; + + if ( typeof expected === "string" ) { + message = expected; + expected = null; + } + + config.current.ignoreGlobalErrors = true; + try { + block.call( config.current.testEnvironment ); + } catch (e) { + actual = e; + } + config.current.ignoreGlobalErrors = false; + + if ( actual ) { + // we don't want to validate thrown error + if ( !expected ) { + ok = true; + // expected is a regexp + } else if ( QUnit.objectType( expected ) === "regexp" ) { + ok = expected.test( actual ); + // expected is a constructor + } else if ( actual instanceof expected ) { + ok = true; + // expected is a validation function which returns true is validation passed + } else if ( expected.call( {}, actual ) === true ) { + ok = true; + } + } + + QUnit.push( ok, actual, null, message ); + } +}; + +// @deprecated: Kept assertion helpers in root for backwards compatibility +extend( QUnit, QUnit.assert ); + +/** + * @deprecated: Kept for backwards compatibility + * next step: remove entirely + */ +QUnit.equals = function() { + QUnit.push( false, false, false, "QUnit.equals has been deprecated since 2009 (e88049a0), use QUnit.equal instead" ); +}; +QUnit.same = function() { + QUnit.push( false, false, false, "QUnit.same has been deprecated since 2009 (e88049a0), use QUnit.deepEqual instead" ); +}; + +// We want access to the constructor's prototype +(function() { + function F() {} + F.prototype = QUnit; + QUnit = new F(); + // Make F QUnit's constructor so that we can add to the prototype later + QUnit.constructor = F; +}()); + +/** + * Config object: Maintain internal state + * Later exposed as QUnit.config + * `config` initialized at top of scope + */ +config = { + // The queue of tests to run + queue: [], + + // block until document ready + blocking: true, + + // when enabled, show only failing tests + // gets persisted through sessionStorage and can be changed in UI via checkbox + hidepassed: false, + + // by default, run previously failed tests first + // very useful in combination with "Hide passed tests" checked + reorder: true, + + // by default, modify document.title when suite is done + altertitle: true, + + // when enabled, all tests must call expect() + requireExpects: false, + + urlConfig: [ "noglobals", "notrycatch" ], + + // logging callback queues + begin: [], + done: [], + log: [], + testStart: [], + testDone: [], + moduleStart: [], + moduleDone: [] +}; + +// Initialize more QUnit.config and QUnit.urlParams +(function() { + var i, + location = window.location || { search: "", protocol: "file:" }, + params = location.search.slice( 1 ).split( "&" ), + length = params.length, + urlParams = {}, + current; + + if ( params[ 0 ] ) { + for ( i = 0; i < length; i++ ) { + current = params[ i ].split( "=" ); + current[ 0 ] = decodeURIComponent( current[ 0 ] ); + // allow just a key to turn on a flag, e.g., test.html?noglobals + current[ 1 ] = current[ 1 ] ? decodeURIComponent( current[ 1 ] ) : true; + urlParams[ current[ 0 ] ] = current[ 1 ]; + } + } + + QUnit.urlParams = urlParams; + + // String search anywhere in moduleName+testName + config.filter = urlParams.filter; + + // Exact match of the module name + config.module = urlParams.module; + + config.testNumber = parseInt( urlParams.testNumber, 10 ) || null; + + // Figure out if we're running the tests from a server or not + QUnit.isLocal = location.protocol === "file:"; +}()); + +// Export global variables, unless an 'exports' object exists, +// in that case we assume we're in CommonJS (dealt with on the bottom of the script) +if ( typeof exports === "undefined" ) { + extend( window, QUnit ); + + // Expose QUnit object + window.QUnit = QUnit; +} + +// Extend QUnit object, +// these after set here because they should not be exposed as global functions +extend( QUnit, { + config: config, + + // Initialize the configuration options + init: function() { + extend( config, { + stats: { all: 0, bad: 0 }, + moduleStats: { all: 0, bad: 0 }, + started: +new Date(), + updateRate: 1000, + blocking: false, + autostart: true, + autorun: false, + filter: "", + queue: [], + semaphore: 0 + }); + + var tests, banner, result, + qunit = id( "qunit" ); + + if ( qunit ) { + qunit.innerHTML = + "

" + escapeInnerText( document.title ) + "

" + + "

" + + "
" + + "

" + + "
    "; + } + + tests = id( "qunit-tests" ); + banner = id( "qunit-banner" ); + result = id( "qunit-testresult" ); + + if ( tests ) { + tests.innerHTML = ""; + } + + if ( banner ) { + banner.className = ""; + } + + if ( result ) { + result.parentNode.removeChild( result ); + } + + if ( tests ) { + result = document.createElement( "p" ); + result.id = "qunit-testresult"; + result.className = "result"; + tests.parentNode.insertBefore( result, tests ); + result.innerHTML = "Running...
     "; + } + }, + + // Resets the test setup. Useful for tests that modify the DOM. + // If jQuery is available, uses jQuery's html(), otherwise just innerHTML. + reset: function() { + var fixture; + + if ( window.jQuery ) { + jQuery( "#qunit-fixture" ).html( config.fixture ); + } else { + fixture = id( "qunit-fixture" ); + if ( fixture ) { + fixture.innerHTML = config.fixture; + } + } + }, + + // Trigger an event on an element. + // @example triggerEvent( document.body, "click" ); + triggerEvent: function( elem, type, event ) { + if ( document.createEvent ) { + event = document.createEvent( "MouseEvents" ); + event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, + 0, 0, 0, 0, 0, false, false, false, false, 0, null); + + elem.dispatchEvent( event ); + } else if ( elem.fireEvent ) { + elem.fireEvent( "on" + type ); + } + }, + + // Safe object type checking + is: function( type, obj ) { + return QUnit.objectType( obj ) == type; + }, + + objectType: function( obj ) { + if ( typeof obj === "undefined" ) { + return "undefined"; + // consider: typeof null === object + } + if ( obj === null ) { + return "null"; + } + + var type = toString.call( obj ).match(/^\[object\s(.*)\]$/)[1] || ""; + + switch ( type ) { + case "Number": + if ( isNaN(obj) ) { + return "nan"; + } + return "number"; + case "String": + case "Boolean": + case "Array": + case "Date": + case "RegExp": + case "Function": + return type.toLowerCase(); + } + if ( typeof obj === "object" ) { + return "object"; + } + return undefined; + }, + + push: function( result, actual, expected, message ) { + if ( !config.current ) { + throw new Error( "assertion outside test context, was " + sourceFromStacktrace() ); + } + + var output, source, + details = { + result: result, + message: message, + actual: actual, + expected: expected + }; + + message = escapeInnerText( message ) || ( result ? "okay" : "failed" ); + message = "" + message + ""; + output = message; + + if ( !result ) { + expected = escapeInnerText( QUnit.jsDump.parse(expected) ); + actual = escapeInnerText( QUnit.jsDump.parse(actual) ); + output += ""; + + if ( actual != expected ) { + output += ""; + output += ""; + } + + source = sourceFromStacktrace(); + + if ( source ) { + details.source = source; + output += ""; + } + + output += "
    Expected:
    " + expected + "
    Result:
    " + actual + "
    Diff:
    " + QUnit.diff( expected, actual ) + "
    Source:
    " + escapeInnerText( source ) + "
    "; + } + + runLoggingCallbacks( "log", QUnit, details ); + + config.current.assertions.push({ + result: !!result, + message: output + }); + }, + + pushFailure: function( message, source ) { + if ( !config.current ) { + throw new Error( "pushFailure() assertion outside test context, was " + sourceFromStacktrace(2) ); + } + + var output, + details = { + result: false, + message: message + }; + + message = escapeInnerText(message ) || "error"; + message = "" + message + ""; + output = message; + + if ( source ) { + details.source = source; + output += "
    Source:
    " + escapeInnerText( source ) + "
    "; + } + + runLoggingCallbacks( "log", QUnit, details ); + + config.current.assertions.push({ + result: false, + message: output + }); + }, + + url: function( params ) { + params = extend( extend( {}, QUnit.urlParams ), params ); + var key, + querystring = "?"; + + for ( key in params ) { + if ( !hasOwn.call( params, key ) ) { + continue; + } + querystring += encodeURIComponent( key ) + "=" + + encodeURIComponent( params[ key ] ) + "&"; + } + return window.location.pathname + querystring.slice( 0, -1 ); + }, + + extend: extend, + id: id, + addEvent: addEvent + // load, equiv, jsDump, diff: Attached later +}); + +/** + * @deprecated: Created for backwards compatibility with test runner that set the hook function + * into QUnit.{hook}, instead of invoking it and passing the hook function. + * QUnit.constructor is set to the empty F() above so that we can add to it's prototype here. + * Doing this allows us to tell if the following methods have been overwritten on the actual + * QUnit object. + */ +extend( QUnit.constructor.prototype, { + + // Logging callbacks; all receive a single argument with the listed properties + // run test/logs.html for any related changes + begin: registerLoggingCallback( "begin" ), + + // done: { failed, passed, total, runtime } + done: registerLoggingCallback( "done" ), + + // log: { result, actual, expected, message } + log: registerLoggingCallback( "log" ), + + // testStart: { name } + testStart: registerLoggingCallback( "testStart" ), + + // testDone: { name, failed, passed, total } + testDone: registerLoggingCallback( "testDone" ), + + // moduleStart: { name } + moduleStart: registerLoggingCallback( "moduleStart" ), + + // moduleDone: { name, failed, passed, total } + moduleDone: registerLoggingCallback( "moduleDone" ) +}); + +if ( typeof document === "undefined" || document.readyState === "complete" ) { + config.autorun = true; +} + +QUnit.load = function() { + runLoggingCallbacks( "begin", QUnit, {} ); + + // Initialize the config, saving the execution queue + var banner, filter, i, label, len, main, ol, toolbar, userAgent, val, + urlConfigHtml = "", + oldconfig = extend( {}, config ); + + QUnit.init(); + extend(config, oldconfig); + + config.blocking = false; + + len = config.urlConfig.length; + + for ( i = 0; i < len; i++ ) { + val = config.urlConfig[i]; + config[val] = QUnit.urlParams[val]; + urlConfigHtml += ""; + } + + // `userAgent` initialized at top of scope + userAgent = id( "qunit-userAgent" ); + if ( userAgent ) { + userAgent.innerHTML = navigator.userAgent; + } + + // `banner` initialized at top of scope + banner = id( "qunit-header" ); + if ( banner ) { + banner.innerHTML = "" + banner.innerHTML + " " + urlConfigHtml; + addEvent( banner, "change", function( event ) { + var params = {}; + params[ event.target.name ] = event.target.checked ? true : undefined; + window.location = QUnit.url( params ); + }); + } + + // `toolbar` initialized at top of scope + toolbar = id( "qunit-testrunner-toolbar" ); + if ( toolbar ) { + // `filter` initialized at top of scope + filter = document.createElement( "input" ); + filter.type = "checkbox"; + filter.id = "qunit-filter-pass"; + + addEvent( filter, "click", function() { + var tmp, + ol = document.getElementById( "qunit-tests" ); + + if ( filter.checked ) { + ol.className = ol.className + " hidepass"; + } else { + tmp = " " + ol.className.replace( /[\n\t\r]/g, " " ) + " "; + ol.className = tmp.replace( / hidepass /, " " ); + } + if ( defined.sessionStorage ) { + if (filter.checked) { + sessionStorage.setItem( "qunit-filter-passed-tests", "true" ); + } else { + sessionStorage.removeItem( "qunit-filter-passed-tests" ); + } + } + }); + + if ( config.hidepassed || defined.sessionStorage && sessionStorage.getItem( "qunit-filter-passed-tests" ) ) { + filter.checked = true; + // `ol` initialized at top of scope + ol = document.getElementById( "qunit-tests" ); + ol.className = ol.className + " hidepass"; + } + toolbar.appendChild( filter ); + + // `label` initialized at top of scope + label = document.createElement( "label" ); + label.setAttribute( "for", "qunit-filter-pass" ); + label.innerHTML = "Hide passed tests"; + toolbar.appendChild( label ); + } + + // `main` initialized at top of scope + main = id( "qunit-fixture" ); + if ( main ) { + config.fixture = main.innerHTML; + } + + if ( config.autostart ) { + QUnit.start(); + } +}; + +addEvent( window, "load", QUnit.load ); + +// `onErrorFnPrev` initialized at top of scope +// Preserve other handlers +onErrorFnPrev = window.onerror; + +// Cover uncaught exceptions +// Returning true will surpress the default browser handler, +// returning false will let it run. +window.onerror = function ( error, filePath, linerNr ) { + var ret = false; + if ( onErrorFnPrev ) { + ret = onErrorFnPrev( error, filePath, linerNr ); + } + + // Treat return value as window.onerror itself does, + // Only do our handling if not surpressed. + if ( ret !== true ) { + if ( QUnit.config.current ) { + if ( QUnit.config.current.ignoreGlobalErrors ) { + return true; + } + QUnit.pushFailure( error, filePath + ":" + linerNr ); + } else { + QUnit.test( "global failure", function() { + QUnit.pushFailure( error, filePath + ":" + linerNr ); + }); + } + return false; + } + + return ret; +}; + +function done() { + config.autorun = true; + + // Log the last module results + if ( config.currentModule ) { + runLoggingCallbacks( "moduleDone", QUnit, { + name: config.currentModule, + failed: config.moduleStats.bad, + passed: config.moduleStats.all - config.moduleStats.bad, + total: config.moduleStats.all + }); + } + + var i, key, + banner = id( "qunit-banner" ), + tests = id( "qunit-tests" ), + runtime = +new Date() - config.started, + passed = config.stats.all - config.stats.bad, + html = [ + "Tests completed in ", + runtime, + " milliseconds.
    ", + "", + passed, + " tests of ", + config.stats.all, + " passed, ", + config.stats.bad, + " failed." + ].join( "" ); + + if ( banner ) { + banner.className = ( config.stats.bad ? "qunit-fail" : "qunit-pass" ); + } + + if ( tests ) { + id( "qunit-testresult" ).innerHTML = html; + } + + if ( config.altertitle && typeof document !== "undefined" && document.title ) { + // show ✖ for good, ✔ for bad suite result in title + // use escape sequences in case file gets loaded with non-utf-8-charset + document.title = [ + ( config.stats.bad ? "\u2716" : "\u2714" ), + document.title.replace( /^[\u2714\u2716] /i, "" ) + ].join( " " ); + } + + // clear own sessionStorage items if all tests passed + if ( config.reorder && defined.sessionStorage && config.stats.bad === 0 ) { + // `key` & `i` initialized at top of scope + for ( i = 0; i < sessionStorage.length; i++ ) { + key = sessionStorage.key( i++ ); + if ( key.indexOf( "qunit-test-" ) === 0 ) { + sessionStorage.removeItem( key ); + } + } + } + + runLoggingCallbacks( "done", QUnit, { + failed: config.stats.bad, + passed: passed, + total: config.stats.all, + runtime: runtime + }); +} + +/** @return Boolean: true if this test should be ran */ +function validTest( test ) { + var include, + filter = config.filter && config.filter.toLowerCase(), + module = config.module, + fullName = (test.module + ": " + test.testName).toLowerCase(); + + if ( config.testNumber ) { + return test.testNumber === config.testNumber; + } + + if ( module && test.module !== module ) { + return false; + } + + if ( !filter ) { + return true; + } + + include = filter.charAt( 0 ) !== "!"; + if ( !include ) { + filter = filter.slice( 1 ); + } + + // If the filter matches, we need to honour include + if ( fullName.indexOf( filter ) !== -1 ) { + return include; + } + + // Otherwise, do the opposite + return !include; +} + +// so far supports only Firefox, Chrome and Opera (buggy), Safari (for real exceptions) +// Later Safari and IE10 are supposed to support error.stack as well +// See also https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error/Stack +function extractStacktrace( e, offset ) { + offset = offset === undefined ? 3 : offset; + + var stack, include, i, regex; + + if ( e.stacktrace ) { + // Opera + return e.stacktrace.split( "\n" )[ offset + 3 ]; + } else if ( e.stack ) { + // Firefox, Chrome + stack = e.stack.split( "\n" ); + if (/^error$/i.test( stack[0] ) ) { + stack.shift(); + } + if ( fileName ) { + include = []; + for ( i = offset; i < stack.length; i++ ) { + if ( stack[ i ].indexOf( fileName ) != -1 ) { + break; + } + include.push( stack[ i ] ); + } + if ( include.length ) { + return include.join( "\n" ); + } + } + return stack[ offset ]; + } else if ( e.sourceURL ) { + // Safari, PhantomJS + // hopefully one day Safari provides actual stacktraces + // exclude useless self-reference for generated Error objects + if ( /qunit.js$/.test( e.sourceURL ) ) { + return; + } + // for actual exceptions, this is useful + return e.sourceURL + ":" + e.line; + } +} +function sourceFromStacktrace( offset ) { + try { + throw new Error(); + } catch ( e ) { + return extractStacktrace( e, offset ); + } +} + +function escapeInnerText( s ) { + if ( !s ) { + return ""; + } + s = s + ""; + return s.replace( /[\&<>]/g, function( s ) { + switch( s ) { + case "&": return "&"; + case "<": return "<"; + case ">": return ">"; + default: return s; + } + }); +} + +function synchronize( callback, last ) { + config.queue.push( callback ); + + if ( config.autorun && !config.blocking ) { + process( last ); + } +} + +function process( last ) { + function next() { + process( last ); + } + var start = new Date().getTime(); + config.depth = config.depth ? config.depth + 1 : 1; + + while ( config.queue.length && !config.blocking ) { + if ( !defined.setTimeout || config.updateRate <= 0 || ( ( new Date().getTime() - start ) < config.updateRate ) ) { + config.queue.shift()(); + } else { + window.setTimeout( next, 13 ); + break; + } + } + config.depth--; + if ( last && !config.blocking && !config.queue.length && config.depth === 0 ) { + done(); + } +} + +function saveGlobal() { + config.pollution = []; + + if ( config.noglobals ) { + for ( var key in window ) { + // in Opera sometimes DOM element ids show up here, ignore them + if ( !hasOwn.call( window, key ) || /^qunit-test-output/.test( key ) ) { + continue; + } + config.pollution.push( key ); + } + } +} + +function checkPollution( name ) { + var newGlobals, + deletedGlobals, + old = config.pollution; + + saveGlobal(); + + newGlobals = diff( config.pollution, old ); + if ( newGlobals.length > 0 ) { + QUnit.pushFailure( "Introduced global variable(s): " + newGlobals.join(", ") ); + } + + deletedGlobals = diff( old, config.pollution ); + if ( deletedGlobals.length > 0 ) { + QUnit.pushFailure( "Deleted global variable(s): " + deletedGlobals.join(", ") ); + } +} + +// returns a new Array with the elements that are in a but not in b +function diff( a, b ) { + var i, j, + result = a.slice(); + + for ( i = 0; i < result.length; i++ ) { + for ( j = 0; j < b.length; j++ ) { + if ( result[i] === b[j] ) { + result.splice( i, 1 ); + i--; + break; + } + } + } + return result; +} + +function extend( a, b ) { + for ( var prop in b ) { + if ( b[ prop ] === undefined ) { + delete a[ prop ]; + + // Avoid "Member not found" error in IE8 caused by setting window.constructor + } else if ( prop !== "constructor" || a !== window ) { + a[ prop ] = b[ prop ]; + } + } + + return a; +} + +function addEvent( elem, type, fn ) { + if ( elem.addEventListener ) { + elem.addEventListener( type, fn, false ); + } else if ( elem.attachEvent ) { + elem.attachEvent( "on" + type, fn ); + } else { + fn(); + } +} + +function id( name ) { + return !!( typeof document !== "undefined" && document && document.getElementById ) && + document.getElementById( name ); +} + +function registerLoggingCallback( key ) { + return function( callback ) { + config[key].push( callback ); + }; +} + +// Supports deprecated method of completely overwriting logging callbacks +function runLoggingCallbacks( key, scope, args ) { + //debugger; + var i, callbacks; + if ( QUnit.hasOwnProperty( key ) ) { + QUnit[ key ].call(scope, args ); + } else { + callbacks = config[ key ]; + for ( i = 0; i < callbacks.length; i++ ) { + callbacks[ i ].call( scope, args ); + } + } +} + +// Test for equality any JavaScript type. +// Author: Philippe Rathé +QUnit.equiv = (function() { + + // Call the o related callback with the given arguments. + function bindCallbacks( o, callbacks, args ) { + var prop = QUnit.objectType( o ); + if ( prop ) { + if ( QUnit.objectType( callbacks[ prop ] ) === "function" ) { + return callbacks[ prop ].apply( callbacks, args ); + } else { + return callbacks[ prop ]; // or undefined + } + } + } + + // the real equiv function + var innerEquiv, + // stack to decide between skip/abort functions + callers = [], + // stack to avoiding loops from circular referencing + parents = [], + + getProto = Object.getPrototypeOf || function ( obj ) { + return obj.__proto__; + }, + callbacks = (function () { + + // for string, boolean, number and null + function useStrictEquality( b, a ) { + if ( b instanceof a.constructor || a instanceof b.constructor ) { + // to catch short annotaion VS 'new' annotation of a + // declaration + // e.g. var i = 1; + // var j = new Number(1); + return a == b; + } else { + return a === b; + } + } + + return { + "string": useStrictEquality, + "boolean": useStrictEquality, + "number": useStrictEquality, + "null": useStrictEquality, + "undefined": useStrictEquality, + + "nan": function( b ) { + return isNaN( b ); + }, + + "date": function( b, a ) { + return QUnit.objectType( b ) === "date" && a.valueOf() === b.valueOf(); + }, + + "regexp": function( b, a ) { + return QUnit.objectType( b ) === "regexp" && + // the regex itself + a.source === b.source && + // and its modifers + a.global === b.global && + // (gmi) ... + a.ignoreCase === b.ignoreCase && + a.multiline === b.multiline; + }, + + // - skip when the property is a method of an instance (OOP) + // - abort otherwise, + // initial === would have catch identical references anyway + "function": function() { + var caller = callers[callers.length - 1]; + return caller !== Object && typeof caller !== "undefined"; + }, + + "array": function( b, a ) { + var i, j, len, loop; + + // b could be an object literal here + if ( QUnit.objectType( b ) !== "array" ) { + return false; + } + + len = a.length; + if ( len !== b.length ) { + // safe and faster + return false; + } + + // track reference to avoid circular references + parents.push( a ); + for ( i = 0; i < len; i++ ) { + loop = false; + for ( j = 0; j < parents.length; j++ ) { + if ( parents[j] === a[i] ) { + loop = true;// dont rewalk array + } + } + if ( !loop && !innerEquiv(a[i], b[i]) ) { + parents.pop(); + return false; + } + } + parents.pop(); + return true; + }, + + "object": function( b, a ) { + var i, j, loop, + // Default to true + eq = true, + aProperties = [], + bProperties = []; + + // comparing constructors is more strict than using + // instanceof + if ( a.constructor !== b.constructor ) { + // Allow objects with no prototype to be equivalent to + // objects with Object as their constructor. + if ( !(( getProto(a) === null && getProto(b) === Object.prototype ) || + ( getProto(b) === null && getProto(a) === Object.prototype ) ) ) { + return false; + } + } + + // stack constructor before traversing properties + callers.push( a.constructor ); + // track reference to avoid circular references + parents.push( a ); + + for ( i in a ) { // be strict: don't ensures hasOwnProperty + // and go deep + loop = false; + for ( j = 0; j < parents.length; j++ ) { + if ( parents[j] === a[i] ) { + // don't go down the same path twice + loop = true; + } + } + aProperties.push(i); // collect a's properties + + if (!loop && !innerEquiv( a[i], b[i] ) ) { + eq = false; + break; + } + } + + callers.pop(); // unstack, we are done + parents.pop(); + + for ( i in b ) { + bProperties.push( i ); // collect b's properties + } + + // Ensures identical properties name + return eq && innerEquiv( aProperties.sort(), bProperties.sort() ); + } + }; + }()); + + innerEquiv = function() { // can take multiple arguments + var args = [].slice.apply( arguments ); + if ( args.length < 2 ) { + return true; // end transition + } + + return (function( a, b ) { + if ( a === b ) { + return true; // catch the most you can + } else if ( a === null || b === null || typeof a === "undefined" || + typeof b === "undefined" || + QUnit.objectType(a) !== QUnit.objectType(b) ) { + return false; // don't lose time with error prone cases + } else { + return bindCallbacks(a, callbacks, [ b, a ]); + } + + // apply transition with (1..n) arguments + }( args[0], args[1] ) && arguments.callee.apply( this, args.splice(1, args.length - 1 )) ); + }; + + return innerEquiv; +}()); + +/** + * jsDump Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | + * http://flesler.blogspot.com Licensed under BSD + * (http://www.opensource.org/licenses/bsd-license.php) Date: 5/15/2008 + * + * @projectDescription Advanced and extensible data dumping for Javascript. + * @version 1.0.0 + * @author Ariel Flesler + * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} + */ +QUnit.jsDump = (function() { + function quote( str ) { + return '"' + str.toString().replace( /"/g, '\\"' ) + '"'; + } + function literal( o ) { + return o + ""; + } + function join( pre, arr, post ) { + var s = jsDump.separator(), + base = jsDump.indent(), + inner = jsDump.indent(1); + if ( arr.join ) { + arr = arr.join( "," + s + inner ); + } + if ( !arr ) { + return pre + post; + } + return [ pre, inner + arr, base + post ].join(s); + } + function array( arr, stack ) { + var i = arr.length, ret = new Array(i); + this.up(); + while ( i-- ) { + ret[i] = this.parse( arr[i] , undefined , stack); + } + this.down(); + return join( "[", ret, "]" ); + } + + var reName = /^function (\w+)/, + jsDump = { + parse: function( obj, type, stack ) { //type is used mostly internally, you can fix a (custom)type in advance + stack = stack || [ ]; + var inStack, res, + parser = this.parsers[ type || this.typeOf(obj) ]; + + type = typeof parser; + inStack = inArray( obj, stack ); + + if ( inStack != -1 ) { + return "recursion(" + (inStack - stack.length) + ")"; + } + //else + if ( type == "function" ) { + stack.push( obj ); + res = parser.call( this, obj, stack ); + stack.pop(); + return res; + } + // else + return ( type == "string" ) ? parser : this.parsers.error; + }, + typeOf: function( obj ) { + var type; + if ( obj === null ) { + type = "null"; + } else if ( typeof obj === "undefined" ) { + type = "undefined"; + } else if ( QUnit.is( "regexp", obj) ) { + type = "regexp"; + } else if ( QUnit.is( "date", obj) ) { + type = "date"; + } else if ( QUnit.is( "function", obj) ) { + type = "function"; + } else if ( typeof obj.setInterval !== undefined && typeof obj.document !== "undefined" && typeof obj.nodeType === "undefined" ) { + type = "window"; + } else if ( obj.nodeType === 9 ) { + type = "document"; + } else if ( obj.nodeType ) { + type = "node"; + } else if ( + // native arrays + toString.call( obj ) === "[object Array]" || + // NodeList objects + ( typeof obj.length === "number" && typeof obj.item !== "undefined" && ( obj.length ? obj.item(0) === obj[0] : ( obj.item( 0 ) === null && typeof obj[0] === "undefined" ) ) ) + ) { + type = "array"; + } else { + type = typeof obj; + } + return type; + }, + separator: function() { + return this.multiline ? this.HTML ? "
    " : "\n" : this.HTML ? " " : " "; + }, + indent: function( extra ) {// extra can be a number, shortcut for increasing-calling-decreasing + if ( !this.multiline ) { + return ""; + } + var chr = this.indentChar; + if ( this.HTML ) { + chr = chr.replace( /\t/g, " " ).replace( / /g, " " ); + } + return new Array( this._depth_ + (extra||0) ).join(chr); + }, + up: function( a ) { + this._depth_ += a || 1; + }, + down: function( a ) { + this._depth_ -= a || 1; + }, + setParser: function( name, parser ) { + this.parsers[name] = parser; + }, + // The next 3 are exposed so you can use them + quote: quote, + literal: literal, + join: join, + // + _depth_: 1, + // This is the list of parsers, to modify them, use jsDump.setParser + parsers: { + window: "[Window]", + document: "[Document]", + error: "[ERROR]", //when no parser is found, shouldn"t happen + unknown: "[Unknown]", + "null": "null", + "undefined": "undefined", + "function": function( fn ) { + var ret = "function", + name = "name" in fn ? fn.name : (reName.exec(fn) || [])[1];//functions never have name in IE + + if ( name ) { + ret += " " + name; + } + ret += "( "; + + ret = [ ret, QUnit.jsDump.parse( fn, "functionArgs" ), "){" ].join( "" ); + return join( ret, QUnit.jsDump.parse(fn,"functionCode" ), "}" ); + }, + array: array, + nodelist: array, + "arguments": array, + object: function( map, stack ) { + var ret = [ ], keys, key, val, i; + QUnit.jsDump.up(); + if ( Object.keys ) { + keys = Object.keys( map ); + } else { + keys = []; + for ( key in map ) { + keys.push( key ); + } + } + keys.sort(); + for ( i = 0; i < keys.length; i++ ) { + key = keys[ i ]; + val = map[ key ]; + ret.push( QUnit.jsDump.parse( key, "key" ) + ": " + QUnit.jsDump.parse( val, undefined, stack ) ); + } + QUnit.jsDump.down(); + return join( "{", ret, "}" ); + }, + node: function( node ) { + var a, val, + open = QUnit.jsDump.HTML ? "<" : "<", + close = QUnit.jsDump.HTML ? ">" : ">", + tag = node.nodeName.toLowerCase(), + ret = open + tag; + + for ( a in QUnit.jsDump.DOMAttrs ) { + val = node[ QUnit.jsDump.DOMAttrs[a] ]; + if ( val ) { + ret += " " + a + "=" + QUnit.jsDump.parse( val, "attribute" ); + } + } + return ret + close + open + "/" + tag + close; + }, + functionArgs: function( fn ) {//function calls it internally, it's the arguments part of the function + var args, + l = fn.length; + + if ( !l ) { + return ""; + } + + args = new Array(l); + while ( l-- ) { + args[l] = String.fromCharCode(97+l);//97 is 'a' + } + return " " + args.join( ", " ) + " "; + }, + key: quote, //object calls it internally, the key part of an item in a map + functionCode: "[code]", //function calls it internally, it's the content of the function + attribute: quote, //node calls it internally, it's an html attribute value + string: quote, + date: quote, + regexp: literal, //regex + number: literal, + "boolean": literal + }, + DOMAttrs: { + //attributes to dump from nodes, name=>realName + id: "id", + name: "name", + "class": "className" + }, + HTML: false,//if true, entities are escaped ( <, >, \t, space and \n ) + indentChar: " ",//indentation unit + multiline: true //if true, items in a collection, are separated by a \n, else just a space. + }; + + return jsDump; +}()); + +// from Sizzle.js +function getText( elems ) { + var i, elem, + ret = ""; + + for ( i = 0; elems[i]; i++ ) { + elem = elems[i]; + + // Get the text from text nodes and CDATA nodes + if ( elem.nodeType === 3 || elem.nodeType === 4 ) { + ret += elem.nodeValue; + + // Traverse everything else, except comment nodes + } else if ( elem.nodeType !== 8 ) { + ret += getText( elem.childNodes ); + } + } + + return ret; +} + +// from jquery.js +function inArray( elem, array ) { + if ( array.indexOf ) { + return array.indexOf( elem ); + } + + for ( var i = 0, length = array.length; i < length; i++ ) { + if ( array[ i ] === elem ) { + return i; + } + } + + return -1; +} + +/* + * Javascript Diff Algorithm + * By John Resig (http://ejohn.org/) + * Modified by Chu Alan "sprite" + * + * Released under the MIT license. + * + * More Info: + * http://ejohn.org/projects/javascript-diff-algorithm/ + * + * Usage: QUnit.diff(expected, actual) + * + * QUnit.diff( "the quick brown fox jumped over", "the quick fox jumps over" ) == "the quick brown fox jumped jumps over" + */ +QUnit.diff = (function() { + function diff( o, n ) { + var i, + ns = {}, + os = {}; + + for ( i = 0; i < n.length; i++ ) { + if ( ns[ n[i] ] == null ) { + ns[ n[i] ] = { + rows: [], + o: null + }; + } + ns[ n[i] ].rows.push( i ); + } + + for ( i = 0; i < o.length; i++ ) { + if ( os[ o[i] ] == null ) { + os[ o[i] ] = { + rows: [], + n: null + }; + } + os[ o[i] ].rows.push( i ); + } + + for ( i in ns ) { + if ( !hasOwn.call( ns, i ) ) { + continue; + } + if ( ns[i].rows.length == 1 && typeof os[i] != "undefined" && os[i].rows.length == 1 ) { + n[ ns[i].rows[0] ] = { + text: n[ ns[i].rows[0] ], + row: os[i].rows[0] + }; + o[ os[i].rows[0] ] = { + text: o[ os[i].rows[0] ], + row: ns[i].rows[0] + }; + } + } + + for ( i = 0; i < n.length - 1; i++ ) { + if ( n[i].text != null && n[ i + 1 ].text == null && n[i].row + 1 < o.length && o[ n[i].row + 1 ].text == null && + n[ i + 1 ] == o[ n[i].row + 1 ] ) { + + n[ i + 1 ] = { + text: n[ i + 1 ], + row: n[i].row + 1 + }; + o[ n[i].row + 1 ] = { + text: o[ n[i].row + 1 ], + row: i + 1 + }; + } + } + + for ( i = n.length - 1; i > 0; i-- ) { + if ( n[i].text != null && n[ i - 1 ].text == null && n[i].row > 0 && o[ n[i].row - 1 ].text == null && + n[ i - 1 ] == o[ n[i].row - 1 ]) { + + n[ i - 1 ] = { + text: n[ i - 1 ], + row: n[i].row - 1 + }; + o[ n[i].row - 1 ] = { + text: o[ n[i].row - 1 ], + row: i - 1 + }; + } + } + + return { + o: o, + n: n + }; + } + + return function( o, n ) { + o = o.replace( /\s+$/, "" ); + n = n.replace( /\s+$/, "" ); + + var i, pre, + str = "", + out = diff( o === "" ? [] : o.split(/\s+/), n === "" ? [] : n.split(/\s+/) ), + oSpace = o.match(/\s+/g), + nSpace = n.match(/\s+/g); + + if ( oSpace == null ) { + oSpace = [ " " ]; + } + else { + oSpace.push( " " ); + } + + if ( nSpace == null ) { + nSpace = [ " " ]; + } + else { + nSpace.push( " " ); + } + + if ( out.n.length === 0 ) { + for ( i = 0; i < out.o.length; i++ ) { + str += "" + out.o[i] + oSpace[i] + ""; + } + } + else { + if ( out.n[0].text == null ) { + for ( n = 0; n < out.o.length && out.o[n].text == null; n++ ) { + str += "" + out.o[n] + oSpace[n] + ""; + } + } + + for ( i = 0; i < out.n.length; i++ ) { + if (out.n[i].text == null) { + str += "" + out.n[i] + nSpace[i] + ""; + } + else { + // `pre` initialized at top of scope + pre = ""; + + for ( n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++ ) { + pre += "" + out.o[n] + oSpace[n] + ""; + } + str += " " + out.n[i].text + nSpace[i] + pre; + } + } + } + + return str; + }; +}()); + +// for CommonJS enviroments, export everything +if ( typeof exports !== "undefined" ) { + extend(exports, QUnit); +} + +// get at whatever the global object is, like window in browsers +}( (function() {return this;}.call()) )); From 5defe7d97543b79e40aeb2ce1f4492240aa5a581 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 16 Jul 2012 14:34:48 -0400 Subject: [PATCH 21/21] Bump to v0.4.2. Former-commit-id: 48638d63970b9d4300661620b881ea34854d24d2 --- README.md | 64 ++++++++++-------- doc/README.md | 176 +++++++++++++++++++++++++------------------------- doc/parse.php | 2 +- lodash.js | 34 ++++++---- lodash.min.js | 8 +-- package.json | 2 +- 6 files changed, 152 insertions(+), 134 deletions(-) diff --git a/README.md b/README.md index afa72ca320..e0d8492004 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Lo-Dash v0.4.1 +# Lo-Dash v0.4.2 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). @@ -6,8 +6,8 @@ Lo-Dash’s performance is gained by avoiding slower native methods, instead opt ## Download - * [Development source](https://raw.github.com/bestiejs/lodash/v0.4.1/lodash.js) - * [Production source](https://raw.github.com/bestiejs/lodash/v0.4.1/lodash.min.js) + * [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/) * For optimal performance, [create a custom build](https://github.com/bestiejs/lodash#custom-builds) with only the features you need @@ -64,6 +64,11 @@ lodash legacy * Mobile builds, with IE < 9 bug fixes and method compilation removed, may be created using the `mobile` modifier argument. ~~~ bash 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. +~~~ bash +lodash strict ~~~ Custom builds may be created in three ways: @@ -91,7 +96,7 @@ All arguments, except `exclude` with `include` and `legacy` with `mobile`, may b ~~~ bash lodash backbone legacy category=utilities exclude=first,last -lodash backbone mobile category=functions include=pick,uniq +lodash backbone mobile strict category=functions include=pick,uniq ~~~ The `lodash` command-line utility is available when Lo-Dash is installed as a global package (i.e. `npm install -g lodash`). @@ -146,29 +151,29 @@ require({ ## Closed 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.4.1/test/test.js#L306-312)] - * Ensure array-like objects with invalid `length` properties are treated like regular objects [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L257-263), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L607-621), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L863-866)] - * Ensure *"Arrays"* methods allow falsey `array` arguments [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L931-970)] - * 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.1/test/test.js#L265-283), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L623-640), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L868-871)] - * Ensure templates compiled with errors are inspectable [[#666](https://github.com/documentcloud/underscore/issues/666), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L737-744)] - * Fix cross-browser object iteration bugs [[#376](https://github.com/documentcloud/underscore/issues/376), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L195-207), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L317-342), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L438-449), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L457-459), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L477-497), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L667-669)] + * 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 *"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)] * 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.1/test/test.js#L86-92)] - * 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.1/test/test.js#L70-84)] - * `_(…)` should return passed wrapper instances [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L104-107)] - * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L138-147)] - * `_.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.4.1/test/test.js#L176-179)] - * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L252-255)] - * `_.groupBy` should add values to own, not inherited, properties [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L357-364)] - * `_isNaN(new Number(NaN))` should return `true` [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L467-469)] - * `_.reduceRight` should pass correct callback arguments when iterating objects [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L591-605)] - * `_.size` should return the `length` of string values [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L650-652)] - * `_.size` shouldn't error on falsey values [[#650](https://github.com/documentcloud/underscore/pull/650), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L654-661)] - * `_.size` should work with `arguments` objects cross-browser [[#653](https://github.com/documentcloud/underscore/issues/653), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L663-665)] - * `_.sortedIndex` should support arrays with high `length` values [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L707-716)] - * `_.template` should not augment the `options` object [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L731-735)] - * `_.throttle` should work when called in a tight loop [[#502](https://github.com/documentcloud/underscore/issues/502), [test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L814-824)] - * `_.zipObject` should accept less than two arguments [[test](https://github.com/bestiejs/lodash/blob/v0.4.1/test/test.js#L893-895)] + * 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)] + * `_(…)` should return passed wrapper instances [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L114-117)] + * `_.contains` should work with strings [[#667](https://github.com/documentcloud/underscore/pull/667), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L148-157)] + * `_.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.4.2/test/test.js#L205-208)] + * `_.forEach` should be chainable [[#142](https://github.com/documentcloud/underscore/issues/142), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L310-313)] + * `_.groupBy` should add values to own, not inherited, properties [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L415-422)] + * `_isNaN(new Number(NaN))` should return `true` [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L525-527)] + * `_.reduceRight` should pass correct callback arguments when iterating objects [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L649-663)] + * `_.size` should return the `length` of string values [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L708-710)] + * `_.size` shouldn't error on falsey values [[#650](https://github.com/documentcloud/underscore/pull/650), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L712-719)] + * `_.size` should work with `arguments` objects cross-browser [[#653](https://github.com/documentcloud/underscore/issues/653), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L721-723)] + * `_.sortedIndex` should support arrays with high `length` values [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L765-774)] + * `_.template` should not augment the `options` object [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L789-793)] + * `_.throttle` should work when called in a loop [[#502](https://github.com/documentcloud/underscore/issues/502), [test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L872-882)] + * `_.zipObject` should accept less than two arguments [[test](https://github.com/bestiejs/lodash/blob/v0.4.2/test/test.js#L951-953)] ## Optimized methods (50+) @@ -233,6 +238,13 @@ require({ ## Release Notes +### v0.4.2 + + * Added `strict` build + * Ensured `_.bindAll`, `_.extend`, and `_.defaults` 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 + ### v0.4.1 * Fixed `_.template` regression diff --git a/doc/README.md b/doc/README.md index 135f7cc3a8..75930cb596 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,4 +1,4 @@ -# Lo-Dash v0.4.1 +# Lo-Dash v0.4.2 @@ -148,7 +148,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3603 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3608 "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#L1981 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1985 "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#L2035 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2039 "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#L2105 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2109 "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#L3528 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3533 "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#L2435 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2439 "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#L1223 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1227 "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#L2141 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2145 "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#L758 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L762 "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#L2174 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2178 "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#L2458 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2462 "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#L2239 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2243 "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#L2219 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2223 "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#L1255 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1259 "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#L3168 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3173 "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#L786 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L790 "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#L2477 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2481 "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#L806 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L810 "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#L827 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L831 "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#L1292 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1296 "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#L1316 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1320 "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#L853 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L857 "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#L2506 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2510 "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#L2529 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2533 "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#L2546 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2550 "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#L880 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L884 "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#L2569 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2573 "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#L3187 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3192 "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#L1360 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1364 "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#L1400 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1404 "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#L1421 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1425 "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#L914 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L918 "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#L2589 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2593 "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#L2615 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2620 "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#L2632 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2637 "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#L2649 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2654 "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#L2666 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2671 "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#L2690 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2695 "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#L2724 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2729 "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#L2886 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2891 "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#L2903 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2908 "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#L2955 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2960 "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#L2978 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2983 "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#L2995 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3000 "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#L2924 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2929 "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#L3012 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3017 "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#L3029 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3034 "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#L3047 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3052 "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#L3064 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3069 "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#L1462 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1466 "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#L1488 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1492 "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#L950 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L954 "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#L1528 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1532 "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#L2262 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2266 "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#L1578 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1582 "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#L3213 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3218 "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#L3244 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3249 "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#L2288 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2292 "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#L2321 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2325 "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#L3086 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3091 "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#L973 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L977 "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#L1639 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1643 "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#L1001 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1005 "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#L1038 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1042 "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#L1093 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1097 "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#L1676 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1680 "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#L3276 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3281 "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#L1697 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1701 "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#L3125 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3130 "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#L1116 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1120 "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#L1148 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1152 "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#L1749 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1753 "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#L3555 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3560 "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#L3336 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3341 "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#L2357 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2361 "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#L3471 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3476 "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#L1191 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1195 "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#L1789 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1793 "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#L1834 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1838 "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#L3498 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3503 "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#L3146 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3151 "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#L1883 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1887 "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#L2409 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2413 "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#L1916 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1920 "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#L1945 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1949 "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#L3573 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3578 "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#L3590 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3595 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/doc/parse.php b/doc/parse.php index 7ac59c84ad..aa7e45a98e 100644 --- a/doc/parse.php +++ b/doc/parse.php @@ -21,7 +21,7 @@ // generate Markdown $markdown = docdown(array( 'path' => '../' . $file, - 'title' => 'Lo-Dash v0.4.1', + 'title' => 'Lo-Dash v0.4.2', 'url' => 'https://github.com/bestiejs/lodash/blob/master/lodash.js' )); diff --git a/lodash.js b/lodash.js index 6d39dafc08..af689d3aa7 100644 --- a/lodash.js +++ b/lodash.js @@ -1,5 +1,5 @@ /*! - * Lo-Dash v0.4.1 + * Lo-Dash v0.4.2 * Copyright 2012 John-David Dalton * Based on Underscore.js 1.3.3, copyright 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. * @@ -459,18 +459,22 @@ if (isLarge) { // init value cache - var value, + var key, index = fromIndex - 1; while (++index < length) { - value = array[index]; - (hasOwnProperty.call(cache, value) ? cache[value] : (cache[value] = [])).push(value); + // manually coerce `value` to string because `hasOwnProperty`, in some + // older versions of Firefox, coerces objects incorrectly + key = array[index] + ''; + (hasOwnProperty.call(cache, key) ? cache[key] : (cache[key] = [])).push(array[index]); } } return function(value) { - return isLarge - ? hasOwnProperty.call(cache, value) && indexOf(cache[value], value) > -1 - : indexOf(cache, value, fromIndex) > -1; + if (isLarge) { + var key = value + ''; + return hasOwnProperty.call(cache, key) && indexOf(cache[key], value) > -1; + } + return indexOf(cache, value, fromIndex) > -1; } } @@ -2589,7 +2593,8 @@ var isArguments = function(value) { return toString.call(value) == '[object Arguments]'; }; - // fallback for browser like IE < 9 which detect `arguments` as `[object Object]` + // fallback for browser like Firefox < 4 and IE < 9 which detect + // `arguments` as `[object Object]` if (!isArguments(arguments)) { isArguments = function(value) { return !!(value && hasOwnProperty.call(value, 'callee')); @@ -3600,7 +3605,7 @@ * @memberOf _ * @type String */ - lodash.VERSION = '0.4.1'; + lodash.VERSION = '0.4.2'; // assign static methods lodash.after = after; @@ -3730,11 +3735,12 @@ var value = this._wrapped; func.apply(value, arguments); - // IE compatibility mode and IE < 9 have buggy Array `shift()` and `splice()` - // functions that fail to remove the last element, `value[0]`, of - // array-like objects even though the `length` property is set to `0`. - // The `shift()` method is buggy in IE 8 compatibility mode, while `splice()` - // is buggy regardless of mode in IE < 9 and buggy in compatibility mode in IE 9. + // Firefox < 10, IE compatibility mode, and IE < 9 have buggy Array + // `shift()` and `splice()` functions that fail to remove the last element, + // `value[0]`, of array-like objects even though the `length` property is + // set to `0`. The `shift()` method is buggy in IE 8 compatibility mode, + // while `splice()` is buggy regardless of mode in IE < 9 and buggy in + // compatibility mode in IE 9. if (value.length === 0) { delete value[0]; } diff --git a/lodash.min.js b/lodash.min.js index 2b3b34e874..42c9d5a95b 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -1,9 +1,9 @@ /*! - Lo-Dash 0.4.1 lodash.com/license + 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+="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) @@ -19,7 +19,7 @@ t.constructor)return i;for(var l in e)if(Y.call(e,l)&&(f++,!(a=Y.call(t,l)&&k(e[ ,j:"[]",i:"D.push(n)"}),_t=a({a:"g,H",j:"false",n:i,d:{b:"if(J.call(p)==G)return g.indexOf(H)>-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) +),s.isArguments(arguments)||(s.isArguments=function(e){return!!e&&!!Y.call(e,"callee")});var Gt=it||function(e){return nt.call(e)==ut},Yt=a({a:"K",j:"true",p:"var f=J.call(K);if(f==c||f==G)return!K.length",i:{l:"return false"}}),Zt=ot?function(e){return"function"==typeof e&&et.call(e,"prototype")?Mt(e):ot(e)}:Mt,en=a({a:"w",j:"[]",i:"D.push(p[n])"});s.VERSION="0.4.2",s.after=function(e,t){return 1>e?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!! diff --git a/package.json b/package.json index 252c5dfc87..de6869b0a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash", - "version": "0.4.1", + "version": "0.4.2", "description": "A drop-in replacement for Underscore.js that delivers performance improvements, bug fixes, and additional features.", "homepage": "http://lodash.com", "main": "lodash",