From be50df81dbae9a8af8f8b32accfeee058b54ef9e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 30 Jan 2013 01:02:55 -0800 Subject: [PATCH] Update builds and docs. Former-commit-id: c0e38666fb1aee210c3dbd6401b040d8a2bee23d --- build/post-compile.js | 2 +- doc/README.md | 265 +++++++++++++++++++++++---------------- lodash.js | 97 ++++++++++---- lodash.min.js | 4 +- lodash.underscore.js | 102 ++++++++++++--- lodash.underscore.min.js | 54 ++++---- test/test-build.js | 2 +- 7 files changed, 345 insertions(+), 181 deletions(-) diff --git a/build/post-compile.js b/build/post-compile.js index bb3581f15..acc9c67a3 100644 --- a/build/post-compile.js +++ b/build/post-compile.js @@ -10,7 +10,7 @@ '/**', ' * @license', ' * Lo-Dash <%= VERSION %> lodash.com/license', - ' * Underscore.js 1.4.3 underscorejs.org/LICENSE', + ' * Underscore.js 1.4.4 underscorejs.org/LICENSE', ' */' ].join('\n'); diff --git a/doc/README.md b/doc/README.md index 662b1c627..f15c733b0 100644 --- a/doc/README.md +++ b/doc/README.md @@ -197,7 +197,7 @@ ### `_.compact(array)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2859 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2912 "View in source") [Ⓣ][1] Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey. @@ -221,7 +221,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.difference(array [, array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2889 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2942 "View in source") [Ⓣ][1] Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`. @@ -246,7 +246,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.first(array [, callback|n, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2933 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2986 "View in source") [Ⓣ][1] Gets the first element of the `array`. If a number `n` is passed, the first `n` elements of the `array` are returned. If a `callback` function is passed, the first elements the `callback` returns truthy for are returned. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -283,7 +283,7 @@ _.first([1, 2, 3], function(num) { ### `_.flatten(array, shallow)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2972 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3025 "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. @@ -311,7 +311,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.indexOf(array, value [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3014 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3067 "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 `fromIndex` will run a faster binary search. @@ -343,7 +343,7 @@ _.indexOf([1, 1, 2, 2, 3, 3], 2, true); ### `_.initial(array [, callback|n=1, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3060 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3113 "View in source") [Ⓣ][1] Gets all but the last element of `array`. If a number `n` is passed, the last `n` elements are excluded from the result. If a `callback` function is passed, the last elements the `callback` returns truthy for are excluded from the result. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -377,7 +377,7 @@ _.initial([1, 2, 3], function(num) { ### `_.intersection([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3094 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3147 "View in source") [Ⓣ][1] Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -401,7 +401,7 @@ _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]); ### `_.last(array [, callback|n, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3156 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3209 "View in source") [Ⓣ][1] Gets the last element of the `array`. If a number `n` is passed, the last `n` elements of the `array` are returned. If a `callback` function is passed, the last elements the `callback` returns truthy for are returned. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -435,7 +435,7 @@ _.last([1, 2, 3], function(num) { ### `_.lastIndexOf(array, value [, fromIndex=array.length-1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3197 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3250 "View in source") [Ⓣ][1] Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the offset from the end of the collection. @@ -464,7 +464,7 @@ _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); ### `_.object(keys [, values=[]])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3227 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3280 "View in source") [Ⓣ][1] Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`. @@ -489,7 +489,7 @@ _.object(['moe', 'larry'], [30, 40]); ### `_.range([start=0], end [, step=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3271 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3324 "View in source") [Ⓣ][1] Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `end`. @@ -527,7 +527,7 @@ _.range(0); ### `_.rest(array [, callback|n=1, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3321 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3374 "View in source") [Ⓣ][1] The opposite of `_.initial`, this method gets all but the first value of `array`. If a number `n` is passed, the first `n` values are excluded from the result. If a `callback` function is passed, the first elements the `callback` returns truthy for are excluded from the result. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -564,7 +564,7 @@ _.rest([1, 2, 3], function(num) { ### `_.sortedIndex(array, value [, callback=identity|property, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3377 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3430 "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 one argument; *(value)*. The `callback` argument may also be the name of a property to order by. @@ -608,7 +608,7 @@ _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) { ### `_.union([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3409 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3462 "View in source") [Ⓣ][1] Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`. @@ -632,7 +632,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#L3443 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3496 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*. @@ -671,7 +671,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.without(array [, value1, value2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3502 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3555 "View in source") [Ⓣ][1] Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`. @@ -696,7 +696,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.zip([array1, array2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3533 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3586 "View in source") [Ⓣ][1] Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. @@ -756,7 +756,7 @@ The wrapper functions `first` and `last` return wrapped values when `n` is passe ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4428 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4481 "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. @@ -786,7 +786,7 @@ _([1, 2, 3, 4]) ### `_.prototype.toString()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4445 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4498 "View in source") [Ⓣ][1] Produces the `toString` result of the wrapped value. @@ -807,7 +807,7 @@ _([1, 2, 3]).toString(); ### `_.prototype.valueOf()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4462 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4515 "View in source") [Ⓣ][1] Extracts the wrapped value. @@ -838,7 +838,7 @@ _([1, 2, 3]).valueOf(); ### `_.at(collection [, index1, index2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2047 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2099 "View in source") [Ⓣ][1] Creates an array of elements from the specified index(es), or keys, of the `collection`. Indexes may be specified as individual arguments or as arrays of indexes. @@ -866,7 +866,7 @@ _.at(['moe', 'larry', 'curly'], 0, 2); ### `_.contains(collection, target [, fromIndex=0])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2089 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2141 "View in source") [Ⓣ][1] Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the offset from the end of the collection. @@ -904,7 +904,7 @@ _.contains('curly', 'ur'); ### `_.countBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2136 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2188 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is the number of times the key was returned by `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to count by *(e.g. 'length')*. @@ -936,7 +936,7 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.every(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2166 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2218 "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 three arguments; *(value, index|key, collection)*. @@ -965,7 +965,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.filter(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2205 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2257 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -994,9 +994,9 @@ var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }) ### `_.find(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2249 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2302 "View in source") [Ⓣ][1] -Examines each element in a `collection`, returning the first one the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. +Examines each element in a `collection`, returning the first that the `callback` returns truthy for. The function returns as soon as it finds an acceptable element, and does not iterate over the entire `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. #### Aliases *detect* @@ -1023,7 +1023,7 @@ var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.forEach(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2284 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2337 "View in source") [Ⓣ][1] Iterates over a `collection`, executing the `callback` for each element in the `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. Callbacks may exit iteration early by explicitly returning `false`. @@ -1055,7 +1055,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.groupBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2326 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2379 "View in source") [Ⓣ][1] Creates an object composed of keys returned from running each element of `collection` through a `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to group by *(e.g. 'length')*. @@ -1087,7 +1087,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.invoke(collection, methodName [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2359 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2412 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. 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`. @@ -1116,7 +1116,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.map(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2393 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2446 "View in source") [Ⓣ][1] Creates an array of values by running each element in the `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. @@ -1148,7 +1148,7 @@ _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; }); ### `_.max(collection [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2437 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2490 "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 three arguments; *(value, index, collection)*. @@ -1182,7 +1182,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.min(collection [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2493 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2546 "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 three arguments; *(value, index, collection)*. @@ -1216,7 +1216,7 @@ _.min(stooges, function(stooge) { return stooge.age; }); ### `_.pluck(collection, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2543 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2596 "View in source") [Ⓣ][1] Retrieves the value of a specified property from all elements in the `collection`. @@ -1246,7 +1246,7 @@ _.pluck(stooges, 'name'); ### `_.reduce(collection [, callback=identity, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2567 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2620 "View in source") [Ⓣ][1] Reduces 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 four arguments; for arrays they are *(accumulator, value, index|key, collection)*. @@ -1276,7 +1276,7 @@ var sum = _.reduce([1, 2, 3], function(memo, num) { return memo + num; }); ### `_.reduceRight(collection [, callback=identity, accumulator, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2610 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2663 "View in source") [Ⓣ][1] This method is similar to `_.reduce`, except that it iterates over a `collection` from right to left. @@ -1307,7 +1307,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#L2648 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2701 "View in source") [Ⓣ][1] The opposite of `_.filter`, this method returns the elements of a `collection` that `callback` does **not** return truthy for. @@ -1333,7 +1333,7 @@ var odds = _.reject([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); ### `_.shuffle(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2669 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2722 "View in source") [Ⓣ][1] Creates an array of shuffled `array` values, using a version of the Fisher-Yates shuffle. See http://en.wikipedia.org/wiki/Fisher-Yates_shuffle. @@ -1357,7 +1357,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2702 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2755 "View in source") [Ⓣ][1] Gets the size of the `collection` by returning `collection.length` for arrays and array-like objects or the number of own enumerable properties for objects. @@ -1387,7 +1387,7 @@ _.size('curly'); ### `_.some(collection [, callback=identity, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2727 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2780 "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 three arguments; *(value, index|key, collection)*. @@ -1416,7 +1416,7 @@ _.some([null, 0, 'yes', false], Boolean); ### `_.sortBy(collection, callback|property [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2773 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2826 "View in source") [Ⓣ][1] Creates an array, stable sorted in ascending order by the results of running each element of `collection` through a `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. The `callback` argument may also be the name of a property to sort by *(e.g. 'length')*. @@ -1448,7 +1448,7 @@ _.sortBy(['banana', 'strawberry', 'apple'], 'length'); ### `_.toArray(collection)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2808 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2861 "View in source") [Ⓣ][1] Converts the `collection` to an array. @@ -1472,7 +1472,7 @@ Converts the `collection` to an array. ### `_.where(collection, properties)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2839 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2892 "View in source") [Ⓣ][1] Examines each element in a `collection`, returning an array of all elements that have the given `properties`. When checking `properties`, this method performs a deep comparison between values to determine if they are equivalent to each other. @@ -1481,7 +1481,7 @@ Examines each element in a `collection`, returning an array of all elements that 2. `properties` *(Object)*: The object of property values to filter by. #### Returns -*(Array)*: Returns a new array of elements that contain the given `properties`. +*(Array)*: Returns a new array of elements that have the given `properties`. #### Example ```js @@ -1509,7 +1509,7 @@ _.where(stooges, { 'age': 40 }); ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3566 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [Ⓣ][1] Creates a function that is restricted to executing `func` only after it is called `n` times. The `func` is executed with the `this` binding of the created function. @@ -1537,7 +1537,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3599 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3652 "View in source") [Ⓣ][1] Creates a 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. @@ -1568,7 +1568,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3630 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3683 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. Method names may be specified as individual arguments or as arrays of method names. If no method names are provided, all the function properties of `object` will be bound. @@ -1599,7 +1599,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.bindKey(object, key [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3676 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3729 "View in source") [Ⓣ][1] Creates a function that, when called, invokes the method at `object[key]` and prepends any additional `bindKey` arguments to those passed to the bound function. This method differs from `_.bind` by allowing bound functions to reference methods that will be redefined or don't yet exist. See http://michaux.ca/articles/lazy-function-definition-pattern. @@ -1640,7 +1640,7 @@ func(); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3699 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3752 "View in source") [Ⓣ][1] Creates a function that is the composition of the passed functions, where each function consumes the return value of the function that follows. For example, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. Each function is executed with the `this` binding of the composed function. @@ -1652,11 +1652,11 @@ Creates a function that is the composition of the passed functions, where each f #### Example ```js -var greet = function(name) { return 'hi: ' + name; }; +var greet = function(name) { return 'hi ' + name; }; var exclaim = function(statement) { return statement + '!'; }; var welcome = _.compose(exclaim, greet); welcome('moe'); -// => 'hi: moe!' +// => 'hi moe!' ``` * * * @@ -1667,7 +1667,7 @@ welcome('moe'); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3732 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3785 "View in source") [Ⓣ][1] Creates a 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. @@ -1693,7 +1693,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3796 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3849 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments will be passed to `func` when it is invoked. @@ -1718,7 +1718,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3776 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3829 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments will be passed to `func` when it is invoked. @@ -1745,7 +1745,7 @@ _.delay(log, 1000, 'logged later'); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3820 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3873 "View in source") [Ⓣ][1] Creates a 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. The `func` is executed with the `this` binding of the memoized function. @@ -1771,7 +1771,7 @@ var fibonacci = _.memoize(function(n) { ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3847 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3900 "View in source") [Ⓣ][1] Creates a function that is restricted to execute `func` once. Repeat calls to the function will return the value of the first call. The `func` is executed with the `this` binding of the created function. @@ -1797,7 +1797,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3882 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3935 "View in source") [Ⓣ][1] Creates a function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the new function. This method is similar to `_.bind`, except it does **not** alter the `this` binding. @@ -1810,10 +1810,10 @@ Creates a function that, when called, invokes `func` with any additional `partia #### Example ```js -var greet = function(greeting, name) { return greeting + ': ' + name; }; +var greet = function(greeting, name) { return greeting + ' ' + name; }; var hi = _.partial(greet, 'hi'); hi('moe'); -// => 'hi: moe' +// => 'hi moe' ``` * * * @@ -1824,7 +1824,7 @@ hi('moe'); ### `_.partialRight(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3915 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3968 "View in source") [Ⓣ][1] This method is similar to `_.partial`, except that `partial` arguments are appended to those passed to the new function. @@ -1863,7 +1863,7 @@ options.imports ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3937 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3990 "View in source") [Ⓣ][1] Creates a 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. @@ -1888,7 +1888,7 @@ jQuery(window).on('scroll', throttled); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3990 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4043 "View in source") [Ⓣ][1] Creates a function that passes `value` to the `wrapper` function as its first argument. Additional arguments passed to the function are appended to those passed to the `wrapper` function. The `wrapper` is executed with the `this` binding of the created function. @@ -1952,7 +1952,7 @@ _.assign({ 'name': 'moe' }, { 'age': 40 }); ### `_.clone(value [, deep=false, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1069 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1079 "View in source") [Ⓣ][1] Creates a clone of `value`. If `deep` is `true`, nested objects will also be cloned, otherwise they will be assigned by reference. If a `callback` function is passed, it will be executed to produce the cloned values. If `callback` returns the value it was passed, cloning will be handled by the method instead. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. @@ -1979,6 +1979,16 @@ shallow[0] === stooges[0]; var deep = _.clone(stooges, true); deep[0] === stooges[0]; // => false + +_.mixin({ + 'clone': _.partialRight(_.clone, function(value) { + return _.isElement(value) ? value.cloneNode(false) : value; + }) +}); + +var clone = _.clone(document.body); +clone.childNodes.length; +// => 0 ``` * * * @@ -1989,15 +1999,15 @@ deep[0] === stooges[0]; ### `_.cloneDeep(value [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1175 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1200 "View in source") [Ⓣ][1] -Creates a deep clone of `value`. Functions and DOM nodes are **not** cloned. The enumerable properties of `arguments` objects and objects created by constructors other than `Object` are cloned to plain `Object` objects. +Creates a deep clone of `value`. If a `callback` function is passed, it will be executed to produce the cloned values. If `callback` returns the value it was passed, cloning will be handled by the method instead. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*. -Note: This function is loosely based on the structured clone algorithm. See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm. +Note: This function is loosely based on the structured clone algorithm. Functions and DOM nodes are **not** cloned. The enumerable properties of `arguments` objects and objects created by constructors other than `Object` are cloned to plain `Object` objects. See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm. #### Arguments 1. `value` *(Mixed)*: The value to deep clone. -2. `[callback]` *(Function)*: The function called to produce custom cloned values. +2. `[callback]` *(Function)*: The function to customize cloning values. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`. #### Returns @@ -2013,6 +2023,18 @@ var stooges = [ var deep = _.cloneDeep(stooges); deep[0] === stooges[0]; // => false + +var view = { + 'id': 'docs', + 'node': element +}; + +var clone = _.cloneDeep(view, function(value) { + return _.isElement(value) ? value.cloneNode(true) : value; +}); + +clone.node == view.node; +// => false ``` * * * @@ -2023,7 +2045,7 @@ deep[0] === stooges[0]; ### `_.defaults(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1199 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1224 "View in source") [Ⓣ][1] Assigns own enumerable properties of source object(s) to the `destination` object for all `destination` properties that resolve to `null`/`undefined`. Once a property is set, additional defaults of the same property will be ignored. @@ -2113,7 +2135,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1218 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1243 "View in source") [Ⓣ][1] Creates a sorted array of all enumerable properties, own and inherited, of `object` that have function values. @@ -2140,7 +2162,7 @@ _.functions(_); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1243 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1268 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -2165,7 +2187,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.invert(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1260 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1285 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of the given `object`. @@ -2243,7 +2265,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1286 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1311 "View in source") [Ⓣ][1] Checks if `value` is a boolean value. @@ -2267,7 +2289,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1303 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1328 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -2291,7 +2313,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1320 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1345 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -2315,7 +2337,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1345 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1370 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays, strings, or `arguments` objects with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -2345,7 +2367,7 @@ _.isEmpty(''); ### `_.isEqual(a, b [, callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1394 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1431 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. If `callback` is passed, it will be executed to compare values. If `callback` returns a non-boolean value, comparisons will be handled by the method instead. The `callback` is bound to `thisArg` and invoked with two arguments; *(a, b)*. @@ -2360,13 +2382,25 @@ Performs a deep comparison between two values to determine if they are equivalen #### Example ```js -var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; -var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; +var moe = { 'name': 'moe', 'age': 40 }; +var copy = { 'name': 'moe', 'age': 40 }; -moe == clone; +moe == copy; // => false -_.isEqual(moe, clone); +_.isEqual(moe, copy); +// => true + +var words = ['hello', 'goodbye']; +var otherWords = ['hi', 'goodbye']; + +_.isEqual(words, otherWords, function(a, b) { + var reGreet = /^(?:hello|hi)$/i, + aGreet = _.isString(a) && reGreet.test(a), + bGreet = _.isString(b) && reGreet.test(b); + + return (aGreet || bGreet) ? (aGreet == bGreet) : undefined; +}); // => true ``` @@ -2378,7 +2412,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1557 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1594 "View in source") [Ⓣ][1] Checks if `value` is, or can be coerced to, a finite number. @@ -2416,7 +2450,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1574 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1611 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -2440,7 +2474,7 @@ _.isFunction(_); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1637 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1674 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. @@ -2475,7 +2509,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1659 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1696 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -2502,7 +2536,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1676 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1713 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -2526,7 +2560,7 @@ _.isNumber(8.4 * 5); ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1604 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1641 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)* @@ -2556,7 +2590,7 @@ _.isObject(1); ### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1704 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1741 "View in source") [Ⓣ][1] Checks if a given `value` is an object created by the `Object` constructor. @@ -2591,7 +2625,7 @@ _.isPlainObject({ 'name': 'moe', 'age': 40 }); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1729 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1766 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -2615,7 +2649,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1746 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1783 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -2639,7 +2673,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1763 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1800 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -2687,7 +2721,7 @@ _.keys({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.merge(object [, source1, source2, ..., callback, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1807 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1859 "View in source") [Ⓣ][1] Recursively merges own enumerable properties of the source object(s), that don't resolve to `undefined`, into the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. If a `callback` function is passed, it will be executed to produce the merged values of the destination and source properties. The `callback` is bound to `thisArg` and invoked with two arguments; *(objectValue, sourceValue)*. @@ -2718,6 +2752,21 @@ var ages = { _.merge(names, ages); // => { 'stooges': [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] } + +var food = { + 'fruits': ['apple'], + 'vegetables': ['asparagus'] +}; + +var otherFood = { + 'fruits': ['banana'], + 'vegetables': ['beets'] +}; + +_.merge(food, otherFood, function(a, b) { + return _.isObject(a) ? (_.isArray(a) ? a.concat(b) : _.merge(a, b)) : b; +}); +// => { 'fruits': ['apple', 'banana'], 'vegetables': ['asparagus', 'beets'] } ``` * * * @@ -2728,7 +2777,7 @@ _.merge(names, ages); ### `_.omit(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1903 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1955 "View in source") [Ⓣ][1] Creates a shallow clone of `object` excluding the specified properties. Property names may be specified as individual arguments or as arrays of property names. If a `callback` function is passed, it will be executed for each property in the `object`, omitting the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -2759,7 +2808,7 @@ _.omit({ 'name': 'moe', '_hint': 'knucklehead', '_seed': '96c4eb' }, function(va ### `_.pairs(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1937 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1989 "View in source") [Ⓣ][1] Creates a two dimensional array of the given object's key-value pairs, i.e. `[[key1, value1], [key2, value2]]`. @@ -2783,7 +2832,7 @@ _.pairs({ 'moe': 30, 'larry': 40 }); ### `_.pick(object, callback|[prop1, prop2, ..., thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L1975 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2027 "View in source") [Ⓣ][1] Creates a shallow clone of `object` composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. If `callback` is passed, it will be executed for each property in the `object`, picking the properties `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, key, object)*. @@ -2814,7 +2863,7 @@ _.pick({ 'name': 'moe', '_userid': 'moe1' }, function(value, key) { ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2012 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2064 "View in source") [Ⓣ][1] Creates an array composed of the own enumerable property values of `object`. @@ -2845,7 +2894,7 @@ _.values({ 'one': 1, 'two': 2, 'three': 3 }); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4014 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4067 "View in source") [Ⓣ][1] Converts the characters `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding HTML entities. @@ -2869,7 +2918,7 @@ _.escape('Moe, Larry & Curly'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4032 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4085 "View in source") [Ⓣ][1] This function returns the first argument passed to it. @@ -2894,7 +2943,7 @@ moe === _.identity(moe); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4058 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4111 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -2924,7 +2973,7 @@ _('moe').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4082 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4135 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -2944,7 +2993,7 @@ var lodash = _.noConflict(); ### `_.random([min=0, max=1])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4105 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4158 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` *(inclusive)*. If only one argument is passed, a number between `0` and the given number will be returned. @@ -2972,7 +3021,7 @@ _.random(5); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4143 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4196 "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. @@ -3007,7 +3056,7 @@ _.result(object, 'stuff'); ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4228 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4281 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -3060,11 +3109,11 @@ compiled(data); // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector // using the `variable` option to ensure a with-statement isn't used in the compiled template -var compiled = _.template('hello <%= data.name %>!', null, { 'variable': 'data' }); +var compiled = _.template('hi <%= data.name %>!', null, { 'variable': 'data' }); compiled.source; // => function(data) { var __t, __p = '', __e = _.escape; - __p += 'hello ' + ((__t = ( data.name )) == null ? '' : __t) + '!'; + __p += 'hi ' + ((__t = ( data.name )) == null ? '' : __t) + '!'; return __p; } @@ -3085,7 +3134,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4354 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4407 "View in source") [Ⓣ][1] Executes the `callback` function `n` times, returning an array of the results of each `callback` execution. The `callback` is bound to `thisArg` and invoked with one argument; *(index)*. @@ -3117,7 +3166,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.unescape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4380 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4433 "View in source") [Ⓣ][1] The opposite of `_.escape`, this method converts the HTML entities `&`, `<`, `>`, `"`, and `'` in `string` to their corresponding characters. @@ -3141,7 +3190,7 @@ _.unescape('Moe, Larry & Curly'); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4400 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4453 "View in source") [Ⓣ][1] Generates a unique ID. If `prefix` is passed, the ID will be appended to it. @@ -3194,7 +3243,7 @@ A reference to the `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4630 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4683 "View in source") [Ⓣ][1] *(String)*: The semantic version number. diff --git a/lodash.js b/lodash.js index 3d3ae715e..c1aca66f0 100644 --- a/lodash.js +++ b/lodash.js @@ -2,7 +2,7 @@ * @license * Lo-Dash 1.0.0-rc.3 * Copyright 2012-2013 The Dojo Foundation - * Based on Underscore.js 1.4.3 + * Based on Underscore.js 1.4.4 * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc. * Available under MIT license */ @@ -1065,6 +1065,16 @@ * var deep = _.clone(stooges, true); * deep[0] === stooges[0]; * // => false + * + * _.mixin({ + * 'clone': _.partialRight(_.clone, function(value) { + * return _.isElement(value) ? value.cloneNode(false) : value; + * }) + * }); + * + * var clone = _.clone(document.body); + * clone.childNodes.length; + * // => 0 */ function clone(value, deep, callback, thisArg, stackA, stackB) { var result = value; @@ -1147,18 +1157,21 @@ } /** - * Creates a deep clone of `value`. Functions and DOM nodes are **not** cloned. - * The enumerable properties of `arguments` objects and objects created by - * constructors other than `Object` are cloned to plain `Object` objects. + * Creates a deep clone of `value`. If a `callback` function is passed, it will + * be executed to produce the cloned values. If `callback` returns the value it + * was passed, cloning will be handled by the method instead. The `callback` is + * bound to `thisArg` and invoked with one argument; (value). * - * Note: This function is loosely based on the structured clone algorithm. + * Note: This function is loosely based on the structured clone algorithm. Functions + * and DOM nodes are **not** cloned. The enumerable properties of `arguments` objects and + * objects created by constructors other than `Object` are cloned to plain `Object` objects. * See http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm. * * @static * @memberOf _ * @category Objects * @param {Mixed} value The value to deep clone. - * @param {Function} [callback] The function called to produce custom cloned values. + * @param {Function} [callback] The function to customize cloning values. * @param {Mixed} [thisArg] The `this` binding of `callback`. * @returns {Mixed} Returns the deep cloned `value`. * @example @@ -1171,6 +1184,18 @@ * var deep = _.cloneDeep(stooges); * deep[0] === stooges[0]; * // => false + * + * var view = { + * 'id': 'docs', + * 'node': element + * }; + * + * var clone = _.cloneDeep(view, function(value) { + * return _.isElement(value) ? value.cloneNode(true) : value; + * }); + * + * clone.node == view.node; + * // => false */ function cloneDeep(value, callback, thisArg) { return clone(value, true, callback, thisArg); @@ -1382,13 +1407,25 @@ * @returns {Boolean} Returns `true`, if the values are equvalent, else `false`. * @example * - * var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; - * var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; + * var moe = { 'name': 'moe', 'age': 40 }; + * var copy = { 'name': 'moe', 'age': 40 }; * - * moe == clone; + * moe == copy; * // => false * - * _.isEqual(moe, clone); + * _.isEqual(moe, copy); + * // => true + * + * var words = ['hello', 'goodbye']; + * var otherWords = ['hi', 'goodbye']; + * + * _.isEqual(words, otherWords, function(a, b) { + * var reGreet = /^(?:hello|hi)$/i, + * aGreet = _.isString(a) && reGreet.test(a), + * bGreet = _.isString(b) && reGreet.test(b); + * + * return (aGreet || bGreet) ? (aGreet == bGreet) : undefined; + * }); * // => true */ function isEqual(a, b, callback, thisArg, whereIndicator, stackA, stackB) { @@ -1803,6 +1840,21 @@ * * _.merge(names, ages); * // => { 'stooges': [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] } + * + * var food = { + * 'fruits': ['apple'], + * 'vegetables': ['asparagus'] + * }; + * + * var otherFood = { + * 'fruits': ['banana'], + * 'vegetables': ['beets'] + * }; + * + * _.merge(food, otherFood, function(a, b) { + * return _.isObject(a) ? (_.isArray(a) ? a.concat(b) : _.merge(a, b)) : b; + * }); + * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['asparagus', 'beets'] } */ function merge(object, source, deepIndicator) { var args = arguments, @@ -2227,10 +2279,11 @@ } /** - * Examines each element in a `collection`, returning the first one the `callback` - * returns truthy for. The function returns as soon as it finds an acceptable - * element, and does not iterate over the entire `collection`. The `callback` is - * bound to `thisArg` and invoked with three arguments; (value, index|key, collection). + * Examines each element in a `collection`, returning the first that the + * `callback` returns truthy for. The function returns as soon as it finds + * an acceptable element, and does not iterate over the entire `collection`. + * The `callback` is bound to `thisArg` and invoked with three arguments; + * (value, index|key, collection). * * @static * @memberOf _ @@ -2825,7 +2878,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Object} properties The object of property values to filter by. - * @returns {Array} Returns a new array of elements that contain the given `properties`. + * @returns {Array} Returns a new array of elements that have the given `properties`. * @example * * var stooges = [ @@ -3690,11 +3743,11 @@ * @returns {Function} Returns the new composed function. * @example * - * var greet = function(name) { return 'hi: ' + name; }; + * var greet = function(name) { return 'hi ' + name; }; * var exclaim = function(statement) { return statement + '!'; }; * var welcome = _.compose(exclaim, greet); * welcome('moe'); - * // => 'hi: moe!' + * // => 'hi moe!' */ function compose() { var funcs = arguments; @@ -3874,10 +3927,10 @@ * @returns {Function} Returns the new partially applied function. * @example * - * var greet = function(greeting, name) { return greeting + ': ' + name; }; + * var greet = function(greeting, name) { return greeting + ' ' + name; }; * var hi = _.partial(greet, 'hi'); * hi('moe'); - * // => 'hi: moe' + * // => 'hi moe' */ function partial(func) { return createBound(func, slice(arguments, 1)); @@ -4143,7 +4196,7 @@ function result(object, property) { // based on Backbone's private `getValue` function // https://github.com/documentcloud/backbone/blob/0.9.2/backbone.js#L1419-1424 - var value = object ? object[property] : null; + var value = object ? object[property] : undefined; return isFunction(value) ? object[property]() : value; } @@ -4209,11 +4262,11 @@ * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector * * // using the `variable` option to ensure a with-statement isn't used in the compiled template - * var compiled = _.template('hello <%= data.name %>!', null, { 'variable': 'data' }); + * var compiled = _.template('hi <%= data.name %>!', null, { 'variable': 'data' }); * compiled.source; * // => function(data) { * var __t, __p = '', __e = _.escape; - * __p += 'hello ' + ((__t = ( data.name )) == null ? '' : __t) + '!'; + * __p += 'hi ' + ((__t = ( data.name )) == null ? '' : __t) + '!'; * return __p; * } * diff --git a/lodash.min.js b/lodash.min.js index b252e9118..31ace526d 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -1,7 +1,7 @@ /** * @license * Lo-Dash 1.0.0-rc.3 lodash.com/license - * Underscore.js 1.4.3 underscorejs.org/LICENSE + * Underscore.js 1.4.4 underscorejs.org/LICENSE */ ;(function(n,t){function r(n){return n&&typeof n=="object"&&n.__wrapped__?n:this instanceof r?(this.__wrapped__=n,void 0):new r(n)}function e(n,t,r){t||(t=0);var e=n.length,u=e-t>=(r||et);if(u){var o={};for(r=t-1;++rt||typeof n=="undefined")return 1;if(nr?Nt(0,e+r):Rt(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},r.mixin=H,r.noConflict=function(){return n._=ut,this -},r.random=function(n,t){return null==n&&null==t&&(t=1),n=+n||0,null==t&&(t=n,n=0),n+dt($t()*((+t||0)-n+1))},r.reduce=T,r.reduceRight=B,r.result=function(n,t){var r=n?n[t]:null;return w(r)?n[t]():r},r.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:cr(n).length},r.some=M,r.sortedIndex=L,r.template=function(n,e,u){var o=r.templateSettings;n||(n=""),u=vr({},u,o);var i,a=vr({},u.imports,o.imports),o=cr(a),a=k(a),f=0,l=u.interpolate||vt,p="__p+='";n.replace(RegExp((u.escape||vt).source+"|"+l.source+"|"+(l===st?pt:vt).source+"|"+(u.evaluate||vt).source+"|$","g"),function(t,r,e,u,o,a){return e||(e=u),p+=n.slice(f,a).replace(yt,c),r&&(p+="'+__e("+r+")+'"),o&&(i=!0,p+="';"+o+";__p+='"),e&&(p+="'+((__t=("+e+"))==null?'':__t)+'"),f=a+t.length,t +},r.random=function(n,t){return null==n&&null==t&&(t=1),n=+n||0,null==t&&(t=n,n=0),n+dt($t()*((+t||0)-n+1))},r.reduce=T,r.reduceRight=B,r.result=function(n,r){var e=n?n[r]:t;return w(e)?n[r]():e},r.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:cr(n).length},r.some=M,r.sortedIndex=L,r.template=function(n,e,u){var o=r.templateSettings;n||(n=""),u=vr({},u,o);var i,a=vr({},u.imports,o.imports),o=cr(a),a=k(a),f=0,l=u.interpolate||vt,p="__p+='";n.replace(RegExp((u.escape||vt).source+"|"+l.source+"|"+(l===st?pt:vt).source+"|"+(u.evaluate||vt).source+"|$","g"),function(t,r,e,u,o,a){return e||(e=u),p+=n.slice(f,a).replace(yt,c),r&&(p+="'+__e("+r+")+'"),o&&(i=!0,p+="';"+o+";__p+='"),e&&(p+="'+((__t=("+e+"))==null?'':__t)+'"),f=a+t.length,t }),p+="';\n",l=u=u.variable,l||(u="obj",p="with("+u+"){"+p+"}"),p=(i?p.replace(it,""):p).replace(at,"$1").replace(ft,"$1;"),p="function("+u+"){"+(l?"":u+"||("+u+"={});")+"var __t,__p='',__e=_.escape"+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":(l?"":",__d="+u+"."+u+"||"+u)+";")+p+"return __p}";try{var s=Function(o,"return "+p).apply(t,a)}catch(v){throw v.source=p,v}return e?s(e):(s.source=p,s)},r.unescape=function(n){return null==n?"":(n+"").replace(ot,g)},r.uniqueId=function(n){var t=++tt; return(null==n?"":n+"")+t},r.all=q,r.any=M,r.detect=R,r.foldl=T,r.foldr=B,r.include=E,r.inject=T,ar(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(){var t=[this.__wrapped__];return wt.apply(t,arguments),n.apply(r,t)})}),r.first=P,r.last=function(n,t,r){if(n){var e=0,u=n.length;if(typeof t=="function"){var o=u;for(t=a(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,null==e||r)return n[u-1];return v(n,Nt(0,u-e))}},r.take=P,r.head=P,ar(r,function(n,t){r.prototype[t]||(r.prototype[t]=function(t,e){var u=n(this.__wrapped__,t,e); return null==t||e&&typeof t!="function"?u:new r(u)})}),r.VERSION="1.0.0-rc.3",r.prototype.toString=function(){return this.__wrapped__+""},r.prototype.value=J,r.prototype.valueOf=J,or(["join","pop","shift"],function(n){var t=Z[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments)}}),or(["push","reverse","sort","unshift"],function(n){var t=Z[n];r.prototype[n]=function(){return t.apply(this.__wrapped__,arguments),this}}),or(["concat","slice","splice"],function(n){var t=Z[n];r.prototype[n]=function(){return new r(t.apply(this.__wrapped__,arguments)) diff --git a/lodash.underscore.js b/lodash.underscore.js index 9cf426867..4a6fd2200 100644 --- a/lodash.underscore.js +++ b/lodash.underscore.js @@ -3,7 +3,7 @@ * Lo-Dash 1.0.0-rc.3 (Custom Build) * Build: `lodash underscore -d -o ./lodash.underscore.js` * Copyright 2012-2013 The Dojo Foundation - * Based on Underscore.js 1.4.3 + * Based on Underscore.js 1.4.4 * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud Inc. * Available under MIT license */ @@ -336,16 +336,31 @@ * @param {Object} [rightIndicator] Used to indicate partially applying arguments from the right. * @returns {Function} Returns the new bound function. */ - function createBound(func, thisArg, partialArgs) { + function createBound(func, thisArg, partialArgs, rightIndicator) { + var isFunc = isFunction(func), + isPartial = !partialArgs, + key = thisArg; + + // juggle arguments + if (isPartial) { + partialArgs = thisArg; + } + if (!isFunc) { + thisArg = func; + } + function bound() { // `Function#bind` spec // http://es5.github.com/#x15.3.4.5 var args = arguments, - thisBinding = thisArg; + thisBinding = isPartial ? this : thisArg; + if (!isFunc) { + func = thisArg[key]; + } if (partialArgs.length) { args = args.length - ? partialArgs.concat(slice(args)) + ? (args = slice(args), rightIndicator ? args.concat(partialArgs) : partialArgs.concat(args)) : partialArgs; } if (this instanceof bound) { @@ -863,6 +878,16 @@ * var deep = _.clone(stooges, true); * deep[0] === stooges[0]; * // => false + * + * _.mixin({ + * 'clone': _.partialRight(_.clone, function(value) { + * return _.isElement(value) ? value.cloneNode(false) : value; + * }) + * }); + * + * var clone = _.clone(document.body); + * clone.childNodes.length; + * // => 0 */ function clone(value) { return isObject(value) @@ -1085,13 +1110,25 @@ * @returns {Boolean} Returns `true`, if the values are equvalent, else `false`. * @example * - * var moe = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; - * var clone = { 'name': 'moe', 'luckyNumbers': [13, 27, 34] }; + * var moe = { 'name': 'moe', 'age': 40 }; + * var copy = { 'name': 'moe', 'age': 40 }; * - * moe == clone; + * moe == copy; * // => false * - * _.isEqual(moe, clone); + * _.isEqual(moe, copy); + * // => true + * + * var words = ['hello', 'goodbye']; + * var otherWords = ['hi', 'goodbye']; + * + * _.isEqual(words, otherWords, function(a, b) { + * var reGreet = /^(?:hello|hi)$/i, + * aGreet = _.isString(a) && reGreet.test(a), + * bGreet = _.isString(b) && reGreet.test(b); + * + * return (aGreet || bGreet) ? (aGreet == bGreet) : undefined; + * }); * // => true */ function isEqual(a, b, stackA, stackB) { @@ -1683,10 +1720,11 @@ } /** - * Examines each element in a `collection`, returning the first one the `callback` - * returns truthy for. The function returns as soon as it finds an acceptable - * element, and does not iterate over the entire `collection`. The `callback` is - * bound to `thisArg` and invoked with three arguments; (value, index|key, collection). + * Examines each element in a `collection`, returning the first that the + * `callback` returns truthy for. The function returns as soon as it finds + * an acceptable element, and does not iterate over the entire `collection`. + * The `callback` is bound to `thisArg` and invoked with three arguments; + * (value, index|key, collection). * * @static * @memberOf _ @@ -2272,7 +2310,7 @@ * @category Collections * @param {Array|Object|String} collection The collection to iterate over. * @param {Object} properties The object of property values to filter by. - * @returns {Array} Returns a new array of elements that contain the given `properties`. + * @returns {Array} Returns a new array of elements that have the given `properties`. * @example * * var stooges = [ @@ -2283,8 +2321,8 @@ * _.where(stooges, { 'age': 40 }); * // => [{ 'name': 'moe', 'age': 40 }] */ - function where(collection, properties) { - return filter(collection, properties); + function where(collection, properties, first) { + return (first ? find : filter)(collection, properties); } /*--------------------------------------------------------------------------*/ @@ -3073,11 +3111,11 @@ * @returns {Function} Returns the new composed function. * @example * - * var greet = function(name) { return 'hi: ' + name; }; + * var greet = function(name) { return 'hi ' + name; }; * var exclaim = function(statement) { return statement + '!'; }; * var welcome = _.compose(exclaim, greet); * welcome('moe'); - * // => 'hi: moe!' + * // => 'hi moe!' */ function compose() { var funcs = arguments; @@ -3244,6 +3282,28 @@ }; } + /** + * Creates a function that, when called, invokes `func` with any additional + * `partial` arguments prepended to those passed to the new function. This + * method is similar to `_.bind`, except it does **not** alter the `this` binding. + * + * @static + * @memberOf _ + * @category Functions + * @param {Function} func The function to partially apply arguments to. + * @param {Mixed} [arg1, arg2, ...] Arguments to be partially applied. + * @returns {Function} Returns the new partially applied function. + * @example + * + * var greet = function(greeting, name) { return greeting + ' ' + name; }; + * var hi = _.partial(greet, 'hi'); + * hi('moe'); + * // => 'hi moe' + */ + function partial(func) { + return createBound(func, slice(arguments, 1)); + } + /** * Creates a function that, when executed, will only call the `func` * function at most once per every `wait` milliseconds. If the throttled @@ -3477,7 +3537,7 @@ function result(object, property) { // based on Backbone's private `getValue` function // https://github.com/documentcloud/backbone/blob/0.9.2/backbone.js#L1419-1424 - var value = object ? object[property] : null; + var value = object ? object[property] : undefined; return isFunction(value) ? object[property]() : value; } @@ -3543,11 +3603,11 @@ * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector * * // using the `variable` option to ensure a with-statement isn't used in the compiled template - * var compiled = _.template('hello <%= data.name %>!', null, { 'variable': 'data' }); + * var compiled = _.template('hi <%= data.name %>!', null, { 'variable': 'data' }); * compiled.source; * // => function(data) { * var __t, __p = '', __e = _.escape; - * __p += 'hello ' + ((__t = ( data.name )) == null ? '' : __t) + '!'; + * __p += 'hi ' + ((__t = ( data.name )) == null ? '' : __t) + '!'; * return __p; * } * @@ -3827,6 +3887,7 @@ lodash.omit = omit; lodash.once = once; lodash.pairs = pairs; + lodash.partial = partial; lodash.pick = pick; lodash.pluck = pluck; lodash.range = range; @@ -3864,6 +3925,7 @@ lodash.escape = escape; lodash.every = every; lodash.find = find; + lodash.findWhere = find; lodash.has = has; lodash.identity = identity; lodash.indexOf = indexOf; diff --git a/lodash.underscore.min.js b/lodash.underscore.min.js index 0a80a3bfb..08d062ee4 100644 --- a/lodash.underscore.min.js +++ b/lodash.underscore.min.js @@ -2,32 +2,32 @@ * @license * Lo-Dash 1.0.0-rc.3 (Custom Build) lodash.com/license * Build: `lodash underscore -m -o ./lodash.underscore.min.js` - * Underscore.js 1.4.3 underscorejs.org/LICENSE + * Underscore.js 1.4.4 underscorejs.org/LICENSE */ -;(function(n,t){function r(n,t){var r;if(n&&Nt[typeof n])for(r in t||(t=U),n)if(t(n[r],r,n)===X)break}function e(n,t,r){if(n){t=t&&typeof r=="undefined"?t:i(t,r);var e=n.length;if(r=-1,typeof e=="number")for(;++rt||typeof n=="undefined")return 1;if(nr?0:r);++eo&&(o=f)}}else t=i(t,r),e(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function R(n,t){return N(n,t+"")}function T(n,t,r,u){var o=3>arguments.length;if(t=i(t,u,4),Rt(n)){var a=-1,f=n.length;for(o&&(r=n[++a]);++aarguments.length; -if(typeof u!="number")var a=Tt(n),u=a.length;return t=i(t,e,4),k(n,function(e,i,f){i=a?a[--u]:--u,r=o?(o=J,n[i]):t(r,n[i],i,f)}),r}function B(n,t,r){var u;if(t=i(t,r),Rt(n)){r=-1;for(var o=n.length;++rr?ht(0,u+r):r||0)-1;else if(r)return e=z(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])$(f,c))&&(r&&f.push(c),a.push(e))}return a}function P(n,t){var r;if(Ot||lt&&2"']/g,et=/['\n\r\t\u2028\u2029\\]/g,ut=Math.ceil,ot=Q.concat,it=Math.floor,at=L.hasOwnProperty,ft=Q.push,ct=L.toString,lt=nt.test(lt=l.bind)&<,pt=nt.test(pt=Array.isArray)&&pt,st=n.isFinite,vt=n.isNaN,gt=nt.test(gt=Object.keys)&>,ht=Math.max,yt=Math.min,_t=Math.random,mt="[object Arguments]",dt="[object Array]",bt="[object Boolean]",jt="[object Date]",wt="[object Number]",xt="[object Object]",At="[object RegExp]",Et="[object String]",L=!!n.attachEvent,L=lt&&!/\n|true/.test(lt+L),Ot=lt&&!L,St=(St={0:1,length:1},Q.splice.call(St,0,1),St[0]),kt=arguments.constructor==Object,Nt={"boolean":J,"function":G,object:G,number:J,string:J,undefined:J},Ft={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"}; -u.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},s(arguments)||(s=function(n){return n?at.call(n,"callee"):J});var Rt=pt||function(n){return kt&&n instanceof Array||ct.call(n)==dt},Tt=gt?function(n){return b(n)?gt(n):[]}:v,qt={"&":"&","<":"<",">":">",'"':""","'":"'"},Bt=_(qt);d(/x/)&&(d=function(n){return n instanceof Function||"[object Function]"==ct.call(n)}),u.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0 -}},u.bind=P,u.bindAll=function(n){for(var t=ot.apply(Q,arguments),r=1$(e,o,r)&&u.push(o)}return u},u.filter=O,u.flatten=M,u.forEach=k,u.functions=y,u.groupBy=function(n,t,r){var e={}; -return t=i(t,r),k(n,function(n,r,u){r=t(n,r,u)+"",(at.call(e,r)?e[r]:e[r]=[]).push(n)}),e},u.initial=function(n,t,r){if(!n)return[];var e=0,u=n.length;if(typeof t=="function"){var o=u;for(t=i(t,r);o--&&t(n[o],o,n);)e++}else e=t==H||r?1:t||e;return l(n,0,yt(ht(0,u-e),u))},u.intersection=function(n){var t=arguments,r=t.length,e=-1,u=n?n.length:0,o=[];n:for(;++e$(o,i)){for(var a=r;--a;)if(0>$(t[a],i))continue n;o.push(i)}}return o},u.invert=_,u.invoke=function(n,t){var r=l(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=Array(typeof o=="number"?o:0); -return k(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},u.keys=Tt,u.map=N,u.max=F,u.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+"";return at.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},u.min=function(n,t,r){var u=1/0,o=u;if(!t&&Rt(n)){r=-1;for(var a=n.length;++r$(t,r,1)&&(e[r]=n)}),e},u.once=function(n){var t,r;return function(){return t?r:(t=G,r=n.apply(this,arguments),n=H,r)}},u.pairs=function(n){for(var t=-1,r=Tt(n),e=r.length,u=Array(e);++t$(arguments,u,1)&&e.push(u)}return e},u.wrap=function(n,t){return function(){var r=[n];return ft.apply(r,arguments),t.apply(this,r)}},u.zip=function(n){for(var t=-1,r=n?F(R(arguments,"length")):0,e=Array(r);++tr?ht(0,e+r):yt(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=V,u.noConflict=function(){return n._=Y,this},u.random=function(n,t){return n==H&&t==H&&(t=1),n=+n||0,t==H&&(t=n,n=0),n+it(_t()*((+t||0)-n+1))},u.reduce=T,u.reduceRight=q,u.result=function(n,t){var r=n?n[t]:H; -return d(r)?n[t]():r},u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:Tt(n).length},u.some=B,u.sortedIndex=z,u.template=function(n,t,r){n||(n=""),r=h({},r,u.templateSettings);var e=0,o="__p+='",i=r.variable;n.replace(RegExp((r.escape||tt).source+"|"+(r.interpolate||tt).source+"|"+(r.evaluate||tt).source+"|$","g"),function(t,r,u,i,f){return o+=n.slice(e,f).replace(et,a),r&&(o+="'+_['escape']("+r+")+'"),i&&(o+="';"+i+";__p+='"),u&&(o+="'+((__t=("+u+"))==null?'':__t)+'"),e=f+t.length,t -}),o+="';\n",i||(i="obj",o="with("+i+"||{}){"+o+"}"),o="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+o+"return __p}";try{var f=Function("_","return "+o)(u)}catch(c){throw c.source=o,c}return t?f(t):(f.source=o,f)},u.unescape=function(n){return n==H?"":(n+"").replace(Z,p)},u.uniqueId=function(n){var t=++W+"";return n?n+t:t},u.all=E,u.any=B,u.detect=S,u.foldl=T,u.foldr=q,u.include=A,u.inject=T,u.first=D,u.last=function(n,t,r){if(n){var e=0,u=n.length; -if(typeof t=="function"){var o=u;for(t=i(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,e==H||r)return n[u-1];return l(n,ht(0,u-e))}},u.take=D,u.head=D,u.chain=function(n){return n=new u(n),n.__chain__=G,n},u.VERSION="1.0.0-rc.3",V(u),u.prototype.chain=function(){return this.__chain__=G,this},u.prototype.value=function(){return this.__wrapped__},e("pop push reverse shift sort splice unshift".split(" "),function(n){var t=Q[n];u.prototype[n]=function(){var n=this.__wrapped__;return t.apply(n,arguments),St&&0===n.length&&delete n[0],this +;(function(n,t){function r(n,t){var r;if(n&&Ft[typeof n])for(r in t||(t=V),n)if(t(n[r],r,n)===Y)break}function e(n,t,r){if(n){t=t&&typeof r=="undefined"?t:a(t,r);var e=n.length;if(r=-1,typeof e=="number")for(;++rt||typeof n=="undefined")return 1;if(nr?0:r);++eo&&(o=f)}}else t=a(t,r),e(n,function(n,r,e){r=t(n,r,e),r>u&&(u=r,o=n)});return o}function T(n,t){return F(n,t+"") +}function q(n,t,r,u){var o=3>arguments.length;if(t=a(t,u,4),Tt(n)){var i=-1,f=n.length;for(o&&(r=n[++i]);++iarguments.length;if(typeof u!="number")var i=qt(n),u=i.length;return t=a(t,e,4),N(n,function(e,a,f){a=i?i[--u]:--u,r=o?(o=J,n[a]):t(r,n[a],a,f)}),r}function D(n,t,r){var u;if(t=a(t,r),Tt(n)){r=-1;for(var o=n.length;++rr?yt(0,u+r):r||0)-1;else if(r)return e=C(n,t),n[e]===t?e:-1;for(;++e>>1,r(n[e])I(f,c))&&(r&&f.push(c),i.push(e))}return i}function U(n,t){return St||pt&&2"']/g,ut=/['\n\r\t\u2028\u2029\\]/g,ot=Math.ceil,it=Q.concat,at=Math.floor,ft=L.hasOwnProperty,ct=Q.push,lt=L.toString,pt=tt.test(pt=p.bind)&&pt,st=tt.test(st=Array.isArray)&&st,vt=n.isFinite,ht=n.isNaN,gt=tt.test(gt=Object.keys)&>,yt=Math.max,_t=Math.min,mt=Math.random,dt="[object Arguments]",bt="[object Array]",jt="[object Boolean]",wt="[object Date]",xt="[object Number]",At="[object Object]",Et="[object RegExp]",Ot="[object String]",L=!!n.attachEvent,L=pt&&!/\n|true/.test(pt+L),St=pt&&!L,kt=(kt={0:1,length:1},Q.splice.call(kt,0,1),kt[0]),Nt=arguments.constructor==Object,Ft={"boolean":J,"function":G,object:G,number:J,string:J,undefined:J},Rt={"\\":"\\","'":"'","\n":"n","\r":"r"," ":"t","\u2028":"u2028","\u2029":"u2029"}; +u.templateSettings={escape:/<%-([\s\S]+?)%>/g,evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,variable:""},v(arguments)||(v=function(n){return n?ft.call(n,"callee"):J});var Tt=st||function(n){return Nt&&n instanceof Array||lt.call(n)==bt},qt=gt?function(n){return j(n)?gt(n):[]}:h,Bt={"&":"&","<":"<",">":">",'"':""","'":"'"},Dt=m(Bt);b(/x/)&&(b=function(n){return n instanceof Function||"[object Function]"==lt.call(n)}),u.after=function(n,t){return 1>n?t():function(){return 1>--n?t.apply(this,arguments):void 0 +}},u.bind=U,u.bindAll=function(n){for(var t=it.apply(Q,arguments),r=1I(e,o,r)&&u.push(o)}return u},u.filter=S,u.flatten=$,u.forEach=N,u.functions=_,u.groupBy=function(n,t,r){var e={}; +return t=a(t,r),N(n,function(n,r,u){r=t(n,r,u)+"",(ft.call(e,r)?e[r]:e[r]=[]).push(n)}),e},u.initial=function(n,t,r){if(!n)return[];var e=0,u=n.length;if(typeof t=="function"){var o=u;for(t=a(t,r);o--&&t(n[o],o,n);)e++}else e=t==H||r?1:t||e;return p(n,0,_t(yt(0,u-e),u))},u.intersection=function(n){var t=arguments,r=t.length,e=-1,u=n?n.length:0,o=[];n:for(;++eI(o,i)){for(var a=r;--a;)if(0>I(t[a],i))continue n;o.push(i)}}return o},u.invert=m,u.invoke=function(n,t){var r=p(arguments,2),e=-1,u=typeof t=="function",o=n?n.length:0,i=Array(typeof o=="number"?o:0); +return N(n,function(n){i[++e]=(u?t:n[t]).apply(n,r)}),i},u.keys=qt,u.map=F,u.max=R,u.memoize=function(n,t){var r={};return function(){var e=(t?t.apply(this,arguments):arguments[0])+"";return ft.call(r,e)?r[e]:r[e]=n.apply(this,arguments)}},u.min=function(n,t,r){var u=1/0,o=u;if(!t&&Tt(n)){r=-1;for(var i=n.length;++rI(t,r,1)&&(e[r]=n)}),e},u.once=function(n){var t,r;return function(){return t?r:(t=G,r=n.apply(this,arguments),n=H,r)}},u.pairs=function(n){for(var t=-1,r=qt(n),e=r.length,u=Array(e);++tI(arguments,u,1)&&e.push(u)}return e},u.wrap=function(n,t){return function(){var r=[n];return ct.apply(r,arguments),t.apply(this,r)}},u.zip=function(n){for(var t=-1,r=n?R(T(arguments,"length")):0,e=Array(r);++tr?yt(0,e+r):_t(r,e-1))+1);e--;)if(n[e]===t)return e;return-1},u.mixin=W,u.noConflict=function(){return n._=Z,this},u.random=function(n,t){return n==H&&t==H&&(t=1),n=+n||0,t==H&&(t=n,n=0),n+at(mt()*((+t||0)-n+1))},u.reduce=q,u.reduceRight=B,u.result=function(n,r){var e=n?n[r]:t; +return b(e)?n[r]():e},u.size=function(n){var t=n?n.length:0;return typeof t=="number"?t:qt(n).length},u.some=D,u.sortedIndex=C,u.template=function(n,t,r){n||(n=""),r=y({},r,u.templateSettings);var e=0,o="__p+='",i=r.variable;n.replace(RegExp((r.escape||rt).source+"|"+(r.interpolate||rt).source+"|"+(r.evaluate||rt).source+"|$","g"),function(t,r,u,i,a){return o+=n.slice(e,a).replace(ut,f),r&&(o+="'+_['escape']("+r+")+'"),i&&(o+="';"+i+";__p+='"),u&&(o+="'+((__t=("+u+"))==null?'':__t)+'"),e=a+t.length,t +}),o+="';\n",i||(i="obj",o="with("+i+"||{}){"+o+"}"),o="function("+i+"){var __t,__p='',__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}"+o+"return __p}";try{var a=Function("_","return "+o)(u)}catch(c){throw c.source=o,c}return t?a(t):(a.source=o,a)},u.unescape=function(n){return n==H?"":(n+"").replace(nt,s)},u.uniqueId=function(n){var t=++X+"";return n?n+t:t},u.all=O,u.any=D,u.detect=k,u.foldl=q,u.foldr=B,u.include=E,u.inject=q,u.first=M,u.last=function(n,t,r){if(n){var e=0,u=n.length; +if(typeof t=="function"){var o=u;for(t=a(t,r);o--&&t(n[o],o,n);)e++}else if(e=t,e==H||r)return n[u-1];return p(n,yt(0,u-e))}},u.take=M,u.head=M,u.chain=function(n){return n=new u(n),n.__chain__=G,n},u.VERSION="1.0.0-rc.3",W(u),u.prototype.chain=function(){return this.__chain__=G,this},u.prototype.value=function(){return this.__wrapped__},e("pop push reverse shift sort splice unshift".split(" "),function(n){var t=Q[n];u.prototype[n]=function(){var n=this.__wrapped__;return t.apply(n,arguments),kt&&0===n.length&&delete n[0],this }}),e(["concat","join","slice"],function(n){var t=Q[n];u.prototype[n]=function(){var n=t.apply(this.__wrapped__,arguments);return this.__chain__&&(n=new u(n),n.__chain__=G),n}}),K?typeof module=="object"&&module&&module.exports==K?(module.exports=u)._=u:K._=u:n._=u})(this); \ No newline at end of file diff --git a/test/test-build.js b/test/test-build.js index e0ca6a066..8e316def8 100644 --- a/test/test-build.js +++ b/test/test-build.js @@ -14,7 +14,7 @@ var QUnit = ( global.addEventListener || (global.addEventListener = Function.prototype), global.QUnit = require('../vendor/qunit/qunit/qunit.js'), - load('../vendor/qunit-clib/qunit-clib.js'), + require('../vendor/qunit-clib/qunit-clib.js'), global.addEventListener === Function.prototype && delete global.addEventListener, global.QUnit );