From 2ab869e88a1238ec908fce05c7b77933361aadfe Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 23 May 2016 12:25:07 -0700 Subject: [PATCH] Bump to v4.13.1. --- README.md | 4 ++-- _createFind.js | 32 ++++++++++++++++++++++++++++++++ _isMaskable.js | 2 +- find.js | 11 ++--------- findLast.js | 11 ++--------- main.js | 41 +++++++++++++++++++++++++++++------------ package.json | 2 +- 7 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 _createFind.js diff --git a/README.md b/README.md index ff8b77fff..31aa97751 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-amd v4.13.0 +# lodash-amd v4.13.1 The [Lodash](https://lodash.com/) library exported as [AMD](https://github.com/amdjs/amdjs-api/wiki/AMD) modules. @@ -27,4 +27,4 @@ require({ }); ``` -See the [package source](https://github.com/lodash/lodash/tree/4.13.0-amd) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.13.1-amd) for more details. diff --git a/_createFind.js b/_createFind.js new file mode 100644 index 000000000..3b0ead4be --- /dev/null +++ b/_createFind.js @@ -0,0 +1,32 @@ +define(['./_baseIteratee', './isArrayLike', './keys'], function(baseIteratee, isArrayLike, keys) { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined; + + /** + * Creates a `_.find` or `_.findLast` function. + * + * @private + * @param {Function} findIndexFunc The function to find the collection index. + * @returns {Function} Returns the new find function. + */ + function createFind(findIndexFunc) { + return function(collection, predicate, fromIndex) { + var iterable = Object(collection); + predicate = baseIteratee(predicate, 3); + if (!isArrayLike(collection)) { + var props = keys(collection); + } + var index = findIndexFunc(props || collection, function(value, key) { + if (props) { + key = value; + value = iterable[key]; + } + return predicate(value, key, iterable); + }, fromIndex); + return index > -1 ? collection[props ? props[index] : index] : undefined; + }; + } + + return createFind; +}); diff --git a/_isMaskable.js b/_isMaskable.js index 0a99ac968..db043fbf5 100644 --- a/_isMaskable.js +++ b/_isMaskable.js @@ -7,7 +7,7 @@ define(['./_coreJsData', './isFunction', './stubFalse'], function(coreJsData, is * @param {*} value The value to check. * @returns {boolean} Returns `true` if `func` is maskable, else `false`. */ - var isMaskable = !coreJsData ? stubFalse : isFunction; + var isMaskable = coreJsData ? isFunction : stubFalse; return isMaskable; }); diff --git a/find.js b/find.js index 17371499d..9d3cc8e4c 100644 --- a/find.js +++ b/find.js @@ -1,7 +1,4 @@ -define(['./findIndex', './isArrayLike', './values'], function(findIndex, isArrayLike, values) { - - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; +define(['./_createFind', './findIndex'], function(createFind, findIndex) { /** * Iterates over elements of `collection`, returning the first element @@ -40,11 +37,7 @@ define(['./findIndex', './isArrayLike', './values'], function(findIndex, isArray * _.find(users, 'active'); * // => object for 'barney' */ - function find(collection, predicate, fromIndex) { - collection = isArrayLike(collection) ? collection : values(collection); - var index = findIndex(collection, predicate, fromIndex); - return index > -1 ? collection[index] : undefined; - } + var find = createFind(findIndex); return find; }); diff --git a/findLast.js b/findLast.js index baa9eee46..e7de6ddb8 100644 --- a/findLast.js +++ b/findLast.js @@ -1,7 +1,4 @@ -define(['./findLastIndex', './isArrayLike', './values'], function(findLastIndex, isArrayLike, values) { - - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; +define(['./_createFind', './findLastIndex'], function(createFind, findLastIndex) { /** * This method is like `_.find` except that it iterates over elements of @@ -23,11 +20,7 @@ define(['./findLastIndex', './isArrayLike', './values'], function(findLastIndex, * }); * // => 3 */ - function findLast(collection, predicate, fromIndex) { - collection = isArrayLike(collection) ? collection : values(collection); - var index = findLastIndex(collection, predicate, fromIndex); - return index > -1 ? collection[index] : undefined; - } + var findLast = createFind(findLastIndex); return findLast; }); diff --git a/main.js b/main.js index ffb07c88d..04ca61977 100644 --- a/main.js +++ b/main.js @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.13.0'; + var VERSION = '4.13.1'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -4550,6 +4550,31 @@ return wrapper; } + /** + * Creates a `_.find` or `_.findLast` function. + * + * @private + * @param {Function} findIndexFunc The function to find the collection index. + * @returns {Function} Returns the new find function. + */ + function createFind(findIndexFunc) { + return function(collection, predicate, fromIndex) { + var iterable = Object(collection); + predicate = getIteratee(predicate, 3); + if (!isArrayLike(collection)) { + var props = keys(collection); + } + var index = findIndexFunc(props || collection, function(value, key) { + if (props) { + key = value; + value = iterable[key]; + } + return predicate(value, key, iterable); + }, fromIndex); + return index > -1 ? collection[props ? props[index] : index] : undefined; + }; + } + /** * Creates a `_.flow` or `_.flowRight` function. * @@ -5795,7 +5820,7 @@ * @param {*} value The value to check. * @returns {boolean} Returns `true` if `func` is maskable, else `false`. */ - var isMaskable = !coreJsData ? stubFalse : isFunction; + var isMaskable = coreJsData ? isFunction : stubFalse; /** * Checks if `value` is likely a prototype object. @@ -8473,11 +8498,7 @@ * _.find(users, 'active'); * // => object for 'barney' */ - function find(collection, predicate, fromIndex) { - collection = isArrayLike(collection) ? collection : values(collection); - var index = findIndex(collection, predicate, fromIndex); - return index > -1 ? collection[index] : undefined; - } + var find = createFind(findIndex); /** * This method is like `_.find` except that it iterates over elements of @@ -8499,11 +8520,7 @@ * }); * // => 3 */ - function findLast(collection, predicate, fromIndex) { - collection = isArrayLike(collection) ? collection : values(collection); - var index = findLastIndex(collection, predicate, fromIndex); - return index > -1 ? collection[index] : undefined; - } + var findLast = createFind(findLastIndex); /** * Creates a flattened array of values by running each element in `collection` diff --git a/package.json b/package.json index e77373992..82bd5857c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-amd", - "version": "4.13.0", + "version": "4.13.1", "description": "Lodash exported as AMD modules.", "keywords": "amd, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds",