diff --git a/README.md b/README.md index f021e24a2..2419f752a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v4.17.0 +# lodash-es v4.17.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.17.0-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.17.1-es) for more details. diff --git a/_baseGet.js b/_baseGet.js index 18bdab3a2..16a2912ac 100644 --- a/_baseGet.js +++ b/_baseGet.js @@ -1,5 +1,4 @@ import castPath from './_castPath.js'; -import isKey from './_isKey.js'; import toKey from './_toKey.js'; /** @@ -11,7 +10,7 @@ import toKey from './_toKey.js'; * @returns {*} Returns the resolved value. */ function baseGet(object, path) { - path = isKey(path, object) ? [path] : castPath(path); + path = castPath(path, object); var index = 0, length = path.length; diff --git a/_baseInvoke.js b/_baseInvoke.js index 1c2e03de9..e465d8460 100644 --- a/_baseInvoke.js +++ b/_baseInvoke.js @@ -1,6 +1,5 @@ import apply from './_apply.js'; import castPath from './_castPath.js'; -import isKey from './_isKey.js'; import last from './last.js'; import parent from './_parent.js'; import toKey from './_toKey.js'; @@ -16,12 +15,9 @@ import toKey from './_toKey.js'; * @returns {*} Returns the result of the invoked method. */ function baseInvoke(object, path, args) { - if (!isKey(path, object)) { - path = castPath(path); - object = parent(object, path); - path = last(path); - } - var func = object == null ? object : object[toKey(path)]; + path = castPath(path, object); + object = parent(object, path); + var func = object == null ? object : object[toKey(last(path))]; return func == null ? undefined : apply(func, object, args); } diff --git a/_basePullAt.js b/_basePullAt.js index 8820c36e9..175e92070 100644 --- a/_basePullAt.js +++ b/_basePullAt.js @@ -1,6 +1,5 @@ import castPath from './_castPath.js'; import isIndex from './_isIndex.js'; -import isKey from './_isKey.js'; import last from './last.js'; import parent from './_parent.js'; import toKey from './_toKey.js'; @@ -31,17 +30,14 @@ function basePullAt(array, indexes) { if (isIndex(index)) { splice.call(array, index, 1); } - else if (!isKey(index, array)) { - var path = castPath(index), + else { + var path = castPath(index, array), object = parent(array, path); if (object != null) { delete object[toKey(last(path))]; } } - else { - delete array[toKey(index)]; - } } } return array; diff --git a/_baseSet.js b/_baseSet.js index 187b3e5c2..6cdc792c6 100644 --- a/_baseSet.js +++ b/_baseSet.js @@ -1,7 +1,6 @@ import assignValue from './_assignValue.js'; import castPath from './_castPath.js'; import isIndex from './_isIndex.js'; -import isKey from './_isKey.js'; import isObject from './isObject.js'; import toKey from './_toKey.js'; @@ -19,7 +18,7 @@ function baseSet(object, path, value, customizer) { if (!isObject(object)) { return object; } - path = isKey(path, object) ? [path] : castPath(path); + path = castPath(path, object); var index = -1, length = path.length, diff --git a/_baseUnset.js b/_baseUnset.js index b681142b8..404b3c764 100644 --- a/_baseUnset.js +++ b/_baseUnset.js @@ -1,5 +1,4 @@ import castPath from './_castPath.js'; -import isKey from './_isKey.js'; import last from './last.js'; import parent from './_parent.js'; import toKey from './_toKey.js'; @@ -19,9 +18,8 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @returns {boolean} Returns `true` if the property is deleted, else `false`. */ function baseUnset(object, path) { - path = isKey(path, object) ? [path] : castPath(path); + path = castPath(path, object); object = parent(object, path); - var key = toKey(last(path)); return !(object != null && hasOwnProperty.call(object, key)) || delete object[key]; } diff --git a/_castPath.js b/_castPath.js index 55e78cfbc..89aae9551 100644 --- a/_castPath.js +++ b/_castPath.js @@ -1,15 +1,21 @@ import isArray from './isArray.js'; +import isKey from './_isKey.js'; import stringToPath from './_stringToPath.js'; +import toString from './toString.js'; /** * Casts `value` to a path array if it's not one. * * @private * @param {*} value The value to inspect. + * @param {Object} [object] The object to query keys on. * @returns {Array} Returns the cast property path array. */ -function castPath(value) { - return isArray(value) ? value : stringToPath(value); +function castPath(value, object) { + if (isArray(value)) { + return value; + } + return isKey(value, object) ? [value] : stringToPath(toString(value)); } export default castPath; diff --git a/_hasPath.js b/_hasPath.js index a0698dc52..7decc6c06 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -2,7 +2,6 @@ import castPath from './_castPath.js'; import isArguments from './isArguments.js'; import isArray from './isArray.js'; import isIndex from './_isIndex.js'; -import isKey from './_isKey.js'; import isLength from './isLength.js'; import toKey from './_toKey.js'; @@ -16,7 +15,7 @@ import toKey from './_toKey.js'; * @returns {boolean} Returns `true` if `path` exists, else `false`. */ function hasPath(object, path, hasFunc) { - path = isKey(path, object) ? [path] : castPath(path); + path = castPath(path, object); var index = -1, length = path.length, diff --git a/_parent.js b/_parent.js index aab10e6cc..ef6f8b457 100644 --- a/_parent.js +++ b/_parent.js @@ -10,7 +10,7 @@ import baseSlice from './_baseSlice.js'; * @returns {*} Returns the parent value. */ function parent(object, path) { - return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); + return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1)); } export default parent; diff --git a/_stringToPath.js b/_stringToPath.js index 1a61952ec..f0617e7de 100644 --- a/_stringToPath.js +++ b/_stringToPath.js @@ -1,5 +1,4 @@ import memoizeCapped from './_memoizeCapped.js'; -import toString from './toString.js'; /** Used to match property names within property paths. */ var reLeadingDot = /^\./, @@ -16,8 +15,6 @@ var reEscapeChar = /\\(\\)?/g; * @returns {Array} Returns the property path array. */ var stringToPath = memoizeCapped(function(string) { - string = toString(string); - var result = []; if (reLeadingDot.test(string)) { result.push(''); diff --git a/invokeMap.js b/invokeMap.js index 4e23387b2..bab338328 100644 --- a/invokeMap.js +++ b/invokeMap.js @@ -3,7 +3,6 @@ import baseEach from './_baseEach.js'; import baseInvoke from './_baseInvoke.js'; import baseRest from './_baseRest.js'; import isArrayLike from './isArrayLike.js'; -import isKey from './_isKey.js'; /** * Invokes the method at `path` of each element in `collection`, returning @@ -31,12 +30,10 @@ import isKey from './_isKey.js'; var invokeMap = baseRest(function(collection, path, args) { var index = -1, isFunc = typeof path == 'function', - isProp = isKey(path), result = isArrayLike(collection) ? Array(collection.length) : []; baseEach(collection, function(value) { - var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined); - result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args); + result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args); }); return result; }); diff --git a/lodash.default.js b/lodash.default.js index 1862730d4..f59f6b1f7 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -45,7 +45,7 @@ import toInteger from './toInteger.js'; import lodash from './wrapperLodash.js'; /** Used as the semantic version number. */ -var VERSION = '4.17.0'; +var VERSION = '4.17.1'; /** Used to compose bitmasks for function metadata. */ var WRAP_BIND_KEY_FLAG = 2; diff --git a/omit.js b/omit.js index da8eb9f93..4f01ca99b 100644 --- a/omit.js +++ b/omit.js @@ -1,5 +1,7 @@ +import arrayMap from './_arrayMap.js'; import baseClone from './_baseClone.js'; import baseUnset from './_baseUnset.js'; +import castPath from './_castPath.js'; import copyObject from './_copyObject.js'; import flatRest from './_flatRest.js'; import getAllKeysIn from './_getAllKeysIn.js'; @@ -34,8 +36,15 @@ var omit = flatRest(function(object, paths) { if (object == null) { return result; } + var bitmask = CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG; + paths = arrayMap(paths, function(path) { + path = castPath(path, object); + bitmask |= (path.length > 1 ? CLONE_DEEP_FLAG : 0); + return path; + }); + copyObject(object, getAllKeysIn(object), result); - result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG); + result = baseClone(result, bitmask); var length = paths.length; while (length--) { diff --git a/package.json b/package.json index 9f7a677d3..5411a0c4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-es", - "version": "4.17.0", + "version": "4.17.1", "description": "Lodash exported as ES modules.", "keywords": "es6, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", diff --git a/pick.js b/pick.js index e55570f27..fb849922b 100644 --- a/pick.js +++ b/pick.js @@ -1,7 +1,5 @@ -import arrayMap from './_arrayMap.js'; import basePick from './_basePick.js'; import flatRest from './_flatRest.js'; -import toKey from './_toKey.js'; /** * Creates an object composed of the picked `object` properties. @@ -21,7 +19,7 @@ import toKey from './_toKey.js'; * // => { 'a': 1, 'c': 3 } */ var pick = flatRest(function(object, paths) { - return object == null ? {} : basePick(object, arrayMap(paths, toKey)); + return object == null ? {} : basePick(object, paths); }); export default pick; diff --git a/pickBy.js b/pickBy.js index a92abc955..4ff3598f5 100644 --- a/pickBy.js +++ b/pickBy.js @@ -1,3 +1,4 @@ +import arrayMap from './_arrayMap.js'; import baseIteratee from './_baseIteratee.js'; import basePickBy from './_basePickBy.js'; import getAllKeysIn from './_getAllKeysIn.js'; @@ -21,7 +22,16 @@ import getAllKeysIn from './_getAllKeysIn.js'; * // => { 'a': 1, 'c': 3 } */ function pickBy(object, predicate) { - return object == null ? {} : basePickBy(object, getAllKeysIn(object), baseIteratee(predicate)); + if (object == null) { + return {}; + } + var props = arrayMap(getAllKeysIn(object), function(prop) { + return [prop]; + }); + predicate = baseIteratee(predicate); + return basePickBy(object, props, function(value, path) { + return predicate(value, path[0]); + }); } export default pickBy; diff --git a/result.js b/result.js index eb44eea67..9b384e390 100644 --- a/result.js +++ b/result.js @@ -1,6 +1,5 @@ import castPath from './_castPath.js'; import isFunction from './isFunction.js'; -import isKey from './_isKey.js'; import toKey from './_toKey.js'; /** @@ -33,7 +32,7 @@ import toKey from './_toKey.js'; * // => 'default' */ function result(object, path, defaultValue) { - path = isKey(path, object) ? [path] : castPath(path); + path = castPath(path, object); var index = -1, length = path.length; diff --git a/toPath.js b/toPath.js index 55ab01c52..e9f4d16c1 100644 --- a/toPath.js +++ b/toPath.js @@ -4,6 +4,7 @@ import isArray from './isArray.js'; import isSymbol from './isSymbol.js'; import stringToPath from './_stringToPath.js'; import toKey from './_toKey.js'; +import toString from './toString.js'; /** * Converts `value` to a property path array. @@ -26,7 +27,7 @@ function toPath(value) { if (isArray(value)) { return arrayMap(value, toKey); } - return isSymbol(value) ? [value] : copyArray(stringToPath(value)); + return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value))); } export default toPath;