diff --git a/README.md b/README.md index 0a894923f..b9cb70eb4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v4.13.0 +# lodash-es v4.13.1 The [Lodash](https://lodash.com/) library exported as [ES](http://www.ecma-international.org/ecma-262/6.0/) modules. @@ -7,4 +7,4 @@ Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): $ lodash modularize exports=es -o ./ ``` -See the [package source](https://github.com/lodash/lodash/tree/4.13.0-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.13.1-es) for more details. diff --git a/_createFind.js b/_createFind.js new file mode 100644 index 000000000..8d8986aa3 --- /dev/null +++ b/_createFind.js @@ -0,0 +1,30 @@ +import baseIteratee from './_baseIteratee.js'; +import isArrayLike from './isArrayLike.js'; +import keys from './keys.js'; + +/** + * 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; + }; +} + +export default createFind; diff --git a/_isMaskable.js b/_isMaskable.js index 3a4ffd11a..4c17c1c0a 100644 --- a/_isMaskable.js +++ b/_isMaskable.js @@ -9,6 +9,6 @@ import stubFalse from './stubFalse.js'; * @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; export default isMaskable; diff --git a/find.js b/find.js index a45ed0614..b12fa5b9b 100644 --- a/find.js +++ b/find.js @@ -1,6 +1,5 @@ +import createFind from './_createFind.js'; import findIndex from './findIndex.js'; -import isArrayLike from './isArrayLike.js'; -import values from './values.js'; /** * Iterates over elements of `collection`, returning the first element @@ -39,10 +38,6 @@ import values from './values.js'; * _.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); export default find; diff --git a/findLast.js b/findLast.js index f7a53251a..6e3d2e40d 100644 --- a/findLast.js +++ b/findLast.js @@ -1,6 +1,5 @@ +import createFind from './_createFind.js'; import findLastIndex from './findLastIndex.js'; -import isArrayLike from './isArrayLike.js'; -import values from './values.js'; /** * This method is like `_.find` except that it iterates over elements of @@ -22,10 +21,6 @@ import values from './values.js'; * }); * // => 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); export default findLast; diff --git a/lodash.default.js b/lodash.default.js index f90bc9e83..c32ba1bcb 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -44,7 +44,7 @@ import toInteger from './toInteger.js'; import lodash from './wrapperLodash.js'; /** Used as the semantic version number. */ -var VERSION = '4.13.0'; +var VERSION = '4.13.1'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_KEY_FLAG = 2; diff --git a/package.json b/package.json index f0b15919d..292a05d96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-es", - "version": "4.13.0", + "version": "4.13.1", "description": "Lodash exported as ES modules.", "keywords": "es6, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds",