diff --git a/README.md b/README.md index 71c898e9a..87e1f8d6a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-amd v4.17.0 +# lodash-amd v4.17.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.17.0-amd) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.17.1-amd) for more details. diff --git a/_baseGet.js b/_baseGet.js index 6a78fac32..84f50c3fb 100644 --- a/_baseGet.js +++ b/_baseGet.js @@ -1,4 +1,4 @@ -define(['./_castPath', './_isKey', './_toKey'], function(castPath, isKey, toKey) { +define(['./_castPath', './_toKey'], function(castPath, toKey) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -12,7 +12,7 @@ define(['./_castPath', './_isKey', './_toKey'], function(castPath, isKey, toKey) * @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 4e30bab85..0ed110456 100644 --- a/_baseInvoke.js +++ b/_baseInvoke.js @@ -1,4 +1,4 @@ -define(['./_apply', './_castPath', './_isKey', './last', './_parent', './_toKey'], function(apply, castPath, isKey, last, parent, toKey) { +define(['./_apply', './_castPath', './last', './_parent', './_toKey'], function(apply, castPath, last, parent, toKey) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -14,12 +14,9 @@ define(['./_apply', './_castPath', './_isKey', './last', './_parent', './_toKey' * @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 7bb00f33c..443525387 100644 --- a/_basePullAt.js +++ b/_basePullAt.js @@ -1,4 +1,4 @@ -define(['./_castPath', './_isIndex', './_isKey', './last', './_parent', './_toKey'], function(castPath, isIndex, isKey, last, parent, toKey) { +define(['./_castPath', './_isIndex', './last', './_parent', './_toKey'], function(castPath, isIndex, last, parent, toKey) { /** Used for built-in method references. */ var arrayProto = Array.prototype; @@ -26,17 +26,14 @@ define(['./_castPath', './_isIndex', './_isKey', './last', './_parent', './_toKe 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 8f6369326..c812b7f18 100644 --- a/_baseSet.js +++ b/_baseSet.js @@ -1,4 +1,4 @@ -define(['./_assignValue', './_castPath', './_isIndex', './_isKey', './isObject', './_toKey'], function(assignValue, castPath, isIndex, isKey, isObject, toKey) { +define(['./_assignValue', './_castPath', './_isIndex', './isObject', './_toKey'], function(assignValue, castPath, isIndex, isObject, toKey) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -17,7 +17,7 @@ define(['./_assignValue', './_castPath', './_isIndex', './_isKey', './isObject', 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 d39a37e22..e3b99804d 100644 --- a/_baseUnset.js +++ b/_baseUnset.js @@ -1,4 +1,4 @@ -define(['./_castPath', './_isKey', './last', './_parent', './_toKey'], function(castPath, isKey, last, parent, toKey) { +define(['./_castPath', './last', './_parent', './_toKey'], function(castPath, last, parent, toKey) { /** Used for built-in method references. */ var objectProto = Object.prototype; @@ -15,9 +15,8 @@ define(['./_castPath', './_isKey', './last', './_parent', './_toKey'], function( * @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 17e4a5888..eef12a6bd 100644 --- a/_castPath.js +++ b/_castPath.js @@ -1,14 +1,18 @@ -define(['./isArray', './_stringToPath'], function(isArray, stringToPath) { +define(['./isArray', './_isKey', './_stringToPath', './toString'], function(isArray, isKey, stringToPath, toString) { /** * 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)); } return castPath; diff --git a/_hasPath.js b/_hasPath.js index f76bfe504..3d864dd74 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -1,4 +1,4 @@ -define(['./_castPath', './isArguments', './isArray', './_isIndex', './_isKey', './isLength', './_toKey'], function(castPath, isArguments, isArray, isIndex, isKey, isLength, toKey) { +define(['./_castPath', './isArguments', './isArray', './_isIndex', './isLength', './_toKey'], function(castPath, isArguments, isArray, isIndex, isLength, toKey) { /** * Checks if `path` exists on `object`. @@ -10,7 +10,7 @@ define(['./_castPath', './isArguments', './isArray', './_isIndex', './_isKey', ' * @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 6155c060b..098c0d96d 100644 --- a/_parent.js +++ b/_parent.js @@ -9,7 +9,7 @@ define(['./_baseGet', './_baseSlice'], function(baseGet, baseSlice) { * @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)); } return parent; diff --git a/_stringToPath.js b/_stringToPath.js index 2ffcd1188..2145ea809 100644 --- a/_stringToPath.js +++ b/_stringToPath.js @@ -1,4 +1,4 @@ -define(['./_memoizeCapped', './toString'], function(memoizeCapped, toString) { +define(['./_memoizeCapped'], function(memoizeCapped) { /** Used to match property names within property paths. */ var reLeadingDot = /^\./, @@ -15,8 +15,6 @@ define(['./_memoizeCapped', './toString'], function(memoizeCapped, toString) { * @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 3c5b02817..2728f5897 100644 --- a/invokeMap.js +++ b/invokeMap.js @@ -1,7 +1,4 @@ -define(['./_apply', './_baseEach', './_baseInvoke', './_baseRest', './isArrayLike', './_isKey'], function(apply, baseEach, baseInvoke, baseRest, isArrayLike, isKey) { - - /** Used as a safe reference for `undefined` in pre-ES5 environments. */ - var undefined; +define(['./_apply', './_baseEach', './_baseInvoke', './_baseRest', './isArrayLike'], function(apply, baseEach, baseInvoke, baseRest, isArrayLike) { /** * Invokes the method at `path` of each element in `collection`, returning @@ -29,12 +26,10 @@ define(['./_apply', './_baseEach', './_baseInvoke', './_baseRest', './isArrayLik 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/main.js b/main.js index fe28c60ed..87ba5f9e4 100644 --- a/main.js +++ b/main.js @@ -13,7 +13,7 @@ var undefined; /** Used as the semantic version number. */ - var VERSION = '4.17.0'; + var VERSION = '4.17.1'; /** Used as the size to enable large array optimizations. */ var LARGE_ARRAY_SIZE = 200; @@ -3057,7 +3057,7 @@ * @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; @@ -3243,12 +3243,9 @@ * @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); } @@ -3886,17 +3883,14 @@ 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; @@ -4016,7 +4010,7 @@ if (!isObject(object)) { return object; } - path = isKey(path, object) ? [path] : castPath(path); + path = castPath(path, object); var index = -1, length = path.length, @@ -4357,9 +4351,8 @@ * @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]; } @@ -4501,10 +4494,14 @@ * * @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)); } /** @@ -6129,7 +6126,7 @@ * @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, @@ -6606,7 +6603,7 @@ * @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)); } /** @@ -6746,8 +6743,6 @@ * @returns {Array} Returns the property path array. */ var stringToPath = memoizeCapped(function(string) { - string = toString(string); - var result = []; if (reLeadingDot.test(string)) { result.push(''); @@ -9482,12 +9477,10 @@ 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; }); @@ -13478,8 +13471,15 @@ 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--) { @@ -13530,7 +13530,7 @@ * // => { 'a': 1, 'c': 3 } */ var pick = flatRest(function(object, paths) { - return object == null ? {} : basePick(object, arrayMap(paths, toKey)); + return object == null ? {} : basePick(object, paths); }); /** @@ -13552,7 +13552,16 @@ * // => { 'a': 1, 'c': 3 } */ function pickBy(object, predicate) { - return object == null ? {} : basePickBy(object, getAllKeysIn(object), getIteratee(predicate)); + if (object == null) { + return {}; + } + var props = arrayMap(getAllKeysIn(object), function(prop) { + return [prop]; + }); + predicate = getIteratee(predicate); + return basePickBy(object, props, function(value, path) { + return predicate(value, path[0]); + }); } /** @@ -13585,7 +13594,7 @@ * // => 'default' */ function result(object, path, defaultValue) { - path = isKey(path, object) ? [path] : castPath(path); + path = castPath(path, object); var index = -1, length = path.length; @@ -16103,7 +16112,7 @@ if (isArray(value)) { return arrayMap(value, toKey); } - return isSymbol(value) ? [value] : copyArray(stringToPath(value)); + return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value))); } /** diff --git a/omit.js b/omit.js index 8b8d1ad22..e11dbfe8c 100644 --- a/omit.js +++ b/omit.js @@ -1,4 +1,4 @@ -define(['./_baseClone', './_baseUnset', './_copyObject', './_flatRest', './_getAllKeysIn'], function(baseClone, baseUnset, copyObject, flatRest, getAllKeysIn) { +define(['./_arrayMap', './_baseClone', './_baseUnset', './_castPath', './_copyObject', './_flatRest', './_getAllKeysIn'], function(arrayMap, baseClone, baseUnset, castPath, copyObject, flatRest, getAllKeysIn) { /** Used to compose bitmasks for cloning. */ var CLONE_DEEP_FLAG = 1, @@ -30,8 +30,15 @@ define(['./_baseClone', './_baseUnset', './_copyObject', './_flatRest', './_getA 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 2172188b4..4ae382cfb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-amd", - "version": "4.17.0", + "version": "4.17.1", "description": "Lodash exported as AMD modules.", "keywords": "amd, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", diff --git a/pick.js b/pick.js index da9b52494..ae5d439c1 100644 --- a/pick.js +++ b/pick.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_basePick', './_flatRest', './_toKey'], function(arrayMap, basePick, flatRest, toKey) { +define(['./_basePick', './_flatRest'], function(basePick, flatRest) { /** * Creates an object composed of the picked `object` properties. @@ -18,7 +18,7 @@ define(['./_arrayMap', './_basePick', './_flatRest', './_toKey'], function(array * // => { 'a': 1, 'c': 3 } */ var pick = flatRest(function(object, paths) { - return object == null ? {} : basePick(object, arrayMap(paths, toKey)); + return object == null ? {} : basePick(object, paths); }); return pick; diff --git a/pickBy.js b/pickBy.js index b527a3eef..6c67d027f 100644 --- a/pickBy.js +++ b/pickBy.js @@ -1,4 +1,4 @@ -define(['./_baseIteratee', './_basePickBy', './_getAllKeysIn'], function(baseIteratee, basePickBy, getAllKeysIn) { +define(['./_arrayMap', './_baseIteratee', './_basePickBy', './_getAllKeysIn'], function(arrayMap, baseIteratee, basePickBy, getAllKeysIn) { /** * Creates an object composed of the `object` properties `predicate` returns @@ -19,7 +19,16 @@ define(['./_baseIteratee', './_basePickBy', './_getAllKeysIn'], function(baseIte * // => { '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]); + }); } return pickBy; diff --git a/result.js b/result.js index d8cb8c000..bd5301ade 100644 --- a/result.js +++ b/result.js @@ -1,4 +1,4 @@ -define(['./_castPath', './isFunction', './_isKey', './_toKey'], function(castPath, isFunction, isKey, toKey) { +define(['./_castPath', './isFunction', './_toKey'], function(castPath, isFunction, toKey) { /** Used as a safe reference for `undefined` in pre-ES5 environments. */ var undefined; @@ -33,7 +33,7 @@ define(['./_castPath', './isFunction', './_isKey', './_toKey'], function(castPat * // => '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 851804ca0..b0e3a9772 100644 --- a/toPath.js +++ b/toPath.js @@ -1,4 +1,4 @@ -define(['./_arrayMap', './_copyArray', './isArray', './isSymbol', './_stringToPath', './_toKey'], function(arrayMap, copyArray, isArray, isSymbol, stringToPath, toKey) { +define(['./_arrayMap', './_copyArray', './isArray', './isSymbol', './_stringToPath', './_toKey', './toString'], function(arrayMap, copyArray, isArray, isSymbol, stringToPath, toKey, toString) { /** * Converts `value` to a property path array. @@ -21,7 +21,7 @@ define(['./_arrayMap', './_copyArray', './isArray', './isSymbol', './_stringToPa if (isArray(value)) { return arrayMap(value, toKey); } - return isSymbol(value) ? [value] : copyArray(stringToPath(value)); + return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value))); } return toPath;