diff --git a/.gitignore b/.gitignore index e27563e184..58a3a4336a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,5 @@ *.custom.* *.log *.map -lodash.compat.js +lodash.compat.min.js node_modules diff --git a/.travis.yml b/.travis.yml index 75b5f9fb60..f294006555 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,37 @@ language: node_js node_js: - - "0.10" + - "0.12" env: global: - - BIN="node" BUILD="compat" ISTANBUL=false NODE_BIN=$BIN OPTION="" - - IOJS_VERSION="v1.0.4" NPM_VERSION="^2.0.0" SAUCE_LABS=false SAUCE_USERNAME="lodash" + - BIN="node" BUILD="compat" ISTANBUL=false OPTION="" + - NPM_VERSION="^2.0.0" SAUCE_LABS=false SAUCE_USERNAME="lodash" - secure: "tg1JFsIFnxzLaTboFPOnm+aJCuMm5+JdhLlESlqg9x3fwro++7KCnwHKLNovhchaPe4otC43ZMB/nfWhDnDm11dKbm/V6HlTkED+dadTsaLxVDg6J+7yK41QhokBPJOxLV78iDaNaAQVYEirAgZ0yn8kFubxmNKV+bpCGQNc9yU=" matrix: - BUILD="compat" - BUILD="modern" - BUILD="modern" - BUILD="modern" ISTANBUL=true - - BIN="iojs" BUILD="compat" NODE_BIN=$BIN - - BIN="iojs" BUILD="modern" NODE_BIN=$BIN - BIN="phantomjs" - BIN="rhino" - BIN="rhino" OPTION="-require" - BIN="ringo" matrix: include: + - node_js: "io.js" + env: + - node_js: "io.js" + env: BUILD="modern" - node_js: "0.8" env: NPM_VERSION="~1.4.0" - node_js: "0.8" env: BUILD="modern" NPM_VERSION="~1.4.0" - node_js: "0.10" - env: SAUCE_LABS=true + env: - node_js: "0.10" + env: BUILD="modern" + - node_js: "0.12" + env: SAUCE_LABS=true + - node_js: "0.12" env: SAUCE_LABS=true BUILD="modern" git: depth: 10 @@ -36,20 +42,18 @@ before_install: - "nvm use $TRAVIS_NODE_VERSION" - "npm config set loglevel error" - "npm i -g npm@\"$NPM_VERSION\"" - - "[ $SAUCE_LABS == false ] || npm i chalk@\"0.5.1\" ecstatic@\"0.5.8\" request@\"^2.0.0\" sauce-tunnel@\"^2.0.0\"" + - "[ $SAUCE_LABS == false ] || npm i chalk@\"0.5.1\" ecstatic@\"0.5.8\" request@\"^2.0.0\" sauce-tunnel@\"2.1.1\"" - "[ $ISTANBUL == false ] || (npm i -g coveralls@\"^2.0.0\" && npm i istanbul@\"0.3.5\")" - - "[ $BIN != 'iojs' ] || (wget https://iojs.org/dist/${IOJS_VERSION}/iojs-${IOJS_VERSION}-linux-x64.tar.xz && sudo tar xJf iojs-${IOJS_VERSION}-linux-x64.tar.xz -C /opt && rm iojs-${IOJS_VERSION}-linux-x64.tar.xz)" - - "[ $BIN != 'iojs' ] || (sudo ln -s /opt/iojs-${IOJS_VERSION}-linux-x64/bin/iojs /usr/local/bin/iojs && sudo chmod +x $_)" - "[ $BIN != 'rhino' ] || (sudo mkdir /opt/rhino-1.7R5 && sudo wget --no-check-certificate -O $_/js.jar https://lodash.com/_travis/rhino-1.7R5.jar)" - "[ $BIN != 'rhino' ] || (echo -e '#!/bin/sh\\njava -jar /opt/rhino-1.7R5/js.jar $@' | sudo tee /usr/local/bin/rhino && sudo chmod +x /usr/local/bin/rhino)" - "[ $BIN != 'ringo' ] || (wget --no-check-certificate https://lodash.com/_travis/ringojs-0.11.zip && sudo unzip ringojs-0.11 -d /opt && rm ringojs-0.11.zip)" - "[ $BIN != 'ringo' ] || (sudo ln -s /opt/ringojs-0.11/bin/ringo /usr/local/bin/ringo && sudo chmod +x $_)" - "sed -i'' 's|\"lodash\"|\"lodash-compat\"|' ./package.json" - "git clone --depth=10 --branch=master git://github.com/lodash/lodash-cli.git ./node_modules/lodash-cli && mkdir $_/node_modules && cd $_ && ln -s ../../../ ./lodash-compat && cd ../ && npm i && cd ../../" - - "$NODE_BIN ./node_modules/lodash-cli/bin/lodash $BUILD -o ./lodash.$BUILD.js" + - "node ./node_modules/lodash-cli/bin/lodash $BUILD -o ./lodash.$BUILD.js" script: - - "[ $ISTANBUL == false ] || (nvm install 0.11.11 && cp ./lodash.$BUILD.js ./lodash.js && $BIN --harmony ./node_modules/istanbul/lib/cli.js cover -x \"**/vendor/**\" --report lcovonly ./test/test.js -- ./lodash.js)" - - "([ $ISTANBUL == true ] && [ $TRAVIS_SECURE_ENV_VARS == true ] && nvm use $TRAVIS_NODE_VERSION && cat ./coverage/lcov.info | coveralls) || true" + - "[ $ISTANBUL == false ] || (cp ./lodash.$BUILD.js ./lodash.js && node ./node_modules/istanbul/lib/cli.js cover -x \"**/vendor/**\" --report lcovonly ./test/test.js -- ./lodash.js)" + - "[ $ISTANBUL == false ] || [ $TRAVIS_SECURE_ENV_VARS == false ] || (cat ./coverage/lcov.info | coveralls)" - "[ $SAUCE_LABS == true ] || [ $ISTANBUL == true ] || cd ./test" - "[ $SAUCE_LABS == true ] || [ $ISTANBUL == true ] || $BIN $OPTION ./test.js ../lodash.$BUILD.js" - "[ $SAUCE_LABS == true ] || [ $ISTANBUL == true ] || $BIN $OPTION ./test.js ../lodash.$BUILD.min.js" diff --git a/README.md b/README.md index 2eeb10eec9..a1d253d942 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash v3.1.0 +# lodash v3.2.0 The [modern build](https://github.com/lodash/lodash/wiki/Build-Differences) of [lodash](https://lodash.com/) with packages for [Bower](http://bower.io/), [Component](http://component.github.io/), & [Volo](http://volojs.org/). @@ -12,8 +12,8 @@ $ lodash modern -o ./lodash.js lodash is also available in a variety of other builds & module formats. * npm packages for [modern](https://www.npmjs.com/package/lodash), [compatibility](https://www.npmjs.com/package/lodash-compat), & [per method](https://www.npmjs.com/browse/keyword/lodash-modularized) builds - * AMD modules for [modern](https://github.com/lodash/lodash/tree/3.1.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.1.0-amd) builds - * ES modules for the [modern](https://github.com/lodash/lodash/tree/3.1.0-es) build + * AMD modules for [modern](https://github.com/lodash/lodash/tree/3.2.0-amd) & [compatibility](https://github.com/lodash/lodash-compat/tree/3.2.0-amd) builds + * ES modules for the [modern](https://github.com/lodash/lodash/tree/3.2.0-es) build ## Further Reading diff --git a/bower.json b/bower.json index d9a3cdacd3..a4a1a263d6 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "lodash", - "version": "3.1.0", + "version": "3.2.0", "main": "lodash.js", "ignore": [ ".*", diff --git a/component.json b/component.json index 63fa714de0..cf7b6479db 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "lodash", "repo": "lodash/lodash", - "version": "3.1.0", + "version": "3.2.0", "description": "The modern build of lodash.", "license": "MIT", "main": "lodash.js", diff --git a/doc/README.md b/doc/README.md index f69e72e0a2..b624f979a1 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1,4 +1,4 @@ -# lodash v3.1.0 +# lodash v3.2.0 @@ -12,6 +12,7 @@ * `_.dropRight` * `_.dropRightWhile` * `_.dropWhile` +* `_.fill` * `_.findIndex` * `_.findLastIndex` * `_.first` @@ -55,7 +56,10 @@ * `_.tap` * `_.thru` * `_.prototype.chain` +* `_.prototype.commit` +* `_.prototype.plant` * `_.prototype.reverse` +* `_.prototype.run` -> `value` * `_.prototype.toJSON` -> `value` * `_.prototype.toString` * `_.prototype.value` @@ -140,6 +144,7 @@ * `_.partial` * `_.partialRight` * `_.rearg` +* `_.spread` * `_.throttle` * `_.wrap` @@ -160,7 +165,7 @@ * `_.isError` * `_.isFinite` * `_.isFunction` -* `_.isMatch` +* `_.isMatch` * `_.isNaN` * `_.isNative` * `_.isNull` @@ -251,6 +256,7 @@ * `_.identity` * `_.iteratee` -> `callback` * `_.matches` +* `_.matchesProperty` * `_.mixin` * `_.noConflict` * `_.noop` @@ -306,7 +312,7 @@ ### `_.chunk(array, [size=1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4103 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4167 "View in source") [Ⓣ][1] Creates an array of elements split into groups the length of `size`. If `collection` can't be split evenly, the final chunk will be the remaining @@ -314,7 +320,7 @@ elements. #### Arguments 1. `array` *(Array)*: The array to process. -2. `[size=1]` *(numer)*: The length of each chunk. +2. `[size=1]` *(number)*: The length of each chunk. #### Returns *(Array)*: Returns the new array containing chunks. @@ -334,7 +340,7 @@ _.chunk(['a', 'b', 'c', 'd'], 3); ### `_.compact(array)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4134 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4198 "View in source") [Ⓣ][1] Creates an array with all falsey values removed. The values `false`, `null`, `0`, `""`, `undefined`, and `NaN` are falsey. @@ -357,7 +363,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.difference(array, [values])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4169 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4233 "View in source") [Ⓣ][1] Creates an array excluding all values of the provided arrays using `SameValueZero` for equality comparisons. @@ -387,7 +393,7 @@ _.difference([1, 2, 3], [5, 2, 10]); ### `_.drop(array, [n=1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4207 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4270 "View in source") [Ⓣ][1] Creates a slice of `array` with `n` elements dropped from the beginning. @@ -419,7 +425,7 @@ _.drop([1, 2, 3], 0); ### `_.dropRight(array, [n=1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4243 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4305 "View in source") [Ⓣ][1] Creates a slice of `array` with `n` elements dropped from the end. @@ -451,24 +457,29 @@ _.dropRight([1, 2, 3], 0); ### `_.dropRightWhile(array, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4295 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4364 "View in source") [Ⓣ][1] Creates a slice of `array` excluding elements dropped from the end. Elements are dropped until `predicate` returns falsey. The predicate is bound to `thisArg` and invoked with three arguments; (value, index, array).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style -callback returns `true` for elements that have the properties of the given +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style +callback returns `true` for elements that match the properties of the given object, else `false`. #### Arguments 1. `array` *(Array)*: The array to query. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per element. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -480,18 +491,22 @@ _.dropRightWhile([1, 2, 3], function(n) { return n > 1; }); // => [1] var users = [ - { 'user': 'barney', 'status': 'busy', 'active': false }, - { 'user': 'fred', 'status': 'busy', 'active': true }, - { 'user': 'pebbles', 'status': 'away', 'active': true } + { 'user': 'barney', 'active': true }, + { 'user': 'fred', 'active': false }, + { 'user': 'pebbles', 'active': false } ]; -// using the "_.property" callback shorthand -_.pluck(_.dropRightWhile(users, 'active'), 'user'); +// using the `_.matches` callback shorthand +_.pluck(_.dropRightWhile(users, { 'user': pebbles, 'active': false }), 'user'); +// => ['barney', 'fred'] + +// using the `_.matchesProperty` callback shorthand +_.pluck(_.dropRightWhile(users, 'active', false), 'user'); // => ['barney'] -// using the "_.matches" callback shorthand -_.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user'); -// => ['barney', 'fred'] +// using the `_.property` callback shorthand +_.pluck(_.dropRightWhile(users, 'active'), 'user'); +// => ['barney', 'fred', 'pebbles'] ``` * * * @@ -500,24 +515,29 @@ _.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user'); ### `_.dropWhile(array, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4345 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4421 "View in source") [Ⓣ][1] Creates a slice of `array` excluding elements dropped from the beginning. Elements are dropped until `predicate` returns falsey. The predicate is bound to `thisArg` and invoked with three arguments; (value, index, array).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `array` *(Array)*: The array to query. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per element. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -529,18 +549,22 @@ _.dropWhile([1, 2, 3], function(n) { return n < 3; }); // => [3] var users = [ - { 'user': 'barney', 'status': 'busy', 'active': true }, - { 'user': 'fred', 'status': 'busy', 'active': false }, - { 'user': 'pebbles', 'status': 'away', 'active': true } + { 'user': 'barney', 'active': false }, + { 'user': 'fred', 'active': false }, + { 'user': 'pebbles', 'active': true } ]; -// using the "_.property" callback shorthand -_.pluck(_.dropWhile(users, 'active'), 'user'); +// using the `_.matches` callback shorthand +_.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user'); // => ['fred', 'pebbles'] -// using the "_.matches" callback shorthand -_.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user'); +// using the `_.matchesProperty` callback shorthand +_.pluck(_.dropWhile(users, 'active', false), 'user'); // => ['pebbles'] + +// using the `_.property` callback shorthand +_.pluck(_.dropWhile(users, 'active'), 'user'); +// => ['barney', 'fred', 'pebbles'] ``` * * * @@ -548,24 +572,53 @@ _.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user'); +### `_.fill(array, value, [start=0], [end=array.length])` +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4447 "View in source") [Ⓣ][1] + +Fills elements of `array` with `value` from `start` up to, but not +including, `end`. +
+
+**Note:** This method mutates `array`. + +#### Arguments +1. `array` *(Array)*: The array to fill. +2. `value` *(*)*: The value to fill `array` with. +3. `[start=0]` *(number)*: The start position. +4. `[end=array.length]` *(number)*: The end position. + +#### Returns +*(Array)*: Returns `array`. + +* * * + + + + + ### `_.findIndex(array, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4395 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4505 "View in source") [Ⓣ][1] This method is like `_.find` except that it returns the index of the first element `predicate` returns truthy for, instead of the element itself.

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `array` *(Array)*: The array to search. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -574,21 +627,25 @@ object, else `false`. #### Example ```js var users = [ - { 'user': 'barney', 'age': 36, 'active': false }, - { 'user': 'fred', 'age': 40, 'active': true }, - { 'user': 'pebbles', 'age': 1, 'active': false } + { 'user': 'barney', 'active': false }, + { 'user': 'fred', 'active': false }, + { 'user': 'pebbles', 'active': true } ]; -_.findIndex(users, function(chr) { return chr.age < 40; }); +_.findIndex(users, function(chr) { return chr.user == 'barney'; }); // => 0 -// using the "_.matches" callback shorthand -_.findIndex(users, { 'age': 1 }); -// => 2 +// using the `_.matches` callback shorthand +_.findIndex(users, { 'user': 'fred', 'active': false }); +// => 1 + +// using the `_.matchesProperty` callback shorthand +_.findIndex(users, 'active', false); +// => 0 -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.findIndex(users, 'active'); -// => 1 +// => 2 ``` * * * @@ -597,23 +654,28 @@ _.findIndex(users, 'active'); ### `_.findLastIndex(array, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4447 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4564 "View in source") [Ⓣ][1] This method is like `_.findIndex` except that it iterates over elements of `collection` from right to left.

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `array` *(Array)*: The array to search. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -622,19 +684,23 @@ object, else `false`. #### Example ```js var users = [ - { 'user': 'barney', 'age': 36, 'active': true }, - { 'user': 'fred', 'age': 40, 'active': false }, - { 'user': 'pebbles', 'age': 1, 'active': false } + { 'user': 'barney', 'active': true }, + { 'user': 'fred', 'active': false }, + { 'user': 'pebbles', 'active': false } ]; -_.findLastIndex(users, function(chr) { return chr.age < 40; }); +_.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; }); // => 2 -// using the "_.matches" callback shorthand -_.findLastIndex(users, { 'age': 40 }); +// using the `_.matches` callback shorthand +_.findLastIndex(users, { user': 'barney', 'active': true }); +// => 0 + +// using the `_.matchesProperty` callback shorthand +_.findLastIndex(users, 'active', false); // => 1 -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.findLastIndex(users, 'active'); // => 0 ``` @@ -645,7 +711,7 @@ _.findLastIndex(users, 'active'); ### `_.first(array)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4475 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4592 "View in source") [Ⓣ][1] Gets the first element of `array`. @@ -670,7 +736,7 @@ _.first([]); ### `_.flatten(array, [isDeep])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4499 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4616 "View in source") [Ⓣ][1] Flattens a nested array. If `isDeep` is `true` the array is recursively flattened, otherwise it is only flattened a single level. @@ -698,7 +764,7 @@ _.flatten([1, [2], [3, [[4]]]], true); ### `_.flattenDeep(array)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4520 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4637 "View in source") [Ⓣ][1] Recursively flattens a nested array. @@ -720,7 +786,7 @@ _.flattenDeep([1, [2], [3, [[4]]]]); ### `_.indexOf(array, value, [fromIndex=0])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4557 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4674 "View in source") [Ⓣ][1] Gets the index at which the first occurrence of `value` is found in `array` using `SameValueZero` for equality comparisons. If `fromIndex` is negative, @@ -761,7 +827,7 @@ _.indexOf([4, 4, 5, 5, 6, 6], 5, true); ### `_.initial(array)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4586 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4703 "View in source") [Ⓣ][1] Gets all but the last element of `array`. @@ -783,7 +849,7 @@ _.initial([1, 2, 3]); ### `_.intersection([arrays])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4609 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4726 "View in source") [Ⓣ][1] Creates an array of unique values in all provided arrays using `SameValueZero` for equality comparisons. @@ -812,7 +878,7 @@ _.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); ### `_.last(array)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4664 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4781 "View in source") [Ⓣ][1] Gets the last element of `array`. @@ -834,7 +900,7 @@ _.last([1, 2, 3]); ### `_.lastIndexOf(array, value, [fromIndex=array.length-1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4694 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4811 "View in source") [Ⓣ][1] This method is like `_.indexOf` except that it iterates over elements of `array` from right to left. @@ -867,7 +933,7 @@ _.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true); ### `_.pull(array, [values])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4741 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4858 "View in source") [Ⓣ][1] Removes all provided values from `array` using `SameValueZero` for equality comparisons. @@ -902,7 +968,7 @@ console.log(array); ### `_.pullAt(array, [indexes])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4786 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4903 "View in source") [Ⓣ][1] Removes elements from `array` corresponding to the given indexes and returns an array of the removed elements. Indexes may be specified as an array of @@ -936,18 +1002,23 @@ console.log(evens); ### `_.remove(array, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4824 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4944 "View in source") [Ⓣ][1] Removes all elements from `array` that `predicate` returns truthy for and returns an array of the removed elements. The predicate is bound to `thisArg` and invoked with three arguments; (value, index, array).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`.
@@ -956,7 +1027,7 @@ object, else `false`. #### Arguments 1. `array` *(Array)*: The array to modify. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -980,7 +1051,7 @@ console.log(evens); ### `_.rest(array)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4855 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4975 "View in source") [Ⓣ][1] Gets all but the first element of `array`. @@ -1002,7 +1073,7 @@ _.rest([1, 2, 3]); ### `_.slice(array, [start=0], [end=array.length])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4873 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L4993 "View in source") [Ⓣ][1] Creates a slice of `array` from `start` up to, but not including, `end`.
@@ -1025,7 +1096,7 @@ lists in IE < 9 and to ensure dense arrays are returned. ### `_.sortedIndex(array, value, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4930 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5053 "View in source") [Ⓣ][1] Uses a binary search to determine the lowest index at which `value` should be inserted into `array` in order to maintain its sort order. If an iteratee @@ -1034,18 +1105,23 @@ to compute their sort ranking. The iteratee is bound to `thisArg` and invoked with one argument; (value).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `array` *(Array)*: The sorted array to inspect. 2. `value` *(*)*: The value to evaluate. -3. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +3. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 4. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -1068,7 +1144,7 @@ _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) { }, dict); // => 1 -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); // => 1 ``` @@ -1079,7 +1155,7 @@ _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); ### `_.sortedLastIndex(array, value, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4958 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5080 "View in source") [Ⓣ][1] This method is like `_.sortedIndex` except that it returns the highest index at which `value` should be inserted into `array` in order to @@ -1088,7 +1164,7 @@ maintain its sort order. #### Arguments 1. `array` *(Array)*: The sorted array to inspect. 2. `value` *(*)*: The value to evaluate. -3. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +3. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 4. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -1107,7 +1183,7 @@ _.sortedLastIndex([4, 4, 5, 5, 6, 6], 5); ### `_.take(array, [n=1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L4990 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5111 "View in source") [Ⓣ][1] Creates a slice of `array` with `n` elements taken from the beginning. @@ -1139,7 +1215,7 @@ _.take([1, 2, 3], 0); ### `_.takeRight(array, [n=1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5026 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5146 "View in source") [Ⓣ][1] Creates a slice of `array` with `n` elements taken from the end. @@ -1171,24 +1247,29 @@ _.takeRight([1, 2, 3], 0); ### `_.takeRightWhile(array, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5078 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5205 "View in source") [Ⓣ][1] Creates a slice of `array` with elements taken from the end. Elements are taken until `predicate` returns falsey. The predicate is bound to `thisArg` and invoked with three arguments; (value, index, array).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `array` *(Array)*: The array to query. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per element. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -1200,18 +1281,22 @@ _.takeRightWhile([1, 2, 3], function(n) { return n > 1; }); // => [2, 3] var users = [ - { 'user': 'barney', 'status': 'busy', 'active': false }, - { 'user': 'fred', 'status': 'busy', 'active': true }, - { 'user': 'pebbles', 'status': 'away', 'active': true } + { 'user': 'barney', 'active': true }, + { 'user': 'fred', 'active': false }, + { 'user': 'pebbles', 'active': false } ]; -// using the "_.property" callback shorthand -_.pluck(_.takeRightWhile(users, 'active'), 'user'); +// using the `_.matches` callback shorthand +_.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user'); +// => ['pebbles'] + +// using the `_.matchesProperty` callback shorthand +_.pluck(_.takeRightWhile(users, 'active', false), 'user'); // => ['fred', 'pebbles'] -// using the "_.matches" callback shorthand -_.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user'); -// => ['pebbles'] +// using the `_.property` callback shorthand +_.pluck(_.takeRightWhile(users, 'active'), 'user'); +// => [] ``` * * * @@ -1220,24 +1305,29 @@ _.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user'); ### `_.takeWhile(array, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5128 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5262 "View in source") [Ⓣ][1] Creates a slice of `array` with elements taken from the beginning. Elements are taken until `predicate` returns falsey. The predicate is bound to `thisArg` and invoked with three arguments; (value, index, array).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `array` *(Array)*: The array to query. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per element. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -1249,18 +1339,22 @@ _.takeWhile([1, 2, 3], function(n) { return n < 3; }); // => [1, 2] var users = [ - { 'user': 'barney', 'status': 'busy', 'active': true }, - { 'user': 'fred', 'status': 'busy', 'active': false }, - { 'user': 'pebbles', 'status': 'away', 'active': true } + { 'user': 'barney', 'active': false }, + { 'user': 'fred', 'active': false}, + { 'user': 'pebbles', 'active': true } ]; -// using the "_.property" callback shorthand -_.pluck(_.takeWhile(users, 'active'), 'user'); +// using the `_.matches` callback shorthand +_.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user'); // => ['barney'] -// using the "_.matches" callback shorthand -_.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user'); +// using the `_.matchesProperty` callback shorthand +_.pluck(_.takeWhile(users, 'active', false), 'user'); // => ['barney', 'fred'] + +// using the `_.property` callback shorthand +_.pluck(_.takeWhile(users, 'active'), 'user'); +// => [] ``` * * * @@ -1269,7 +1363,7 @@ _.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user'); ### `_.union([arrays])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5158 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5292 "View in source") [Ⓣ][1] Creates an array of unique values, in order, of the provided arrays using `SameValueZero` for equality comparisons. @@ -1298,7 +1392,7 @@ _.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); ### `_.uniq(array, [isSorted], [iteratee], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5210 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5346 "View in source") [Ⓣ][1] Creates a duplicate-value-free version of an array using `SameValueZero` for equality comparisons. Providing `true` for `isSorted` performs a faster @@ -1308,11 +1402,16 @@ uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked with three arguments; (value, index, array).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`.
@@ -1325,7 +1424,7 @@ for more details. #### Arguments 1. `array` *(Array)*: The array to inspect. 2. `[isSorted]` *(boolean)*: Specify the array is sorted. -3. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +3. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. 4. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -1344,7 +1443,7 @@ _.uniq([1, 1, 2], true); _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math); // => [1, 2.5] -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); // => [{ 'x': 1 }, { 'x': 2 }] ``` @@ -1355,7 +1454,7 @@ _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); ### `_.unzip(array)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5248 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5384 "View in source") [Ⓣ][1] This method is like `_.zip` except that it accepts an array of grouped elements and creates an array regrouping the elements to their pre-`_.zip` @@ -1382,7 +1481,7 @@ _.unzip(zipped); ### `_.without(array, [values])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5279 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5415 "View in source") [Ⓣ][1] Creates an array excluding all provided values using `SameValueZero` for equality comparisons. @@ -1412,7 +1511,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.xor([arrays])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5301 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5437 "View in source") [Ⓣ][1] Creates an array that is the symmetric difference of the provided arrays. See [Wikipedia](https://en.wikipedia.org/wiki/Symmetric_difference) for @@ -1439,7 +1538,7 @@ _.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]); ### `_.zip([arrays])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5331 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5467 "View in source") [Ⓣ][1] Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements @@ -1463,7 +1562,7 @@ _.zip(['fred', 'barney'], [30, 40], [true, false]); ### `_.zipObject(props, [values=[]])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5358 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5494 "View in source") [Ⓣ][1] Creates an object composed from arrays of property names and values. Provide either a single two dimensional array, e.g. `[[key1, value1], [key2, value2]]` @@ -1494,9 +1593,9 @@ _.zipObject(['fred', 'barney'], [30, 40]); ### `._(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L919 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L920 "View in source") [Ⓣ][1] -Creates a `lodash` object which wraps `value` to enable intuitive chaining. +Creates a `lodash` object which wraps `value` to enable implicit chaining. Methods that operate on and return arrays, collections, and functions can be chained together. Methods that return a boolean or single value will automatically end the chain returning the unwrapped value. Explicit chaining @@ -1519,31 +1618,33 @@ In addition to lodash methods, wrappers also have the following `Array` methods: and `unshift`

-The wrapper functions that support shortcut fusion are:
-`drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`, -`initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`, -`take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where` +The wrapper methods that support shortcut fusion are:
+`compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, +`first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, +`slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`, +and `where`

-The chainable wrapper functions are:
+The chainable wrapper methods are:
`after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`, -`callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`, -`create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, -`drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, -`flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`, -`forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`, -`initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`, -`mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`, -`omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`, -`pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, -`rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, -`sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`, -`takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, -`transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, -`where`, `without`, `wrap`, `xor`, `zip`, and `zipObject` -
-
-The wrapper functions that are **not** chainable by default are:
+`callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`, +`countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, +`difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`, +`filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`, +`forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, +`groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, +`keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, +`mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, +`partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`, +`pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`, +`shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`, +`take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, +`thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`, +`unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`, +`zip`, and `zipObject` +
+
+The wrapper methods that are **not** chainable by default are:
`attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, @@ -1559,14 +1660,14 @@ The wrapper functions that are **not** chainable by default are:
`trunc`, `unescape`, `uniqueId`, `value`, and `words`

-The wrapper function `sample` will return a wrapped value when `n` is provided, +The wrapper method `sample` will return a wrapped value when `n` is provided, otherwise an unwrapped value is returned. #### Arguments 1. `value` *(*)*: The value to wrap in a `lodash` instance. #### Returns -*(Object)*: Returns a `lodash` instance. +*(Object)*: Returns the new `lodash` wrapper instance. #### Example ```js @@ -1592,7 +1693,7 @@ _.isArray(squares.value()); ### `_.chain(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5403 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5539 "View in source") [Ⓣ][1] Creates a `lodash` object that wraps `value` with explicit method chaining enabled. @@ -1601,7 +1702,7 @@ chaining enabled. 1. `value` *(*)*: The value to wrap. #### Returns -*(Object)*: Returns the new `lodash` object. +*(Object)*: Returns the new `lodash` wrapper instance. #### Example ```js @@ -1625,7 +1726,7 @@ var youngest = _.chain(users) ### `_.tap(value, interceptor, [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5430 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5566 "View in source") [Ⓣ][1] This method invokes `interceptor` and returns `value`. The interceptor is bound to `thisArg` and invoked with one argument; (value). The purpose of @@ -1655,7 +1756,7 @@ _([1, 2, 3]) ### `_.thru(value, interceptor, [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5453 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5589 "View in source") [Ⓣ][1] This method is like `_.tap` except that it returns the result of `interceptor`. @@ -1682,12 +1783,12 @@ _([1, 2, 3]) ### `_.prototype.chain()` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5482 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5618 "View in source") [Ⓣ][1] Enables explicit method chaining on the wrapper object. #### Returns -*(*)*: Returns the `lodash` object. +*(Object)*: Returns the new `lodash` wrapper instance. #### Example ```js @@ -1713,8 +1814,70 @@ _(users).chain() +### `_.prototype.commit()` +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5647 "View in source") [Ⓣ][1] + +Executes the chained sequence and returns the wrapped result. + +#### Returns +*(Object)*: Returns the new `lodash` wrapper instance. + +#### Example +```js +var array = [1, 2]; +var wrapper = _(array).push(3); + +console.log(array); +// => [1, 2] + +wrapper = wrapper.commit(); +console.log(array); +// => [1, 2, 3] + +wrapper.last(); +// => 3 + +console.log(array); +// => [1, 2, 3] +``` +* * * + + + + + +### `_.prototype.plant()` +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5674 "View in source") [Ⓣ][1] + +Creates a clone of the chained sequence planting `value` as the wrapped value. + +#### Returns +*(Object)*: Returns the new `lodash` wrapper instance. + +#### Example +```js +var array = [1, 2]; +var wrapper = _(array).map(function(value) { + return Math.pow(value, 2); +}); + +var other = [3, 4]; +var otherWrapper = wrapper.plant(other); + +otherWrapper.value(); +// => [9, 16] + +wrapper.value(); +// => [1, 4] +``` +* * * + + + + + ### `_.prototype.reverse()` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5506 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5712 "View in source") [Ⓣ][1] Reverses the wrapped array so the first element becomes the last, the second element becomes the second to last, and so on. @@ -1723,7 +1886,7 @@ second element becomes the second to last, and so on. **Note:** This method mutates the wrapped array. #### Returns -*(Object)*: Returns the new reversed `lodash` object. +*(Object)*: Returns the new reversed `lodash` wrapper instance. #### Example ```js @@ -1742,7 +1905,7 @@ console.log(array); ### `_.prototype.toString()` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5531 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5737 "View in source") [Ⓣ][1] Produces the result of coercing the unwrapped value to a string. @@ -1761,7 +1924,7 @@ _([1, 2, 3]).toString(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5548 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5754 "View in source") [Ⓣ][1] Executes the chained sequence to extract the unwrapped value. @@ -1786,7 +1949,7 @@ _([1, 2, 3]).value(); ### `_.at(collection, [props])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5574 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5780 "View in source") [Ⓣ][1] Creates an array of elements corresponding to the given keys, or indexes, of `collection`. Keys may be specified as individual arguments or as arrays @@ -1814,7 +1977,7 @@ _.at(['fred', 'barney', 'pebbles'], 0, 2); ### `_.countBy(collection, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5667 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5876 "View in source") [Ⓣ][1] Creates an object composed of keys generated from the results of running each element of `collection` through `iteratee`. The corresponding value @@ -1823,17 +1986,22 @@ The `iteratee` is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -1857,24 +2025,29 @@ _.countBy(['one', 'two', 'three'], 'length'); ### `_.every(collection, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5712 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5928 "View in source") [Ⓣ][1] Checks if `predicate` returns truthy for **all** elements of `collection`. The predicate is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -1883,20 +2056,24 @@ else `false`. #### Example ```js -_.every([true, 1, null, 'yes']); +_.every([true, 1, null, 'yes'], Boolean); // => false var users = [ - { 'user': 'barney', 'age': 36 }, - { 'user': 'fred', 'age': 40 } + { 'user': 'barney', 'active': false }, + { 'user': 'fred', 'active': false } ]; -// using the "_.property" callback shorthand -_.every(users, 'age'); +// using the `_.matches` callback shorthand +_.every(users, { 'user': 'barney', 'active': false }); +// => false + +// using the `_.matchesProperty` callback shorthand +_.every(users, 'active', false); // => true -// using the "_.matches" callback shorthand -_.every(users, { 'age': 36 }); +// using the `_.property` callback shorthand +_.every(users, 'active'); // => false ``` * * * @@ -1906,24 +2083,29 @@ _.every(users, { 'age': 36 }); ### `_.filter(collection, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5760 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5983 "View in source") [Ⓣ][1] Iterates over elements of `collection`, returning an array of all elements `predicate` returns truthy for. The predicate is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -1935,16 +2117,20 @@ var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; }); // => [2, 4] var users = [ - { 'user': 'barney', 'age': 36, 'active': false }, - { 'user': 'fred', 'age': 40, 'active': true } + { 'user': 'barney', 'age': 36, 'active': true }, + { 'user': 'fred', 'age': 40, 'active': false } ]; -// using the "_.property" callback shorthand -_.pluck(_.filter(users, 'active'), 'user'); +// using the `_.matches` callback shorthand +_.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user'); +// => ['barney'] + +// using the `_.matchesProperty` callback shorthand +_.pluck(_.filter(users, 'active', false), 'user'); // => ['fred'] -// using the "_.matches" callback shorthand -_.pluck(_.filter(users, { 'age': 36 }), 'user'); +// using the `_.property` callback shorthand +_.pluck(_.filter(users, 'active'), 'user'); // => ['barney'] ``` * * * @@ -1954,24 +2140,29 @@ _.pluck(_.filter(users, { 'age': 36 }), 'user'); ### `_.find(collection, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5807 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6037 "View in source") [Ⓣ][1] Iterates over elements of `collection`, returning the first element `predicate` returns truthy for. The predicate is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to search. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -1980,21 +2171,25 @@ object, else `false`. #### Example ```js var users = [ - { 'user': 'barney', 'age': 36, 'active': false }, - { 'user': 'fred', 'age': 40, 'active': true }, - { 'user': 'pebbles', 'age': 1, 'active': false } + { 'user': 'barney', 'age': 36, 'active': true }, + { 'user': 'fred', 'age': 40, 'active': false }, + { 'user': 'pebbles', 'age': 1, 'active': true } ]; _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user'); // => 'barney' -// using the "_.matches" callback shorthand -_.result(_.find(users, { 'age': 1 }), 'user'); +// using the `_.matches` callback shorthand +_.result(_.find(users, { 'age': 1, 'active': true }), 'user'); // => 'pebbles' -// using the "_.property" callback shorthand -_.result(_.find(users, 'active'), 'user'); +// using the `_.matchesProperty` callback shorthand +_.result(_.find(users, 'active', false), 'user'); // => 'fred' + +// using the `_.property` callback shorthand +_.result(_.find(users, 'active'), 'user'); +// => 'barney' ``` * * * @@ -2003,14 +2198,14 @@ _.result(_.find(users, 'active'), 'user'); ### `_.findLast(collection, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5834 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6063 "View in source") [Ⓣ][1] This method is like `_.find` except that it iterates over elements of `collection` from right to left. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to search. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -2028,11 +2223,17 @@ _.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; }); ### `_.findWhere(collection, source)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5863 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6097 "View in source") [Ⓣ][1] Performs a deep comparison between each element in `collection` and the source object, returning the first element that has equivalent property values. +
+
+**Note:** This method supports comparing arrays, booleans, `Date` objects, +numbers, `Object` objects, regexes, and strings. Objects are compared by +their own, not inherited, enumerable properties. For comparing a single +own or inherited property value see `_.matchesProperty`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to search. @@ -2044,14 +2245,14 @@ values. #### Example ```js var users = [ - { 'user': 'barney', 'age': 36, 'status': 'busy' }, - { 'user': 'fred', 'age': 40, 'status': 'busy' } + { 'user': 'barney', 'age': 36, 'active': true }, + { 'user': 'fred', 'age': 40, 'active': false } ]; -_.result(_.findWhere(users, { 'status': 'busy' }), 'user'); +_.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user'); // => 'barney' -_.result(_.findWhere(users, { 'age': 40 }), 'user'); +_.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user'); // => 'fred' ``` * * * @@ -2061,7 +2262,7 @@ _.result(_.findWhere(users, { 'age': 40 }), 'user'); ### `_.forEach(collection, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5893 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6127 "View in source") [Ⓣ][1] Iterates over elements of `collection` invoking `iteratee` for each element. The `iteratee` is bound to `thisArg` and invoked with three arguments; @@ -2096,7 +2297,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, ### `_.forEachRight(collection, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5916 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6150 "View in source") [Ⓣ][1] This method is like `_.forEach` except that it iterates over elements of `collection` from right to left. @@ -2121,7 +2322,7 @@ _([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(','); ### `_.groupBy(collection, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5957 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6194 "View in source") [Ⓣ][1] Creates an object composed of keys generated from the results of running each element of `collection` through `iteratee`. The corresponding value @@ -2130,17 +2331,22 @@ The `iteratee` is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -2154,7 +2360,7 @@ _.groupBy([4.2, 6.1, 6.4], function(n) { return Math.floor(n); }); _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math); // => { '4': [4.2], '6': [6.1, 6.4] } -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.groupBy(['one', 'two', 'three'], 'length'); // => { '3': ['one', 'two'], '5': ['three'] } ``` @@ -2165,7 +2371,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.includes(collection, target, [fromIndex=0])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L5614 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L5820 "View in source") [Ⓣ][1] Checks if `value` is in `collection` using `SameValueZero` for equality comparisons. If `fromIndex` is negative, it is used as the offset from @@ -2206,7 +2412,7 @@ _.includes('pebbles', 'eb'); ### `_.indexBy(collection, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6004 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6244 "View in source") [Ⓣ][1] Creates an object composed of keys generated from the results of running each element of `collection` through `iteratee`. The corresponding value @@ -2215,17 +2421,22 @@ iteratee function is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -2254,7 +2465,7 @@ _.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, ### `_.invoke(collection, methodName, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6030 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6270 "View in source") [Ⓣ][1] Invokes the method named by `methodName` on each element in `collection`, returning an array of the results of each invoked method. Any additional @@ -2284,24 +2495,40 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.map(collection, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6073 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6326 "View in source") [Ⓣ][1] Creates an array of values by running each element in `collection` through `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. +
+
+Many lodash methods are guarded to work as interatees for methods like +`_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. +
+
+The guarded methods are:
+`ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`, +`dropRight`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, `slice`, +`sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`, +`trunc`, `random`, `range`, `sample`, `uniq`, and `words` #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. create a `_.property` or `_.matches` style callback respectively. 3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -2320,7 +2547,7 @@ var users = [ { 'user': 'fred' } ]; -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.map(users, 'user'); // => ['barney', 'fred'] ``` @@ -2331,7 +2558,7 @@ _.map(users, 'user'); ### `_.max(collection, [iteratee], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6122 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6377 "View in source") [Ⓣ][1] Gets the maximum value of `collection`. If `collection` is empty or falsey `-Infinity` is returned. If an iteratee function is provided it is invoked @@ -2340,17 +2567,22 @@ is ranked. The `iteratee` is bound to `thisArg` and invoked with three arguments; (value, index, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -2372,7 +2604,7 @@ var users = [ _.max(users, function(chr) { return chr.age; }); // => { 'user': 'fred', 'age': 40 }; -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.max(users, 'age'); // => { 'user': 'fred', 'age': 40 }; ``` @@ -2383,7 +2615,7 @@ _.max(users, 'age'); ### `_.min(collection, [iteratee], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6167 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6424 "View in source") [Ⓣ][1] Gets the minimum value of `collection`. If `collection` is empty or falsey `Infinity` is returned. If an iteratee function is provided it is invoked @@ -2392,17 +2624,22 @@ is ranked. The `iteratee` is bound to `thisArg` and invoked with three arguments; (value, index, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -2424,7 +2661,7 @@ var users = [ _.min(users, function(chr) { return chr.age; }); // => { 'user': 'barney', 'age': 36 }; -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.min(users, 'age'); // => { 'user': 'barney', 'age': 36 }; ``` @@ -2435,7 +2672,7 @@ _.min(users, 'age'); ### `_.partition(collection, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6213 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6479 "View in source") [Ⓣ][1] Creates an array of elements split into two groups, the first of which contains elements `predicate` returns truthy for, while the second of which @@ -2443,17 +2680,22 @@ contains elements `predicate` returns falsey for. The predicate is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -2473,12 +2715,18 @@ var users = [ { 'user': 'pebbles', 'age': 1, 'active': false } ]; -// using the "_.matches" callback shorthand -_.map(_.partition(users, { 'age': 1 }), function(array) { return _.pluck(array, 'user'); }); +var mapper = function(array) { return _.pluck(array, 'user'); }; + +// using the `_.matches` callback shorthand +_.map(_.partition(users, { 'age': 1, 'active': false }), mapper); // => [['pebbles'], ['barney', 'fred']] -// using the "_.property" callback shorthand -_.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'user'); }); +// using the `_.matchesProperty` callback shorthand +_.map(_.partition(users, 'active', false), mapper); +// => [['barney', 'pebbles'], ['fred']] + +// using the `_.property` callback shorthand +_.map(_.partition(users, 'active'), mapper); // => [['fred'], ['barney', 'pebbles']] ``` * * * @@ -2488,7 +2736,7 @@ _.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'use ### `_.pluck(collection, key)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6240 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6506 "View in source") [Ⓣ][1] Gets the value of `key` from all elements in `collection`. @@ -2520,7 +2768,7 @@ _.pluck(userIndex, 'age'); ### `_.reduce(collection, [iteratee=_.identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6272 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6544 "View in source") [Ⓣ][1] Reduces `collection` to a value which is the accumulated result of running each element in `collection` through `iteratee`, where each successive @@ -2528,6 +2776,14 @@ invocation is supplied the return value of the previous. If `accumulator` is not provided the first element of `collection` is used as the initial value. The `iteratee` is bound to `thisArg`and invoked with four arguments; (accumulator, value, index|key, collection). +
+
+Many lodash methods are guarded to work as interatees for methods like +`_.reduce`, `_.reduceRight`, and `_.transform`. +
+
+The guarded methods are:
+`assign`, `defaults`, `merge`, and `sortAllBy` #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. @@ -2556,7 +2812,7 @@ var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) { ### `_.reduceRight(collection, [iteratee=_.identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6296 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6568 "View in source") [Ⓣ][1] This method is like `_.reduce` except that it iterates over elements of `collection` from right to left. @@ -2583,23 +2839,28 @@ _.reduceRight(array, function(flattened, other) { return flattened.concat(other) ### `_.reject(collection, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6339 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6618 "View in source") [Ⓣ][1] The opposite of `_.filter`; this method returns the elements of `collection` that `predicate` does **not** return truthy for.

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -2615,13 +2876,17 @@ var users = [ { 'user': 'fred', 'age': 40, 'active': true } ]; -// using the "_.property" callback shorthand -_.pluck(_.reject(users, 'active'), 'user'); +// using the `_.matches` callback shorthand +_.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user'); // => ['barney'] -// using the "_.matches" callback shorthand -_.pluck(_.reject(users, { 'age': 36 }), 'user'); +// using the `_.matchesProperty` callback shorthand +_.pluck(_.reject(users, 'active', false), 'user'); // => ['fred'] + +// using the `_.property` callback shorthand +_.pluck(_.reject(users, 'active'), 'user'); +// => ['barney'] ``` * * * @@ -2630,7 +2895,7 @@ _.pluck(_.reject(users, { 'age': 36 }), 'user'); ### `_.sample(collection, [n])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6365 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6644 "View in source") [Ⓣ][1] Gets a random element or `n` random elements from a collection. @@ -2656,7 +2921,7 @@ _.sample([1, 2, 3, 4], 2); ### `_.shuffle(collection)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6391 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6670 "View in source") [Ⓣ][1] Creates an array of shuffled values, using a version of the Fisher-Yates shuffle. See [Wikipedia](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle) @@ -2680,7 +2945,7 @@ _.shuffle([1, 2, 3, 4]); ### `_.size(collection)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6428 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6707 "View in source") [Ⓣ][1] Gets the size of `collection` by returning `collection.length` for array-like values or the number of own enumerable properties for objects. @@ -2709,7 +2974,7 @@ _.size('pebbles'); ### `_.some(collection, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6475 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6761 "View in source") [Ⓣ][1] Checks if `predicate` returns truthy for **any** element of `collection`. The function returns as soon as it finds a passing value and does not iterate @@ -2717,17 +2982,22 @@ over the entire collection. The predicate is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -2740,17 +3010,21 @@ _.some([null, 0, 'yes', false], Boolean); // => true var users = [ - { 'user': 'barney', 'age': 36, 'active': false }, - { 'user': 'fred', 'age': 40, 'active': true } + { 'user': 'barney', 'active': true }, + { 'user': 'fred', 'active': false } ]; -// using the "_.property" callback shorthand -_.some(users, 'active'); +// using the `_.matches` callback shorthand +_.some(users, { user': 'barney', 'active': false }); +// => false + +// using the `_.matchesProperty` callback shorthand +_.some(users, 'active', false); // => true -// using the "_.matches" callback shorthand -_.some(users, { 'age': 1 }); -// => false +// using the `_.property` callback shorthand +_.some(users, 'active'); +// => true ``` * * * @@ -2759,7 +3033,7 @@ _.some(users, { 'age': 1 }); ### `_.sortBy(collection, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6524 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6814 "View in source") [Ⓣ][1] Creates an array of elements, sorted in ascending order by the results of running each element in a collection through `iteratee`. This method performs @@ -2768,17 +3042,22 @@ The `iteratee` is bound to `thisArg` and invoked with three arguments; (value, index|key, collection).

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to iterate over. -2. `[iteratee=_.identity]` *(Array|Function|Object|string)*: The function invoked per iteration. If a property name or an object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[iteratee=_.identity]` *(Array|Function|Object|string)*: The function invoked per iteration. If a property name or an object is provided it is used to create a `_.property` or `_.matches` style callback respectively. 3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -2798,7 +3077,7 @@ var users = [ { 'user': 'barney' } ]; -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.pluck(_.sortBy(users, 'user'), 'user'); // => ['barney', 'fred', 'pebbles'] ``` @@ -2809,7 +3088,7 @@ _.pluck(_.sortBy(users, 'user'), 'user'); ### `_.sortByAll(collection, props)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6562 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6852 "View in source") [Ⓣ][1] This method is like `_.sortBy` except that it sorts by property names instead of an iteratee function. @@ -2840,11 +3119,17 @@ _.map(_.sortByAll(users, ['user', 'age']), _.values); ### `_.where(collection, source)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6611 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6903 "View in source") [Ⓣ][1] Performs a deep comparison between each element in `collection` and the source object, returning an array of all elements that have equivalent property values. +
+
+**Note:** This method supports comparing arrays, booleans, `Date` objects, +numbers, `Object` objects, regexes, and strings. Objects are compared by +their own, not inherited, enumerable properties. For comparing a single +own or inherited property value see `_.matchesProperty`. #### Arguments 1. `collection` *(Array|Object|string)*: The collection to search. @@ -2856,18 +3141,15 @@ property values. #### Example ```js var users = [ - { 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] }, - { 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] } + { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] }, + { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] } ]; -_.pluck(_.where(users, { 'age': 36 }), 'user'); +_.pluck(_.where(users, { 'age': 36, 'active': false }), 'user'); // => ['barney'] _.pluck(_.where(users, { 'pets': ['dino'] }), 'user'); // => ['fred'] - -_.pluck(_.where(users, { 'status': 'busy' }), 'user'); -// => ['barney', 'fred'] ``` * * * @@ -2882,7 +3164,7 @@ _.pluck(_.where(users, { 'status': 'busy' }), 'user'); ### `_.now` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6629 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6921 "View in source") [Ⓣ][1] Gets the number of milliseconds that have elapsed since the Unix epoch (1 January 1970 00:00:00 UTC). @@ -2905,7 +3187,7 @@ _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); ### `_.after(n, func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6658 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6950 "View in source") [Ⓣ][1] The opposite of `_.before`; this method creates a function that invokes `func` once it is called `n` or more times. @@ -2937,7 +3219,7 @@ _.forEach(saves, function(type) { ### `_.ary(func, [n=func.length])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6692 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L6984 "View in source") [Ⓣ][1] Creates a function that accepts up to `n` arguments ignoring any additional arguments. @@ -2961,7 +3243,7 @@ _.map(['6', '8', '10'], _.ary(parseInt, 1)); ### `_.before(n, func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6716 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7008 "View in source") [Ⓣ][1] Creates a function that invokes `func`, with the `this` binding and arguments of the created function, while it is called less than `n` times. Subsequent @@ -2986,7 +3268,7 @@ jQuery('#add').on('click', _.before(5, addContactToList)); ### `_.bind(func, thisArg, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6772 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7064 "View in source") [Ⓣ][1] Creates a function that invokes `func` with the `this` binding of `thisArg` and prepends any additional `_.bind` arguments to those provided to the @@ -3032,7 +3314,7 @@ bound('hi'); ### `_.bindAll(object, [methodNames])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6809 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7101 "View in source") [Ⓣ][1] Binds methods of an object to the object itself, overwriting the existing method. Method names may be specified as individual arguments or as arrays @@ -3067,7 +3349,7 @@ jQuery('#docs').on('click', view.onClick); ### `_.bindKey(object, key, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6861 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7153 "View in source") [Ⓣ][1] Creates a function that invokes the method at `object[key]` and prepends any additional `_.bindKey` arguments to those provided to the bound function. @@ -3122,7 +3404,7 @@ bound('hi'); ### `_.curry(func, [arity=func.length])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6912 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7204 "View in source") [Ⓣ][1] Creates a function that accepts one or more arguments of `func` that when called either invokes `func` returning its result, if all `func` arguments @@ -3172,7 +3454,7 @@ curried(1)(_, 3)(2); ### `_.curryRight(func, [arity=func.length])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L6958 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7250 "View in source") [Ⓣ][1] This method is like `_.curry` except that arguments are applied to `func` in the manner of `_.partialRight` instead of `_.partial`. @@ -3219,7 +3501,7 @@ curried(3)(1, _)(2); ### `_.debounce(func, wait, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7029 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7321 "View in source") [Ⓣ][1] Creates a function that delays invoking `func` until after `wait` milliseconds have elapsed since the last time it was invoked. The created function comes @@ -3289,7 +3571,7 @@ delete models.todo; ### `_.defer(func, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7158 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7450 "View in source") [Ⓣ][1] Defers invoking the `func` until the current call stack has cleared. Any additional arguments are provided to `func` when it is invoked. @@ -3313,7 +3595,7 @@ _.defer(function(text) { console.log(text); }, 'deferred'); ### `_.delay(func, wait, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7178 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7470 "View in source") [Ⓣ][1] Invokes `func` after `wait` milliseconds. Any additional arguments are provided to `func` when it is invoked. @@ -3338,7 +3620,7 @@ _.delay(function(text) { console.log(text); }, 1000, 'later'); ### `_.flow([funcs])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7206 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7498 "View in source") [Ⓣ][1] Creates a function that returns the result of invoking the provided functions with the `this` binding of the created function, where each @@ -3371,7 +3653,7 @@ addSquare(1, 2); ### `_.flowRight([funcs])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7251 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7543 "View in source") [Ⓣ][1] This method is like `_.flow` except that it creates a function that invokes the provided functions from right to left. @@ -3403,7 +3685,7 @@ addSquare(1, 2); ### `_.memoize(func, [resolver])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7325 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7617 "View in source") [Ⓣ][1] Creates a function that memoizes the result of `func`. If `resolver` is provided it determines the cache key for storing the result based on the @@ -3466,7 +3748,7 @@ identity(other); ### `_.negate(predicate)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7363 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7655 "View in source") [Ⓣ][1] Creates a function that negates the result of the predicate `func`. The `func` predicate is invoked with the `this` binding and arguments of the @@ -3494,7 +3776,7 @@ _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); ### `_.once(func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7390 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7681 "View in source") [Ⓣ][1] Creates a function that is restricted to invoking `func` once. Repeat calls to the function return the value of the first call. The `func` is invoked @@ -3520,7 +3802,7 @@ initialize(); ### `_.partial(func, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7426 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7717 "View in source") [Ⓣ][1] Creates a function that invokes `func` with `partial` arguments prepended to those provided to the new function. This method is like `_.bind` except @@ -3563,7 +3845,7 @@ greetFred('hi'); ### `_.partialRight(func, [args])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7464 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7755 "View in source") [Ⓣ][1] This method is like `_.partial` except that partially applied arguments are appended to those provided to the new function. @@ -3605,7 +3887,7 @@ sayHelloTo('fred'); ### `_.rearg(func, indexes)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7497 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7788 "View in source") [Ⓣ][1] Creates a function that invokes `func` with arguments arranged according to the specified indexes where the argument value at the first index is @@ -3638,8 +3920,47 @@ map(function(n) { return n * 3; }, [1, 2, 3]); +### `_.spread(func)` +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7823 "View in source") [Ⓣ][1] + +Creates a function that invokes `func` with the `this` binding of the +created function and the array of arguments provided to the created +function much like [Function#apply](http://es5.github.io/#x15.3.4.3). + +#### Arguments +1. `func` *(Function)*: The function to spread arguments over. + +#### Returns +*(*)*: Returns the new function. + +#### Example +```js +var spread = _.spread(function(who, what) { + return who + ' says ' + what; +}); + +spread(['Fred', 'hello']); +// => 'Fred says hello' + +// with a Promise +var numbers = Promise.all([ + Promise.resolve(40), + Promise.resolve(36) +]); + +numbers.then(_.spread(function(x, y) { + return x + y; +})); +// => a Promise of 76 +``` +* * * + + + + + ### `_.throttle(func, wait, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7540 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7870 "View in source") [Ⓣ][1] Creates a function that only invokes `func` at most once per every `wait` milliseconds. The created function comes with a `cancel` method to cancel @@ -3686,7 +4007,7 @@ jQuery(window).on('popstate', throttled.cancel); ### `_.wrap(value, wrapper)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7580 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7910 "View in source") [Ⓣ][1] Creates a function that provides `value` to the wrapper function as its first argument. Any additional arguments provided to the function are @@ -3722,7 +4043,7 @@ p('fred, barney, & pebbles'); ### `_.clone(value, [isDeep], [customizer], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7636 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L7966 "View in source") [Ⓣ][1] Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned, otherwise they are assigned by reference. If `customizer` is provided it is @@ -3781,7 +4102,7 @@ body.childNodes.length; ### `_.cloneDeep(value, [customizer], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7690 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8020 "View in source") [Ⓣ][1] Creates a deep clone of `value`. If `customizer` is provided it is invoked to produce the cloned values. If `customizer` returns `undefined` cloning @@ -3834,7 +4155,7 @@ body.childNodes.length; ### `_.isArguments(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7711 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8041 "View in source") [Ⓣ][1] Checks if `value` is classified as an `arguments` object. @@ -3859,7 +4180,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7740 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8070 "View in source") [Ⓣ][1] Checks if `value` is classified as an `Array` object. @@ -3884,7 +4205,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7760 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8090 "View in source") [Ⓣ][1] Checks if `value` is classified as a boolean primitive or object. @@ -3909,7 +4230,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7780 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8110 "View in source") [Ⓣ][1] Checks if `value` is classified as a `Date` object. @@ -3934,7 +4255,7 @@ _.isDate('Mon April 23 2012'); ### `_.isElement(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7800 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8130 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -3959,7 +4280,7 @@ _.isElement(''); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7838 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8168 "View in source") [Ⓣ][1] Checks if a value is empty. A value is considered empty unless it is an `arguments` object, array, string, or jQuery-like collection with a length @@ -3995,7 +4316,7 @@ _.isEmpty({ 'a': 1 }); ### `_.isEqual(value, other, [customizer], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7890 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8221 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent. If `customizer` is provided it is invoked to compare values. @@ -4005,7 +4326,8 @@ arguments; (value, other [, index|key]).

**Note:** This method supports comparing arrays, booleans, `Date` objects, -numbers, `Object` objects, regexes, and strings. Functions and DOM nodes +numbers, `Object` objects, regexes, and strings. Objects are compared by +their own, not inherited, enumerable properties. Functions and DOM nodes are **not** supported. Provide a customizer function to extend support for comparing other values. @@ -4045,7 +4367,7 @@ _.isEqual(array, other, function(value, other) { ### `_.isError(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7916 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8247 "View in source") [Ⓣ][1] Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, `SyntaxError`, `TypeError`, or `URIError` object. @@ -4071,7 +4393,7 @@ _.isError(Error); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7949 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8280 "View in source") [Ⓣ][1] Checks if `value` is a finite primitive number.
@@ -4110,7 +4432,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L7969 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8300 "View in source") [Ⓣ][1] Checks if `value` is classified as a `Function` object. @@ -4134,8 +4456,8 @@ _.isFunction(/abc/); -### `_.isMatch(source, source, [customizer], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8052 "View in source") [Ⓣ][1] +### `_.isMatch(object, source, [customizer], [thisArg])` +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8383 "View in source") [Ⓣ][1] Performs a deep comparison between `object` and `source` to determine if `object` contains equivalent property values. If `customizer` is provided @@ -4150,7 +4472,7 @@ and DOM nodes are **not** supported. Provide a customizer function to extend support for comparing other values. #### Arguments -1. `source` *(Object)*: The object to inspect. +1. `object` *(Object)*: The object to inspect. 2. `source` *(Object)*: The object of property values to match. 3. `[customizer]` *(Function)*: The function to customize comparing values. 4. `[thisArg]` *(*)*: The `this` binding of `customizer`. @@ -4184,7 +4506,7 @@ _.isMatch(object, source, function(value, other) { ### `_.isNaN(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8101 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8432 "View in source") [Ⓣ][1] Checks if `value` is `NaN`.
@@ -4220,7 +4542,7 @@ _.isNaN(undefined); ### `_.isNative(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8123 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8454 "View in source") [Ⓣ][1] Checks if `value` is a native function. @@ -4245,7 +4567,7 @@ _.isNative(_); ### `_.isNull(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8150 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8481 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -4270,7 +4592,7 @@ _.isNull(void 0); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8176 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8507 "View in source") [Ⓣ][1] Checks if `value` is classified as a `Number` primitive or object.
@@ -4302,7 +4624,7 @@ _.isNumber('8.4'); ### `_.isObject(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8006 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8337 "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('')`) @@ -4334,7 +4656,7 @@ _.isObject(1); ### `_.isPlainObject(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8210 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8541 "View in source") [Ⓣ][1] Checks if `value` is a plain object, that is, an object created by the `Object` constructor or one with a `[[Prototype]]` of `null`. @@ -4374,7 +4696,7 @@ _.isPlainObject(Object.create(null)); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8238 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8569 "View in source") [Ⓣ][1] Checks if `value` is classified as a `RegExp` object. @@ -4399,7 +4721,7 @@ _.isRegExp('/abc/'); ### `_.isString(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8258 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8589 "View in source") [Ⓣ][1] Checks if `value` is classified as a `String` primitive or object. @@ -4424,7 +4746,7 @@ _.isString(1); ### `_.isTypedArray(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8278 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8609 "View in source") [Ⓣ][1] Checks if `value` is classified as a typed array. @@ -4449,7 +4771,7 @@ _.isTypedArray([]); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8298 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8629 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -4474,7 +4796,7 @@ _.isUndefined(null); ### `_.toArray(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8315 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8646 "View in source") [Ⓣ][1] Converts `value` to an array. @@ -4496,7 +4818,7 @@ Converts `value` to an array. ### `_.toPlainObject(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8351 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8682 "View in source") [Ⓣ][1] Converts `value` to a plain object flattening inherited enumerable properties of `value` to own properties of the plain object. @@ -4534,7 +4856,7 @@ _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); ### `_.random([min=0], [max=1], [floating])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9238 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9586 "View in source") [Ⓣ][1] Produces a random number between `min` and `max` (inclusive). If only one argument is provided a number between `0` and the given number is returned. @@ -4576,7 +4898,7 @@ _.random(1.2, 5.2); ### `_.assign(object, [sources], [customizer], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8386 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8717 "View in source") [Ⓣ][1] Assigns own enumerable properties of source object(s) to the destination object. Subsequent sources overwrite property assignments of previous sources. @@ -4613,7 +4935,7 @@ defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); ### `_.create(prototype, [properties])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8420 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8751 "View in source") [Ⓣ][1] Creates an object that inherits from the given `prototype` object. If a `properties` object is provided its own enumerable properties are assigned @@ -4653,7 +4975,7 @@ circle instanceof Shape; ### `_.defaults(object, [sources])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8444 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8775 "View in source") [Ⓣ][1] Assigns own enumerable properties of source object(s) to the destination object for all destination properties that resolve to `undefined`. Once a @@ -4678,23 +5000,28 @@ _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); ### `_.findKey(object, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8492 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8830 "View in source") [Ⓣ][1] This method is like `_.findIndex` except that it returns the key of the first element `predicate` returns truthy for, instead of the element itself.

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `object` *(Object)*: The object to search. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -4711,11 +5038,15 @@ var users = { _.findKey(users, function(chr) { return chr.age < 40; }); // => 'barney' (iteration order is not guaranteed) -// using the "_.matches" callback shorthand -_.findKey(users, { 'age': 1 }); +// using the `_.matches` callback shorthand +_.findKey(users, { 'age': 1, 'active': true }); // => 'pebbles' -// using the "_.property" callback shorthand +// using the `_.matchesProperty` callback shorthand +_.findKey(users, 'active', false); +// => 'fred' + +// using the `_.property` callback shorthand _.findKey(users, 'active'); // => 'barney' ``` @@ -4726,23 +5057,28 @@ _.findKey(users, 'active'); ### `_.findLastKey(object, [predicate=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8536 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8881 "View in source") [Ⓣ][1] This method is like `_.findKey` except that it iterates over elements of a collection in the opposite order.

-If a property name is provided for `predicate` the created "_.property" +If a property name is provided for `predicate` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `predicate` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `predicate` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `object` *(Object)*: The object to search. -2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `predicate`. #### Returns @@ -4759,11 +5095,15 @@ var users = { _.findLastKey(users, function(chr) { return chr.age < 40; }); // => returns `pebbles` assuming `_.findKey` returns `barney` -// using the "_.matches" callback shorthand -_.findLastKey(users, { 'age': 36 }); +// using the `_.matches` callback shorthand +_.findLastKey(users, { 'age': 36, 'active': true }); // => 'barney' -// using the "_.property" callback shorthand +// using the `_.matchesProperty` callback shorthand +_.findLastKey(users, 'active', false); +// => 'fred' + +// using the `_.property` callback shorthand _.findLastKey(users, 'active'); // => 'pebbles' ``` @@ -4774,7 +5114,7 @@ _.findLastKey(users, 'active'); ### `_.forIn(object, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8568 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8913 "View in source") [Ⓣ][1] Iterates over own and inherited enumerable properties of an object invoking `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked @@ -4810,7 +5150,7 @@ _.forIn(new Foo, function(value, key) { ### `_.forInRight(object, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8600 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8945 "View in source") [Ⓣ][1] This method is like `_.forIn` except that it iterates over properties of `object` in the opposite order. @@ -4844,7 +5184,7 @@ _.forInRight(new Foo, function(value, key) { ### `_.forOwn(object, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8625 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8970 "View in source") [Ⓣ][1] Iterates over own enumerable properties of an object invoking `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked with @@ -4873,7 +5213,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) { ### `_.forOwnRight(object, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8650 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L8995 "View in source") [Ⓣ][1] This method is like `_.forOwn` except that it iterates over properties of `object` in the opposite order. @@ -4900,7 +5240,7 @@ _.forOwnRight({ '0': 'zero', '1': 'one', 'length': 2 }, function(n, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8670 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9015 "View in source") [Ⓣ][1] Creates an array of function property names from all enumerable properties, own and inherited, of `object`. @@ -4923,7 +5263,7 @@ _.functions(_); ### `_.has(object, key)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8689 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9034 "View in source") [Ⓣ][1] Checks if `key` exists as a direct property of `object` instead of an inherited property. @@ -4947,7 +5287,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.invert(object, [multiValue])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8718 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9063 "View in source") [Ⓣ][1] Creates an object composed of the inverted keys and values of `object`. If `object` contains duplicate values, subsequent values overwrite property @@ -4980,7 +5320,7 @@ _.invert({ 'first': 'fred', 'second': 'barney', 'third': 'fred' }, true); ### `_.keys(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8772 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9117 "View in source") [Ⓣ][1] Creates an array of the own enumerable property names of `object`.
@@ -5017,7 +5357,7 @@ _.keys('hi'); ### `_.keysIn(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8806 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9151 "View in source") [Ⓣ][1] Creates an array of the own and inherited enumerable property names of `object`.
@@ -5049,7 +5389,7 @@ _.keysIn(new Foo); ### `_.mapValues(object, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8900 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9248 "View in source") [Ⓣ][1] Creates an object with the same keys as `object` and values generated by running each own enumerable property of `object` through `iteratee`. The @@ -5057,17 +5397,22 @@ iteratee function is bound to `thisArg` and invoked with three arguments; (value, key, object).

-If a property name is provided for `iteratee` the created "_.property" +If a property name is provided for `iteratee` the created `_.property` style callback returns the property value of the given element.

-If an object is provided for `iteratee` the created "_.matches" style +If a value is also provided for `thisArg` the created `_.matchesProperty` +style callback returns `true` for elements that have a matching property +value, else `false`. +
+
+If an object is provided for `iteratee` the created `_.matches` style callback returns `true` for elements that have the properties of the given object, else `false`. #### Arguments 1. `object` *(Object)*: The object to iterate over. -2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. If a property name or object is provided it is used to create a "_.property" or "_.matches" style callback respectively. +2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration. 3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. #### Returns @@ -5083,7 +5428,7 @@ var users = { 'pebbles': { 'user': 'pebbles', 'age': 1 } }; -// using the "_.property" callback shorthand +// using the `_.property` callback shorthand _.mapValues(users, 'age'); // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) ``` @@ -5094,7 +5439,7 @@ _.mapValues(users, 'age'); ### `_.merge(object, [sources], [customizer], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8956 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9304 "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 @@ -5149,7 +5494,7 @@ _.merge(object, other, function(a, b) { ### `_.omit(object, [predicate], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L8986 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9334 "View in source") [Ⓣ][1] The opposite of `_.pick`; this method creates an object composed of the own and inherited enumerable properties of `object` that are not omitted. @@ -5184,7 +5529,7 @@ _.omit(object, _.isNumber); ### `_.pairs(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9014 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9362 "View in source") [Ⓣ][1] Creates a two dimensional array of the key-value pairs for `object`, e.g. `[[key1, value1], [key2, value2]]`. @@ -5207,7 +5552,7 @@ _.pairs({ 'barney': 36, 'fred': 40 }); ### `_.pick(object, [predicate], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9053 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9401 "View in source") [Ⓣ][1] Creates an object composed of the picked `object` properties. Property names may be specified as individual arguments or as arrays of property @@ -5240,7 +5585,7 @@ _.pick(object, _.isString); ### `_.result(object, key, [defaultValue])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9092 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9440 "View in source") [Ⓣ][1] Resolves the value of property `key` on `object`. If the value of `key` is a function it is invoked with the `this` binding of `object` and its result @@ -5278,7 +5623,7 @@ _.result(object, 'status', _.constant('busy')); ### `_.transform(object, [iteratee=_.identity], [accumulator], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9131 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9479 "View in source") [Ⓣ][1] An alternative to `_.reduce`; this method transforms `object` to a new `accumulator` object which is the result of running each of its own enumerable @@ -5318,7 +5663,7 @@ var mapped = _.transform({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) { ### `_.values(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9178 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9526 "View in source") [Ⓣ][1] Creates an array of the own enumerable property values of `object`.
@@ -5353,7 +5698,7 @@ _.values('hi'); ### `_.valuesIn(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9205 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9553 "View in source") [Ⓣ][1] Creates an array of the own and inherited enumerable property values of `object`. @@ -5392,7 +5737,7 @@ _.valuesIn(new Foo); ### `_.camelCase([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9295 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9643 "View in source") [Ⓣ][1] Converts `string` to camel case. See [Wikipedia](https://en.wikipedia.org/wiki/CamelCase) for more details. @@ -5421,7 +5766,7 @@ _.camelCase('__foo_bar__'); ### `_.capitalize([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9313 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9661 "View in source") [Ⓣ][1] Capitalizes the first character of `string`. @@ -5443,7 +5788,7 @@ _.capitalize('fred'); ### `_.deburr([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9333 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9681 "View in source") [Ⓣ][1] Deburrs `string` by converting latin-1 supplementary letters to basic latin letters. See [Wikipedia](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) @@ -5467,7 +5812,7 @@ _.deburr('déjà vu'); ### `_.endsWith([string=''], [target], [position=string.length])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9359 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9707 "View in source") [Ⓣ][1] Checks if `string` ends with the given target string. @@ -5497,7 +5842,7 @@ _.endsWith('abc', 'b', 2); ### `_.escape([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9400 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9748 "View in source") [Ⓣ][1] Converts the characters "&", "<", ">", '"', "'", and '`', in `string` to their corresponding HTML entities. @@ -5542,7 +5887,7 @@ _.escape('fred, barney, & pebbles'); ### `_.escapeRegExp([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9422 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9770 "View in source") [Ⓣ][1] Escapes the `RegExp` special characters "\", "^", "$", ".", "|", "?", "*", "+", "(", ")", "[", "]", "{" and "}" in `string`. @@ -5565,7 +5910,7 @@ _.escapeRegExp('[lodash](https://lodash.com/)'); ### `_.kebabCase([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9450 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9798 "View in source") [Ⓣ][1] Converts `string` to kebab case (a.k.a. spinal case). See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles) for @@ -5595,7 +5940,7 @@ _.kebabCase('__foo_bar__'); ### `_.pad([string=''], [length=0], [chars=' '])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9477 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9825 "View in source") [Ⓣ][1] Pads `string` on the left and right sides if it is shorter then the given padding length. The `chars` string may be truncated if the number of padding @@ -5627,7 +5972,7 @@ _.pad('abc', 3); ### `_.padLeft([string=''], [length=0], [chars=' '])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9516 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9864 "View in source") [Ⓣ][1] Pads `string` on the left side if it is shorter then the given padding length. The `chars` string may be truncated if the number of padding @@ -5659,7 +6004,7 @@ _.padLeft('abc', 3); ### `_.padRight([string=''], [length=0], [chars=' '])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9544 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9892 "View in source") [Ⓣ][1] Pads `string` on the right side if it is shorter then the given padding length. The `chars` string may be truncated if the number of padding @@ -5691,7 +6036,7 @@ _.padRight('abc', 3); ### `_.parseInt(string, [radix])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9572 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9920 "View in source") [Ⓣ][1] Converts `string` to an integer of the specified radix. If `radix` is `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal, @@ -5723,7 +6068,7 @@ _.map(['6', '08', '10'], _.parseInt); ### `_.repeat([string=''], [n=0])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9614 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L9962 "View in source") [Ⓣ][1] Repeats the given string `n` times. @@ -5752,7 +6097,7 @@ _.repeat('abc', 0); ### `_.snakeCase([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9654 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10002 "View in source") [Ⓣ][1] Converts `string` to snake case. See [Wikipedia](https://en.wikipedia.org/wiki/Snake_case) for more details. @@ -5781,7 +6126,7 @@ _.snakeCase('--foo-bar'); ### `_.startCase([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9679 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10027 "View in source") [Ⓣ][1] Converts `string` to start case. See [Wikipedia](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage) @@ -5811,7 +6156,7 @@ _.startCase('__foo_bar__'); ### `_.startsWith([string=''], [target], [position=0])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9704 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10052 "View in source") [Ⓣ][1] Checks if `string` starts with the given target string. @@ -5841,7 +6186,7 @@ _.startsWith('abc', 'b', 1); ### `_.template([string=''], [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9806 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10154 "View in source") [Ⓣ][1] Creates a compiled template function that can interpolate data properties in "interpolate" delimiters, HTML-escape interpolated data properties in @@ -5948,7 +6293,7 @@ fs.writeFileSync(path.join(cwd, 'jst.js'), '\ ### `_.trim([string=''], [chars=whitespace])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9933 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10281 "View in source") [Ⓣ][1] Removes leading and trailing whitespace or specified characters from `string`. @@ -5977,7 +6322,7 @@ _.map([' foo ', ' bar '], _.trim); ### `_.trimLeft([string=''], [chars=whitespace])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9964 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10312 "View in source") [Ⓣ][1] Removes leading whitespace or specified characters from `string`. @@ -6003,7 +6348,7 @@ _.trimLeft('-_-abc-_-', '_-'); ### `_.trimRight([string=''], [chars=whitespace])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L9994 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10342 "View in source") [Ⓣ][1] Removes trailing whitespace or specified characters from `string`. @@ -6029,7 +6374,7 @@ _.trimRight('-_-abc-_-', '_-'); ### `_.trunc([string=''], [options], [options.length=30], [options.omission='...'], [options.separator])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10038 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10386 "View in source") [Ⓣ][1] Truncates `string` if it is longer than the given maximum string length. The last characters of the truncated string are replaced with the omission @@ -6069,7 +6414,7 @@ _.trunc('hi-diddly-ho there, neighborino', { 'omission': ' [...]' }); ### `_.unescape([string=''])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10108 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10456 "View in source") [Ⓣ][1] The inverse of `_.escape`; this method converts the HTML entities `&`, `<`, `>`, `"`, `'`, and ``` in `string` to their @@ -6097,7 +6442,7 @@ _.unescape('fred, barney, & pebbles'); ### `_.words([string=''], [pattern])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10133 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10481 "View in source") [Ⓣ][1] Splits `string` into an array of its words. @@ -6129,10 +6474,10 @@ _.words('fred, barney, & pebbles', /[^, ]+/g); ### `_.attempt(func)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10163 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10511 "View in source") [Ⓣ][1] -Attempts to invoke `func`, returning either the result or the caught -error object. +Attempts to invoke `func`, returning either the result or the caught error +object. Any additional arguments are provided to `func` when it is invoked. #### Arguments 1. `func` *(*)*: The function to attempt. @@ -6143,9 +6488,9 @@ error object. #### Example ```js // avoid throwing errors for invalid selectors -var elements = _.attempt(function() { +var elements = _.attempt(function(selector) { return document.querySelectorAll(selector); -}); +}, '>_>'); if (_.isError(elements)) { elements = []; @@ -6158,12 +6503,13 @@ if (_.isError(elements)) { ### `_.callback([func=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10206 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10555 "View in source") [Ⓣ][1] -Creates a function bound to an optional `thisArg`. If `func` is a property -name the created callback returns the property value for a given element. -If `func` is an object the created callback returns `true` for elements -that contain the equivalent object properties, otherwise it returns `false`. +Creates a function that invokes `func` with the `this` binding of `thisArg` +and arguments of the created function. If `func` is a property name the +created callback returns the property value for a given element. If `func` +is an object the created callback returns `true` for elements that contain +the equivalent object properties, otherwise it returns `false`. #### Arguments 1. `[func=_.identity]` *(*)*: The value to convert to a callback. @@ -6200,7 +6546,7 @@ _.filter(users, 'age__gt36'); ### `_.constant(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10230 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10579 "View in source") [Ⓣ][1] Creates a function that returns `value`. @@ -6224,7 +6570,7 @@ getter() === object; ### `_.identity(value)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10250 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10599 "View in source") [Ⓣ][1] This method returns the first argument provided to it. @@ -6247,11 +6593,17 @@ _.identity(object) === object; ### `_.matches(source)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10279 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10628 "View in source") [Ⓣ][1] Creates a function which performs a deep comparison between a given object and `source`, returning `true` if the given object has equivalent property values, else `false`. +
+
+**Note:** This method supports comparing arrays, booleans, `Date` objects, +numbers, `Object` objects, regexes, and strings. Objects are compared by +their own, not inherited, enumerable properties. For comparing a single +own or inherited property value see `_.matchesProperty`. #### Arguments 1. `source` *(Object)*: The object of property values to match. @@ -6262,17 +6614,47 @@ values, else `false`. #### Example ```js var users = [ - { 'user': 'fred', 'age': 40 }, - { 'user': 'barney', 'age': 36 } + { 'user': 'barney', 'age': 36, 'active': true }, + { 'user': 'fred', 'age': 40, 'active': false } ]; -var matchesAge = _.matches({ 'age': 36 }); +_.filter(users, _.matches({ 'age': 40, 'active': false })); +// => [{ 'user': 'fred', 'age': 40, 'active': false }] +``` +* * * + + + + -_.filter(users, matchesAge); -// => [{ 'user': 'barney', 'age': 36 }] +### `_.matchesProperty(key, value)` +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10657 "View in source") [Ⓣ][1] -_.find(users, matchesAge); -// => { 'user': 'barney', 'age': 36 } +Creates a function which compares the property value of `key` on a given +object to `value`. +
+
+**Note:** This method supports comparing arrays, booleans, `Date` objects, +numbers, `Object` objects, regexes, and strings. Objects are compared by +their own, not inherited, enumerable properties. + +#### Arguments +1. `key` *(string)*: The key of the property to get. +2. `value` *(*)*: The value to compare. + +#### Returns +*(Function)*: Returns the new function. + +#### Example +```js +var users = [ + { 'user': 'barney' }, + { 'user': 'fred' }, + { 'user': 'pebbles' } +]; + +_.find(users, _.matchesProperty('user', 'fred')); +// => { 'user': 'fred', 'age': 40 } ``` * * * @@ -6281,7 +6663,7 @@ _.find(users, matchesAge); ### `_.mixin([object=this], source, [options])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10316 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10697 "View in source") [Ⓣ][1] Adds all own enumerable function properties of a source object to the destination object. If `object` is a function then methods are added to @@ -6304,6 +6686,9 @@ function vowels(string) { }); } +// use `_.runInContext` to avoid potential conflicts (esp. in Node.js) +var _ = require('lodash').runInContext(); + _.mixin({ 'vowels': vowels }); _.vowels('fred'); // => ['e'] @@ -6322,7 +6707,7 @@ _('fred').vowels(); ### `_.noConflict()` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10379 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10760 "View in source") [Ⓣ][1] Reverts the `_` variable to its previous value and returns a reference to the `lodash` function. @@ -6341,7 +6726,7 @@ var lodash = _.noConflict(); ### `_.noop()` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10396 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10777 "View in source") [Ⓣ][1] A no-operation function. @@ -6358,7 +6743,7 @@ _.noop(object) === undefined; ### `_.property(key)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10423 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10804 "View in source") [Ⓣ][1] Creates a function which returns the property value of `key` on a given object. @@ -6390,7 +6775,7 @@ _.pluck(_.sortBy(users, getName), 'user'); ### `_.propertyOf(object)` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10446 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10827 "View in source") [Ⓣ][1] The inverse of `_.property`; this method creates a function which returns the property value of a given key on `object`. @@ -6418,7 +6803,7 @@ _.sortBy(['a', 'b', 'c'], _.propertyOf(object)); ### `_.range([start=0], end, [step=1])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10484 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10865 "View in source") [Ⓣ][1] Creates an array of numbers (positive and/or negative) progressing from `start` up to, but not including, `end`. If `start` is less than `end` a @@ -6459,7 +6844,7 @@ _.range(0); ### `_.runInContext([context=root])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L689 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L689 "View in source") [Ⓣ][1] Create a new pristine `lodash` function using the given `context` object. @@ -6503,7 +6888,7 @@ var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; ### `_.times(n, [iteratee=_.identity], [thisArg])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10533 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10914 "View in source") [Ⓣ][1] Invokes the iteratee function `n` times, returning an array of the results of each invocation. The `iteratee` is bound to `thisArg` and invoked with @@ -6535,7 +6920,7 @@ _.times(3, function(n) { this.cast(n); }, mage); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10571 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L10952 "View in source") [Ⓣ][1] Generates a unique ID. If `prefix` is provided the ID is appended to it. @@ -6566,7 +6951,7 @@ _.uniqueId(); ### `_.templateSettings.imports._` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1163 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1164 "View in source") [Ⓣ][1] A reference to the `lodash` function. @@ -6583,7 +6968,7 @@ A reference to the `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L10832 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L11220 "View in source") [Ⓣ][1] (string): The semantic version number. @@ -6594,7 +6979,7 @@ A reference to the `lodash` function. ### `_.support` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L952 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L953 "View in source") [Ⓣ][1] (Object): An object environment feature flags. @@ -6605,7 +6990,7 @@ A reference to the `lodash` function. ### `_.support.argsTag` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L969 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L970 "View in source") [Ⓣ][1] (boolean): Detect if the `toStringTag` of `arguments` objects is resolvable (all but Firefox < 4, IE < 9). @@ -6617,7 +7002,7 @@ A reference to the `lodash` function. ### `_.support.enumErrorProps` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L978 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L979 "View in source") [Ⓣ][1] (boolean): Detect if `name` or `message` properties of `Error.prototype` are enumerable by default (IE < 9, Safari < 5.1). @@ -6629,7 +7014,7 @@ enumerable by default (IE < 9, Safari < 5.1). ### `_.support.enumPrototypes` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L992 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L993 "View in source") [Ⓣ][1] (boolean): Detect if `prototype` properties are enumerable by default.
@@ -6646,7 +7031,7 @@ property to `true`. ### `_.support.funcDecomp` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1002 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1003 "View in source") [Ⓣ][1] (boolean): Detect if functions can be decompiled by `Function#toString` (all but Firefox OS certified apps, older Opera mobile browsers, and @@ -6659,7 +7044,7 @@ the PlayStation 3; forced `false` for Windows 8 apps). ### `_.support.funcNames` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1010 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1011 "View in source") [Ⓣ][1] (boolean): Detect if `Function#name` is supported (all but IE). @@ -6670,7 +7055,7 @@ the PlayStation 3; forced `false` for Windows 8 apps). ### `_.support.nodeTag` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1018 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1019 "View in source") [Ⓣ][1] (boolean): Detect if the `toStringTag` of DOM nodes is resolvable (all but IE < 9). @@ -6681,7 +7066,7 @@ the PlayStation 3; forced `false` for Windows 8 apps). ### `_.support.nonEnumShadows` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1039 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1040 "View in source") [Ⓣ][1] (boolean): Detect if properties shadowing those on `Object.prototype` are non-enumerable. @@ -6697,7 +7082,7 @@ are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug). ### `_.support.nonEnumStrings` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1027 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1028 "View in source") [Ⓣ][1] (boolean): Detect if string indexes are non-enumerable (IE < 9, RingoJS, Rhino, Narwhal). @@ -6709,7 +7094,7 @@ are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug). ### `_.support.ownLast` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1047 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1048 "View in source") [Ⓣ][1] (boolean): Detect if own properties are iterated after inherited properties (IE < 9). @@ -6720,7 +7105,7 @@ are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug). ### `_.support.spliceObjects` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1062 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1063 "View in source") [Ⓣ][1] (boolean): Detect if `Array#shift` and `Array#splice` augment array-like objects correctly. @@ -6739,7 +7124,7 @@ is buggy regardless of mode in IE < 9. ### `_.support.unindexedChars` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1073 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1074 "View in source") [Ⓣ][1] (boolean): Detect lack of support for accessing string characters by index.
@@ -6754,7 +7139,7 @@ by index on string literals, not string objects. ### `_.templateSettings` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1115 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1116 "View in source") [Ⓣ][1] (Object): By default, the template delimiters used by lodash are like those in embedded Ruby (ERB). Change the following template settings to use @@ -6767,7 +7152,7 @@ alternative delimiters. ### `_.templateSettings.escape` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1123 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1124 "View in source") [Ⓣ][1] (RegExp): Used to detect `data` property values to be HTML-escaped. @@ -6778,7 +7163,7 @@ alternative delimiters. ### `_.templateSettings.evaluate` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1131 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1132 "View in source") [Ⓣ][1] (RegExp): Used to detect code to be evaluated. @@ -6789,7 +7174,7 @@ alternative delimiters. ### `_.templateSettings.imports` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1155 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1156 "View in source") [Ⓣ][1] (Object): Used to import variables into the compiled template. @@ -6800,7 +7185,7 @@ alternative delimiters. ### `_.templateSettings.interpolate` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1139 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1140 "View in source") [Ⓣ][1] (RegExp): Used to detect `data` property values to inject. @@ -6811,7 +7196,7 @@ alternative delimiters. ### `_.templateSettings.variable` -# [Ⓢ](https://github.com/lodash/lodash/blob/3.1.0/lodash.src.js#L1147 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/lodash/lodash/blob/3.2.0/lodash.src.js#L1148 "View in source") [Ⓣ][1] (string): Used to reference the data object in the template text. diff --git a/lodash.js b/lodash.js index 11b3e2cd6c..40ab9b793e 100644 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 3.1.0 (Custom Build) + * lodash 3.2.0 (Custom Build) * Build: `lodash modern -o ./lodash.js` * Copyright 2012-2015 The Dojo Foundation * Based on Underscore.js 1.7.0 @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '3.1.0'; + var VERSION = '3.2.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -728,7 +728,6 @@ setTimeout = context.setTimeout, splice = arrayProto.splice, Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array, - unshift = arrayProto.unshift, WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap; /** Used to clone array buffers. */ @@ -780,7 +779,7 @@ /*------------------------------------------------------------------------*/ /** - * Creates a `lodash` object which wraps `value` to enable intuitive chaining. + * Creates a `lodash` object which wraps `value` to enable implicit chaining. * Methods that operate on and return arrays, collections, and functions can * be chained together. Methods that return a boolean or single value will * automatically end the chain returning the unwrapped value. Explicit chaining @@ -799,29 +798,31 @@ * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`, * and `unshift` * - * The wrapper functions that support shortcut fusion are: - * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`, - * `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`, - * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where` + * The wrapper methods that support shortcut fusion are: + * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, + * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, + * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`, + * and `where` * - * The chainable wrapper functions are: + * The chainable wrapper methods are: * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`, - * `callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`, - * `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, - * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, - * `flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`, - * `forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`, - * `initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`, - * `mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`, - * `omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`, - * `pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, - * `rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, - * `sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`, - * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, - * `transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, - * `where`, `without`, `wrap`, `xor`, `zip`, and `zipObject` - * - * The wrapper functions that are **not** chainable by default are: + * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`, + * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, + * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`, + * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`, + * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, + * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, + * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, + * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, + * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`, + * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`, + * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`, + * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, + * `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`, + * `unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`, + * `zip`, and `zipObject` + * + * The wrapper methods that are **not** chainable by default are: * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`, * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, @@ -836,14 +837,14 @@ * `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, * `trunc`, `unescape`, `uniqueId`, `value`, and `words` * - * The wrapper function `sample` will return a wrapped value when `n` is provided, + * The wrapper method `sample` will return a wrapped value when `n` is provided, * otherwise an unwrapped value is returned. * * @name _ * @constructor * @category Chain * @param {*} value The value to wrap in a `lodash` instance. - * @returns {Object} Returns a `lodash` instance. + * @returns {Object} Returns the new `lodash` wrapper instance. * @example * * var wrapped = _([1, 2, 3]); @@ -862,12 +863,12 @@ * // => true */ function lodash(value) { - if (isObjectLike(value) && !isArray(value)) { + if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { if (value instanceof LodashWrapper) { return value; } - if (hasOwnProperty.call(value, '__wrapped__')) { - return new LodashWrapper(value.__wrapped__, value.__chain__, arrayCopy(value.__actions__)); + if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) { + return wrapperClone(value); } } return new LodashWrapper(value); @@ -882,9 +883,9 @@ * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value. */ function LodashWrapper(value, chainAll, actions) { + this.__wrapped__ = value; this.__actions__ = actions || []; this.__chain__ = !!chainAll; - this.__wrapped__ = value; } /** @@ -1017,14 +1018,14 @@ * @param {*} value The value to wrap. */ function LazyWrapper(value) { - this.actions = null; - this.dir = 1; - this.dropCount = 0; - this.filtered = false; - this.iteratees = null; - this.takeCount = POSITIVE_INFINITY; - this.views = null; - this.wrapped = value; + this.__wrapped__ = value; + this.__actions__ = null; + this.__dir__ = 1; + this.__dropCount__ = 0; + this.__filtered__ = false; + this.__iteratees__ = null; + this.__takeCount__ = POSITIVE_INFINITY; + this.__views__ = null; } /** @@ -1036,18 +1037,18 @@ * @returns {Object} Returns the cloned `LazyWrapper` object. */ function lazyClone() { - var actions = this.actions, - iteratees = this.iteratees, - views = this.views, - result = new LazyWrapper(this.wrapped); - - result.actions = actions ? arrayCopy(actions) : null; - result.dir = this.dir; - result.dropCount = this.dropCount; - result.filtered = this.filtered; - result.iteratees = iteratees ? arrayCopy(iteratees) : null; - result.takeCount = this.takeCount; - result.views = views ? arrayCopy(views) : null; + var actions = this.__actions__, + iteratees = this.__iteratees__, + views = this.__views__, + result = new LazyWrapper(this.__wrapped__); + + result.__actions__ = actions ? arrayCopy(actions) : null; + result.__dir__ = this.__dir__; + result.__dropCount__ = this.__dropCount__; + result.__filtered__ = this.__filtered__; + result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null; + result.__takeCount__ = this.__takeCount__; + result.__views__ = views ? arrayCopy(views) : null; return result; } @@ -1060,13 +1061,13 @@ * @returns {Object} Returns the new reversed `LazyWrapper` object. */ function lazyReverse() { - if (this.filtered) { + if (this.__filtered__) { var result = new LazyWrapper(this); - result.dir = -1; - result.filtered = true; + result.__dir__ = -1; + result.__filtered__ = true; } else { result = this.clone(); - result.dir *= -1; + result.__dir__ *= -1; } return result; } @@ -1080,20 +1081,20 @@ * @returns {*} Returns the unwrapped value. */ function lazyValue() { - var array = this.wrapped.value(); + var array = this.__wrapped__.value(); if (!isArray(array)) { - return baseWrapperValue(array, this.actions); + return baseWrapperValue(array, this.__actions__); } - var dir = this.dir, + var dir = this.__dir__, isRight = dir < 0, - view = getView(0, array.length, this.views), + view = getView(0, array.length, this.__views__), start = view.start, end = view.end, length = end - start, - dropCount = this.dropCount, - takeCount = nativeMin(length, this.takeCount - dropCount), + dropCount = this.__dropCount__, + takeCount = nativeMin(length, this.__takeCount__), index = isRight ? end : start - 1, - iteratees = this.iteratees, + iteratees = this.__iteratees__, iterLength = iteratees ? iteratees.length : 0, resIndex = 0, result = []; @@ -1538,7 +1539,7 @@ return baseCopy(source, object, props); } var index = -1, - length = props.length + length = props.length; while (++index < length) { var key = props[index], @@ -1645,10 +1646,12 @@ if (func == null) { return identity; } - // Handle "_.property" and "_.matches" style callback shorthands. - return type == 'object' - ? baseMatches(func) - : baseProperty(func + ''); + if (type == 'object') { + return baseMatches(func); + } + return typeof thisArg == 'undefined' + ? baseProperty(func + '') + : baseMatchesProperty(func + '', thisArg); } /** @@ -1749,7 +1752,7 @@ * @returns {number} Returns the timer id. */ function baseDelay(func, wait, args, fromIndex) { - if (!isFunction(func)) { + if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait); @@ -1869,6 +1872,36 @@ return result; } + /** + * The base implementation of `_.fill` without an iteratee call guard. + * + * @private + * @param {Array} array The array to fill. + * @param {*} value The value to fill `array` with. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns `array`. + */ + function baseFill(array, value, start, end) { + var length = array.length; + + start = start == null ? 0 : (+start || 0); + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = (typeof end == 'undefined' || end > length) ? length : (+end || 0); + if (end < 0) { + end += length; + } + length = start > end ? 0 : end >>> 0; + start >>>= 0; + + while (start < length) { + array[start++] = value; + } + return array; + } + /** * The base implementation of `_.filter` without support for callback * shorthands or `this` binding. @@ -2201,7 +2234,7 @@ * shorthands or `this` binding. * * @private - * @param {Object} source The object to inspect. + * @param {Object} object The object to inspect. * @param {Array} props The source property names to match. * @param {Array} values The source values to match. * @param {Array} strictCompareFlags Strict comparison flags for source values. @@ -2263,8 +2296,7 @@ } /** - * The base implementation of `_.matches` which supports specifying whether - * `source` should be cloned. + * The base implementation of `_.matches` which does not clone `source`. * * @private * @param {Object} source The object of property values to match. @@ -2280,7 +2312,7 @@ if (isStrictComparable(value)) { return function(object) { - return object != null && value === object[key] && hasOwnProperty.call(object, key); + return object != null && object[key] === value && hasOwnProperty.call(object, key); }; } } @@ -2297,6 +2329,26 @@ }; } + /** + * The base implementation of `_.matchesProperty` which does not coerce `key` + * to a string. + * + * @private + * @param {string} key The key of the property to get. + * @param {*} value The value to compare. + * @returns {Function} Returns the new function. + */ + function baseMatchesProperty(key, value) { + if (isStrictComparable(value)) { + return function(object) { + return object != null && object[key] === value; + }; + } + return function(object) { + return object != null && baseIsEqual(value, object[key], null, true); + }; + } + /** * The base implementation of `_.merge` without support for argument juggling, * multiple sources, and `this` binding `customizer` functions. @@ -2459,7 +2511,7 @@ eachFunc(collection, function(value, index, collection) { accumulator = initFromCollection ? (initFromCollection = false, value) - : iteratee(accumulator, value, index, collection) + : iteratee(accumulator, value, index, collection); }); return accumulator; } @@ -2835,8 +2887,7 @@ /** * Creates a function that aggregates a collection, creating an accumulator * object composed from the results of running each element in the collection - * through an iteratee. The `setter` sets the keys and values of the accumulator - * object. If `initializer` is provided initializes the accumulator object. + * through an iteratee. * * @private * @param {Function} setter The function to set keys and values of the accumulator object. @@ -3173,7 +3224,7 @@ */ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { var isBindKey = bitmask & BIND_KEY_FLAG; - if (!isBindKey && !isFunction(func)) { + if (!isBindKey && typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } var length = partials ? partials.length : 0; @@ -3203,9 +3254,9 @@ if (bitmask == BIND_FLAG) { var result = createBindWrapper(newData[0], newData[2]); } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) { - result = createPartialWrapper.apply(null, newData); + result = createPartialWrapper.apply(undefined, newData); } else { - result = createHybridWrapper.apply(null, newData); + result = createHybridWrapper.apply(undefined, newData); } var setter = data ? baseSetData : setData; return setter(result, newData); @@ -3893,6 +3944,19 @@ return isObject(value) ? value : Object(value); } + /** + * Creates a clone of `wrapper`. + * + * @private + * @param {Object} wrapper The wrapper to clone. + * @returns {Object} Returns the cloned wrapper. + */ + function wrapperClone(wrapper) { + return wrapper instanceof LazyWrapper + ? wrapper.clone() + : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__)); + } + /*------------------------------------------------------------------------*/ /** @@ -3904,7 +3968,7 @@ * @memberOf _ * @category Array * @param {Array} array The array to process. - * @param {numer} [size=1] The length of each chunk. + * @param {number} [size=1] The length of each chunk. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`. * @returns {Array} Returns the new array containing chunks. * @example @@ -3999,7 +4063,6 @@ * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to drop. @@ -4035,7 +4098,6 @@ * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to drop. @@ -4072,20 +4134,23 @@ * Elements are dropped until `predicate` returns falsey. The predicate is * bound to `thisArg` and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style - * callback returns `true` for elements that have the properties of the given + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style + * callback returns `true` for elements that match the properties of the given * object, else `false`. * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per element. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the slice of `array`. * @example @@ -4094,18 +4159,22 @@ * // => [1] * * var users = [ - * { 'user': 'barney', 'status': 'busy', 'active': false }, - * { 'user': 'fred', 'status': 'busy', 'active': true }, - * { 'user': 'pebbles', 'status': 'away', 'active': true } + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.dropRightWhile(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.dropRightWhile(users, { 'user': pebbles, 'active': false }), 'user'); + * // => ['barney', 'fred'] + * + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.dropRightWhile(users, 'active', false), 'user'); * // => ['barney'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user'); - * // => ['barney', 'fred'] + * // using the `_.property` callback shorthand + * _.pluck(_.dropRightWhile(users, 'active'), 'user'); + * // => ['barney', 'fred', 'pebbles'] */ function dropRightWhile(array, predicate, thisArg) { var length = array ? array.length : 0; @@ -4122,20 +4191,23 @@ * Elements are dropped until `predicate` returns falsey. The predicate is * bound to `thisArg` and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per element. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the slice of `array`. * @example @@ -4144,18 +4216,22 @@ * // => [3] * * var users = [ - * { 'user': 'barney', 'status': 'busy', 'active': true }, - * { 'user': 'fred', 'status': 'busy', 'active': false }, - * { 'user': 'pebbles', 'status': 'away', 'active': true } + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.dropWhile(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user'); * // => ['fred', 'pebbles'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user'); + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.dropWhile(users, 'active', false), 'user'); * // => ['pebbles'] + * + * // using the `_.property` callback shorthand + * _.pluck(_.dropWhile(users, 'active'), 'user'); + * // => ['barney', 'fred', 'pebbles'] */ function dropWhile(array, predicate, thisArg) { var length = array ? array.length : 0; @@ -4168,14 +4244,45 @@ return baseSlice(array, index); } + /** + * Fills elements of `array` with `value` from `start` up to, but not + * including, `end`. + * + * **Note:** This method mutates `array`. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to fill. + * @param {*} value The value to fill `array` with. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns `array`. + */ + function fill(array, value, start, end) { + var length = array ? array.length : 0; + if (!length) { + return []; + } + if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { + start = 0; + end = length; + } + return baseFill(array, value, start, end); + } + /** * This method is like `_.find` except that it returns the index of the first * element `predicate` returns truthy for, instead of the element itself. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -4184,28 +4291,31 @@ * @category Array * @param {Array} array The array to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {number} Returns the index of the found element, else `-1`. * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true }, - * { 'user': 'pebbles', 'age': 1, 'active': false } + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } * ]; * - * _.findIndex(users, function(chr) { return chr.age < 40; }); + * _.findIndex(users, function(chr) { return chr.user == 'barney'; }); * // => 0 * - * // using the "_.matches" callback shorthand - * _.findIndex(users, { 'age': 1 }); - * // => 2 + * // using the `_.matches` callback shorthand + * _.findIndex(users, { 'user': 'fred', 'active': false }); + * // => 1 * - * // using the "_.property" callback shorthand + * // using the `_.matchesProperty` callback shorthand + * _.findIndex(users, 'active', false); + * // => 0 + * + * // using the `_.property` callback shorthand * _.findIndex(users, 'active'); - * // => 1 + * // => 2 */ function findIndex(array, predicate, thisArg) { var index = -1, @@ -4224,10 +4334,14 @@ * This method is like `_.findIndex` except that it iterates over elements * of `collection` from right to left. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -4236,26 +4350,29 @@ * @category Array * @param {Array} array The array to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {number} Returns the index of the found element, else `-1`. * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': true }, - * { 'user': 'fred', 'age': 40, 'active': false }, - * { 'user': 'pebbles', 'age': 1, 'active': false } + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } * ]; * - * _.findLastIndex(users, function(chr) { return chr.age < 40; }); + * _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; }); * // => 2 * - * // using the "_.matches" callback shorthand - * _.findLastIndex(users, { 'age': 40 }); + * // using the `_.matches` callback shorthand + * _.findLastIndex(users, { user': 'barney', 'active': true }); + * // => 0 + * + * // using the `_.matchesProperty` callback shorthand + * _.findLastIndex(users, 'active', false); * // => 1 * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.findLastIndex(users, 'active'); * // => 0 */ @@ -4607,10 +4724,14 @@ * and returns an array of the removed elements. The predicate is bound to * `thisArg` and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -4621,8 +4742,7 @@ * @category Array * @param {Array} array The array to modify. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the new array of removed elements. * @example @@ -4704,10 +4824,14 @@ * to compute their sort ranking. The iteratee is bound to `thisArg` and * invoked with one argument; (value). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -4717,8 +4841,7 @@ * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {number} Returns the index at which `value` should be inserted * into `array`. @@ -4738,7 +4861,7 @@ * }, dict); * // => 1 * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); * // => 1 */ @@ -4760,8 +4883,7 @@ * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {number} Returns the index at which `value` should be inserted * into `array`. @@ -4782,7 +4904,6 @@ * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to take. @@ -4818,7 +4939,6 @@ * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to take. @@ -4855,20 +4975,23 @@ * taken until `predicate` returns falsey. The predicate is bound to `thisArg` * and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per element. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the slice of `array`. * @example @@ -4877,18 +5000,22 @@ * // => [2, 3] * * var users = [ - * { 'user': 'barney', 'status': 'busy', 'active': false }, - * { 'user': 'fred', 'status': 'busy', 'active': true }, - * { 'user': 'pebbles', 'status': 'away', 'active': true } + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.takeRightWhile(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user'); + * // => ['pebbles'] + * + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.takeRightWhile(users, 'active', false), 'user'); * // => ['fred', 'pebbles'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user'); - * // => ['pebbles'] + * // using the `_.property` callback shorthand + * _.pluck(_.takeRightWhile(users, 'active'), 'user'); + * // => [] */ function takeRightWhile(array, predicate, thisArg) { var length = array ? array.length : 0; @@ -4905,20 +5032,23 @@ * are taken until `predicate` returns falsey. The predicate is bound to * `thisArg` and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per element. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the slice of `array`. * @example @@ -4927,18 +5057,22 @@ * // => [1, 2] * * var users = [ - * { 'user': 'barney', 'status': 'busy', 'active': true }, - * { 'user': 'fred', 'status': 'busy', 'active': false }, - * { 'user': 'pebbles', 'status': 'away', 'active': true } + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false}, + * { 'user': 'pebbles', 'active': true } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.takeWhile(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user'); * // => ['barney'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user'); + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.takeWhile(users, 'active', false), 'user'); * // => ['barney', 'fred'] + * + * // using the `_.property` callback shorthand + * _.pluck(_.takeWhile(users, 'active'), 'user'); + * // => [] */ function takeWhile(array, predicate, thisArg) { var length = array ? array.length : 0; @@ -4982,10 +5116,14 @@ * uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked * with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5001,8 +5139,6 @@ * @param {Array} array The array to inspect. * @param {boolean} [isSorted] Specify the array is sorted. * @param {Function|Object|string} [iteratee] The function invoked per iteration. - * If a property name or object is provided it is used to create a "_.property" - * or "_.matches" style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Array} Returns the new duplicate-value-free array. * @example @@ -5018,7 +5154,7 @@ * _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math); * // => [1, 2.5] * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ @@ -5199,7 +5335,7 @@ * @memberOf _ * @category Chain * @param {*} value The value to wrap. - * @returns {Object} Returns the new `lodash` object. + * @returns {Object} Returns the new `lodash` wrapper instance. * @example * * var users = [ @@ -5275,7 +5411,7 @@ * @name chain * @memberOf _ * @category Chain - * @returns {*} Returns the `lodash` object. + * @returns {Object} Returns the new `lodash` wrapper instance. * @example * * var users = [ @@ -5298,6 +5434,76 @@ return chain(this); } + /** + * Executes the chained sequence and returns the wrapped result. + * + * @name commit + * @memberOf _ + * @category Chain + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var array = [1, 2]; + * var wrapper = _(array).push(3); + * + * console.log(array); + * // => [1, 2] + * + * wrapper = wrapper.commit(); + * console.log(array); + * // => [1, 2, 3] + * + * wrapper.last(); + * // => 3 + * + * console.log(array); + * // => [1, 2, 3] + */ + function wrapperCommit() { + return new LodashWrapper(this.value(), this.__chain__); + } + + /** + * Creates a clone of the chained sequence planting `value` as the wrapped value. + * + * @name plant + * @memberOf _ + * @category Chain + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var array = [1, 2]; + * var wrapper = _(array).map(function(value) { + * return Math.pow(value, 2); + * }); + * + * var other = [3, 4]; + * var otherWrapper = wrapper.plant(other); + * + * otherWrapper.value(); + * // => [9, 16] + * + * wrapper.value(); + * // => [1, 4] + */ + function wrapperPlant(value) { + var result, + parent = this; + + while (parent instanceof LodashWrapper) { + var clone = wrapperClone(parent); + if (result) { + previous.__wrapped__ = clone; + } else { + result = clone; + } + var previous = clone; + parent = parent.__wrapped__; + } + previous.__wrapped__ = value; + return result; + } + /** * Reverses the wrapped array so the first element becomes the last, the * second element becomes the second to last, and so on. @@ -5307,7 +5513,7 @@ * @name reverse * @memberOf _ * @category Chain - * @returns {Object} Returns the new reversed `lodash` object. + * @returns {Object} Returns the new reversed `lodash` wrapper instance. * @example * * var array = [1, 2, 3]; @@ -5324,7 +5530,7 @@ if (this.__actions__.length) { value = new LazyWrapper(this); } - return new LodashWrapper(value.reverse()); + return new LodashWrapper(value.reverse(), this.__chain__); } return this.thru(function(value) { return value.reverse(); @@ -5352,7 +5558,7 @@ * * @name value * @memberOf _ - * @alias toJSON, valueOf + * @alias run, toJSON, valueOf * @category Chain * @returns {*} Returns the resolved unwrapped value. * @example @@ -5452,10 +5658,14 @@ * The `iteratee` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5464,8 +5674,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Object} Returns the composed aggregate object. * @example @@ -5488,10 +5697,14 @@ * The predicate is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5501,27 +5714,30 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {boolean} Returns `true` if all elements pass the predicate check, * else `false`. * @example * - * _.every([true, 1, null, 'yes']); + * _.every([true, 1, null, 'yes'], Boolean); * // => false * * var users = [ - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 } + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.every(users, 'age'); + * // using the `_.matches` callback shorthand + * _.every(users, { 'user': 'barney', 'active': false }); + * // => false + * + * // using the `_.matchesProperty` callback shorthand + * _.every(users, 'active', false); * // => true * - * // using the "_.matches" callback shorthand - * _.every(users, { 'age': 36 }); + * // using the `_.property` callback shorthand + * _.every(users, 'active'); * // => false */ function every(collection, predicate, thisArg) { @@ -5537,10 +5753,14 @@ * `predicate` returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5550,8 +5770,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the new filtered array. * @example @@ -5560,16 +5779,20 @@ * // => [2, 4] * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.filter(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user'); + * // => ['barney'] + * + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.filter(users, 'active', false), 'user'); * // => ['fred'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.filter(users, { 'age': 36 }), 'user'); + * // using the `_.property` callback shorthand + * _.pluck(_.filter(users, 'active'), 'user'); * // => ['barney'] */ function filter(collection, predicate, thisArg) { @@ -5583,10 +5806,14 @@ * `predicate` returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5596,28 +5823,31 @@ * @category Collection * @param {Array|Object|string} collection The collection to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {*} Returns the matched element, else `undefined`. * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true }, - * { 'user': 'pebbles', 'age': 1, 'active': false } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false }, + * { 'user': 'pebbles', 'age': 1, 'active': true } * ]; * * _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user'); * // => 'barney' * - * // using the "_.matches" callback shorthand - * _.result(_.find(users, { 'age': 1 }), 'user'); + * // using the `_.matches` callback shorthand + * _.result(_.find(users, { 'age': 1, 'active': true }), 'user'); * // => 'pebbles' * - * // using the "_.property" callback shorthand - * _.result(_.find(users, 'active'), 'user'); + * // using the `_.matchesProperty` callback shorthand + * _.result(_.find(users, 'active', false), 'user'); * // => 'fred' + * + * // using the `_.property` callback shorthand + * _.result(_.find(users, 'active'), 'user'); + * // => 'barney' */ function find(collection, predicate, thisArg) { if (isArray(collection)) { @@ -5637,8 +5867,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {*} Returns the matched element, else `undefined`. * @example @@ -5656,6 +5885,11 @@ * source object, returning the first element that has equivalent property * values. * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. For comparing a single + * own or inherited property value see `_.matchesProperty`. + * * @static * @memberOf _ * @category Collection @@ -5665,14 +5899,14 @@ * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'status': 'busy' }, - * { 'user': 'fred', 'age': 40, 'status': 'busy' } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * - * _.result(_.findWhere(users, { 'status': 'busy' }), 'user'); + * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user'); * // => 'barney' * - * _.result(_.findWhere(users, { 'age': 40 }), 'user'); + * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user'); * // => 'fred' */ function findWhere(collection, source) { @@ -5741,10 +5975,14 @@ * The `iteratee` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5753,8 +5991,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Object} Returns the composed aggregate object. * @example @@ -5765,7 +6002,7 @@ * _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math); * // => { '4': [4.2], '6': [6.1, 6.4] } * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ @@ -5784,10 +6021,14 @@ * iteratee function is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5796,8 +6037,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Object} Returns the composed aggregate object. * @example @@ -5851,21 +6091,34 @@ * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three * arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * + * Many lodash methods are guarded to work as interatees for methods like + * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. + * + * The guarded methods are: + * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`, + * `dropRight`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, `slice`, + * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`, + * `trunc`, `random`, `range`, `sample`, `uniq`, and `words` + * * @static * @memberOf _ * @alias collect * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. + * create a `_.property` or `_.matches` style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Array} Returns the new mapped array. * @example @@ -5881,7 +6134,7 @@ * { 'user': 'fred' } * ]; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.map(users, 'user'); * // => ['barney', 'fred'] */ @@ -5898,10 +6151,14 @@ * is ranked. The `iteratee` is bound to `thisArg` and invoked with three * arguments; (value, index, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5910,8 +6167,6 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee] The function invoked per iteration. - * If a property name or object is provided it is used to create a "_.property" - * or "_.matches" style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {*} Returns the maximum value. * @example @@ -5930,7 +6185,7 @@ * _.max(users, function(chr) { return chr.age; }); * // => { 'user': 'fred', 'age': 40 }; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.max(users, 'age'); * // => { 'user': 'fred', 'age': 40 }; */ @@ -5943,10 +6198,14 @@ * is ranked. The `iteratee` is bound to `thisArg` and invoked with three * arguments; (value, index, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5955,8 +6214,6 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee] The function invoked per iteration. - * If a property name or object is provided it is used to create a "_.property" - * or "_.matches" style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {*} Returns the minimum value. * @example @@ -5975,7 +6232,7 @@ * _.min(users, function(chr) { return chr.age; }); * // => { 'user': 'barney', 'age': 36 }; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.min(users, 'age'); * // => { 'user': 'barney', 'age': 36 }; */ @@ -5987,10 +6244,14 @@ * contains elements `predicate` returns falsey for. The predicate is bound * to `thisArg` and invoked with three arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5999,8 +6260,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the array of grouped elements. * @example @@ -6017,12 +6277,18 @@ * { 'user': 'pebbles', 'age': 1, 'active': false } * ]; * - * // using the "_.matches" callback shorthand - * _.map(_.partition(users, { 'age': 1 }), function(array) { return _.pluck(array, 'user'); }); + * var mapper = function(array) { return _.pluck(array, 'user'); }; + * + * // using the `_.matches` callback shorthand + * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper); * // => [['pebbles'], ['barney', 'fred']] * - * // using the "_.property" callback shorthand - * _.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'user'); }); + * // using the `_.matchesProperty` callback shorthand + * _.map(_.partition(users, 'active', false), mapper); + * // => [['barney', 'pebbles'], ['fred']] + * + * // using the `_.property` callback shorthand + * _.map(_.partition(users, 'active'), mapper); * // => [['fred'], ['barney', 'pebbles']] */ var partition = createAggregator(function(result, value, key) { @@ -6053,7 +6319,7 @@ * // => [36, 40] (iteration order is not guaranteed) */ function pluck(collection, key) { - return map(collection, baseProperty(key + '')); + return map(collection, baseProperty(key)); } /** @@ -6064,6 +6330,12 @@ * value. The `iteratee` is bound to `thisArg`and invoked with four arguments; * (accumulator, value, index|key, collection). * + * Many lodash methods are guarded to work as interatees for methods like + * `_.reduce`, `_.reduceRight`, and `_.transform`. + * + * The guarded methods are: + * `assign`, `defaults`, `merge`, and `sortAllBy` + * * @static * @memberOf _ * @alias foldl, inject @@ -6117,10 +6389,14 @@ * The opposite of `_.filter`; this method returns the elements of `collection` * that `predicate` does **not** return truthy for. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6129,8 +6405,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the new filtered array. * @example @@ -6143,13 +6418,17 @@ * { 'user': 'fred', 'age': 40, 'active': true } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.reject(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user'); * // => ['barney'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.reject(users, { 'age': 36 }), 'user'); + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.reject(users, 'active', false), 'user'); * // => ['fred'] + * + * // using the `_.property` callback shorthand + * _.pluck(_.reject(users, 'active'), 'user'); + * // => ['barney'] */ function reject(collection, predicate, thisArg) { var func = isArray(collection) ? arrayFilter : baseFilter; @@ -6251,10 +6530,14 @@ * over the entire collection. The predicate is bound to `thisArg` and invoked * with three arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6264,8 +6547,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {boolean} Returns `true` if any element passes the predicate check, * else `false`. @@ -6275,17 +6557,21 @@ * // => true * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true } + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.some(users, 'active'); + * // using the `_.matches` callback shorthand + * _.some(users, { user': 'barney', 'active': false }); + * // => false + * + * // using the `_.matchesProperty` callback shorthand + * _.some(users, 'active', false); * // => true * - * // using the "_.matches" callback shorthand - * _.some(users, { 'age': 1 }); - * // => false + * // using the `_.property` callback shorthand + * _.some(users, 'active'); + * // => true */ function some(collection, predicate, thisArg) { var func = isArray(collection) ? arraySome : baseSome; @@ -6302,10 +6588,14 @@ * The `iteratee` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6315,7 +6605,7 @@ * @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Function|Object|string} [iteratee=_.identity] The function * invoked per iteration. If a property name or an object is provided it is - * used to create a "_.property" or "_.matches" style callback respectively. + * used to create a `_.property` or `_.matches` style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Array} Returns the new sorted array. * @example @@ -6332,7 +6622,7 @@ * { 'user': 'barney' } * ]; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.pluck(_.sortBy(users, 'user'), 'user'); * // => ['barney', 'fred', 'pebbles'] */ @@ -6384,7 +6674,7 @@ props = baseFlatten(args, false, false, 1), result = isLength(length) ? Array(length) : []; - baseEach(collection, function(value, key, collection) { + baseEach(collection, function(value) { var length = props.length, criteria = Array(length); @@ -6401,6 +6691,11 @@ * source object, returning an array of all elements that have equivalent * property values. * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. For comparing a single + * own or inherited property value see `_.matchesProperty`. + * * @static * @memberOf _ * @category Collection @@ -6410,18 +6705,15 @@ * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] }, - * { 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] } + * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] }, + * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] } * ]; * - * _.pluck(_.where(users, { 'age': 36 }), 'user'); + * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user'); * // => ['barney'] * * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user'); * // => ['fred'] - * - * _.pluck(_.where(users, { 'status': 'busy' }), 'user'); - * // => ['barney', 'fred'] */ function where(collection, source) { return filter(collection, baseMatches(source)); @@ -6471,8 +6763,8 @@ * // => logs 'done saving!' after the two async saves have completed */ function after(n, func) { - if (!isFunction(func)) { - if (isFunction(n)) { + if (typeof func != 'function') { + if (typeof n == 'function') { var temp = n; n = func; func = temp; @@ -6530,8 +6822,8 @@ */ function before(n, func) { var result; - if (!isFunction(func)) { - if (isFunction(n)) { + if (typeof func != 'function') { + if (typeof n == 'function') { var temp = n; n = func; func = temp; @@ -6853,7 +7145,7 @@ maxWait = false, trailing = true; - if (!isFunction(func)) { + if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } wait = wait < 0 ? 0 : wait; @@ -7023,7 +7315,7 @@ length = funcs.length; if (!length) { - return function() {}; + return function() { return arguments[0]; }; } if (!arrayEvery(funcs, isFunction)) { throw new TypeError(FUNC_ERROR_TEXT); @@ -7068,7 +7360,7 @@ fromIndex = funcs.length - 1; if (fromIndex < 0) { - return function() {}; + return function() { return arguments[0]; }; } if (!arrayEvery(funcs, isFunction)) { throw new TypeError(FUNC_ERROR_TEXT); @@ -7138,7 +7430,7 @@ * // => { 'user': 'barney' } */ function memoize(func, resolver) { - if (!isFunction(func) || (resolver && !isFunction(resolver))) { + if (typeof func != 'function' || (resolver && typeof resolver != 'function')) { throw new TypeError(FUNC_ERROR_TEXT); } var memoized = function() { @@ -7176,7 +7468,7 @@ * // => [1, 3, 5] */ function negate(predicate) { - if (!isFunction(predicate)) { + if (typeof predicate != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } return function() { @@ -7191,7 +7483,6 @@ * * @static * @memberOf _ - * @type Function * @category Function * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. @@ -7314,6 +7605,45 @@ return createWrapper(func, REARG_FLAG, null, null, null, indexes); } + /** + * Creates a function that invokes `func` with the `this` binding of the + * created function and the array of arguments provided to the created + * function much like [Function#apply](http://es5.github.io/#x15.3.4.3). + * + * @static + * @memberOf _ + * @category Function + * @param {Function} func The function to spread arguments over. + * @returns {*} Returns the new function. + * @example + * + * var spread = _.spread(function(who, what) { + * return who + ' says ' + what; + * }); + * + * spread(['Fred', 'hello']); + * // => 'Fred says hello' + * + * // with a Promise + * var numbers = Promise.all([ + * Promise.resolve(40), + * Promise.resolve(36) + * ]); + * + * numbers.then(_.spread(function(x, y) { + * return x + y; + * })); + * // => a Promise of 76 + */ + function spread(func) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + return function(array) { + return func.apply(this, array); + }; + } + /** * Creates a function that only invokes `func` at most once per every `wait` * milliseconds. The created function comes with a `cancel` method to cancel @@ -7356,7 +7686,7 @@ var leading = true, trailing = true; - if (!isFunction(func)) { + if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } if (options === false) { @@ -7662,7 +7992,8 @@ * arguments; (value, other [, index|key]). * * **Note:** This method supports comparing arrays, booleans, `Date` objects, - * numbers, `Object` objects, regexes, and strings. Functions and DOM nodes + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. Functions and DOM nodes * are **not** supported. Provide a customizer function to extend support * for comparing other values. * @@ -7832,7 +8163,7 @@ * @static * @memberOf _ * @category Lang - * @param {Object} source The object to inspect. + * @param {Object} object The object to inspect. * @param {Object} source The object of property values to match. * @param {Function} [customizer] The function to customize comparing values. * @param {*} [thisArg] The `this` binding of `customizer`. @@ -8258,10 +8589,14 @@ * This method is like `_.findIndex` except that it returns the key of the * first element `predicate` returns truthy for, instead of the element itself. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -8270,8 +8605,7 @@ * @category Object * @param {Object} object The object to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {string|undefined} Returns the key of the matched element, else `undefined`. * @example @@ -8285,11 +8619,15 @@ * _.findKey(users, function(chr) { return chr.age < 40; }); * // => 'barney' (iteration order is not guaranteed) * - * // using the "_.matches" callback shorthand - * _.findKey(users, { 'age': 1 }); + * // using the `_.matches` callback shorthand + * _.findKey(users, { 'age': 1, 'active': true }); * // => 'pebbles' * - * // using the "_.property" callback shorthand + * // using the `_.matchesProperty` callback shorthand + * _.findKey(users, 'active', false); + * // => 'fred' + * + * // using the `_.property` callback shorthand * _.findKey(users, 'active'); * // => 'barney' */ @@ -8302,10 +8640,14 @@ * This method is like `_.findKey` except that it iterates over elements of * a collection in the opposite order. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -8314,8 +8656,7 @@ * @category Object * @param {Object} object The object to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {string|undefined} Returns the key of the matched element, else `undefined`. * @example @@ -8329,11 +8670,15 @@ * _.findLastKey(users, function(chr) { return chr.age < 40; }); * // => returns `pebbles` assuming `_.findKey` returns `barney` * - * // using the "_.matches" callback shorthand - * _.findLastKey(users, { 'age': 36 }); + * // using the `_.matches` callback shorthand + * _.findLastKey(users, { 'age': 36, 'active': true }); * // => 'barney' * - * // using the "_.property" callback shorthand + * // using the `_.matchesProperty` callback shorthand + * _.findLastKey(users, 'active', false); + * // => 'fred' + * + * // using the `_.property` callback shorthand * _.findLastKey(users, 'active'); * // => 'pebbles' */ @@ -8620,7 +8965,7 @@ var Ctor = object.constructor, index = -1, - isProto = typeof Ctor == 'function' && Ctor.prototype == object, + isProto = typeof Ctor == 'function' && Ctor.prototype === object, result = Array(length), skipIndexes = length > 0; @@ -8642,10 +8987,14 @@ * iteratee function is bound to `thisArg` and invoked with three arguments; * (value, key, object). * - * If a property name is provided for `iteratee` the created "_.property" + * If a property name is provided for `iteratee` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `iteratee` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `iteratee` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -8654,8 +9003,7 @@ * @category Object * @param {Object} object The object to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Object} Returns the new mapped object. * @example @@ -8668,7 +9016,7 @@ * 'pebbles': { 'user': 'pebbles', 'age': 1 } * }; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.mapValues(users, 'age'); * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) */ @@ -8913,7 +9261,7 @@ if (isArr) { accumulator = isArray(object) ? new Ctor : []; } else { - accumulator = baseCreate(typeof Ctor == 'function' && Ctor.prototype); + accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype); } } else { accumulator = {}; @@ -9743,7 +10091,7 @@ return string; } if (guard ? isIterateeCall(value, chars, guard) : chars == null) { - return string.slice(trimmedLeftIndex(string)) + return string.slice(trimmedLeftIndex(string)); } return string.slice(charsLeftIndex(string, (chars + ''))); } @@ -9773,7 +10121,7 @@ return string; } if (guard ? isIterateeCall(value, chars, guard) : chars == null) { - return string.slice(0, trimmedRightIndex(string) + 1) + return string.slice(0, trimmedRightIndex(string) + 1); } return string.slice(0, charsRightIndex(string, (chars + '')) + 1); } @@ -9916,8 +10264,8 @@ /*------------------------------------------------------------------------*/ /** - * Attempts to invoke `func`, returning either the result or the caught - * error object. + * Attempts to invoke `func`, returning either the result or the caught error + * object. Any additional arguments are provided to `func` when it is invoked. * * @static * @memberOf _ @@ -9927,9 +10275,9 @@ * @example * * // avoid throwing errors for invalid selectors - * var elements = _.attempt(function() { + * var elements = _.attempt(function(selector) { * return document.querySelectorAll(selector); - * }); + * }, '>_>'); * * if (_.isError(elements)) { * elements = []; @@ -9937,17 +10285,18 @@ */ function attempt(func) { try { - return func(); + return func.apply(undefined, baseSlice(arguments, 1)); } catch(e) { - return isError(e) ? e : Error(e); + return isError(e) ? e : new Error(e); } } /** - * Creates a function bound to an optional `thisArg`. If `func` is a property - * name the created callback returns the property value for a given element. - * If `func` is an object the created callback returns `true` for elements - * that contain the equivalent object properties, otherwise it returns `false`. + * Creates a function that invokes `func` with the `this` binding of `thisArg` + * and arguments of the created function. If `func` is a property name the + * created callback returns the property value for a given element. If `func` + * is an object the created callback returns `true` for elements that contain + * the equivalent object properties, otherwise it returns `false`. * * @static * @memberOf _ @@ -10031,6 +10380,11 @@ * and `source`, returning `true` if the given object has equivalent property * values, else `false`. * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. For comparing a single + * own or inherited property value see `_.matchesProperty`. + * * @static * @memberOf _ * @category Utility @@ -10039,22 +10393,46 @@ * @example * * var users = [ - * { 'user': 'fred', 'age': 40 }, - * { 'user': 'barney', 'age': 36 } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * - * var matchesAge = _.matches({ 'age': 36 }); - * - * _.filter(users, matchesAge); - * // => [{ 'user': 'barney', 'age': 36 }] - * - * _.find(users, matchesAge); - * // => { 'user': 'barney', 'age': 36 } + * _.filter(users, _.matches({ 'age': 40, 'active': false })); + * // => [{ 'user': 'fred', 'age': 40, 'active': false }] */ function matches(source) { return baseMatches(baseClone(source, true)); } + /** + * Creates a function which compares the property value of `key` on a given + * object to `value`. + * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. + * + * @static + * @memberOf _ + * @category Utility + * @param {string} key The key of the property to get. + * @param {*} value The value to compare. + * @returns {Function} Returns the new function. + * @example + * + * var users = [ + * { 'user': 'barney' }, + * { 'user': 'fred' }, + * { 'user': 'pebbles' } + * ]; + * + * _.find(users, _.matchesProperty('user', 'fred')); + * // => { 'user': 'fred', 'age': 40 } + */ + function matchesProperty(key, value) { + return baseMatchesProperty(key + '', baseClone(value, true)); + } + /** * Adds all own enumerable function properties of a source object to the * destination object. If `object` is a function then methods are added to @@ -10077,6 +10455,9 @@ * }); * } * + * // use `_.runInContext` to avoid potential conflicts (esp. in Node.js) + * var _ = require('lodash').runInContext(); + * * _.mixin({ 'vowels': vowels }); * _.vowels('fred'); * // => ['e'] @@ -10351,7 +10732,11 @@ /*------------------------------------------------------------------------*/ // Ensure `new LodashWrapper` is an instance of `lodash`. - LodashWrapper.prototype = lodash.prototype; + LodashWrapper.prototype = baseCreate(lodash.prototype); + + // Ensure `new LazyWraper` is an instance of `LodashWrapper` + LazyWrapper.prototype = baseCreate(LodashWrapper.prototype); + LazyWrapper.prototype.constructor = LazyWrapper; // Add functions to the `Map` cache. MapCache.prototype['delete'] = mapDelete; @@ -10392,6 +10777,7 @@ lodash.dropRight = dropRight; lodash.dropRightWhile = dropRightWhile; lodash.dropWhile = dropWhile; + lodash.fill = fill; lodash.filter = filter; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; @@ -10415,6 +10801,7 @@ lodash.map = map; lodash.mapValues = mapValues; lodash.matches = matches; + lodash.matchesProperty = matchesProperty; lodash.memoize = memoize; lodash.merge = merge; lodash.mixin = mixin; @@ -10440,6 +10827,7 @@ lodash.slice = slice; lodash.sortBy = sortBy; lodash.sortByAll = sortByAll; + lodash.spread = spread; lodash.take = take; lodash.takeRight = takeRight; lodash.takeRightWhile = takeRightWhile; @@ -10613,14 +11001,15 @@ // Add `LazyWrapper` methods that accept an `iteratee` value. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) { - var isFilter = index == LAZY_FILTER_FLAG; + var isFilter = index == LAZY_FILTER_FLAG, + isWhile = index == LAZY_WHILE_FLAG; LazyWrapper.prototype[methodName] = function(iteratee, thisArg) { var result = this.clone(), - filtered = result.filtered, - iteratees = result.iteratees || (result.iteratees = []); + filtered = result.__filtered__, + iteratees = result.__iteratees__ || (result.__iteratees__ = []); - result.filtered = filtered || isFilter || (index == LAZY_WHILE_FLAG && result.dir < 0); + result.__filtered__ = filtered || isFilter || (isWhile && result.__dir__ < 0); iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 3), 'type': index }); return result; }; @@ -10628,19 +11017,19 @@ // Add `LazyWrapper` methods for `_.drop` and `_.take` variants. arrayEach(['drop', 'take'], function(methodName, index) { - var countName = methodName + 'Count', + var countName = '__' + methodName + 'Count__', whileName = methodName + 'While'; LazyWrapper.prototype[methodName] = function(n) { - n = n == null ? 1 : nativeMax(+n || 0, 0); + n = n == null ? 1 : nativeMax(floor(n) || 0, 0); var result = this.clone(); - if (result.filtered) { + if (result.__filtered__) { var value = result[countName]; result[countName] = index ? nativeMin(value, n) : (value + n); } else { - var views = result.views || (result.views = []); - views.push({ 'size': n, 'type': methodName + (result.dir < 0 ? 'Right' : '') }); + var views = result.__views__ || (result.__views__ = []); + views.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') }); } return result; }; @@ -10656,7 +11045,7 @@ // Add `LazyWrapper` methods for `_.first` and `_.last`. arrayEach(['first', 'last'], function(methodName, index) { - var takeName = 'take' + (index ? 'Right': ''); + var takeName = 'take' + (index ? 'Right' : ''); LazyWrapper.prototype[methodName] = function() { return this[takeName](1).value()[0]; @@ -10678,27 +11067,26 @@ createCallback = index ? baseMatches : baseProperty; LazyWrapper.prototype[methodName] = function(value) { - return this[operationName](createCallback(index ? value : (value + ''))); + return this[operationName](createCallback(value)); }; }); - LazyWrapper.prototype.dropWhile = function(iteratee, thisArg) { - var done, - lastIndex, - isRight = this.dir < 0; + LazyWrapper.prototype.compact = function() { + return this.filter(identity); + }; - iteratee = getCallback(iteratee, thisArg, 3); + LazyWrapper.prototype.dropWhile = function(predicate, thisArg) { + var done; + predicate = getCallback(predicate, thisArg, 3); return this.filter(function(value, index, array) { - done = done && (isRight ? index < lastIndex : index > lastIndex); - lastIndex = index; - return done || (done = !iteratee(value, index, array)); + return done || (done = !predicate(value, index, array)); }); }; - LazyWrapper.prototype.reject = function(iteratee, thisArg) { - iteratee = getCallback(iteratee, thisArg, 3); + LazyWrapper.prototype.reject = function(predicate, thisArg) { + predicate = getCallback(predicate, thisArg, 3); return this.filter(function(value, index, array) { - return !iteratee(value, index, array); + return !predicate(value, index, array); }); }; @@ -10713,6 +11101,10 @@ return result; }; + LazyWrapper.prototype.toArray = function() { + return this.drop(0); + }; + // Add `LazyWrapper` methods to `lodash.prototype`. baseForOwn(LazyWrapper.prototype, function(func, methodName) { var lodashFunc = lodash[methodName], @@ -10740,8 +11132,8 @@ var wrapper = onlyLazy ? value : new LazyWrapper(this), result = func.apply(wrapper, args); - if (!retUnwrapped && (isHybrid || result.actions)) { - var actions = result.actions || (result.actions = []); + if (!retUnwrapped && (isHybrid || result.__actions__)) { + var actions = result.__actions__ || (result.__actions__ = []); actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash }); } return new LodashWrapper(result, chainAll); @@ -10774,9 +11166,11 @@ // Add chaining functions to the lodash wrapper. lodash.prototype.chain = wrapperChain; + lodash.prototype.commit = wrapperCommit; + lodash.prototype.plant = wrapperPlant; lodash.prototype.reverse = wrapperReverse; lodash.prototype.toString = wrapperToString; - lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; + lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; // Add function aliases to the lodash wrapper. lodash.prototype.collect = lodash.prototype.map; diff --git a/lodash.min.js b/lodash.min.js index b83eca6055..e29d33a988 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -1,85 +1,88 @@ /** * @license - * lodash 3.1.0 (Custom Build) lodash.com/license | Underscore.js 1.7.0 underscorejs.org/LICENSE + * lodash 3.2.0 (Custom Build) lodash.com/license | Underscore.js 1.7.0 underscorejs.org/LICENSE * Build: `lodash modern -o ./lodash.js` */ ;(function(){function n(n,t){if(n!==t){var r=n===n,e=t===t;if(n>t||!r||typeof n=="undefined"&&e)return 1;if(n=n&&9<=n&&13>=n||32==n||160==n||5760==n||6158==n||8192<=n&&(8202>=n||8232==n||8233==n||8239==n||8287==n||12288==n||65279==n) -}function v(n,t){for(var r=-1,e=n.length,u=-1,o=[];++re&&(e=u)}return e}function Yt(n,t,r,e){var u=-1,o=n.length;for(e&&o&&(r=n[++u]);++ui(r,f)&&u.push(f);return u}function or(n,t){var r=n?n.length:0;if(!ue(r))return gr(n,t);for(var e=-1,u=se(n);++et&&(t=-t>u?0:u+t),r=typeof r=="undefined"||r>u?u:+r||0,0>r&&(r+=u),u=t>r?0:r-t>>>0,t>>>=0,r=_u(u);++eu(f,s)&&((r||a)&&f.push(s),c.push(l))}return c}function Or(n,t){for(var r=-1,e=t.length,u=_u(e);++r>>1,i=n[o]; -(r?i<=t:it||null==r)return r;if(3=o&&a<=i&&(e=O&&t>u||e>u&&t>=O)||o)&&(t&x&&(r[2]=p[2],a|=e&x?0:j),(e=p[3])&&(u=r[3],r[3]=u?Ur(u,e,p[4]):zt(e),r[4]=u?v(r[3],B):zt(p[4])),(e=p[5])&&(u=r[5],r[5]=u?Fr(u,e,p[6]):zt(e),r[6]=u?v(r[5],B):zt(p[6])),(e=p[7])&&(r[7]=zt(e)),t&C&&(r[8]=null==r[8]?p[8]:eo(r[8],p[8])),null==r[9]&&(r[9]=p[9]),r[0]=p[0],r[1]=a),t=r[1],a=r[9]}return r[9]=null==a?f?0:n.length:ro(a-c,0)||0,(p?mo:xo)(t==x?Br(r[0],r[2]):t!=R&&t!=(x|R)||r[4].length?qr.apply(null,r):Kr.apply(null,r),r) -}function Yr(n,t,r,e,u,o,i){var a=-1,f=n.length,c=t.length,l=true;if(f!=c&&(!u||c<=f))return false;for(;l&&++au)||i===e&&i===o)&&(u=i,o=n) -}),o}function Xr(n,t,r){var e=Wt.callback||pu,e=e===pu?tr:e;return r?e(n,t,r):e}function Hr(n,r,e){var u=Wt.indexOf||de,u=u===de?t:u;return n?u(n,r,e):u}function Qr(n){var t=n.length,r=new n.constructor(t);return t&&"string"==typeof n[0]&&Wu.call(n,"index")&&(r.index=n.index,r.input=n.input),r}function ne(n){return n=n.constructor,typeof n=="function"&&n instanceof n||(n=ju),new n}function te(n,t,r){var e=n.constructor;switch(t){case J:return Nr(n);case M:case q:return new e(+n);case X:case H:case Q:case nt:case tt:case rt:case et:case ut:case ot:return t=n.buffer,new e(r?Nr(t):t,n.byteOffset,n.length); -case V:case G:return new e(n);case Z:var u=new e(n.source,yt.exec(n));u.lastIndex=n.lastIndex}return u}function re(n,t){return n=+n,t=null==t?go:t,-1t?0:t)):[]}function he(n,t,r){var e=n?n.length:0;return e?((r?ee(n,t,r):null==t)&&(t=1),t=e-(+t||0),Er(n,0,0>t?0:t)):[]}function ge(n,t,r){var e=-1,u=n?n.length:0;for(t=Xr(t,r,3);++ee?ro(u+e,0):e||0;else if(e)return e=Tr(n,r),n=n[e],(r===r?r===n:n!==n)?e:-1; -return t(n,r,e)}function ye(n){return pe(n,1)}function _e(n,r,e,u){if(!n||!n.length)return[];typeof r!="boolean"&&null!=r&&(u=e,e=ee(n,r,u)?null:r,r=false);var o=Xr();if((o!==tr||null!=e)&&(e=o(e,u,3)),r&&Hr()==t){r=e;var i;e=-1,u=n.length;for(var o=-1,a=[];++e>>0,e=_u(r);++tr?ro(e+r,0):r||0:0,typeof n=="string"||!Co(n)&&Qe(n)?rarguments.length,or)}function Te(n,t,r,e){return(Co(n)?Zt:kr)(n,Xr(t,e,4),r,3>arguments.length,ir)}function Se(n,t,r){return(r?ee(n,t,r):null==t)?(n=le(n),t=n.length,0t?0:+t||0,n.length),n) -}function We(n){n=le(n);for(var t=-1,r=n.length,e=_u(r);++t=r||r>t?(a&&Du(a),r=p,a=s=p=b,r&&(h=Oo(),f=n.apply(l,i),s||a||(i=l=null))):s=Yu(e,r)}function u(){s&&Du(s),a=s=p=b,(v||g!==t)&&(h=Oo(),f=n.apply(l,i),s||a||(i=l=null)) -}function o(){if(i=arguments,c=Oo(),l=this,p=v&&(s||!d),false===g)var r=d&&!s;else{a||d||(h=c);var o=g-(c-h),y=0>=o||o>g;y?(a&&(a=Du(a)),h=c,f=n.apply(l,i)):a||(a=Yu(u,o))}return y&&s?s=Du(s):s||t===g||(s=Yu(e,t)),r&&(y=true,f=n.apply(l,i)),!y||s||a||(i=l=null),f}var i,a,f,c,l,s,p,h=0,g=false,v=true;if(!Ze(n))throw new Ru($);if(t=0>t?0:t,true===r)var d=true,v=false;else Ge(r)&&(d=r.leading,g="maxWait"in r&&ro(+r.maxWait||0,t),v="trailing"in r?r.trailing:v);return o.cancel=function(){s&&Du(s),a&&Du(a),a=s=p=b},o}function De(){var n=arguments,t=n.length-1; -if(0>t)return function(){};if(!qt(n,Ze))throw new Ru($);return function(){for(var r=t,e=n[r].apply(this,arguments);r--;)e=n[r].call(this,e);return e}}function Me(n,t){function r(){var e=r.cache,u=t?t.apply(this,arguments):arguments[0];if(e.has(u))return e.get(u);var o=n.apply(this,arguments);return e.set(u,o),o}if(!Ze(n)||t&&!Ze(t))throw new Ru($);return r.cache=new Me.Cache,r}function qe(n){var t=Er(arguments,1),r=v(t,qe.placeholder);return Vr(n,R,null,t,r)}function Pe(n){var t=Er(arguments,1),r=v(t,Pe.placeholder); -return Vr(n,I,null,t,r)}function Ke(n){return ue(h(n)?n.length:b)&&Uu.call(n)==z||false}function Ve(n){return n&&1===n.nodeType&&h(n)&&-1t||!n||!no(t))return r;do t%2&&(r+=n),t=Mu(t/2),n+=n;while(t);return r}function cu(n,t,r){var u=n;return(n=e(n))?(r?ee(u,t,r):null==t)?n.slice(d(n),y(n)+1):(t+="",n.slice(o(n,t),i(n,t)+1)):n}function lu(n,t,r){return r&&ee(n,t,r)&&(t=null),n=e(n),n.match(t||Rt)||[] -}function su(n){try{return n()}catch(t){return Ye(t)?t:bu(t)}}function pu(n,t,r){return r&&ee(n,t,r)&&(t=null),h(n)?vu(n):tr(n,t)}function hu(n){return function(){return n}}function gu(n){return n}function vu(n){return wr(rr(n,true))}function du(n,t,r){if(null==r){var e=Ge(t),u=e&&No(t);((u=u&&u.length&&dr(t,u))?u.length:e)||(u=false,r=t,t=n,n=this)}u||(u=dr(t,No(t)));var o=true,e=-1,i=Ze(n),a=u.length;false===r?o=false:Ge(r)&&"chain"in r&&(o=r.chain);for(;++e>>1,ho=Xu?Xu.BYTES_PER_ELEMENT:0,go=xu.pow(2,53)-1,vo=Ju&&new Ju,yo=Wt.support={};!function(n){yo.funcDecomp=!Je(g.WinRTError)&&kt.test(m),yo.funcNames=typeof wu.name=="string";try{yo.dom=11===Cu.createDocumentFragment().nodeType -}catch(t){yo.dom=false}try{yo.nonEnumArgs=!Ku.call(arguments,1)}catch(r){yo.nonEnumArgs=true}}(0,0),Wt.templateSettings={escape:ht,evaluate:gt,interpolate:vt,variable:"",imports:{_:Wt}};var _o=function(){function n(){}return function(t){if(Ge(t)){n.prototype=t;var r=new n;n.prototype=null}return r||g.Object()}}(),mo=vo?function(n,t){return vo.set(n,t),n}:gu;Bu||(Nr=$u&&Gu?function(n){var t=n.byteLength,r=Xu?Mu(t/ho):0,e=r*ho,u=new $u(t);if(r){var o=new Xu(u,0,r);o.set(new Xu(n,0,r))}return t!=e&&(o=new Gu(u,e),o.set(new Gu(n,e))),u -}:hu(null));var bo=Qu&&Vu?function(n){return new Lt(n)}:hu(null),wo=vo?function(n){return vo.get(n)}:yu,xo=function(){var n=0,t=0;return function(r,e){var u=Oo(),o=N-(u-t);if(t=u,0=W)return r}else n=0;return mo(r,e)}}(),Ao=Lr(function(n,t,r){Wu.call(n,r)?++n[r]:n[r]=1}),jo=Lr(function(n,t,r){Wu.call(n,r)?n[r].push(t):n[r]=[t]}),ko=Lr(function(n,t,r){n[r]=t}),Eo=Mr(Vt),Ro=Mr(function(n){for(var t=-1,r=n.length,e=co;++t--n?t.apply(this,arguments):void 0}},Wt.ary=function(n,t,r){return r&&ee(n,t,r)&&(t=null),t=n&&null==t?n.length:ro(+t||0,0),Vr(n,C,null,null,null,null,t)},Wt.assign=Wo,Wt.at=function(n){return ue(n?n.length:0)&&(n=le(n)),Qt(n,lr(arguments,false,false,1))},Wt.before=Ue,Wt.bind=Fe,Wt.bindAll=function(n){for(var t=n,r=1(s?Bt(s,a):o(l,a))){for(r=e;--r;){var p=u[r];if(0>(p?Bt(p,a):o(n[r],a)))continue n}s&&s.push(a),l.push(a) -}return l},Wt.invert=function(n,t,r){r&&ee(n,t,r)&&(t=null),r=-1;for(var e=No(n),u=e.length,o={};++rt?0:t)):[] -},Wt.takeRight=function(n,t,r){var e=n?n.length:0;return e?((r?ee(n,t,r):null==t)&&(t=1),t=e-(+t||0),Er(n,0>t?0:t)):[]},Wt.takeRightWhile=function(n,t,r){var e=n?n.length:0;if(!e)return[];for(t=Xr(t,r,3);e--&&t(n[e],e,n););return Er(n,e+1)},Wt.takeWhile=function(n,t,r){var e=n?n.length:0;if(!e)return[];var u=-1;for(t=Xr(t,r,3);++un||!no(n))return[];var e=-1,u=_u(eo(n,lo));for(t=Wr(t,r,1);++er?0:+r||0,u))-t.length,0<=r&&n.indexOf(t,r)==r},Wt.escape=function(n){return(n=e(n))&&pt.test(n)?n.replace(lt,l):n},Wt.escapeRegExp=iu,Wt.every=je,Wt.find=Ee,Wt.findIndex=ge,Wt.findKey=function(n,t,r){return t=Xr(t,r,3),cr(n,t,gr,true) -},Wt.findLast=function(n,t,r){return t=Xr(t,r,3),cr(n,t,ir)},Wt.findLastIndex=function(n,t,r){var e=n?n.length:0;for(t=Xr(t,r,3);e--;)if(t(n[e],e,n))return e;return-1},Wt.findLastKey=function(n,t,r){return t=Xr(t,r,3),cr(n,t,vr,true)},Wt.findWhere=function(n,t){return Ee(n,wr(t))},Wt.first=ve,Wt.has=function(n,t){return n?Wu.call(n,t):false},Wt.identity=gu,Wt.includes=Ae,Wt.indexOf=de,Wt.isArguments=Ke,Wt.isArray=Co,Wt.isBoolean=function(n){return true===n||false===n||h(n)&&Uu.call(n)==M||false},Wt.isDate=function(n){return h(n)&&Uu.call(n)==q||false -},Wt.isElement=Ve,Wt.isEmpty=function(n){if(null==n)return true;var t=n.length;return ue(t)&&(Co(n)||Qe(n)||Ke(n)||h(n)&&Ze(n.splice))?!t:!No(n).length},Wt.isEqual=function(n,t,r,e){return r=typeof r=="function"&&Wr(r,e,3),!r&&oe(n)&&oe(t)?n===t:(e=r?r(n,t):b,typeof e=="undefined"?_r(n,t,r):!!e)},Wt.isError=Ye,Wt.isFinite=To,Wt.isFunction=Ze,Wt.isMatch=function(n,t,r,e){var u=No(t),o=u.length;if(r=typeof r=="function"&&Wr(r,e,3),!r&&1==o){var i=u[0];if(e=t[i],oe(e))return null!=n&&e===n[i]&&Wu.call(n,i) -}for(var i=_u(o),a=_u(o);o--;)e=i[o]=t[u[o]],a[o]=oe(e);return mr(n,u,i,a,r)},Wt.isNaN=function(n){return Xe(n)&&n!=+n},Wt.isNative=Je,Wt.isNull=function(n){return null===n},Wt.isNumber=Xe,Wt.isObject=Ge,Wt.isPlainObject=So,Wt.isRegExp=He,Wt.isString=Qe,Wt.isTypedArray=nu,Wt.isUndefined=function(n){return typeof n=="undefined"},Wt.kebabCase=Lo,Wt.last=function(n){var t=n?n.length:0;return t?n[t-1]:b},Wt.lastIndexOf=function(n,t,r){var e=n?n.length:0;if(!e)return-1;var u=e;if(typeof r=="number")u=(0>r?ro(e+r,0):eo(r||0,e-1))+1; -else if(r)return u=Tr(n,t,true)-1,n=n[u],(t===t?t===n:n!==n)?u:-1;if(t!==t)return p(n,u,true);for(;u--;)if(n[u]===t)return u;return-1},Wt.max=Eo,Wt.min=Ro,Wt.noConflict=function(){return g._=Fu,this},Wt.noop=yu,Wt.now=Oo,Wt.pad=function(n,t,r){n=e(n),t=+t;var u=n.length;return ur?0:+r||0,n.length),n.lastIndexOf(t,r)==r},Wt.template=function(n,t,r){var u=Wt.templateSettings;r&&ee(n,t,r)&&(t=r=null),n=e(n),t=Ht(Ht({},r||t),u,Xt),r=Ht(Ht({},t.imports),u.imports,Xt);var o,i,a=No(r),f=Or(r,a),c=0;r=t.interpolate||xt;var l="__p+='";r=ku((t.escape||xt).source+"|"+r.source+"|"+(r===vt?dt:xt).source+"|"+(t.evaluate||xt).source+"|$","g"); -var p="sourceURL"in t?"//# sourceURL="+t.sourceURL+"\n":"";if(n.replace(r,function(t,r,e,u,a,f){return e||(e=u),l+=n.slice(c,f).replace(Et,s),r&&(o=true,l+="'+__e("+r+")+'"),a&&(i=true,l+="';"+a+";\n__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),c=f+t.length,t}),l+="';",(t=t.variable)||(l="with(obj){"+l+"}"),l=(i?l.replace(it,""):l).replace(at,"$1").replace(ft,"$1;"),l="function("+(t||"obj")+"){"+(t?"":"obj||(obj={});")+"var __t,__p=''"+(o?",__e=_.escape":"")+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}",t=su(function(){return wu(a,p+"return "+l).apply(b,f) -}),t.source=l,Ye(t))throw t;return t},Wt.trim=cu,Wt.trimLeft=function(n,t,r){var u=n;return(n=e(n))?n.slice((r?ee(u,t,r):null==t)?d(n):o(n,t+"")):n},Wt.trimRight=function(n,t,r){var u=n;return(n=e(n))?(r?ee(u,t,r):null==t)?n.slice(0,y(n)+1):n.slice(0,i(n,t+"")+1):n},Wt.trunc=function(n,t,r){r&&ee(n,t,r)&&(t=null);var u=T;if(r=S,null!=t)if(Ge(t)){var o="separator"in t?t.separator:o,u="length"in t?+t.length||0:u;r="omission"in t?e(t.omission):r}else u=+t||0;if(n=e(n),u>=n.length)return n;if(u-=r.length,1>u)return r; -if(t=n.slice(0,u),null==o)return t+r;if(He(o)){if(n.slice(u).search(o)){var i,a=n.slice(0,u);for(o.global||(o=ku(o.source,(yt.exec(o)||"")+"g")),o.lastIndex=0;n=o.exec(a);)i=n.index;t=t.slice(0,null==i?u:i)}}else n.indexOf(o,u)!=u&&(o=t.lastIndexOf(o),-1u.dir,i.push({iteratee:Xr(n,e,3),type:t}),u -}}),Mt(["drop","take"],function(n,t){var r=n+"Count",e=n+"While";Ut.prototype[n]=function(e){e=null==e?1:ro(+e||0,0);var u=this.clone();if(u.filtered){var o=u[r];u[r]=t?eo(o,e):o+e}else(u.views||(u.views=[])).push({size:e,type:n+(0>u.dir?"Right":"")});return u},Ut.prototype[n+"Right"]=function(t){return this.reverse()[n](t).reverse()},Ut.prototype[n+"RightWhile"]=function(n,t){return this.reverse()[e](n,t).reverse()}}),Mt(["first","last"],function(n,t){var r="take"+(t?"Right":"");Ut.prototype[n]=function(){return this[r](1).value()[0] -}}),Mt(["initial","rest"],function(n,t){var r="drop"+(t?"":"Right");Ut.prototype[n]=function(){return this[r](1)}}),Mt(["pluck","where"],function(n,t){var r=t?"filter":"map",e=t?wr:Ar;Ut.prototype[n]=function(n){return this[r](e(t?n:n+""))}}),Ut.prototype.dropWhile=function(n,t){var r,e,u=0>this.dir;return n=Xr(n,t,3),this.filter(function(t,o,i){return r=r&&(u?oe),e=o,r||(r=!n(t,o,i))})},Ut.prototype.reject=function(n,t){return n=Xr(n,t,3),this.filter(function(t,r,e){return!n(t,r,e)})},Ut.prototype.slice=function(n,t){n=null==n?0:+n||0; -var r=0>n?this.takeRight(-n):this.drop(n);return typeof t!="undefined"&&(t=+t||0,r=0>t?r.dropRight(-t):r.take(t-n)),r},gr(Ut.prototype,function(n,t){var r=Wt[t],e=/^(?:first|last)$/.test(t);Wt.prototype[t]=function(){function t(n){return n=[n],Pu.apply(n,o),r.apply(Wt,n)}var u=this.__wrapped__,o=arguments,i=this.__chain__,a=!!this.__actions__.length,f=u instanceof Ut,c=f&&!a;return e&&!i?c?n.call(u):r.call(Wt,this.value()):f||Co(u)?(u=n.apply(c?u:new Ut(this),o),e||!a&&!u.actions||(u.actions||(u.actions=[])).push({func:xe,args:[t],thisArg:Wt}),new Nt(u,i)):this.thru(t) -}}),Mt("concat join pop push shift sort splice unshift".split(" "),function(n){var t=Iu[n],r=/^(?:push|sort|unshift)$/.test(n)?"tap":"thru",e=/^(?:join|pop|shift)$/.test(n);Wt.prototype[n]=function(){var n=arguments;return e&&!this.__chain__?t.apply(this.value(),n):this[r](function(r){return t.apply(r,n)})}}),Ut.prototype.clone=function(){var n=this.actions,t=this.iteratees,r=this.views,e=new Ut(this.wrapped);return e.actions=n?zt(n):null,e.dir=this.dir,e.dropCount=this.dropCount,e.filtered=this.filtered,e.iteratees=t?zt(t):null,e.takeCount=this.takeCount,e.views=r?zt(r):null,e -},Ut.prototype.reverse=function(){if(this.filtered){var n=new Ut(this);n.dir=-1,n.filtered=true}else n=this.clone(),n.dir*=-1;return n},Ut.prototype.value=function(){var n=this.wrapped.value();if(!Co(n))return Cr(n,this.actions);var t,r=this.dir,e=0>r;t=n.length;for(var u=this.views,o=0,i=-1,a=u?u.length:0;++i"'`]/g,st=RegExp(ct.source),pt=RegExp(lt.source),ht=/<%-([\s\S]+?)%>/g,gt=/<%([\s\S]+?)%>/g,vt=/<%=([\s\S]+?)%>/g,dt=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,yt=/\w*$/,_t=/^\s*function[ \n\r\t]+\w/,mt=/^0[xX]/,bt=/^\[object .+?Constructor\]$/,wt=/[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g,xt=/($^)/,At=/[.*+?^${}()|[\]\/\\]/g,jt=RegExp(At.source),kt=/\bthis\b/,Et=/['\n\r\u2028\u2029\\]/g,Rt=RegExp("[A-Z\\xc0-\\xd6\\xd8-\\xde]{2,}(?=[A-Z\\xc0-\\xd6\\xd8-\\xde][a-z\\xdf-\\xf6\\xf8-\\xff]+)|[A-Z\\xc0-\\xd6\\xd8-\\xde]?[a-z\\xdf-\\xf6\\xf8-\\xff]+|[A-Z\\xc0-\\xd6\\xd8-\\xde]+|[0-9]+","g"),It=" \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",Ot="Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout document isFinite parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap window WinRTError".split(" "),Ct={}; +}function i(n,t){for(var r=n.length;r--&&-1=n&&9<=n&&13>=n||32==n||160==n||5760==n||6158==n||8192<=n&&(8202>=n||8232==n||8233==n||8239==n||8287==n||12288==n||65279==n) +}function g(n,t){for(var r=-1,e=n.length,u=-1,o=[];++re&&(e=u)}return e}function Yt(n,t,r,e){var u=-1,o=n.length;for(e&&o&&(r=n[++u]);++ui(r,a)&&u.push(a);return u}function or(n,t){var r=n?n.length:0;if(!oe(r))return _r(n,t);for(var e=-1,u=pe(n);++et&&(t=-t>u?0:u+t),r=typeof r=="undefined"||r>u?u:+r||0,0>r&&(r+=u),u=t>r?0:r-t>>>0,t>>>=0,r=wu(u);++eu(a,s)&&((r||f)&&a.push(s),c.push(l))}return c}function Cr(n,t){for(var r=-1,e=t.length,u=wu(e);++r>>1,i=n[o];(r?i<=t:it||null==r)return r;if(3=o&&f<=i&&(e=O&&t>u||e>u&&t>=O)||o)&&(t&x&&(r[2]=p[2],f|=e&x?0:j),(e=p[3])&&(u=r[3],r[3]=u?Fr(u,e,p[4]):zt(e),r[4]=u?g(r[3],B):zt(p[4])),(e=p[5])&&(u=r[5],r[5]=u?Lr(u,e,p[6]):zt(e),r[6]=u?g(r[5],B):zt(p[6])),(e=p[7])&&(r[7]=zt(e)),t&C&&(r[8]=null==r[8]?p[8]:oo(r[8],p[8])),null==r[9]&&(r[9]=p[9]),r[0]=p[0],r[1]=f),t=r[1],f=r[9] +}return r[9]=null==f?a?0:n.length:uo(f-c,0)||0,(p?bo:jo)(t==x?zr(r[0],r[2]):t!=R&&t!=(x|R)||r[4].length?Pr.apply(w,r):Vr.apply(w,r),r)}function Zr(n,t,r,e,u,o,i){var f=-1,a=n.length,c=t.length,l=true;if(a!=c&&(!u||c<=a))return false;for(;l&&++fu)||i===e&&i===o)&&(u=i,o=n)}),o}function Hr(n,t,r){var e=Wt.callback||_u,e=e===_u?tr:e;return r?e(n,t,r):e}function Qr(n,r,e){var u=Wt.indexOf||de,u=u===de?t:u;return n?u(n,r,e):u}function ne(n){var t=n.length,r=new n.constructor(t);return t&&"string"==typeof n[0]&&Uu.call(n,"index")&&(r.index=n.index,r.input=n.input),r}function te(n){return n=n.constructor,typeof n=="function"&&n instanceof n||(n=Eu),new n +}function re(n,t,r){var e=n.constructor;switch(t){case J:return Ur(n);case M:case q:return new e(+n);case X:case H:case Q:case nt:case tt:case rt:case et:case ut:case ot:return t=n.buffer,new e(r?Ur(t):t,n.byteOffset,n.length);case V:case G:return new e(n);case Z:var u=new e(n.source,yt.exec(n));u.lastIndex=n.lastIndex}return u}function ee(n,t){return n=+n,t=null==t?vo:t,-1t?0:t)):[]}function ge(n,t,r){var e=n?n.length:0; +return e?((r?ue(n,t,r):null==t)&&(t=1),t=e-(+t||0),Rr(n,0,0>t?0:t)):[]}function ve(n,t,r){var e=-1,u=n?n.length:0;for(t=Hr(t,r,3);++ee?uo(u+e,0):e||0;else if(e)return e=Sr(n,r),n=n[e],(r===r?r===n:n!==n)?e:-1;return t(n,r,e)}function me(n){return _e(n,1)}function we(n,r,e,u){if(!n||!n.length)return[];typeof r!="boolean"&&null!=r&&(u=e,e=ue(n,r,u)?null:r,r=false); +var o=Hr();if((o!==tr||null!=e)&&(e=o(e,u,3)),r&&Qr()==t){r=e;var i;e=-1,u=n.length;for(var o=-1,f=[];++e>>0,e=wu(r);++tr?uo(e+r,0):r||0:0,typeof n=="string"||!So(n)&&tu(n)?rarguments.length,or)}function We(n,t,r,e){return(So(n)?Zt:Er)(n,Hr(t,e,4),r,3>arguments.length,ir)}function Ne(n,t,r){return(r?ue(n,t,r):null==t)?(n=se(n),t=n.length,0t?0:+t||0,n.length),n)}function Ue(n){n=se(n); +for(var t=-1,r=n.length,e=wu(r);++t=r||r>t?(f&&qu(f),r=p,f=s=p=w,r&&(h=To(),a=n.apply(l,i),s||f||(i=l=null))):s=Gu(e,r)}function u(){s&&qu(s),f=s=p=w,(g||_!==t)&&(h=To(),a=n.apply(l,i),s||f||(i=l=null)) +}function o(){if(i=arguments,c=To(),l=this,p=g&&(s||!v),false===_)var r=v&&!s;else{f||v||(h=c);var o=_-(c-h),y=0>=o||o>_;y?(f&&(f=qu(f)),h=c,a=n.apply(l,i)):f||(f=Gu(u,o))}return y&&s?s=qu(s):s||t===_||(s=Gu(e,t)),r&&(y=true,a=n.apply(l,i)),!y||s||f||(i=l=null),a}var i,f,a,c,l,s,p,h=0,_=false,g=true;if(typeof n!="function")throw new Ou($);if(t=0>t?0:t,true===r)var v=true,g=false;else Xe(r)&&(v=r.leading,_="maxWait"in r&&uo(+r.maxWait||0,t),g="trailing"in r?r.trailing:g);return o.cancel=function(){s&&qu(s),f&&qu(f),f=s=p=w +},o}function qe(){var n=arguments,t=n.length-1;if(0>t)return function(n){return n};if(!qt(n,Je))throw new Ou($);return function(){for(var r=t,e=n[r].apply(this,arguments);r--;)e=n[r].call(this,e);return e}}function Pe(n,t){function r(){var e=r.cache,u=t?t.apply(this,arguments):arguments[0];if(e.has(u))return e.get(u);var o=n.apply(this,arguments);return e.set(u,o),o}if(typeof n!="function"||t&&typeof t!="function")throw new Ou($);return r.cache=new Pe.Cache,r}function Ke(n){var t=Rr(arguments,1),r=g(t,Ke.placeholder); +return Yr(n,R,null,t,r)}function Ve(n){var t=Rr(arguments,1),r=g(t,Ve.placeholder);return Yr(n,I,null,t,r)}function Ye(n){return oe(h(n)?n.length:w)&&Lu.call(n)==z||false}function Ze(n){return n&&1===n.nodeType&&h(n)&&-1t||!n||!ro(t))return r;do t%2&&(r+=n),t=Pu(t/2),n+=n;while(t);return r}function su(n,t,r){var u=n;return(n=e(n))?(r?ue(u,t,r):null==t)?n.slice(v(n),y(n)+1):(t+="",n.slice(o(n,t),i(n,t)+1)):n +}function pu(n,t,r){return r&&ue(n,t,r)&&(t=null),n=e(n),n.match(t||Rt)||[]}function hu(n){try{return n.apply(w,Rr(arguments,1))}catch(t){return Ge(t)?t:new xu(t)}}function _u(n,t,r){return r&&ue(n,t,r)&&(t=null),h(n)?yu(n):tr(n,t)}function gu(n){return function(){return n}}function vu(n){return n}function yu(n){return br(rr(n,true))}function du(n,t,r){if(null==r){var e=Xe(t),u=e&&Fo(t);((u=u&&u.length&&vr(t,u))?u.length:e)||(u=false,r=t,t=n,n=this)}u||(u=vr(t,Fo(t)));var o=true,e=-1,i=Je(n),f=u.length; +!1===r?o=false:Xe(r)&&"chain"in r&&(o=r.chain);for(;++e>>1,go=Qu?Qu.BYTES_PER_ELEMENT:0,vo=ju.pow(2,53)-1,yo=Hu&&new Hu,mo=Wt.support={};!function(n){mo.funcDecomp=!He(_.WinRTError)&&kt.test(m),mo.funcNames=typeof Au.name=="string";try{mo.dom=11===Su.createDocumentFragment().nodeType +}catch(t){mo.dom=false}try{mo.nonEnumArgs=!Yu.call(arguments,1)}catch(r){mo.nonEnumArgs=true}}(0,0),Wt.templateSettings={escape:ht,evaluate:_t,interpolate:gt,variable:"",imports:{_:Wt}};var wo=function(){function n(){}return function(t){if(Xe(t)){n.prototype=t;var r=new n;n.prototype=null}return r||_.Object()}}(),bo=yo?function(n,t){return yo.set(n,t),n}:vu;Du||(Ur=zu&&Xu?function(n){var t=n.byteLength,r=Qu?Pu(t/go):0,e=r*go,u=new zu(t);if(r){var o=new Qu(u,0,r);o.set(new Qu(n,0,r))}return t!=e&&(o=new Xu(u,e),o.set(new Xu(n,e))),u +}:gu(null));var xo=to&&Zu?function(n){return new Lt(n)}:gu(null),Ao=yo?function(n){return yo.get(n)}:mu,jo=function(){var n=0,t=0;return function(r,e){var u=To(),o=N-(u-t);if(t=u,0=W)return r}else n=0;return bo(r,e)}}(),ko=$r(function(n,t,r){Uu.call(n,r)?++n[r]:n[r]=1}),Eo=$r(function(n,t,r){Uu.call(n,r)?n[r].push(t):n[r]=[t]}),Ro=$r(function(n,t,r){n[r]=t}),Io=qr(Vt),Oo=qr(function(n){for(var t=-1,r=n.length,e=so;++t--n?t.apply(this,arguments):void 0}},Wt.ary=function(n,t,r){return r&&ue(n,t,r)&&(t=null),t=n&&null==t?n.length:uo(+t||0,0),Yr(n,C,null,null,null,null,t)},Wt.assign=Uo,Wt.at=function(n){return oe(n?n.length:0)&&(n=se(n)),Qt(n,lr(arguments,false,false,1))},Wt.before=Le,Wt.bind=$e,Wt.bindAll=function(n){for(var t=n,r=1r&&(r=-r>u?0:u+r),e=typeof e=="undefined"||e>u?u:+e||0,0>e&&(e+=u),u=r>e?0:e>>>0,r>>>=0;r(s?Bt(s,f):o(l,f))){for(r=e;--r;){var p=u[r];if(0>(p?Bt(p,f):o(n[r],f)))continue n}s&&s.push(f),l.push(f)}return l},Wt.invert=function(n,t,r){r&&ue(n,t,r)&&(t=null),r=-1; +for(var e=Fo(n),u=e.length,o={};++rt?0:t)):[]},Wt.takeRight=function(n,t,r){var e=n?n.length:0;return e?((r?ue(n,t,r):null==t)&&(t=1),t=e-(+t||0),Rr(n,0>t?0:t)):[]},Wt.takeRightWhile=function(n,t,r){var e=n?n.length:0;if(!e)return[];for(t=Hr(t,r,3);e--&&t(n[e],e,n););return Rr(n,e+1)},Wt.takeWhile=function(n,t,r){var e=n?n.length:0;if(!e)return[];var u=-1;for(t=Hr(t,r,3);++un||!ro(n))return[];var e=-1,u=wu(oo(n,po));for(t=Nr(t,r,1);++er?0:+r||0,u))-t.length,0<=r&&n.indexOf(t,r)==r},Wt.escape=function(n){return(n=e(n))&&pt.test(n)?n.replace(lt,l):n},Wt.escapeRegExp=au,Wt.every=Ee,Wt.find=Ie,Wt.findIndex=ve,Wt.findKey=function(n,t,r){return t=Hr(t,r,3),cr(n,t,_r,true)},Wt.findLast=function(n,t,r){return t=Hr(t,r,3),cr(n,t,ir)},Wt.findLastIndex=function(n,t,r){var e=n?n.length:0; +for(t=Hr(t,r,3);e--;)if(t(n[e],e,n))return e;return-1},Wt.findLastKey=function(n,t,r){return t=Hr(t,r,3),cr(n,t,gr,true)},Wt.findWhere=function(n,t){return Ie(n,br(t))},Wt.first=ye,Wt.has=function(n,t){return n?Uu.call(n,t):false},Wt.identity=vu,Wt.includes=ke,Wt.indexOf=de,Wt.isArguments=Ye,Wt.isArray=So,Wt.isBoolean=function(n){return true===n||false===n||h(n)&&Lu.call(n)==M||false},Wt.isDate=function(n){return h(n)&&Lu.call(n)==q||false},Wt.isElement=Ze,Wt.isEmpty=function(n){if(null==n)return true;var t=n.length; +return oe(t)&&(So(n)||tu(n)||Ye(n)||h(n)&&Je(n.splice))?!t:!Fo(n).length},Wt.isEqual=function(n,t,r,e){return r=typeof r=="function"&&Nr(r,e,3),!r&&ie(n)&&ie(t)?n===t:(e=r?r(n,t):w,typeof e=="undefined"?dr(n,t,r):!!e)},Wt.isError=Ge,Wt.isFinite=Wo,Wt.isFunction=Je,Wt.isMatch=function(n,t,r,e){var u=Fo(t),o=u.length;if(r=typeof r=="function"&&Nr(r,e,3),!r&&1==o){var i=u[0];if(e=t[i],ie(e))return null!=n&&e===n[i]&&Uu.call(n,i)}for(var i=wu(o),f=wu(o);o--;)e=i[o]=t[u[o]],f[o]=ie(e);return mr(n,u,i,f,r) +},Wt.isNaN=function(n){return Qe(n)&&n!=+n},Wt.isNative=He,Wt.isNull=function(n){return null===n},Wt.isNumber=Qe,Wt.isObject=Xe,Wt.isPlainObject=No,Wt.isRegExp=nu,Wt.isString=tu,Wt.isTypedArray=ru,Wt.isUndefined=function(n){return typeof n=="undefined"},Wt.kebabCase=Bo,Wt.last=function(n){var t=n?n.length:0;return t?n[t-1]:w},Wt.lastIndexOf=function(n,t,r){var e=n?n.length:0;if(!e)return-1;var u=e;if(typeof r=="number")u=(0>r?uo(e+r,0):oo(r||0,e-1))+1;else if(r)return u=Sr(n,t,true)-1,n=n[u],(t===t?t===n:n!==n)?u:-1; +if(t!==t)return p(n,u,true);for(;u--;)if(n[u]===t)return u;return-1},Wt.max=Io,Wt.min=Oo,Wt.noConflict=function(){return _._=$u,this},Wt.noop=mu,Wt.now=To,Wt.pad=function(n,t,r){n=e(n),t=+t;var u=n.length;return ur?0:+r||0,n.length),n.lastIndexOf(t,r)==r +},Wt.template=function(n,t,r){var u=Wt.templateSettings;r&&ue(n,t,r)&&(t=r=null),n=e(n),t=Ht(Ht({},r||t),u,Xt),r=Ht(Ht({},t.imports),u.imports,Xt);var o,i,f=Fo(r),a=Cr(r,f),c=0;r=t.interpolate||xt;var l="__p+='";r=Ru((t.escape||xt).source+"|"+r.source+"|"+(r===gt?vt:xt).source+"|"+(t.evaluate||xt).source+"|$","g");var p="sourceURL"in t?"//# sourceURL="+t.sourceURL+"\n":"";if(n.replace(r,function(t,r,e,u,f,a){return e||(e=u),l+=n.slice(c,a).replace(Et,s),r&&(o=true,l+="'+__e("+r+")+'"),f&&(i=true,l+="';"+f+";\n__p+='"),e&&(l+="'+((__t=("+e+"))==null?'':__t)+'"),c=a+t.length,t +}),l+="';",(t=t.variable)||(l="with(obj){"+l+"}"),l=(i?l.replace(it,""):l).replace(ft,"$1").replace(at,"$1;"),l="function("+(t||"obj")+"){"+(t?"":"obj||(obj={});")+"var __t,__p=''"+(o?",__e=_.escape":"")+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+l+"return __p}",t=hu(function(){return Au(f,p+"return "+l).apply(w,a)}),t.source=l,Ge(t))throw t;return t},Wt.trim=su,Wt.trimLeft=function(n,t,r){var u=n;return(n=e(n))?n.slice((r?ue(u,t,r):null==t)?v(n):o(n,t+"")):n +},Wt.trimRight=function(n,t,r){var u=n;return(n=e(n))?(r?ue(u,t,r):null==t)?n.slice(0,y(n)+1):n.slice(0,i(n,t+"")+1):n},Wt.trunc=function(n,t,r){r&&ue(n,t,r)&&(t=null);var u=T;if(r=S,null!=t)if(Xe(t)){var o="separator"in t?t.separator:o,u="length"in t?+t.length||0:u;r="omission"in t?e(t.omission):r}else u=+t||0;if(n=e(n),u>=n.length)return n;if(u-=r.length,1>u)return r;if(t=n.slice(0,u),null==o)return t+r;if(nu(o)){if(n.slice(u).search(o)){var i,f=n.slice(0,u);for(o.global||(o=Ru(o.source,(yt.exec(o)||"")+"g")),o.lastIndex=0;n=o.exec(f);)i=n.index; +t=t.slice(0,null==i?u:i)}}else n.indexOf(o,u)!=u&&(o=t.lastIndexOf(o),-1o.__dir__,f.push({iteratee:Hr(n,u,3),type:t}),o}}),Mt(["drop","take"],function(n,t){var r="__"+n+"Count__",e=n+"While";Ut.prototype[n]=function(e){e=null==e?1:uo(Pu(e)||0,0); +var u=this.clone();if(u.__filtered__){var o=u[r];u[r]=t?oo(o,e):o+e}else(u.__views__||(u.__views__=[])).push({size:e,type:n+(0>u.__dir__?"Right":"")});return u},Ut.prototype[n+"Right"]=function(t){return this.reverse()[n](t).reverse()},Ut.prototype[n+"RightWhile"]=function(n,t){return this.reverse()[e](n,t).reverse()}}),Mt(["first","last"],function(n,t){var r="take"+(t?"Right":"");Ut.prototype[n]=function(){return this[r](1).value()[0]}}),Mt(["initial","rest"],function(n,t){var r="drop"+(t?"":"Right"); +Ut.prototype[n]=function(){return this[r](1)}}),Mt(["pluck","where"],function(n,t){var r=t?"filter":"map",e=t?br:jr;Ut.prototype[n]=function(n){return this[r](e(n))}}),Ut.prototype.compact=function(){return this.filter(vu)},Ut.prototype.dropWhile=function(n,t){var r;return n=Hr(n,t,3),this.filter(function(t,e,u){return r||(r=!n(t,e,u))})},Ut.prototype.reject=function(n,t){return n=Hr(n,t,3),this.filter(function(t,r,e){return!n(t,r,e)})},Ut.prototype.slice=function(n,t){n=null==n?0:+n||0;var r=0>n?this.takeRight(-n):this.drop(n); +return typeof t!="undefined"&&(t=+t||0,r=0>t?r.dropRight(-t):r.take(t-n)),r},Ut.prototype.toArray=function(){return this.drop(0)},_r(Ut.prototype,function(n,t){var r=Wt[t],e=/^(?:first|last)$/.test(t);Wt.prototype[t]=function(){function t(n){return n=[n],Vu.apply(n,o),r.apply(Wt,n)}var u=this.__wrapped__,o=arguments,i=this.__chain__,f=!!this.__actions__.length,a=u instanceof Ut,c=a&&!f;return e&&!i?c?n.call(u):r.call(Wt,this.value()):a||So(u)?(u=n.apply(c?u:new Ut(this),o),e||!f&&!u.__actions__||(u.__actions__||(u.__actions__=[])).push({func:je,args:[t],thisArg:Wt}),new Nt(u,i)):this.thru(t) +}}),Mt("concat join pop push shift sort splice unshift".split(" "),function(n){var t=Cu[n],r=/^(?:push|sort|unshift)$/.test(n)?"tap":"thru",e=/^(?:join|pop|shift)$/.test(n);Wt.prototype[n]=function(){var n=arguments;return e&&!this.__chain__?t.apply(this.value(),n):this[r](function(r){return t.apply(r,n)})}}),Ut.prototype.clone=function(){var n=this.__actions__,t=this.__iteratees__,r=this.__views__,e=new Ut(this.__wrapped__);return e.__actions__=n?zt(n):null,e.__dir__=this.__dir__,e.__dropCount__=this.__dropCount__,e.__filtered__=this.__filtered__,e.__iteratees__=t?zt(t):null,e.__takeCount__=this.__takeCount__,e.__views__=r?zt(r):null,e +},Ut.prototype.reverse=function(){if(this.__filtered__){var n=new Ut(this);n.__dir__=-1,n.__filtered__=true}else n=this.clone(),n.__dir__*=-1;return n},Ut.prototype.value=function(){var n=this.__wrapped__.value();if(!So(n))return Tr(n,this.__actions__);var t,r=this.__dir__,e=0>r;t=n.length;for(var u=this.__views__,o=0,i=-1,f=u?u.length:0;++i"'`]/g,st=RegExp(ct.source),pt=RegExp(lt.source),ht=/<%-([\s\S]+?)%>/g,_t=/<%([\s\S]+?)%>/g,gt=/<%=([\s\S]+?)%>/g,vt=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,yt=/\w*$/,dt=/^\s*function[ \n\r\t]+\w/,mt=/^0[xX]/,wt=/^\[object .+?Constructor\]$/,bt=/[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g,xt=/($^)/,At=/[.*+?^${}()|[\]\/\\]/g,jt=RegExp(At.source),kt=/\bthis\b/,Et=/['\n\r\u2028\u2029\\]/g,Rt=RegExp("[A-Z\\xc0-\\xd6\\xd8-\\xde]{2,}(?=[A-Z\\xc0-\\xd6\\xd8-\\xde][a-z\\xdf-\\xf6\\xf8-\\xff]+)|[A-Z\\xc0-\\xd6\\xd8-\\xde]?[a-z\\xdf-\\xf6\\xf8-\\xff]+|[A-Z\\xc0-\\xd6\\xd8-\\xde]+|[0-9]+","g"),It=" \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000",Ot="Array ArrayBuffer Date Error Float32Array Float64Array Function Int8Array Int16Array Int32Array Math Number Object RegExp Set String _ clearTimeout document isFinite parseInt setTimeout TypeError Uint8Array Uint8ClampedArray Uint16Array Uint32Array WeakMap window WinRTError".split(" "),Ct={}; Ct[X]=Ct[H]=Ct[Q]=Ct[nt]=Ct[tt]=Ct[rt]=Ct[et]=Ct[ut]=Ct[ot]=true,Ct[z]=Ct[D]=Ct[J]=Ct[M]=Ct[q]=Ct[P]=Ct[K]=Ct["[object Map]"]=Ct[V]=Ct[Y]=Ct[Z]=Ct["[object Set]"]=Ct[G]=Ct["[object WeakMap]"]=false;var Tt={};Tt[z]=Tt[D]=Tt[J]=Tt[M]=Tt[q]=Tt[X]=Tt[H]=Tt[Q]=Tt[nt]=Tt[tt]=Tt[V]=Tt[Y]=Tt[Z]=Tt[G]=Tt[rt]=Tt[et]=Tt[ut]=Tt[ot]=true,Tt[P]=Tt[K]=Tt["[object Map]"]=Tt["[object Set]"]=Tt["[object WeakMap]"]=false;var St={leading:false,maxWait:0,trailing:false},Wt={"\xc0":"A","\xc1":"A","\xc2":"A","\xc3":"A","\xc4":"A","\xc5":"A","\xe0":"a","\xe1":"a","\xe2":"a","\xe3":"a","\xe4":"a","\xe5":"a","\xc7":"C","\xe7":"c","\xd0":"D","\xf0":"d","\xc8":"E","\xc9":"E","\xca":"E","\xcb":"E","\xe8":"e","\xe9":"e","\xea":"e","\xeb":"e","\xcc":"I","\xcd":"I","\xce":"I","\xcf":"I","\xec":"i","\xed":"i","\xee":"i","\xef":"i","\xd1":"N","\xf1":"n","\xd2":"O","\xd3":"O","\xd4":"O","\xd5":"O","\xd6":"O","\xd8":"O","\xf2":"o","\xf3":"o","\xf4":"o","\xf5":"o","\xf6":"o","\xf8":"o","\xd9":"U","\xda":"U","\xdb":"U","\xdc":"U","\xf9":"u","\xfa":"u","\xfb":"u","\xfc":"u","\xdd":"Y","\xfd":"y","\xff":"y","\xc6":"Ae","\xe6":"ae","\xde":"Th","\xfe":"th","\xdf":"ss"},Nt={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},Ut={"&":"&","<":"<",">":">",""":'"',"'":"'","`":"`"},Ft={"function":true,object:true},Lt={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},$t=Ft[typeof window]&&window!==(this&&this.window)?window:this,Bt=Ft[typeof exports]&&exports&&!exports.nodeType&&exports,Ft=Ft[typeof module]&&module&&!module.nodeType&&module,zt=Bt&&Ft&&typeof global=="object"&&global; !zt||zt.global!==zt&&zt.window!==zt&&zt.self!==zt||($t=zt);var zt=Ft&&Ft.exports===Bt&&Bt,Dt=m();typeof define=="function"&&typeof define.amd=="object"&&define.amd?($t._=Dt, define(function(){return Dt})):Bt&&Ft?zt?(Ft.exports=Dt)._=Dt:Bt._=Dt:$t._=Dt}).call(this); \ No newline at end of file diff --git a/lodash.src.js b/lodash.src.js index 2f55e9354a..be65b2cd94 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -1,6 +1,6 @@ /** * @license - * lodash 3.1.0 + * lodash 3.2.0 * Copyright 2012-2015 The Dojo Foundation * Based on Underscore.js 1.7.0 * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors @@ -12,7 +12,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '3.1.0'; + var VERSION = '3.2.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_FLAG = 1, @@ -755,7 +755,6 @@ setTimeout = context.setTimeout, splice = arrayProto.splice, Uint8Array = isNative(Uint8Array = context.Uint8Array) && Uint8Array, - unshift = arrayProto.unshift, WeakMap = isNative(WeakMap = context.WeakMap) && WeakMap; /** Used to clone array buffers. */ @@ -835,7 +834,7 @@ /*------------------------------------------------------------------------*/ /** - * Creates a `lodash` object which wraps `value` to enable intuitive chaining. + * Creates a `lodash` object which wraps `value` to enable implicit chaining. * Methods that operate on and return arrays, collections, and functions can * be chained together. Methods that return a boolean or single value will * automatically end the chain returning the unwrapped value. Explicit chaining @@ -854,29 +853,31 @@ * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`, * and `unshift` * - * The wrapper functions that support shortcut fusion are: - * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`, - * `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`, - * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where` + * The wrapper methods that support shortcut fusion are: + * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, + * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, + * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`, + * and `where` * - * The chainable wrapper functions are: + * The chainable wrapper methods are: * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`, - * `callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`, - * `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, - * `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, - * `flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`, - * `forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`, - * `initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`, - * `mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`, - * `omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`, - * `pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, - * `rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, - * `sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`, - * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, - * `transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, - * `where`, `without`, `wrap`, `xor`, `zip`, and `zipObject` - * - * The wrapper functions that are **not** chainable by default are: + * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`, + * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, + * `difference`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `fill`, + * `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`, `forEach`, + * `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `functions`, + * `groupBy`, `indexBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, + * `keysIn`, `map`, `mapValues`, `matches`, `matchesProperty`, `memoize`, `merge`, + * `mixin`, `negate`, `noop`, `omit`, `once`, `pairs`, `partial`, `partialRight`, + * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`, + * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `reverse`, + * `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`, `splice`, `spread`, + * `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `tap`, `throttle`, + * `thru`, `times`, `toArray`, `toPlainObject`, `transform`, `union`, `uniq`, + * `unshift`, `unzip`, `values`, `valuesIn`, `where`, `without`, `wrap`, `xor`, + * `zip`, and `zipObject` + * + * The wrapper methods that are **not** chainable by default are: * `attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`, * `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, * `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, @@ -891,14 +892,14 @@ * `startCase`, `startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, * `trunc`, `unescape`, `uniqueId`, `value`, and `words` * - * The wrapper function `sample` will return a wrapped value when `n` is provided, + * The wrapper method `sample` will return a wrapped value when `n` is provided, * otherwise an unwrapped value is returned. * * @name _ * @constructor * @category Chain * @param {*} value The value to wrap in a `lodash` instance. - * @returns {Object} Returns a `lodash` instance. + * @returns {Object} Returns the new `lodash` wrapper instance. * @example * * var wrapped = _([1, 2, 3]); @@ -917,12 +918,12 @@ * // => true */ function lodash(value) { - if (isObjectLike(value) && !isArray(value)) { + if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { if (value instanceof LodashWrapper) { return value; } - if (hasOwnProperty.call(value, '__wrapped__')) { - return new LodashWrapper(value.__wrapped__, value.__chain__, arrayCopy(value.__actions__)); + if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) { + return wrapperClone(value); } } return new LodashWrapper(value); @@ -937,9 +938,9 @@ * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value. */ function LodashWrapper(value, chainAll, actions) { + this.__wrapped__ = value; this.__actions__ = actions || []; this.__chain__ = !!chainAll; - this.__wrapped__ = value; } /** @@ -1173,14 +1174,14 @@ * @param {*} value The value to wrap. */ function LazyWrapper(value) { - this.actions = null; - this.dir = 1; - this.dropCount = 0; - this.filtered = false; - this.iteratees = null; - this.takeCount = POSITIVE_INFINITY; - this.views = null; - this.wrapped = value; + this.__wrapped__ = value; + this.__actions__ = null; + this.__dir__ = 1; + this.__dropCount__ = 0; + this.__filtered__ = false; + this.__iteratees__ = null; + this.__takeCount__ = POSITIVE_INFINITY; + this.__views__ = null; } /** @@ -1192,18 +1193,18 @@ * @returns {Object} Returns the cloned `LazyWrapper` object. */ function lazyClone() { - var actions = this.actions, - iteratees = this.iteratees, - views = this.views, - result = new LazyWrapper(this.wrapped); - - result.actions = actions ? arrayCopy(actions) : null; - result.dir = this.dir; - result.dropCount = this.dropCount; - result.filtered = this.filtered; - result.iteratees = iteratees ? arrayCopy(iteratees) : null; - result.takeCount = this.takeCount; - result.views = views ? arrayCopy(views) : null; + var actions = this.__actions__, + iteratees = this.__iteratees__, + views = this.__views__, + result = new LazyWrapper(this.__wrapped__); + + result.__actions__ = actions ? arrayCopy(actions) : null; + result.__dir__ = this.__dir__; + result.__dropCount__ = this.__dropCount__; + result.__filtered__ = this.__filtered__; + result.__iteratees__ = iteratees ? arrayCopy(iteratees) : null; + result.__takeCount__ = this.__takeCount__; + result.__views__ = views ? arrayCopy(views) : null; return result; } @@ -1216,13 +1217,13 @@ * @returns {Object} Returns the new reversed `LazyWrapper` object. */ function lazyReverse() { - if (this.filtered) { + if (this.__filtered__) { var result = new LazyWrapper(this); - result.dir = -1; - result.filtered = true; + result.__dir__ = -1; + result.__filtered__ = true; } else { result = this.clone(); - result.dir *= -1; + result.__dir__ *= -1; } return result; } @@ -1236,20 +1237,20 @@ * @returns {*} Returns the unwrapped value. */ function lazyValue() { - var array = this.wrapped.value(); + var array = this.__wrapped__.value(); if (!isArray(array)) { - return baseWrapperValue(array, this.actions); + return baseWrapperValue(array, this.__actions__); } - var dir = this.dir, + var dir = this.__dir__, isRight = dir < 0, - view = getView(0, array.length, this.views), + view = getView(0, array.length, this.__views__), start = view.start, end = view.end, length = end - start, - dropCount = this.dropCount, - takeCount = nativeMin(length, this.takeCount - dropCount), + dropCount = this.__dropCount__, + takeCount = nativeMin(length, this.__takeCount__), index = isRight ? end : start - 1, - iteratees = this.iteratees, + iteratees = this.__iteratees__, iterLength = iteratees ? iteratees.length : 0, resIndex = 0, result = []; @@ -1694,7 +1695,7 @@ return baseCopy(source, object, props); } var index = -1, - length = props.length + length = props.length; while (++index < length) { var key = props[index], @@ -1801,10 +1802,12 @@ if (func == null) { return identity; } - // Handle "_.property" and "_.matches" style callback shorthands. - return type == 'object' - ? baseMatches(func) - : baseProperty(func + ''); + if (type == 'object') { + return baseMatches(func); + } + return typeof thisArg == 'undefined' + ? baseProperty(func + '') + : baseMatchesProperty(func + '', thisArg); } /** @@ -1908,7 +1911,7 @@ * @returns {number} Returns the timer id. */ function baseDelay(func, wait, args, fromIndex) { - if (!isFunction(func)) { + if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } return setTimeout(function() { func.apply(undefined, baseSlice(args, fromIndex)); }, wait); @@ -2028,6 +2031,36 @@ return result; } + /** + * The base implementation of `_.fill` without an iteratee call guard. + * + * @private + * @param {Array} array The array to fill. + * @param {*} value The value to fill `array` with. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns `array`. + */ + function baseFill(array, value, start, end) { + var length = array.length; + + start = start == null ? 0 : (+start || 0); + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = (typeof end == 'undefined' || end > length) ? length : (+end || 0); + if (end < 0) { + end += length; + } + length = start > end ? 0 : end >>> 0; + start >>>= 0; + + while (start < length) { + array[start++] = value; + } + return array; + } + /** * The base implementation of `_.filter` without support for callback * shorthands or `this` binding. @@ -2360,7 +2393,7 @@ * shorthands or `this` binding. * * @private - * @param {Object} source The object to inspect. + * @param {Object} object The object to inspect. * @param {Array} props The source property names to match. * @param {Array} values The source values to match. * @param {Array} strictCompareFlags Strict comparison flags for source values. @@ -2422,8 +2455,7 @@ } /** - * The base implementation of `_.matches` which supports specifying whether - * `source` should be cloned. + * The base implementation of `_.matches` which does not clone `source`. * * @private * @param {Object} source The object of property values to match. @@ -2439,7 +2471,7 @@ if (isStrictComparable(value)) { return function(object) { - return object != null && value === object[key] && hasOwnProperty.call(object, key); + return object != null && object[key] === value && hasOwnProperty.call(object, key); }; } } @@ -2456,6 +2488,26 @@ }; } + /** + * The base implementation of `_.matchesProperty` which does not coerce `key` + * to a string. + * + * @private + * @param {string} key The key of the property to get. + * @param {*} value The value to compare. + * @returns {Function} Returns the new function. + */ + function baseMatchesProperty(key, value) { + if (isStrictComparable(value)) { + return function(object) { + return object != null && object[key] === value; + }; + } + return function(object) { + return object != null && baseIsEqual(value, object[key], null, true); + }; + } + /** * The base implementation of `_.merge` without support for argument juggling, * multiple sources, and `this` binding `customizer` functions. @@ -2618,7 +2670,7 @@ eachFunc(collection, function(value, index, collection) { accumulator = initFromCollection ? (initFromCollection = false, value) - : iteratee(accumulator, value, index, collection) + : iteratee(accumulator, value, index, collection); }); return accumulator; } @@ -2994,8 +3046,7 @@ /** * Creates a function that aggregates a collection, creating an accumulator * object composed from the results of running each element in the collection - * through an iteratee. The `setter` sets the keys and values of the accumulator - * object. If `initializer` is provided initializes the accumulator object. + * through an iteratee. * * @private * @param {Function} setter The function to set keys and values of the accumulator object. @@ -3332,7 +3383,7 @@ */ function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { var isBindKey = bitmask & BIND_KEY_FLAG; - if (!isBindKey && !isFunction(func)) { + if (!isBindKey && typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } var length = partials ? partials.length : 0; @@ -3362,9 +3413,9 @@ if (bitmask == BIND_FLAG) { var result = createBindWrapper(newData[0], newData[2]); } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) { - result = createPartialWrapper.apply(null, newData); + result = createPartialWrapper.apply(undefined, newData); } else { - result = createHybridWrapper.apply(null, newData); + result = createHybridWrapper.apply(undefined, newData); } var setter = data ? baseSetData : setData; return setter(result, newData); @@ -4078,6 +4129,19 @@ return isObject(value) ? value : Object(value); } + /** + * Creates a clone of `wrapper`. + * + * @private + * @param {Object} wrapper The wrapper to clone. + * @returns {Object} Returns the cloned wrapper. + */ + function wrapperClone(wrapper) { + return wrapper instanceof LazyWrapper + ? wrapper.clone() + : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__)); + } + /*------------------------------------------------------------------------*/ /** @@ -4089,7 +4153,7 @@ * @memberOf _ * @category Array * @param {Array} array The array to process. - * @param {numer} [size=1] The length of each chunk. + * @param {number} [size=1] The length of each chunk. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`. * @returns {Array} Returns the new array containing chunks. * @example @@ -4184,7 +4248,6 @@ * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to drop. @@ -4220,7 +4283,6 @@ * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to drop. @@ -4257,20 +4319,23 @@ * Elements are dropped until `predicate` returns falsey. The predicate is * bound to `thisArg` and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style - * callback returns `true` for elements that have the properties of the given + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style + * callback returns `true` for elements that match the properties of the given * object, else `false`. * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per element. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the slice of `array`. * @example @@ -4279,18 +4344,22 @@ * // => [1] * * var users = [ - * { 'user': 'barney', 'status': 'busy', 'active': false }, - * { 'user': 'fred', 'status': 'busy', 'active': true }, - * { 'user': 'pebbles', 'status': 'away', 'active': true } + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.dropRightWhile(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.dropRightWhile(users, { 'user': pebbles, 'active': false }), 'user'); + * // => ['barney', 'fred'] + * + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.dropRightWhile(users, 'active', false), 'user'); * // => ['barney'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user'); - * // => ['barney', 'fred'] + * // using the `_.property` callback shorthand + * _.pluck(_.dropRightWhile(users, 'active'), 'user'); + * // => ['barney', 'fred', 'pebbles'] */ function dropRightWhile(array, predicate, thisArg) { var length = array ? array.length : 0; @@ -4307,20 +4376,23 @@ * Elements are dropped until `predicate` returns falsey. The predicate is * bound to `thisArg` and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per element. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the slice of `array`. * @example @@ -4329,18 +4401,22 @@ * // => [3] * * var users = [ - * { 'user': 'barney', 'status': 'busy', 'active': true }, - * { 'user': 'fred', 'status': 'busy', 'active': false }, - * { 'user': 'pebbles', 'status': 'away', 'active': true } + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.dropWhile(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user'); * // => ['fred', 'pebbles'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user'); + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.dropWhile(users, 'active', false), 'user'); * // => ['pebbles'] + * + * // using the `_.property` callback shorthand + * _.pluck(_.dropWhile(users, 'active'), 'user'); + * // => ['barney', 'fred', 'pebbles'] */ function dropWhile(array, predicate, thisArg) { var length = array ? array.length : 0; @@ -4353,14 +4429,45 @@ return baseSlice(array, index); } + /** + * Fills elements of `array` with `value` from `start` up to, but not + * including, `end`. + * + * **Note:** This method mutates `array`. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to fill. + * @param {*} value The value to fill `array` with. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns `array`. + */ + function fill(array, value, start, end) { + var length = array ? array.length : 0; + if (!length) { + return []; + } + if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { + start = 0; + end = length; + } + return baseFill(array, value, start, end); + } + /** * This method is like `_.find` except that it returns the index of the first * element `predicate` returns truthy for, instead of the element itself. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -4369,28 +4476,31 @@ * @category Array * @param {Array} array The array to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {number} Returns the index of the found element, else `-1`. * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true }, - * { 'user': 'pebbles', 'age': 1, 'active': false } + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } * ]; * - * _.findIndex(users, function(chr) { return chr.age < 40; }); + * _.findIndex(users, function(chr) { return chr.user == 'barney'; }); * // => 0 * - * // using the "_.matches" callback shorthand - * _.findIndex(users, { 'age': 1 }); - * // => 2 + * // using the `_.matches` callback shorthand + * _.findIndex(users, { 'user': 'fred', 'active': false }); + * // => 1 * - * // using the "_.property" callback shorthand + * // using the `_.matchesProperty` callback shorthand + * _.findIndex(users, 'active', false); + * // => 0 + * + * // using the `_.property` callback shorthand * _.findIndex(users, 'active'); - * // => 1 + * // => 2 */ function findIndex(array, predicate, thisArg) { var index = -1, @@ -4409,10 +4519,14 @@ * This method is like `_.findIndex` except that it iterates over elements * of `collection` from right to left. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -4421,26 +4535,29 @@ * @category Array * @param {Array} array The array to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {number} Returns the index of the found element, else `-1`. * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': true }, - * { 'user': 'fred', 'age': 40, 'active': false }, - * { 'user': 'pebbles', 'age': 1, 'active': false } + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } * ]; * - * _.findLastIndex(users, function(chr) { return chr.age < 40; }); + * _.findLastIndex(users, function(chr) { return chr.user == 'pebbles'; }); * // => 2 * - * // using the "_.matches" callback shorthand - * _.findLastIndex(users, { 'age': 40 }); + * // using the `_.matches` callback shorthand + * _.findLastIndex(users, { user': 'barney', 'active': true }); + * // => 0 + * + * // using the `_.matchesProperty` callback shorthand + * _.findLastIndex(users, 'active', false); * // => 1 * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.findLastIndex(users, 'active'); * // => 0 */ @@ -4792,10 +4909,14 @@ * and returns an array of the removed elements. The predicate is bound to * `thisArg` and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -4806,8 +4927,7 @@ * @category Array * @param {Array} array The array to modify. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the new array of removed elements. * @example @@ -4889,10 +5009,14 @@ * to compute their sort ranking. The iteratee is bound to `thisArg` and * invoked with one argument; (value). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -4902,8 +5026,7 @@ * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {number} Returns the index at which `value` should be inserted * into `array`. @@ -4923,7 +5046,7 @@ * }, dict); * // => 1 * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); * // => 1 */ @@ -4945,8 +5068,7 @@ * @param {Array} array The sorted array to inspect. * @param {*} value The value to evaluate. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {number} Returns the index at which `value` should be inserted * into `array`. @@ -4967,7 +5089,6 @@ * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to take. @@ -5003,7 +5124,6 @@ * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {number} [n=1] The number of elements to take. @@ -5040,20 +5160,23 @@ * taken until `predicate` returns falsey. The predicate is bound to `thisArg` * and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per element. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the slice of `array`. * @example @@ -5062,18 +5185,22 @@ * // => [2, 3] * * var users = [ - * { 'user': 'barney', 'status': 'busy', 'active': false }, - * { 'user': 'fred', 'status': 'busy', 'active': true }, - * { 'user': 'pebbles', 'status': 'away', 'active': true } + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.takeRightWhile(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user'); + * // => ['pebbles'] + * + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.takeRightWhile(users, 'active', false), 'user'); * // => ['fred', 'pebbles'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user'); - * // => ['pebbles'] + * // using the `_.property` callback shorthand + * _.pluck(_.takeRightWhile(users, 'active'), 'user'); + * // => [] */ function takeRightWhile(array, predicate, thisArg) { var length = array ? array.length : 0; @@ -5090,20 +5217,23 @@ * are taken until `predicate` returns falsey. The predicate is bound to * `thisArg` and invoked with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * * @static * @memberOf _ - * @type Function * @category Array * @param {Array} array The array to query. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per element. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the slice of `array`. * @example @@ -5112,18 +5242,22 @@ * // => [1, 2] * * var users = [ - * { 'user': 'barney', 'status': 'busy', 'active': true }, - * { 'user': 'fred', 'status': 'busy', 'active': false }, - * { 'user': 'pebbles', 'status': 'away', 'active': true } + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false}, + * { 'user': 'pebbles', 'active': true } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.takeWhile(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user'); * // => ['barney'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user'); + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.takeWhile(users, 'active', false), 'user'); * // => ['barney', 'fred'] + * + * // using the `_.property` callback shorthand + * _.pluck(_.takeWhile(users, 'active'), 'user'); + * // => [] */ function takeWhile(array, predicate, thisArg) { var length = array ? array.length : 0; @@ -5167,10 +5301,14 @@ * uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked * with three arguments; (value, index, array). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5186,8 +5324,6 @@ * @param {Array} array The array to inspect. * @param {boolean} [isSorted] Specify the array is sorted. * @param {Function|Object|string} [iteratee] The function invoked per iteration. - * If a property name or object is provided it is used to create a "_.property" - * or "_.matches" style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Array} Returns the new duplicate-value-free array. * @example @@ -5203,7 +5339,7 @@ * _.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math); * // => [1, 2.5] * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); * // => [{ 'x': 1 }, { 'x': 2 }] */ @@ -5384,7 +5520,7 @@ * @memberOf _ * @category Chain * @param {*} value The value to wrap. - * @returns {Object} Returns the new `lodash` object. + * @returns {Object} Returns the new `lodash` wrapper instance. * @example * * var users = [ @@ -5460,7 +5596,7 @@ * @name chain * @memberOf _ * @category Chain - * @returns {*} Returns the `lodash` object. + * @returns {Object} Returns the new `lodash` wrapper instance. * @example * * var users = [ @@ -5483,6 +5619,76 @@ return chain(this); } + /** + * Executes the chained sequence and returns the wrapped result. + * + * @name commit + * @memberOf _ + * @category Chain + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var array = [1, 2]; + * var wrapper = _(array).push(3); + * + * console.log(array); + * // => [1, 2] + * + * wrapper = wrapper.commit(); + * console.log(array); + * // => [1, 2, 3] + * + * wrapper.last(); + * // => 3 + * + * console.log(array); + * // => [1, 2, 3] + */ + function wrapperCommit() { + return new LodashWrapper(this.value(), this.__chain__); + } + + /** + * Creates a clone of the chained sequence planting `value` as the wrapped value. + * + * @name plant + * @memberOf _ + * @category Chain + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var array = [1, 2]; + * var wrapper = _(array).map(function(value) { + * return Math.pow(value, 2); + * }); + * + * var other = [3, 4]; + * var otherWrapper = wrapper.plant(other); + * + * otherWrapper.value(); + * // => [9, 16] + * + * wrapper.value(); + * // => [1, 4] + */ + function wrapperPlant(value) { + var result, + parent = this; + + while (parent instanceof LodashWrapper) { + var clone = wrapperClone(parent); + if (result) { + previous.__wrapped__ = clone; + } else { + result = clone; + } + var previous = clone; + parent = parent.__wrapped__; + } + previous.__wrapped__ = value; + return result; + } + /** * Reverses the wrapped array so the first element becomes the last, the * second element becomes the second to last, and so on. @@ -5492,7 +5698,7 @@ * @name reverse * @memberOf _ * @category Chain - * @returns {Object} Returns the new reversed `lodash` object. + * @returns {Object} Returns the new reversed `lodash` wrapper instance. * @example * * var array = [1, 2, 3]; @@ -5509,7 +5715,7 @@ if (this.__actions__.length) { value = new LazyWrapper(this); } - return new LodashWrapper(value.reverse()); + return new LodashWrapper(value.reverse(), this.__chain__); } return this.thru(function(value) { return value.reverse(); @@ -5537,7 +5743,7 @@ * * @name value * @memberOf _ - * @alias toJSON, valueOf + * @alias run, toJSON, valueOf * @category Chain * @returns {*} Returns the resolved unwrapped value. * @example @@ -5637,10 +5843,14 @@ * The `iteratee` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5649,8 +5859,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Object} Returns the composed aggregate object. * @example @@ -5673,10 +5882,14 @@ * The predicate is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5686,27 +5899,30 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {boolean} Returns `true` if all elements pass the predicate check, * else `false`. * @example * - * _.every([true, 1, null, 'yes']); + * _.every([true, 1, null, 'yes'], Boolean); * // => false * * var users = [ - * { 'user': 'barney', 'age': 36 }, - * { 'user': 'fred', 'age': 40 } + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.every(users, 'age'); + * // using the `_.matches` callback shorthand + * _.every(users, { 'user': 'barney', 'active': false }); + * // => false + * + * // using the `_.matchesProperty` callback shorthand + * _.every(users, 'active', false); * // => true * - * // using the "_.matches" callback shorthand - * _.every(users, { 'age': 36 }); + * // using the `_.property` callback shorthand + * _.every(users, 'active'); * // => false */ function every(collection, predicate, thisArg) { @@ -5722,10 +5938,14 @@ * `predicate` returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5735,8 +5955,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the new filtered array. * @example @@ -5745,16 +5964,20 @@ * // => [2, 4] * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.filter(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user'); + * // => ['barney'] + * + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.filter(users, 'active', false), 'user'); * // => ['fred'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.filter(users, { 'age': 36 }), 'user'); + * // using the `_.property` callback shorthand + * _.pluck(_.filter(users, 'active'), 'user'); * // => ['barney'] */ function filter(collection, predicate, thisArg) { @@ -5768,10 +5991,14 @@ * `predicate` returns truthy for. The predicate is bound to `thisArg` and * invoked with three arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5781,28 +6008,31 @@ * @category Collection * @param {Array|Object|string} collection The collection to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {*} Returns the matched element, else `undefined`. * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true }, - * { 'user': 'pebbles', 'age': 1, 'active': false } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false }, + * { 'user': 'pebbles', 'age': 1, 'active': true } * ]; * * _.result(_.find(users, function(chr) { return chr.age < 40; }), 'user'); * // => 'barney' * - * // using the "_.matches" callback shorthand - * _.result(_.find(users, { 'age': 1 }), 'user'); + * // using the `_.matches` callback shorthand + * _.result(_.find(users, { 'age': 1, 'active': true }), 'user'); * // => 'pebbles' * - * // using the "_.property" callback shorthand - * _.result(_.find(users, 'active'), 'user'); + * // using the `_.matchesProperty` callback shorthand + * _.result(_.find(users, 'active', false), 'user'); * // => 'fred' + * + * // using the `_.property` callback shorthand + * _.result(_.find(users, 'active'), 'user'); + * // => 'barney' */ function find(collection, predicate, thisArg) { if (isArray(collection)) { @@ -5822,8 +6052,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {*} Returns the matched element, else `undefined`. * @example @@ -5841,6 +6070,11 @@ * source object, returning the first element that has equivalent property * values. * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. For comparing a single + * own or inherited property value see `_.matchesProperty`. + * * @static * @memberOf _ * @category Collection @@ -5850,14 +6084,14 @@ * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'status': 'busy' }, - * { 'user': 'fred', 'age': 40, 'status': 'busy' } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * - * _.result(_.findWhere(users, { 'status': 'busy' }), 'user'); + * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user'); * // => 'barney' * - * _.result(_.findWhere(users, { 'age': 40 }), 'user'); + * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user'); * // => 'fred' */ function findWhere(collection, source) { @@ -5926,10 +6160,14 @@ * The `iteratee` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5938,8 +6176,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Object} Returns the composed aggregate object. * @example @@ -5950,7 +6187,7 @@ * _.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math); * // => { '4': [4.2], '6': [6.1, 6.4] } * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.groupBy(['one', 'two', 'three'], 'length'); * // => { '3': ['one', 'two'], '5': ['three'] } */ @@ -5969,10 +6206,14 @@ * iteratee function is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -5981,8 +6222,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Object} Returns the composed aggregate object. * @example @@ -6036,21 +6276,34 @@ * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three * arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * + * Many lodash methods are guarded to work as interatees for methods like + * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. + * + * The guarded methods are: + * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, `drop`, + * `dropRight`, `fill`, `flatten`, `invert`, `max`, `min`, `parseInt`, `slice`, + * `sortBy`, `take`, `takeRight`, `template`, `trim`, `trimLeft`, `trimRight`, + * `trunc`, `random`, `range`, `sample`, `uniq`, and `words` + * * @static * @memberOf _ * @alias collect * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. + * create a `_.property` or `_.matches` style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Array} Returns the new mapped array. * @example @@ -6066,7 +6319,7 @@ * { 'user': 'fred' } * ]; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.map(users, 'user'); * // => ['barney', 'fred'] */ @@ -6083,10 +6336,14 @@ * is ranked. The `iteratee` is bound to `thisArg` and invoked with three * arguments; (value, index, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6095,8 +6352,6 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee] The function invoked per iteration. - * If a property name or object is provided it is used to create a "_.property" - * or "_.matches" style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {*} Returns the maximum value. * @example @@ -6115,7 +6370,7 @@ * _.max(users, function(chr) { return chr.age; }); * // => { 'user': 'fred', 'age': 40 }; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.max(users, 'age'); * // => { 'user': 'fred', 'age': 40 }; */ @@ -6128,10 +6383,14 @@ * is ranked. The `iteratee` is bound to `thisArg` and invoked with three * arguments; (value, index, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6140,8 +6399,6 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [iteratee] The function invoked per iteration. - * If a property name or object is provided it is used to create a "_.property" - * or "_.matches" style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {*} Returns the minimum value. * @example @@ -6160,7 +6417,7 @@ * _.min(users, function(chr) { return chr.age; }); * // => { 'user': 'barney', 'age': 36 }; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.min(users, 'age'); * // => { 'user': 'barney', 'age': 36 }; */ @@ -6172,10 +6429,14 @@ * contains elements `predicate` returns falsey for. The predicate is bound * to `thisArg` and invoked with three arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6184,8 +6445,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the array of grouped elements. * @example @@ -6202,12 +6462,18 @@ * { 'user': 'pebbles', 'age': 1, 'active': false } * ]; * - * // using the "_.matches" callback shorthand - * _.map(_.partition(users, { 'age': 1 }), function(array) { return _.pluck(array, 'user'); }); + * var mapper = function(array) { return _.pluck(array, 'user'); }; + * + * // using the `_.matches` callback shorthand + * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper); * // => [['pebbles'], ['barney', 'fred']] * - * // using the "_.property" callback shorthand - * _.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'user'); }); + * // using the `_.matchesProperty` callback shorthand + * _.map(_.partition(users, 'active', false), mapper); + * // => [['barney', 'pebbles'], ['fred']] + * + * // using the `_.property` callback shorthand + * _.map(_.partition(users, 'active'), mapper); * // => [['fred'], ['barney', 'pebbles']] */ var partition = createAggregator(function(result, value, key) { @@ -6238,7 +6504,7 @@ * // => [36, 40] (iteration order is not guaranteed) */ function pluck(collection, key) { - return map(collection, baseProperty(key + '')); + return map(collection, baseProperty(key)); } /** @@ -6249,6 +6515,12 @@ * value. The `iteratee` is bound to `thisArg`and invoked with four arguments; * (accumulator, value, index|key, collection). * + * Many lodash methods are guarded to work as interatees for methods like + * `_.reduce`, `_.reduceRight`, and `_.transform`. + * + * The guarded methods are: + * `assign`, `defaults`, `merge`, and `sortAllBy` + * * @static * @memberOf _ * @alias foldl, inject @@ -6302,10 +6574,14 @@ * The opposite of `_.filter`; this method returns the elements of `collection` * that `predicate` does **not** return truthy for. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6314,8 +6590,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {Array} Returns the new filtered array. * @example @@ -6328,13 +6603,17 @@ * { 'user': 'fred', 'age': 40, 'active': true } * ]; * - * // using the "_.property" callback shorthand - * _.pluck(_.reject(users, 'active'), 'user'); + * // using the `_.matches` callback shorthand + * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user'); * // => ['barney'] * - * // using the "_.matches" callback shorthand - * _.pluck(_.reject(users, { 'age': 36 }), 'user'); + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.reject(users, 'active', false), 'user'); * // => ['fred'] + * + * // using the `_.property` callback shorthand + * _.pluck(_.reject(users, 'active'), 'user'); + * // => ['barney'] */ function reject(collection, predicate, thisArg) { var func = isArray(collection) ? arrayFilter : baseFilter; @@ -6436,10 +6715,14 @@ * over the entire collection. The predicate is bound to `thisArg` and invoked * with three arguments; (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6449,8 +6732,7 @@ * @category Collection * @param {Array|Object|string} collection The collection to iterate over. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {boolean} Returns `true` if any element passes the predicate check, * else `false`. @@ -6460,17 +6742,21 @@ * // => true * * var users = [ - * { 'user': 'barney', 'age': 36, 'active': false }, - * { 'user': 'fred', 'age': 40, 'active': true } + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } * ]; * - * // using the "_.property" callback shorthand - * _.some(users, 'active'); + * // using the `_.matches` callback shorthand + * _.some(users, { user': 'barney', 'active': false }); + * // => false + * + * // using the `_.matchesProperty` callback shorthand + * _.some(users, 'active', false); * // => true * - * // using the "_.matches" callback shorthand - * _.some(users, { 'age': 1 }); - * // => false + * // using the `_.property` callback shorthand + * _.some(users, 'active'); + * // => true */ function some(collection, predicate, thisArg) { var func = isArray(collection) ? arraySome : baseSome; @@ -6487,10 +6773,14 @@ * The `iteratee` is bound to `thisArg` and invoked with three arguments; * (value, index|key, collection). * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -6500,7 +6790,7 @@ * @param {Array|Object|string} collection The collection to iterate over. * @param {Array|Function|Object|string} [iteratee=_.identity] The function * invoked per iteration. If a property name or an object is provided it is - * used to create a "_.property" or "_.matches" style callback respectively. + * used to create a `_.property` or `_.matches` style callback respectively. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Array} Returns the new sorted array. * @example @@ -6517,7 +6807,7 @@ * { 'user': 'barney' } * ]; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.pluck(_.sortBy(users, 'user'), 'user'); * // => ['barney', 'fred', 'pebbles'] */ @@ -6569,7 +6859,7 @@ props = baseFlatten(args, false, false, 1), result = isLength(length) ? Array(length) : []; - baseEach(collection, function(value, key, collection) { + baseEach(collection, function(value) { var length = props.length, criteria = Array(length); @@ -6586,6 +6876,11 @@ * source object, returning an array of all elements that have equivalent * property values. * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. For comparing a single + * own or inherited property value see `_.matchesProperty`. + * * @static * @memberOf _ * @category Collection @@ -6595,18 +6890,15 @@ * @example * * var users = [ - * { 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] }, - * { 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] } + * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] }, + * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] } * ]; * - * _.pluck(_.where(users, { 'age': 36 }), 'user'); + * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user'); * // => ['barney'] * * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user'); * // => ['fred'] - * - * _.pluck(_.where(users, { 'status': 'busy' }), 'user'); - * // => ['barney', 'fred'] */ function where(collection, source) { return filter(collection, baseMatches(source)); @@ -6656,8 +6948,8 @@ * // => logs 'done saving!' after the two async saves have completed */ function after(n, func) { - if (!isFunction(func)) { - if (isFunction(n)) { + if (typeof func != 'function') { + if (typeof n == 'function') { var temp = n; n = func; func = temp; @@ -6715,8 +7007,8 @@ */ function before(n, func) { var result; - if (!isFunction(func)) { - if (isFunction(n)) { + if (typeof func != 'function') { + if (typeof n == 'function') { var temp = n; n = func; func = temp; @@ -7038,7 +7330,7 @@ maxWait = false, trailing = true; - if (!isFunction(func)) { + if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } wait = wait < 0 ? 0 : wait; @@ -7208,7 +7500,7 @@ length = funcs.length; if (!length) { - return function() {}; + return function() { return arguments[0]; }; } if (!arrayEvery(funcs, isFunction)) { throw new TypeError(FUNC_ERROR_TEXT); @@ -7253,7 +7545,7 @@ fromIndex = funcs.length - 1; if (fromIndex < 0) { - return function() {}; + return function() { return arguments[0]; }; } if (!arrayEvery(funcs, isFunction)) { throw new TypeError(FUNC_ERROR_TEXT); @@ -7323,7 +7615,7 @@ * // => { 'user': 'barney' } */ function memoize(func, resolver) { - if (!isFunction(func) || (resolver && !isFunction(resolver))) { + if (typeof func != 'function' || (resolver && typeof resolver != 'function')) { throw new TypeError(FUNC_ERROR_TEXT); } var memoized = function() { @@ -7361,7 +7653,7 @@ * // => [1, 3, 5] */ function negate(predicate) { - if (!isFunction(predicate)) { + if (typeof predicate != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } return function() { @@ -7376,7 +7668,6 @@ * * @static * @memberOf _ - * @type Function * @category Function * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. @@ -7499,6 +7790,45 @@ return createWrapper(func, REARG_FLAG, null, null, null, indexes); } + /** + * Creates a function that invokes `func` with the `this` binding of the + * created function and the array of arguments provided to the created + * function much like [Function#apply](http://es5.github.io/#x15.3.4.3). + * + * @static + * @memberOf _ + * @category Function + * @param {Function} func The function to spread arguments over. + * @returns {*} Returns the new function. + * @example + * + * var spread = _.spread(function(who, what) { + * return who + ' says ' + what; + * }); + * + * spread(['Fred', 'hello']); + * // => 'Fred says hello' + * + * // with a Promise + * var numbers = Promise.all([ + * Promise.resolve(40), + * Promise.resolve(36) + * ]); + * + * numbers.then(_.spread(function(x, y) { + * return x + y; + * })); + * // => a Promise of 76 + */ + function spread(func) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + return function(array) { + return func.apply(this, array); + }; + } + /** * Creates a function that only invokes `func` at most once per every `wait` * milliseconds. The created function comes with a `cancel` method to cancel @@ -7541,7 +7871,7 @@ var leading = true, trailing = true; - if (!isFunction(func)) { + if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } if (options === false) { @@ -7855,7 +8185,8 @@ * arguments; (value, other [, index|key]). * * **Note:** This method supports comparing arrays, booleans, `Date` objects, - * numbers, `Object` objects, regexes, and strings. Functions and DOM nodes + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. Functions and DOM nodes * are **not** supported. Provide a customizer function to extend support * for comparing other values. * @@ -8025,7 +8356,7 @@ * @static * @memberOf _ * @category Lang - * @param {Object} source The object to inspect. + * @param {Object} object The object to inspect. * @param {Object} source The object of property values to match. * @param {Function} [customizer] The function to customize comparing values. * @param {*} [thisArg] The `this` binding of `customizer`. @@ -8454,10 +8785,14 @@ * This method is like `_.findIndex` except that it returns the key of the * first element `predicate` returns truthy for, instead of the element itself. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -8466,8 +8801,7 @@ * @category Object * @param {Object} object The object to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {string|undefined} Returns the key of the matched element, else `undefined`. * @example @@ -8481,11 +8815,15 @@ * _.findKey(users, function(chr) { return chr.age < 40; }); * // => 'barney' (iteration order is not guaranteed) * - * // using the "_.matches" callback shorthand - * _.findKey(users, { 'age': 1 }); + * // using the `_.matches` callback shorthand + * _.findKey(users, { 'age': 1, 'active': true }); * // => 'pebbles' * - * // using the "_.property" callback shorthand + * // using the `_.matchesProperty` callback shorthand + * _.findKey(users, 'active', false); + * // => 'fred' + * + * // using the `_.property` callback shorthand * _.findKey(users, 'active'); * // => 'barney' */ @@ -8498,10 +8836,14 @@ * This method is like `_.findKey` except that it iterates over elements of * a collection in the opposite order. * - * If a property name is provided for `predicate` the created "_.property" + * If a property name is provided for `predicate` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `predicate` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -8510,8 +8852,7 @@ * @category Object * @param {Object} object The object to search. * @param {Function|Object|string} [predicate=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `predicate`. * @returns {string|undefined} Returns the key of the matched element, else `undefined`. * @example @@ -8525,11 +8866,15 @@ * _.findLastKey(users, function(chr) { return chr.age < 40; }); * // => returns `pebbles` assuming `_.findKey` returns `barney` * - * // using the "_.matches" callback shorthand - * _.findLastKey(users, { 'age': 36 }); + * // using the `_.matches` callback shorthand + * _.findLastKey(users, { 'age': 36, 'active': true }); * // => 'barney' * - * // using the "_.property" callback shorthand + * // using the `_.matchesProperty` callback shorthand + * _.findLastKey(users, 'active', false); + * // => 'fred' + * + * // using the `_.property` callback shorthand * _.findLastKey(users, 'active'); * // => 'pebbles' */ @@ -8819,12 +9164,12 @@ var Ctor = object.constructor, index = -1, - proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto, + proto = (isFunction(Ctor) && Ctor.prototype) || objectProto, isProto = proto === object, result = Array(length), skipIndexes = length > 0, skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error), - skipProto = support.enumPrototypes && typeof object == 'function'; + skipProto = support.enumPrototypes && isFunction(object); while (++index < length) { result[index] = (index + ''); @@ -8867,10 +9212,14 @@ * iteratee function is bound to `thisArg` and invoked with three arguments; * (value, key, object). * - * If a property name is provided for `iteratee` the created "_.property" + * If a property name is provided for `iteratee` the created `_.property` * style callback returns the property value of the given element. * - * If an object is provided for `iteratee` the created "_.matches" style + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `iteratee` the created `_.matches` style * callback returns `true` for elements that have the properties of the given * object, else `false`. * @@ -8879,8 +9228,7 @@ * @category Object * @param {Object} object The object to iterate over. * @param {Function|Object|string} [iteratee=_.identity] The function invoked - * per iteration. If a property name or object is provided it is used to - * create a "_.property" or "_.matches" style callback respectively. + * per iteration. * @param {*} [thisArg] The `this` binding of `iteratee`. * @returns {Object} Returns the new mapped object. * @example @@ -8893,7 +9241,7 @@ * 'pebbles': { 'user': 'pebbles', 'age': 1 } * }; * - * // using the "_.property" callback shorthand + * // using the `_.property` callback shorthand * _.mapValues(users, 'age'); * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) */ @@ -9138,7 +9486,7 @@ if (isArr) { accumulator = isArray(object) ? new Ctor : []; } else { - accumulator = baseCreate(typeof Ctor == 'function' && Ctor.prototype); + accumulator = baseCreate(isFunction(Ctor) && Ctor.prototype); } } else { accumulator = {}; @@ -9968,7 +10316,7 @@ return string; } if (guard ? isIterateeCall(value, chars, guard) : chars == null) { - return string.slice(trimmedLeftIndex(string)) + return string.slice(trimmedLeftIndex(string)); } return string.slice(charsLeftIndex(string, (chars + ''))); } @@ -9998,7 +10346,7 @@ return string; } if (guard ? isIterateeCall(value, chars, guard) : chars == null) { - return string.slice(0, trimmedRightIndex(string) + 1) + return string.slice(0, trimmedRightIndex(string) + 1); } return string.slice(0, charsRightIndex(string, (chars + '')) + 1); } @@ -10141,8 +10489,8 @@ /*------------------------------------------------------------------------*/ /** - * Attempts to invoke `func`, returning either the result or the caught - * error object. + * Attempts to invoke `func`, returning either the result or the caught error + * object. Any additional arguments are provided to `func` when it is invoked. * * @static * @memberOf _ @@ -10152,9 +10500,9 @@ * @example * * // avoid throwing errors for invalid selectors - * var elements = _.attempt(function() { + * var elements = _.attempt(function(selector) { * return document.querySelectorAll(selector); - * }); + * }, '>_>'); * * if (_.isError(elements)) { * elements = []; @@ -10162,17 +10510,18 @@ */ function attempt(func) { try { - return func(); + return func.apply(undefined, baseSlice(arguments, 1)); } catch(e) { - return isError(e) ? e : Error(e); + return isError(e) ? e : new Error(e); } } /** - * Creates a function bound to an optional `thisArg`. If `func` is a property - * name the created callback returns the property value for a given element. - * If `func` is an object the created callback returns `true` for elements - * that contain the equivalent object properties, otherwise it returns `false`. + * Creates a function that invokes `func` with the `this` binding of `thisArg` + * and arguments of the created function. If `func` is a property name the + * created callback returns the property value for a given element. If `func` + * is an object the created callback returns `true` for elements that contain + * the equivalent object properties, otherwise it returns `false`. * * @static * @memberOf _ @@ -10256,6 +10605,11 @@ * and `source`, returning `true` if the given object has equivalent property * values, else `false`. * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. For comparing a single + * own or inherited property value see `_.matchesProperty`. + * * @static * @memberOf _ * @category Utility @@ -10264,22 +10618,46 @@ * @example * * var users = [ - * { 'user': 'fred', 'age': 40 }, - * { 'user': 'barney', 'age': 36 } + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } * ]; * - * var matchesAge = _.matches({ 'age': 36 }); - * - * _.filter(users, matchesAge); - * // => [{ 'user': 'barney', 'age': 36 }] - * - * _.find(users, matchesAge); - * // => { 'user': 'barney', 'age': 36 } + * _.filter(users, _.matches({ 'age': 40, 'active': false })); + * // => [{ 'user': 'fred', 'age': 40, 'active': false }] */ function matches(source) { return baseMatches(baseClone(source, true)); } + /** + * Creates a function which compares the property value of `key` on a given + * object to `value`. + * + * **Note:** This method supports comparing arrays, booleans, `Date` objects, + * numbers, `Object` objects, regexes, and strings. Objects are compared by + * their own, not inherited, enumerable properties. + * + * @static + * @memberOf _ + * @category Utility + * @param {string} key The key of the property to get. + * @param {*} value The value to compare. + * @returns {Function} Returns the new function. + * @example + * + * var users = [ + * { 'user': 'barney' }, + * { 'user': 'fred' }, + * { 'user': 'pebbles' } + * ]; + * + * _.find(users, _.matchesProperty('user', 'fred')); + * // => { 'user': 'fred', 'age': 40 } + */ + function matchesProperty(key, value) { + return baseMatchesProperty(key + '', baseClone(value, true)); + } + /** * Adds all own enumerable function properties of a source object to the * destination object. If `object` is a function then methods are added to @@ -10302,6 +10680,9 @@ * }); * } * + * // use `_.runInContext` to avoid potential conflicts (esp. in Node.js) + * var _ = require('lodash').runInContext(); + * * _.mixin({ 'vowels': vowels }); * _.vowels('fred'); * // => ['e'] @@ -10576,7 +10957,11 @@ /*------------------------------------------------------------------------*/ // Ensure `new LodashWrapper` is an instance of `lodash`. - LodashWrapper.prototype = lodash.prototype; + LodashWrapper.prototype = baseCreate(lodash.prototype); + + // Ensure `new LazyWraper` is an instance of `LodashWrapper` + LazyWrapper.prototype = baseCreate(LodashWrapper.prototype); + LazyWrapper.prototype.constructor = LazyWrapper; // Add functions to the `Map` cache. MapCache.prototype['delete'] = mapDelete; @@ -10617,6 +11002,7 @@ lodash.dropRight = dropRight; lodash.dropRightWhile = dropRightWhile; lodash.dropWhile = dropWhile; + lodash.fill = fill; lodash.filter = filter; lodash.flatten = flatten; lodash.flattenDeep = flattenDeep; @@ -10640,6 +11026,7 @@ lodash.map = map; lodash.mapValues = mapValues; lodash.matches = matches; + lodash.matchesProperty = matchesProperty; lodash.memoize = memoize; lodash.merge = merge; lodash.mixin = mixin; @@ -10665,6 +11052,7 @@ lodash.slice = slice; lodash.sortBy = sortBy; lodash.sortByAll = sortByAll; + lodash.spread = spread; lodash.take = take; lodash.takeRight = takeRight; lodash.takeRightWhile = takeRightWhile; @@ -10838,14 +11226,15 @@ // Add `LazyWrapper` methods that accept an `iteratee` value. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) { - var isFilter = index == LAZY_FILTER_FLAG; + var isFilter = index == LAZY_FILTER_FLAG, + isWhile = index == LAZY_WHILE_FLAG; LazyWrapper.prototype[methodName] = function(iteratee, thisArg) { var result = this.clone(), - filtered = result.filtered, - iteratees = result.iteratees || (result.iteratees = []); + filtered = result.__filtered__, + iteratees = result.__iteratees__ || (result.__iteratees__ = []); - result.filtered = filtered || isFilter || (index == LAZY_WHILE_FLAG && result.dir < 0); + result.__filtered__ = filtered || isFilter || (isWhile && result.__dir__ < 0); iteratees.push({ 'iteratee': getCallback(iteratee, thisArg, 3), 'type': index }); return result; }; @@ -10853,19 +11242,19 @@ // Add `LazyWrapper` methods for `_.drop` and `_.take` variants. arrayEach(['drop', 'take'], function(methodName, index) { - var countName = methodName + 'Count', + var countName = '__' + methodName + 'Count__', whileName = methodName + 'While'; LazyWrapper.prototype[methodName] = function(n) { - n = n == null ? 1 : nativeMax(+n || 0, 0); + n = n == null ? 1 : nativeMax(floor(n) || 0, 0); var result = this.clone(); - if (result.filtered) { + if (result.__filtered__) { var value = result[countName]; result[countName] = index ? nativeMin(value, n) : (value + n); } else { - var views = result.views || (result.views = []); - views.push({ 'size': n, 'type': methodName + (result.dir < 0 ? 'Right' : '') }); + var views = result.__views__ || (result.__views__ = []); + views.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') }); } return result; }; @@ -10881,7 +11270,7 @@ // Add `LazyWrapper` methods for `_.first` and `_.last`. arrayEach(['first', 'last'], function(methodName, index) { - var takeName = 'take' + (index ? 'Right': ''); + var takeName = 'take' + (index ? 'Right' : ''); LazyWrapper.prototype[methodName] = function() { return this[takeName](1).value()[0]; @@ -10903,27 +11292,26 @@ createCallback = index ? baseMatches : baseProperty; LazyWrapper.prototype[methodName] = function(value) { - return this[operationName](createCallback(index ? value : (value + ''))); + return this[operationName](createCallback(value)); }; }); - LazyWrapper.prototype.dropWhile = function(iteratee, thisArg) { - var done, - lastIndex, - isRight = this.dir < 0; + LazyWrapper.prototype.compact = function() { + return this.filter(identity); + }; - iteratee = getCallback(iteratee, thisArg, 3); + LazyWrapper.prototype.dropWhile = function(predicate, thisArg) { + var done; + predicate = getCallback(predicate, thisArg, 3); return this.filter(function(value, index, array) { - done = done && (isRight ? index < lastIndex : index > lastIndex); - lastIndex = index; - return done || (done = !iteratee(value, index, array)); + return done || (done = !predicate(value, index, array)); }); }; - LazyWrapper.prototype.reject = function(iteratee, thisArg) { - iteratee = getCallback(iteratee, thisArg, 3); + LazyWrapper.prototype.reject = function(predicate, thisArg) { + predicate = getCallback(predicate, thisArg, 3); return this.filter(function(value, index, array) { - return !iteratee(value, index, array); + return !predicate(value, index, array); }); }; @@ -10938,6 +11326,10 @@ return result; }; + LazyWrapper.prototype.toArray = function() { + return this.drop(0); + }; + // Add `LazyWrapper` methods to `lodash.prototype`. baseForOwn(LazyWrapper.prototype, function(func, methodName) { var lodashFunc = lodash[methodName], @@ -10965,8 +11357,8 @@ var wrapper = onlyLazy ? value : new LazyWrapper(this), result = func.apply(wrapper, args); - if (!retUnwrapped && (isHybrid || result.actions)) { - var actions = result.actions || (result.actions = []); + if (!retUnwrapped && (isHybrid || result.__actions__)) { + var actions = result.__actions__ || (result.__actions__ = []); actions.push({ 'func': thru, 'args': [interceptor], 'thisArg': lodash }); } return new LodashWrapper(result, chainAll); @@ -11010,9 +11402,11 @@ // Add chaining functions to the lodash wrapper. lodash.prototype.chain = wrapperChain; + lodash.prototype.commit = wrapperCommit; + lodash.prototype.plant = wrapperPlant; lodash.prototype.reverse = wrapperReverse; lodash.prototype.toString = wrapperToString; - lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; + lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue; // Add function aliases to the lodash wrapper. lodash.prototype.collect = lodash.prototype.map; diff --git a/package.json b/package.json index a5ad81146b..c7ea952ece 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "name": "lodash", - "version": "3.1.0", + "version": "3.2.0", "main": "lodash.src.js", "private": true, "devDependencies": { "curl-amd": "0.8.12", - "dojo": "~1.10.2", - "jquery": "~1.11.2", + "dojo": "~1.10.0", + "jquery": "~1.11.0", "platform": "~1.3.0", "qunit-extras": "~1.4.0", - "qunitjs": "~1.16.0", - "requirejs": "~2.1.15" + "qunitjs": "~1.17.0", + "requirejs": "~2.1.0" }, "volo": { "type": "directory", diff --git a/test/backbone.html b/test/backbone.html index f9dc8ab96e..61834c8d05 100644 --- a/test/backbone.html +++ b/test/backbone.html @@ -42,12 +42,7 @@

Test

}()); QUnit.config.asyncRetries = 10; - - QUnit.begin(function() { - QUnit.config.hidepassed = true; - document.getElementById('qunit-tests').className += ' hidepass'; - document.getElementById('qunit-urlconfig-hidepassed').checked = true; - }); + QUnit.config.hidepassed = true; // load lodash if (!ui.isModularize) { diff --git a/test/saucelabs.js b/test/saucelabs.js index ad6eb83ad8..975df98336 100644 --- a/test/saucelabs.js +++ b/test/saucelabs.js @@ -102,7 +102,8 @@ var browserNameMap = { /** List of platforms to load the runner on. */ var platforms = [ - ['Linux', 'android', '4.3'], + ['Linux', 'android', '5.0'], + ['Linux', 'android', '4.4'], ['Linux', 'android', '4.0'], ['Windows 8.1', 'firefox', '35'], ['Windows 8.1', 'firefox', '34'], diff --git a/test/test.js b/test/test.js index f1bfde13d2..4eef133963 100644 --- a/test/test.js +++ b/test/test.js @@ -49,14 +49,18 @@ freeze = Object.freeze, hasOwnProperty = objectProto.hasOwnProperty, JSON = root.JSON, - noop = function() {}, objToString = objectProto.toString, + noop = function() {}, params = root.arguments, push = arrayProto.push, slice = arrayProto.slice, system = root.system, Uint8Array = root.Uint8Array; + /** Math helpers. */ + var add = function(x, y) { return x + y; }, + square = function(n) { return n * n; }; + /** Used to set property descriptors. */ var defineProperty = (function() { try { @@ -147,7 +151,7 @@ QUnit = QUnit.QUnit || QUnit )); - /** Load and install QUnit Extras and ES6 Set/WeakMap shims. */ + /** Load QUnit Extras and ES6 Set/WeakMap shims. */ (function() { var paths = [ './asset/set.js', @@ -1076,6 +1080,11 @@ strictEqual(_.attempt(_.constant('x')), 'x'); }); + test('should provide additional arguments to `func`', 1, function() { + var actual = _.attempt(function() { return slice.call(arguments); }, 1, 2); + deepEqual(actual, [1, 2]); + }); + test('should return the caught error', 1, function() { var expected = _.map(errors, _.constant(true)); @@ -1776,8 +1785,8 @@ var object = { 'a': value, 'b': { 'c': value } }, actual = func(object); - notStrictEqual(actual, object); deepEqual(actual, object); + notStrictEqual(actual, object); var expected = typeof value == 'function' ? { 'c': Foo.c } : (value && {}); deepEqual(func(value), expected); @@ -1915,8 +1924,11 @@ }); test('`_.' + methodName + '` should create an object from the same realm as `value`', 1, function() { + var props = []; + var objects = _.transform(_, function(result, value, key) { if (_.startsWith(key, '_') && _.isObject(value) && !_.isArguments(value) && !_.isElement(value) && !_.isFunction(value)) { + props.push(_.capitalize(_.camelCase(key))); result.push(value); } }, []); @@ -1930,7 +1942,7 @@ return result !== object && (result instanceof Ctor || !(new Ctor instanceof Ctor)); }); - deepEqual(actual, expected); + deepEqual(actual, expected, props.join(', ')); }); test('`_.' + methodName + '` should return a unwrapped value when chaining', 2, function() { @@ -1971,16 +1983,28 @@ test('should work when in between lazy operators', 2, function() { if (!isNpm) { - var actual = _(falsey).slice().compact().slice().value(); + var actual = _(falsey).thru(_.slice).compact().thru(_.slice).value(); deepEqual(actual, []); - actual = _(falsey).slice().push(true, 1).compact().push('a').slice().value(); + actual = _(falsey).thru(_.slice).push(true, 1).compact().push('a').value(); deepEqual(actual, [true, 1, 'a']); } else { skipTest(2); } }); + + test('should work in a lazy chain sequence', 1, function() { + if (!isNpm) { + var array = [1, null, 3], + actual = _(array).map(square).compact().reverse().take().value(); + + deepEqual(actual, [9]); + } + else { + skipTest(); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -2003,19 +2027,9 @@ isFlow = methodName == 'flow'; test('`_.' + methodName + '` should supply each function with the return value of the previous', 1, function() { - function add(x, y) { - return x + y; - } - - function square(n) { - return n * n; - } - - function fixed(n) { - return n.toFixed(1); - } + var fixed = function(n) { return n.toFixed(1); }, + combined = isFlow ? func(add, square, fixed) : func(fixed, square, add); - var combined = isFlow ? func(add, square, fixed) : func(fixed, square, add); strictEqual(combined(1, 2), '9.0'); }); @@ -2023,15 +2037,15 @@ notStrictEqual(func(_.noop), _.noop); }); - test('`_.' + methodName + '` should return a noop function when no arguments are provided', 2, function() { + test('`_.' + methodName + '` should return an identity function when no arguments are provided', 2, function() { var combined = func(); try { - strictEqual(combined(), undefined); + strictEqual(combined('a'), 'a'); } catch(e) { ok(false, e.message); } - notStrictEqual(combined, _.noop); + notStrictEqual(combined, _.identity); }); test('`_.' + methodName + '` should return a wrapped value when chaining', 1, function() { @@ -2148,7 +2162,7 @@ deepEqual(actual.hasOwnProperty, 2); }); - test('should work with a "_.pluck" style `iteratee`', 1, function() { + test('should work with a "_.property" style `iteratee`', 1, function() { var actual = _.countBy(['one', 'two', 'three'], 'length'); deepEqual(actual, { '3': 2, '5': 1 }); }); @@ -2175,10 +2189,10 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { var array = [1, 2, 1, 3], - predicate = function(value) { return value > 1; }, - actual = _(array).countBy(_.identity).map(String).filter(predicate).take().value(); + predicate = function(value) { return value > 2; }, + actual = _(array).countBy(_.identity).map(square).filter(predicate).take().value(); - deepEqual(actual, ['2']); + deepEqual(actual, [4]); } else { skipTest(); @@ -2342,6 +2356,19 @@ strictEqual(callback({}), false); }); + test('should return a callback created by `_.matchesProperty` when `func` is a number or string and `thisArg` is not `undefined`', 3, function() { + var array = ['a'], + callback = _.callback(0, 'a'); + + strictEqual(callback(array), true); + + callback = _.callback('0', 'a'); + strictEqual(callback(array), true); + + callback = _.callback(1, undefined); + strictEqual(callback(array), undefined); + }); + test('should return a callback created by `_.property` when `func` is a number or string', 2, function() { var array = ['a'], callback = _.callback(0); @@ -3378,16 +3405,16 @@ } }); - asyncTest('should accept additional arguments', 1, function() { + asyncTest('should provide additional arguments to `func`', 1, function() { if (!(isRhino && isModularize)) { var args; _.defer(function() { args = slice.call(arguments); - }, 1, 2, 3); + }, 1, 2); setTimeout(function() { - deepEqual(args, [1, 2, 3]); + deepEqual(args, [1, 2]); QUnit.start(); }, 128); } @@ -3444,16 +3471,16 @@ } }); - asyncTest('should accept additional arguments', 1, function() { + asyncTest('should provide additional arguments to `func`', 1, function() { if (!(isRhino && isModularize)) { var args; _.delay(function() { args = slice.call(arguments); - }, 32, 1, 2, 3); + }, 32, 1, 2); setTimeout(function() { - deepEqual(args, [1, 2, 3]); + deepEqual(args, [1, 2]); QUnit.start(); }, 128); } @@ -3705,7 +3732,7 @@ QUnit.module('lodash.dropRightWhile'); (function() { - var array = [1, 2, 3]; + var array = [1, 2, 3, 4]; var objects = [ { 'a': 0, 'b': 0 }, @@ -3715,10 +3742,10 @@ test('should drop elements while `predicate` returns truthy', 1, function() { var actual = _.dropRightWhile(array, function(num) { - return num > 1; + return num > 2; }); - deepEqual(actual, [1]); + deepEqual(actual, [1, 2]); }); test('should provide the correct `predicate` arguments', 1, function() { @@ -3728,38 +3755,57 @@ args = slice.call(arguments); }); - deepEqual(args, [3, 2, array]); + deepEqual(args, [4, 3, array]); }); test('should support the `thisArg` argument', 1, function() { var actual = _.dropRightWhile(array, function(num, index) { - return this[index] > 1; + return this[index] > 2; }, array); - deepEqual(actual, [1]); + deepEqual(actual, [1, 2]); }); - test('should work with a "_.pluck" style `predicate`', 1, function() { - deepEqual(_.dropRightWhile(objects, 'b'), objects.slice(0, 1)); + test('should work with a "_.matches" style `predicate`', 1, function() { + deepEqual(_.dropRightWhile(objects, { 'b': 2 }), objects.slice(0, 2)); }); - test('should work with a "_.where" style `predicate`', 1, function() { - deepEqual(_.dropRightWhile(objects, { 'b': 2 }), objects.slice(0, 2)); + test('should work with a "_.matchesProperty" style `predicate`', 1, function() { + deepEqual(_.dropRightWhile(objects, 'b', 2), objects.slice(0, 2)); + }); + + test('should work with a "_.property" style `predicate`', 1, function() { + deepEqual(_.dropRightWhile(objects, 'b'), objects.slice(0, 1)); }); test('should return a wrapped value when chaining', 2, function() { if (!isNpm) { var wrapped = _(array).dropRightWhile(function(num) { - return num > 1; + return num > 2; }); ok(wrapped instanceof _); - deepEqual(wrapped.value(), [1]); + deepEqual(wrapped.value(), [1, 2]); } else { skipTest(2); } }); + + test('should provide the correct `predicate` arguments in a lazy chain sequence', 1, function() { + if (!isNpm) { + var args; + + _(array).map(function(n) { return n * n; }).dropRightWhile(function() { + args = slice.call(arguments); + }).value(); + + deepEqual(args, [16, 3, array]); + } + else { + skipTest(1); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -3767,7 +3813,7 @@ QUnit.module('lodash.dropWhile'); (function() { - var array = [1, 2, 3]; + var array = [1, 2, 3, 4]; var objects = [ { 'a': 2, 'b': 2 }, @@ -3780,7 +3826,7 @@ return num < 3; }); - deepEqual(actual, [3]); + deepEqual(actual, [3, 4]); }); test('should provide the correct `predicate` arguments', 1, function() { @@ -3798,15 +3844,19 @@ return this[index] < 3; }, array); - deepEqual(actual, [3]); + deepEqual(actual, [3, 4]); }); - test('should work with a "_.pluck" style `predicate`', 1, function() { - deepEqual(_.dropWhile(objects, 'b'), objects.slice(2)); + test('should work with a "_.matches" style `predicate`', 1, function() { + deepEqual(_.dropWhile(objects, { 'b': 2 }), objects.slice(1)); }); - test('should work with a "_.where" style `predicate`', 1, function() { - deepEqual(_.dropWhile(objects, { 'b': 2 }), objects.slice(1)); + test('should work with a "_.matchesProperty" style `predicate`', 1, function() { + deepEqual(_.dropWhile(objects, 'b', 2), objects.slice(1)); + }); + + test('should work with a "_.property" style `predicate`', 1, function() { + deepEqual(_.dropWhile(objects, 'b'), objects.slice(2)); }); test('should return a wrapped value when chaining', 2, function() { @@ -3816,12 +3866,27 @@ }); ok(wrapped instanceof _); - deepEqual(wrapped.value(), [3]); + deepEqual(wrapped.value(), [3, 4]); } else { skipTest(2); } }); + + test('should provide the correct `predicate` arguments in a lazy chain sequence', 1, function() { + if (!isNpm) { + var args; + + _(array).map(function(n) { return n * n; }).dropWhile(function() { + args = slice.call(arguments); + }).value(); + + deepEqual(args, [1, 0, array]); + } + else { + skipTest(1); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -3952,7 +4017,7 @@ strictEqual(_.every([undefined, undefined, undefined], _.identity), false); }); - test('should work with a "_.pluck" style `predicate`', 2, function() { + test('should work with a "_.property" style `predicate`', 2, function() { var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }]; strictEqual(_.every(objects, 'a'), false); strictEqual(_.every(objects, 'b'), true); @@ -4021,11 +4086,144 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.fill'); + + (function() { + test('should use a default `start` of `0` and a default `end` of `array.length`', 1, function() { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a'), ['a', 'a', 'a']); + }); + + test('should use `undefined` for `value` if not provided', 2, function() { + var array = [1, 2, 3], + actual = _.fill(array); + + deepEqual(actual, [undefined, undefined, undefined]); + ok(_.every(actual, function(value, index) { return index in actual; })); + }); + + test('should work with a positive `start`', 1, function() { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', 1), [1, 'a', 'a']); + }); + + test('should work with a `start` >= `array.length`', 4, function() { + _.each([3, 4, Math.pow(2, 32), Infinity], function(start) { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', start), [1, 2, 3]); + }); + }); + + test('should treat falsey `start` values as `0`', 1, function() { + var expected = _.map(falsey, _.constant(['a', 'a', 'a'])); + + var actual = _.map(falsey, function(start) { + var array = [1, 2, 3]; + return _.fill(array, 'a', start); + }); + + deepEqual(actual, expected); + }); + + test('should work with a negative `start`', 1, function() { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', -1), [1, 2, 'a']); + }); + + test('should work with a negative `start` <= negative `array.length`', 3, function() { + _.each([-3, -4, -Infinity], function(start) { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', start), ['a', 'a', 'a']); + }); + }); + + test('should work with `start` >= `end`', 2, function() { + _.each([2, 3], function(start) { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', start, 2), [1, 2, 3]); + }); + }); + + test('should work with a positive `end`', 1, function() { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', 0, 1), ['a', 2, 3]); + }); + + test('should work with a `end` >= `array.length`', 4, function() { + _.each([3, 4, Math.pow(2, 32), Infinity], function(end) { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', 0, end), ['a', 'a', 'a']); + }); + }); + + test('should treat falsey `end` values, except `undefined`, as `0`', 1, function() { + var expected = _.map(falsey, function(value) { + return value === undefined ? ['a', 'a', 'a'] : [1, 2, 3]; + }); + + var actual = _.map(falsey, function(end) { + var array = [1, 2, 3]; + return _.fill(array, 'a', 0, end); + }); + + deepEqual(actual, expected); + }); + + test('should work with a negative `end`', 1, function() { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', 0, -1), ['a', 'a', 3]); + }); + + test('should work with a negative `end` <= negative `array.length`', 3, function() { + _.each([-3, -4, -Infinity], function(end) { + var array = [1, 2, 3]; + deepEqual(_.fill(array, 'a', 0, end), [1, 2, 3]); + }); + }); + + test('should coerce `start` and `end` to integers', 1, function() { + var positions = [[0.1, 1.1], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]]; + + var actual = _.map(positions, function(pos) { + var array = [1, 2, 3]; + return _.fill.apply(_, [array, 'a'].concat(pos)); + }); + + deepEqual(actual, [['a', 2, 3], ['a', 2, 3], ['a', 2, 3], [1, 'a', 'a'], ['a', 2, 3], [1, 2, 3]]); + }); + + test('should work as an iteratee for `_.map`', 1, function() { + var array = [[1, 2], [3, 4]], + actual = _.map(array, _.fill); + + deepEqual(actual, [[0, 0], [1, 1]]); + }); + + test('should return a wrapped value when chaining', 3, function() { + if (!isNpm) { + var array = [1, 2, 3], + wrapped = _(array).fill('a'), + actual = wrapped.value(); + + ok(wrapped instanceof _); + deepEqual(actual, ['a', 'a', 'a']); + strictEqual(actual, array); + } + else { + skipTest(3); + } + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.filter'); (function() { + var array = [1, 2, 3]; + test('should return elements `predicate` returns truthy for', 1, function() { - var actual = _.filter([1, 2, 3], function(num) { + var actual = _.filter(array, function(num) { return num % 2; }); @@ -4090,22 +4288,25 @@ strictEqual(func(objects, function(object) { return object.a === 3; }), expected[1]); }); - test('should work with a "_.pluck" style `predicate`', 1, function() { - strictEqual(func(objects, 'b'), expected[3]); + test('should work with a "_.matches" style `predicate`', 1, function() { + strictEqual(func(objects, { 'b': 2 }), expected[2]); }); - test('should work with a "_.where" style `predicate`', 1, function() { - strictEqual(func(objects, { 'b': 2 }), expected[2]); + test('should work with a "_.matchesProperty" style `predicate`', 1, function() { + strictEqual(func(objects, 'b', 2), expected[2]); + }); + + test('should work with a "_.property" style `predicate`', 1, function() { + strictEqual(func(objects, 'b'), expected[3]); }); test('should return `' + expected[1] + '` for empty collections', 1, function() { - var actual = [], - emptyValues = _.endsWith(methodName, 'Index') ? _.reject(empties, _.isPlainObject) : empties, - expecting = _.map(emptyValues, function() { return expected[1]; }); + var emptyValues = _.endsWith(methodName, 'Index') ? _.reject(empties, _.isPlainObject) : empties, + expecting = _.map(emptyValues, _.constant(expected[1])); - _.each(emptyValues, function(value) { + var actual = _.map(emptyValues, function(value) { try { - actual.push(func(value, { 'a': 3 })); + return func(value, { 'a': 3 }); } catch(e) {} }); @@ -4417,7 +4618,7 @@ QUnit.module('lodash.takeRightWhile'); (function() { - var array = [1, 2, 3]; + var array = [1, 2, 3, 4]; var objects = [ { 'a': 0, 'b': 0 }, @@ -4427,10 +4628,10 @@ test('should take elements while `predicate` returns truthy', 1, function() { var actual = _.takeRightWhile(array, function(num) { - return num > 1; + return num > 2; }); - deepEqual(actual, [2, 3]); + deepEqual(actual, [3, 4]); }); test('should provide the correct `predicate` arguments', 1, function() { @@ -4440,38 +4641,57 @@ args = slice.call(arguments); }); - deepEqual(args, [3, 2, array]); + deepEqual(args, [4, 3, array]); }); test('should support the `thisArg` argument', 1, function() { var actual = _.takeRightWhile(array, function(num, index) { - return this[index] > 1; + return this[index] > 2; }, array); - deepEqual(actual, [2, 3]); + deepEqual(actual, [3, 4]); }); - test('should work with a "_.pluck" style `predicate`', 1, function() { - deepEqual(_.takeRightWhile(objects, 'b'), objects.slice(1)); + test('should work with a "_.matches" style `predicate`', 1, function() { + deepEqual(_.takeRightWhile(objects, { 'b': 2 }), objects.slice(2)); }); - test('should work with a "_.where" style `predicate`', 1, function() { - deepEqual(_.takeRightWhile(objects, { 'b': 2 }), objects.slice(2)); + test('should work with a "_.matchesProperty" style `predicate`', 1, function() { + deepEqual(_.takeRightWhile(objects, 'b', 2), objects.slice(2)); + }); + + test('should work with a "_.property" style `predicate`', 1, function() { + deepEqual(_.takeRightWhile(objects, 'b'), objects.slice(1)); }); test('should return a wrapped value when chaining', 2, function() { if (!isNpm) { var wrapped = _(array).takeRightWhile(function(num) { - return num > 1; + return num > 2; }); ok(wrapped instanceof _); - deepEqual(wrapped.value(), [2, 3]); + deepEqual(wrapped.value(), [3, 4]); } else { skipTest(2); } }); + + test('should provide the correct `predicate` arguments in a lazy chain sequence', 1, function() { + if (!isNpm) { + var args; + + _(array).map(function(n) { return n * n; }).takeRightWhile(function() { + args = slice.call(arguments); + }).value(); + + deepEqual(args, [16, 3, array]); + } + else { + skipTest(1); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -4479,7 +4699,7 @@ QUnit.module('lodash.takeWhile'); (function() { - var array = [1, 2, 3]; + var array = [1, 2, 3, 4]; var objects = [ { 'a': 2, 'b': 2 }, @@ -4513,12 +4733,15 @@ deepEqual(actual, [1, 2]); }); - test('should work with a "_.pluck" style `predicate`', 1, function() { - deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2)); + test('should work with a "_.matches" style `predicate`', 1, function() { + deepEqual(_.takeWhile(objects, { 'b': 2 }), objects.slice(0, 1)); }); - test('should work with a "_.where" style `predicate`', 1, function() { - deepEqual(_.takeWhile(objects, { 'b': 2 }), objects.slice(0, 1)); + test('should work with a "_.matchesProperty" style `predicate`', 1, function() { + deepEqual(_.takeWhile(objects, 'b', 2), objects.slice(0, 1)); + }); + test('should work with a "_.property" style `predicate`', 1, function() { + deepEqual(_.takeWhile(objects, 'b'), objects.slice(0, 2)); }); test('should return a wrapped value when chaining', 2, function() { @@ -4534,6 +4757,21 @@ skipTest(2); } }); + + test('should provide the correct `predicate` arguments in a lazy chain sequence', 1, function() { + if (!isNpm) { + var args; + + _(array).map(function(n) { return n * n; }).takeWhile(function() { + args = slice.call(arguments); + }).value(); + + deepEqual(args, [1, 0, array]); + } + else { + skipTest(1); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -4741,9 +4979,12 @@ 'groupBy', 'indexBy', 'map', + 'mapValues', 'max', 'min', + 'omit', 'partition', + 'pick', 'reject', 'some' ]; @@ -4775,7 +5016,9 @@ var forInMethods = [ 'forIn', - 'forInRight' + 'forInRight', + 'omit', + 'pick' ]; var iterationMethods = [ @@ -4793,7 +5036,10 @@ 'forIn', 'forInRight', 'forOwn', - 'forOwnRight' + 'forOwnRight', + 'mapValues', + 'omit', + 'pick' ]; var rightMethods = [ @@ -5347,7 +5593,7 @@ deepEqual(actual.hasOwnProperty, [6.1, 6.4]); }); - test('should work with a "_.pluck" style `iteratee`', 1, function() { + test('should work with a "_.property" style `iteratee`', 1, function() { var actual = _.groupBy(['one', 'two', 'three'], 'length'); deepEqual(actual, { '3': ['one', 'two'], '5': ['three'] }); }); @@ -5538,6 +5784,10 @@ strictEqual(_.includes([1, NaN, 3], NaN), true); }); + test('should match `-0` as `0`', 1, function() { + strictEqual(_.includes([-0], 0), true); + }); + test('should be aliased', 2, function() { strictEqual(_.contains, _.includes); strictEqual(_.include, _.includes); @@ -5578,7 +5828,7 @@ deepEqual(actual.hasOwnProperty, 6.4); }); - test('should work with a "_.pluck" style `iteratee`', 1, function() { + test('should work with a "_.property" style `iteratee`', 1, function() { var actual = _.indexBy(['one', 'two', 'three'], 'length'); deepEqual(actual, { '3': 'two', '5': 'three' }); }); @@ -5605,10 +5855,10 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { var array = [1, 2, 1, 3], - predicate = function(value) { return value > 1; }, - actual = _(array).indexBy(_.identity).map(String).filter(predicate).take().value(); + predicate = function(value) { return value > 2; }, + actual = _(array).indexBy(_.identity).map(square).filter(predicate).take().value(); - deepEqual(actual, ['2']); + deepEqual(actual, [4]); } else { skipTest(); @@ -6341,7 +6591,7 @@ strictEqual(_.isEmpty(Foo), true); }); - test('should return an unwrapped value when intuitively chaining', 1, function() { + test('should return an unwrapped value when implicitly chaining', 1, function() { if (!isNpm) { strictEqual(_({}).isEmpty(), true); } @@ -6934,7 +7184,7 @@ } }); - test('should return an unwrapped value when intuitively chaining', 1, function() { + test('should return an unwrapped value when implicitly chaining', 1, function() { if (!isNpm) { strictEqual(_('a').isEqual('a'), true); } @@ -8370,6 +8620,10 @@ strictEqual(func([1, NaN, 3], NaN), 1); strictEqual(func([1, 3, NaN], NaN, true), 2); }); + + test('`_.' + methodName + '` should match `-0` as `0`', 1, function() { + strictEqual(func([-0], 0), 0); + }); }); /*--------------------------------------------------------------------------*/ @@ -8379,6 +8633,14 @@ (function() { var array = [1, 2, 3]; + test('should map values in `collection` to a new array', 2, function() { + var object = { 'a': 1, 'b': 2, 'c': 3 }, + expected = ['1', '2', '3']; + + deepEqual(_.map(array, String), expected); + deepEqual(_.map(object, String), expected); + }); + test('should provide the correct `iteratee` arguments', 1, function() { var args; @@ -8399,7 +8661,7 @@ deepEqual(actual, [3]); }); - test('should work with a "_.pluck" style `iteratee`', 1, function() { + test('should work with a "_.property" style `iteratee`', 1, function() { var objects = [{ 'a': 'x' }, { 'a': 'y' }]; deepEqual(_.map(objects, 'a'), ['x', 'y']); }); @@ -8472,16 +8734,29 @@ QUnit.module('lodash.mapValues'); (function() { - var object = { 'a': 1, 'b': 2, 'c': 3 }; + var array = [1, 2], + object = { 'a': 1, 'b': 2, 'c': 3 }; - test('should provide the correct `iteratee` arguments', 1, function() { - var args; + test('should map values in `object` to a new object', 1, function() { + var actual = _.mapValues(object, String); + deepEqual(actual, { 'a': '1', 'b': '2', 'c': '3' }); + }); - _.mapValues(object, function() { - args || (args = slice.call(arguments)); - }); + test('should treat arrays like objects', 1, function() { + var actual = _.mapValues(array, String); + deepEqual(actual, { '0': '1', '1': '2' }); + }); + + test('should provide the correct `iteratee` arguments', 2, function() { + _.each([object, array], function(value, index) { + var args; + + _.mapValues(value, function() { + args || (args = slice.call(arguments)); + }); - deepEqual(args, [1, 'a', object]); + deepEqual(args, [1, index ? '0' : 'a', value]); + }); }); test('should support the `thisArg` argument', 2, function() { @@ -8496,7 +8771,7 @@ deepEqual(actual, { '0': 3 }); }); - test('should work with a "_.pluck" style `iteratee`', 1, function() { + test('should work with a "_.property" style `iteratee`', 1, function() { var actual = _.mapValues({ 'a': { 'b': 1 } }, 'b'); deepEqual(actual, { 'a': 1 }); }); @@ -8509,9 +8784,10 @@ deepEqual(actual, { 'a': 'a' }); }); - test('should work on an object with no `iteratee`', 1, function() { + test('should work on an object with no `iteratee`', 2, function() { var actual = _.mapValues({ 'a': 1, 'b': 2, 'c': 3 }); deepEqual(actual, object); + notStrictEqual(actual, object); }); test('should accept a falsey `object` argument', 1, function() { @@ -8720,26 +8996,185 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('lodash.max'); + QUnit.module('lodash.matchesProperty'); (function() { - test('should return the largest value from a collection', 1, function() { - strictEqual(3, _.max([1, 2, 3])); - }); + test('should create a function that performs a deep comparison between a property value and `value`', 6, function() { + var object = { 'a': 1, 'b': 2, 'c': 3 }, + matches = _.matchesProperty('a', 1); - test('should return `-Infinity` for empty collections', 1, function() { - var expected = _.map(empties, _.constant(-Infinity)); + strictEqual(matches.length, 1); + strictEqual(matches(object), true); - var actual = _.map(empties, function(value) { - try { - return _.max(value); - } catch(e) {} - }); + matches = _.matchesProperty('b', 3); + strictEqual(matches(object), false); - deepEqual(actual, expected); - }); + matches = _.matchesProperty('a', { 'a': 1, 'c': 3 }); + strictEqual(matches({ 'a': object }), true); - test('should return `-Infinity` for non-numeric collection values', 1, function() { + matches = _.matchesProperty('a', { 'c': 3, 'd': 4 }); + strictEqual(matches(object), false); + + object = { 'a': { 'b': { 'c': 1, 'd': 2 }, 'e': 3 }, 'f': 4 }; + matches = _.matchesProperty('a', { 'b': { 'c': 1 } }); + + strictEqual(matches(object), true); + }); + + test('should compare a variety of values', 2, function() { + var object1 = { 'a': false, 'b': true, 'c': '3', 'd': 4, 'e': [5], 'f': { 'g': 6 } }, + object2 = { 'a': 0, 'b': 1, 'c': 3, 'd': '4', 'e': ['5'], 'f': { 'g': '6' } }, + matches = _.matchesProperty('a', object1); + + strictEqual(matches({ 'a': object1 }), true); + strictEqual(matches({ 'a': object2 }), false); + }); + + test('should not change match behavior if `value` is augmented', 9, function() { + _.each([{ 'a': { 'b': 2, 'c': 3 } }, { 'a': 1, 'b': 2 }, { 'a': 1 }], function(source, index) { + var object = _.cloneDeep(source), + matches = _.matchesProperty('a', source); + + strictEqual(matches({ 'a': object }), true); + + if (index) { + source.a = 2; + source.b = 1; + source.c = 3; + } else { + source.a.b = 1; + source.a.c = 2; + source.a.d = 3; + } + strictEqual(matches({ 'a': object }), true); + strictEqual(matches({ 'a': source }), false); + }); + }); + + test('should return `true` when comparing a `value` of empty arrays and objects', 1, function() { + var objects = [{ 'a': [1], 'b': { 'c': 1 } }, { 'a': [2, 3], 'b': { 'd': 2 } }], + matches = _.matchesProperty('a', { 'a': [], 'b': {} }); + + var actual = _.filter(objects, function(object) { + return matches({ 'a': object }); + }); + + deepEqual(actual, objects); + }); + + test('should not error for falsey `object` values', 1, function() { + var expected = _.map(falsey, _.constant(false)), + matches = _.matchesProperty('a', 1); + + var actual = _.map(falsey, function(value, index) { + try { + return index ? matches(value) : matches(); + } catch(e) {} + }); + + deepEqual(actual, expected); + }); + + test('should search arrays of `value` for values', 3, function() { + var objects = [{ 'a': ['b'] }, { 'a': ['c', 'd'] }], + matches = _.matchesProperty('a', ['d']), + actual = _.filter(objects, matches); + + deepEqual(actual, [objects[1]]); + + matches = _.matchesProperty('a', ['b', 'd']); + actual = _.filter(objects, matches); + deepEqual(actual, []); + + matches = _.matchesProperty('a', ['d', 'b']); + actual = _.filter(objects, matches); + deepEqual(actual, []); + }); + + test('should perform a partial comparison of all objects within arrays of `value`', 1, function() { + var objects = [ + { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 5, 'c': 6 }] }, + { 'a': [{ 'a': 1, 'b': 2 }, { 'a': 4, 'b': 6, 'c': 7 }] } + ]; + + var matches = _.matchesProperty('a', [{ 'a': 1 }, { 'a': 4, 'b': 5 }]), + actual = _.filter(objects, matches); + + deepEqual(actual, [objects[0]]); + }); + + test('should handle a `value` with `undefined` values', 2, function() { + var matches = _.matchesProperty('b', undefined), + objects = [{ 'a': 1 }, { 'a': 1, 'b': 1 }, { 'a': 1, 'b': undefined }], + actual = _.map(objects, matches); + + deepEqual(actual, [true, false, true]); + + matches = _.matchesProperty('a', { 'b': undefined }); + objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 1 } }, { 'a': { 'a': 1, 'b': undefined } }]; + actual = _.map(objects, matches); + + deepEqual(actual, [false, false, true]); + }); + + test('should not match by inherited `value` properties', 1, function() { + function Foo() { this.a = 1; } + Foo.prototype.b = 2; + + var objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': 2 } }], + source = new Foo, + matches = _.matchesProperty('a', source), + actual = _.map(objects, matches), + expected = _.map(objects, _.constant(true)); + + deepEqual(actual, expected); + }); + + test('should work with a function for `value`', 1, function() { + function source() {} + + source.a = 1; + source.b = function() {}; + source.c = 3; + + var matches = _.matchesProperty('a', source), + objects = [{ 'a': { 'a': 1 } }, { 'a': { 'a': 1, 'b': source.b, 'c': 3 } }], + actual = _.map(objects, matches); + + deepEqual(actual, [false, true]); + }); + + test('should match problem JScript properties (test in IE < 9)', 1, function() { + var matches = _.matchesProperty('a', shadowObject), + objects = [{ 'a': {} }, { 'a': shadowObject }], + actual = _.map(objects, matches); + + deepEqual(actual, [false, true]); + }); + }()); + + /*--------------------------------------------------------------------------*/ + + QUnit.module('lodash.max'); + + (function() { + test('should return the largest value from a collection', 1, function() { + strictEqual(3, _.max([1, 2, 3])); + }); + + test('should return `-Infinity` for empty collections', 1, function() { + var expected = _.map(empties, _.constant(-Infinity)); + + var actual = _.map(empties, function(value) { + try { + return _.max(value); + } catch(e) {} + }); + + deepEqual(actual, expected); + }); + + test('should return `-Infinity` for non-numeric collection values', 1, function() { var collections = [['a', 'b'], { 'a': 'a', 'b': 'b' }], expected = _.map(collections, _.constant(-Infinity)); @@ -9185,7 +9620,7 @@ strictEqual(actual, isMax ? 1 : 3); }); - test('should work with a "_.pluck" style `iteratee`', 2, function() { + test('should work with a "_.property" style `iteratee`', 2, function() { var objects = [{ 'a': 2 }, { 'a': 3 }, { 'a': 1 }], actual = func(objects, 'a'); @@ -9225,14 +9660,14 @@ strictEqual(func(array), isMax ? 499999 : 0); }); - test('`_.' + methodName + '` should work as an iteratee for `_.map`', 2, function() { - var array = [[2, 3, 1], [5, 6, 4], [8, 9, 7]], - actual = _.map(array, func); - - deepEqual(actual, isMax ? [3, 6, 9] : [1, 4, 7]); + test('`_.' + methodName + '` should work as an iteratee for `_.map`', 3, function() { + var arrays = [[2, 1], [5, 4], [7, 8]], + objects = [{ 'a': 2, 'b': 1 }, { 'a': 5, 'b': 4 }, { 'a': 7, 'b': 8 }], + expected = isMax ? [2, 5, 8] : [1, 4, 7]; - actual = _.map('abc', func); - deepEqual(actual, ['a', 'b', 'c']); + deepEqual(_.map(arrays, func), expected); + deepEqual(_.map(objects, func), expected); + deepEqual(_.map('abc', func), ['a', 'b', 'c']); }); test('`_.' + methodName + '` should work when chaining on an array with only one value', 1, function() { @@ -9452,11 +9887,11 @@ test('should produce methods that work in a lazy chain sequence', 1, function() { if (!isNpm) { - var predicate = function(value) { return value > 1; }; + var predicate = function(value) { return value > 2; }; _.mixin({ 'a': _.countBy, 'b': _.filter }); - var actual = _([1, 2, 1, 3]).a(_.identity).map(String).b(predicate).take().value(); - deepEqual(actual, ['2']); + var actual = _([1, 2, 1, 3]).a(_.identity).map(square).b(predicate).take().value(); + deepEqual(actual, [4]); delete _.a; delete _.prototype.a; @@ -10250,7 +10685,7 @@ deepEqual(actual, [[1.1, 1.3], [0.2]]); }); - test('should work with a "_.pluck" style `predicate`', 1, function() { + test('should work with a "_.property" style `predicate`', 1, function() { var objects = [{ 'a': 1 }, { 'a': 1 }, { 'b': 2 }], actual = _.partition(objects, 'a'); @@ -11111,8 +11546,10 @@ QUnit.module('lodash.reject'); (function() { + var array = [1, 2, 3]; + test('should return elements the `predicate` returns falsey for', 1, function() { - var actual = _.reject([1, 2, 3], function(num) { + var actual = _.reject(array, function(num) { return num % 2; }); @@ -11137,7 +11574,7 @@ deepEqual(actual, [0]); }); - test('`_.' + methodName + '` should work with a "_.pluck" style `predicate`', 1, function() { + test('`_.' + methodName + '` should work with a "_.property" style `predicate`', 1, function() { var objects = [{ 'a': 0 }, { 'a': 1 }]; deepEqual(func(objects, 'a'), [objects[isFilter ? 1 : 0]]); }); @@ -11226,18 +11663,24 @@ deepEqual(actual, [1, 2]); }); - test('should work with a "_.pluck" style `predicate`', 1, function() { - var objects = [{ 'a': 0 }, { 'a': 1 }]; - _.remove(objects, 'a'); - deepEqual(objects, [{ 'a': 0 }]); + test('should work with a "_.matches" style `predicate`', 1, function() { + var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }]; + _.remove(objects, { 'a': 1 }); + deepEqual(objects, [{ 'a': 0, 'b': 1 }]); }); - test('should work with a "_.where" style `predicate`', 1, function() { + test('should work with a "_.matchesProperty" style `predicate`', 1, function() { var objects = [{ 'a': 0, 'b': 1 }, { 'a': 1, 'b': 2 }]; - _.remove(objects, { 'a': 1 }); + _.remove(objects, 'a', 1); deepEqual(objects, [{ 'a': 0, 'b': 1 }]); }); + test('should work with a "_.property" style `predicate`', 1, function() { + var objects = [{ 'a': 0 }, { 'a': 1 }]; + _.remove(objects, 'a'); + deepEqual(objects, [{ 'a': 0 }]); + }); + test('should preserve holes in arrays', 2, function() { var array = [1, 2, 3, 4]; delete array[1]; @@ -11541,10 +11984,10 @@ test('should return a wrapped value when chaining and `n` is provided', 2, function() { if (!isNpm) { - var wrapped = _(array).sample(2); - ok(wrapped instanceof _); + var wrapped = _(array).sample(2), + actual = wrapped.value(); - var actual = wrapped.value(); + ok(wrapped instanceof _); ok(actual.length == 2 && actual[0] !== actual[1] && _.includes(array, actual[0]) && _.includes(array, actual[1])); } else { @@ -11706,8 +12149,15 @@ (function() { var array = [1, 2, 3]; - test('should work with a positive `start`', 1, function() { + test('should use a default `start` of `0` and a default `end` of `array.length`', 2, function() { + var actual = _.slice(array); + deepEqual(actual, array); + notStrictEqual(actual, array); + }); + + test('should work with a positive `start`', 2, function() { deepEqual(_.slice(array, 1), [2, 3]); + deepEqual(_.slice(array, 1, 3), [2, 3]); }); test('should work with a `start` >= `array.length`', 4, function() { @@ -11775,7 +12225,12 @@ }); test('should coerce `start` and `end` to integers', 1, function() { - var actual = [_.slice(array, 0.1, 1.1), _.slice(array, '0', 1), _.slice(array, 0, '1'), _.slice(array, '1'), _.slice(array, NaN, 1), _.slice(array, 1, NaN)]; + var positions = [[0.1, 1.1], ['0', 1], [0, '1'], ['1'], [NaN, 1], [1, NaN]]; + + var actual = _.map(positions, function(pos) { + return _.slice.apply(_, [array].concat(pos)); + }); + deepEqual(actual, [[1], [1], [1], [2, 3], [1], []]); }); @@ -11784,31 +12239,41 @@ actual = _.map(array, _.slice); deepEqual(actual, array); - notStrictEqual(actual, array) + notStrictEqual(actual, array); }); - test('should work in a lazy chain sequence', 12, function() { + test('should work in a lazy chain sequence', 38, function() { if (!isNpm) { var wrapped = _(array); - deepEqual(wrapped.slice(0, -1).value(), [1, 2]); - deepEqual(wrapped.slice(1).value(), [2, 3]); - deepEqual(wrapped.slice(-1).value(), [3]); - - deepEqual(wrapped.slice(4).value(), []); - deepEqual(wrapped.slice(3, 2).value(), []); - deepEqual(wrapped.slice(0, -4).value(), []); - deepEqual(wrapped.slice(0, null).value(), []); - - deepEqual(wrapped.slice(0, 4).value(), array); - deepEqual(wrapped.slice(-4).value(), array); - deepEqual(wrapped.slice(null).value(), array); - - deepEqual(wrapped.slice(0, 1).value(), [1]); - deepEqual(wrapped.slice(NaN, '1').value(), [1]); + _.each(['map', 'filter'], function(methodName) { + deepEqual(wrapped[methodName]().slice(0, -1).value(), [1, 2]); + deepEqual(wrapped[methodName]().slice(1).value(), [2, 3]); + deepEqual(wrapped[methodName]().slice(1, 3).value(), [2, 3]); + deepEqual(wrapped[methodName]().slice(-1).value(), [3]); + + deepEqual(wrapped[methodName]().slice(4).value(), []); + deepEqual(wrapped[methodName]().slice(3, 2).value(), []); + deepEqual(wrapped[methodName]().slice(0, -4).value(), []); + deepEqual(wrapped[methodName]().slice(0, null).value(), []); + + deepEqual(wrapped[methodName]().slice(0, 4).value(), array); + deepEqual(wrapped[methodName]().slice(-4).value(), array); + deepEqual(wrapped[methodName]().slice(null).value(), array); + + deepEqual(wrapped[methodName]().slice(0, 1).value(), [1]); + deepEqual(wrapped[methodName]().slice(NaN, '1').value(), [1]); + + deepEqual(wrapped[methodName]().slice(0.1, 1.1).value(), [1]); + deepEqual(wrapped[methodName]().slice('0', 1).value(), [1]); + deepEqual(wrapped[methodName]().slice(0, '1').value(), [1]); + deepEqual(wrapped[methodName]().slice('1').value(), [2, 3]); + deepEqual(wrapped[methodName]().slice(NaN, 1).value(), [1]); + deepEqual(wrapped[methodName]().slice(1, NaN).value(), []); + }); } else { - skipTest(12); + skipTest(38); } }); }()); @@ -11844,7 +12309,7 @@ strictEqual(_.some([null, true, null], _.identity), true); }); - test('should work with a "_.pluck" style `predicate`', 2, function() { + test('should work with a "_.property" style `predicate`', 2, function() { var objects = [{ 'a': 0, 'b': 0 }, { 'a': 0, 'b': 1 }]; strictEqual(_.some(objects, 'a'), false); strictEqual(_.some(objects, 'b'), true); @@ -11963,7 +12428,7 @@ deepEqual(actual, [3, 1, 2]); }); - test('should work with a "_.pluck" style `iteratee`', 1, function() { + test('should work with a "_.property" style `iteratee`', 1, function() { var actual = _.pluck(_.sortBy(objects.concat(undefined), 'b'), 'b'); deepEqual(actual, [1, 2, 3, 4, undefined]); }); @@ -12126,7 +12591,7 @@ strictEqual(actual, 1); }); - test('`_.' + methodName + '` should work with a "_.pluck" style `iteratee`', 1, function() { + test('`_.' + methodName + '` should work with a "_.property" style `iteratee`', 1, function() { var actual = func(objects, { 'x': 40 }, 'x'); strictEqual(actual, 1); }); @@ -12175,36 +12640,36 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('lodash.support'); + QUnit.module('lodash.spread'); (function() { - test('should contain properties with boolean values', 1, function() { - ok(_.every(_.values(_.support), function(value) { - return value === true || value === false; - })); + test('should spread arguments to `func`', 1, function() { + var spread = _.spread(add); + strictEqual(spread([4, 2]), 6); }); - test('should not contain minified properties (test production builds)', 1, function() { - var props = [ - 'argsTag', - 'argsObject', - 'dom', - 'enumErrorProps', - 'enumPrototypes', - 'fastBind', - 'funcDecomp', - 'funcNames', - 'hostObject', - 'nodeTag', - 'nonEnumArgs', - 'nonEnumShadows', - 'nonEnumStrings', - 'ownLast', - 'spliceObjects', - 'unindexedChars' - ]; + test('should throw a TypeError when receiving a non-array `array` argument', 1, function() { + raises(function() { _.spread(4, 2); }, TypeError); + }); - ok(_.isEmpty(_.difference(_.keys(_.support), props))); + test('should provide the correct `func` arguments', 1, function() { + var args; + + var spread = _.spread(function() { + args = slice.call(arguments); + }); + + spread([4, 2], 'ignored'); + deepEqual(args, [4, 2]); + }); + + test('should not set a `this` binding', 1, function() { + var spread = _.spread(function(x, y) { + return this[x] + this[y]; + }); + + var object = { 'spread': spread, 'x': 4, 'y': 2 }; + strictEqual(object.spread(['x', 'y']), 6); }); }()); @@ -12287,6 +12752,41 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.support'); + + (function() { + test('should contain properties with boolean values', 1, function() { + ok(_.every(_.values(_.support), function(value) { + return value === true || value === false; + })); + }); + + test('should not contain minified properties (test production builds)', 1, function() { + var props = [ + 'argsTag', + 'argsObject', + 'dom', + 'enumErrorProps', + 'enumPrototypes', + 'fastBind', + 'funcDecomp', + 'funcNames', + 'hostObject', + 'nodeTag', + 'nonEnumArgs', + 'nonEnumShadows', + 'nonEnumStrings', + 'ownLast', + 'spliceObjects', + 'unindexedChars' + ]; + + ok(_.isEmpty(_.difference(_.keys(_.support), props))); + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash.tap'); (function() { @@ -13264,15 +13764,28 @@ (function() { test('should return the values of objects', 1, function() { - var array = [1, 2, 3], - object = { 'a': 1, 'b': 2, 'c': 3 }; + var array = [1, 2], + object = { 'a': 1, 'b': 2 }; deepEqual(_.toArray(object), array); }); test('should work with a string for `collection` (test in Opera < 10.52)', 2, function() { - deepEqual(_.toArray('abc'), ['a', 'b', 'c']); - deepEqual(_.toArray(Object('abc')), ['a', 'b', 'c']); + deepEqual(_.toArray('ab'), ['a', 'b']); + deepEqual(_.toArray(Object('ab')), ['a', 'b']); + }); + + test('should work in a lazy chain sequence', 2, function() { + if (!isNpm) { + var actual = _([1, 2]).map(String).toArray().value(); + deepEqual(actual, ['1', '2']); + + actual = _({ 'a': 1, 'b': 2 }).toArray().map(String).value(); + deepEqual(actual, ['1', '2']); + } + else { + skipTest(2); + } }); }()); @@ -13304,8 +13817,8 @@ test('should return a shallow clone of arrays', 2, function() { var actual = func(array); + deepEqual(actual, array); notStrictEqual(actual, array); - deepEqual(func(array), array); }); test('should work with a node list for `collection` (test in IE < 9)', 1, function() { @@ -13508,8 +14021,8 @@ result[key] = this[key]; }, null, object); - notStrictEqual(actual, object); deepEqual(actual, object); + notStrictEqual(actual, object); }); }); @@ -13758,7 +14271,7 @@ deepEqual(actual, [1, 2, 3]); }); - test('should work with a "_.pluck" style `iteratee`', 2, function() { + test('should work with a "_.property" style `iteratee`', 2, function() { var actual = _.uniq(objects, 'a'); deepEqual(actual, objects.slice(0, 3)); @@ -14218,10 +14731,10 @@ test('should work in a lazy chain sequence', 1, function() { if (!isNpm) { var array = [['a', 1], ['b', 2]], - predicate = function(value) { return value > 1; }, - actual = _(array).zipObject().map(String).filter(predicate).take().value(); + predicate = function(value) { return value > 2; }, + actual = _(array).zipObject().map(square).filter(predicate).take().value(); - deepEqual(actual, ['2']); + deepEqual(actual, [4]); } else { skipTest(); @@ -14235,6 +14748,40 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash(...).commit'); + + (function() { + test('should execute the chained sequence and returns the wrapped result', 4, function() { + if (!isNpm) { + var array = [1], + wrapped = _(array).push(2).push(3); + + deepEqual(array, [1]); + + var otherWrapper = wrapped.commit(); + ok(otherWrapper instanceof _); + deepEqual(otherWrapper.value(), [1, 2, 3]); + deepEqual(wrapped.value(), [1, 2, 3, 2, 3]); + } + else { + skipTest(4); + } + }); + + test('should track the `__chain__` value of a wrapper', 2, function() { + if (!isNpm) { + var wrapper = _([1]).chain().commit().first(); + ok(wrapper instanceof _); + strictEqual(wrapper.value(), 1); + } + else { + skipTest(2); + } + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash(...).concat'); (function() { @@ -14244,9 +14791,9 @@ wrapped = _(array).concat([2, 3]), actual = wrapped.value(); - notStrictEqual(actual, array); - deepEqual(actual, [1, 2, 3]); deepEqual(array, [1]); + deepEqual(actual, [1, 2, 3]); + notStrictEqual(actual, array); } else { skipTest(3); @@ -14276,6 +14823,27 @@ /*--------------------------------------------------------------------------*/ + QUnit.module('lodash(...).plant'); + + (function() { + test('should clone the chained sequence planting `value` as the wrapped value', 2, function() { + if (!isNpm) { + var array1 = [5, null, 3, null, 1], + array2 = [10, null, 8, null, 6], + wrapper1 = _(array1).thru(_.compact).map(square).takeRight(2).sort(), + wrapper2 = wrapper1.plant(array2); + + deepEqual(wrapper2.value(), [36, 64]); + deepEqual(wrapper1.value(), [1, 9]); + } + else { + skipTest(2); + } + }); + }()); + + /*--------------------------------------------------------------------------*/ + QUnit.module('lodash(...).pop'); (function() { @@ -14289,8 +14857,8 @@ strictEqual(wrapped.pop(), 1); var actual = wrapped.value(); - strictEqual(actual, array); deepEqual(actual, []); + strictEqual(actual, array); } else { skipTest(5); @@ -14374,17 +14942,28 @@ var array = [1, 2, 3, null]; _.each(['map', 'filter'], function(methodName) { - var actual = _(array)[methodName](_.identity).compact().reverse().value(); + var actual = _(array)[methodName](_.identity).thru(_.compact).reverse().value(); deepEqual(actual, [3, 2, 1]); - actual = _(array.slice()).pull(2)[methodName](_.identity).compact().pull(1).push(4).reverse().value(); - deepEqual(actual, [4, 3]); + actual = _(array).thru(_.compact)[methodName](_.identity).pull(1).push(4).reverse().value(); + deepEqual(actual, [4, 3, 2]); }); } else { skipTest(4); } }); + + test('should track the `__chain__` value of a wrapper', 2, function() { + if (!isNpm) { + var wrapper = _([1, 2, 3]).chain().reverse().first(); + ok(wrapper instanceof _); + strictEqual(wrapper.value(), 3); + } + else { + skipTest(2); + } + }); }()); /*--------------------------------------------------------------------------*/ @@ -14402,8 +14981,8 @@ strictEqual(wrapped.shift(), 2); var actual = wrapped.value(); - strictEqual(actual, array); deepEqual(actual, []); + strictEqual(actual, array); } else { skipTest(5); @@ -14422,9 +15001,9 @@ wrapped = _(array).slice(0, 2), actual = wrapped.value(); - notStrictEqual(actual, array); - deepEqual(actual, [1, 2]); deepEqual(array, [1, 2, 3]); + deepEqual(actual, [1, 2]); + notStrictEqual(actual, array); } else { skipTest(3); @@ -14464,12 +15043,11 @@ deepEqual(wrapped.splice(1, 1, 3).value(), [2]); deepEqual(wrapped.value(), [1, 3]); - deepEqual(wrapped.splice(0, 2).value(), [1, 3]); var actual = wrapped.value(); - strictEqual(actual, array); deepEqual(actual, []); + strictEqual(actual, array); } else { skipTest(5); @@ -14537,9 +15115,24 @@ /*--------------------------------------------------------------------------*/ - QUnit.module('lodash(...).valueOf'); + QUnit.module('lodash(...).value'); (function() { + test('should execute the chained sequence and extract the unwrapped value', 4, function() { + if (!isNpm) { + var array = [1], + wrapped = _(array).push(2).push(3); + + deepEqual(array, [1]); + deepEqual(wrapped.value(), [1, 2, 3]); + deepEqual(wrapped.value(), [1, 2, 3, 2, 3]); + deepEqual(array, [1, 2, 3, 2, 3]); + } + else { + skipTest(4); + } + }); + test('should return the `valueOf` result of the wrapped value', 1, function() { if (!isNpm) { var wrapped = _(123); @@ -14560,14 +15153,15 @@ } }); - test('should be aliased', 2, function() { + test('should be aliased', 3, function() { if (!isNpm) { - var expected = _.prototype.valueOf; + var expected = _.prototype.value; + strictEqual(_.prototype.run, expected); strictEqual(_.prototype.toJSON, expected); - strictEqual(_.prototype.value, expected); + strictEqual(_.prototype.valueOf, expected); } else { - skipTest(2); + skipTest(3); } }); }()); @@ -14673,7 +15267,7 @@ ]; _.each(funcs, function(methodName) { - test('`_(...).' + methodName + '` should return an unwrapped value when intuitively chaining', 1, function() { + test('`_(...).' + methodName + '` should return an unwrapped value when implicitly chaining', 1, function() { if (!isNpm) { var array = [1, 2, 3], actual = _(array)[methodName](); @@ -14835,6 +15429,7 @@ 'partial', 'partialRight', 'rearg', + 'spread', 'throttle' ]; @@ -14887,7 +15482,7 @@ var acceptFalsey = _.difference(allMethods, rejectFalsey); - test('should accept falsey arguments', 206, function() { + test('should accept falsey arguments', 208, function() { var emptyArrays = _.map(falsey, _.constant([])), isExposed = '_' in root, oldDash = root._; @@ -14953,7 +15548,7 @@ }); }); - test('should throw an error for falsey arguments', 22, function() { + test('should throw an error for falsey arguments', 23, function() { _.each(rejectFalsey, function(methodName) { var expected = _.map(falsey, _.constant(true)), func = _[methodName]; @@ -15062,15 +15657,9 @@ /*--------------------------------------------------------------------------*/ QUnit.config.asyncRetries = 10; + QUnit.config.hidepassed = true; - if (document) { - QUnit.begin(function() { - QUnit.config.hidepassed = true; - document.getElementById('qunit-tests').className += ' hidepass'; - document.getElementById('qunit-urlconfig-hidepassed').checked = true; - }); - } else { - QUnit.config.hidepassed = true; + if (!document) { QUnit.config.noglobals = true; QUnit.load(); } diff --git a/test/underscore.html b/test/underscore.html index c483ec6f64..43bdea2281 100644 --- a/test/underscore.html +++ b/test/underscore.html @@ -37,12 +37,7 @@