diff --git a/README.md b/README.md index 31c1217ac..e8e2de24b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v4.9.0 +# lodash-es v4.10.0 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.9.0-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.10.0-es) for more details. diff --git a/_baseFor.js b/_baseFor.js index 7dbcfb36f..64b462b27 100644 --- a/_baseFor.js +++ b/_baseFor.js @@ -2,7 +2,7 @@ import createBaseFor from './_createBaseFor'; /** * The base implementation of `baseForOwn` which iterates over `object` - * properties returned by `keysFunc` invoking `iteratee` for each property. + * properties returned by `keysFunc` and invokes `iteratee` for each property. * Iteratee functions may exit iteration early by explicitly returning `false`. * * @private diff --git a/_baseGet.js b/_baseGet.js index 0b7194ff6..a34892e8d 100644 --- a/_baseGet.js +++ b/_baseGet.js @@ -1,4 +1,4 @@ -import baseCastPath from './_baseCastPath'; +import castPath from './_castPath'; import isKey from './_isKey'; /** @@ -10,7 +10,7 @@ import isKey from './_isKey'; * @returns {*} Returns the resolved value. */ function baseGet(object, path) { - path = isKey(path, object) ? [path] : baseCastPath(path); + path = isKey(path, object) ? [path] : castPath(path); var index = 0, length = path.length; diff --git a/_baseInvoke.js b/_baseInvoke.js index 8ba20a268..a38b84a83 100644 --- a/_baseInvoke.js +++ b/_baseInvoke.js @@ -1,5 +1,5 @@ import apply from './_apply'; -import baseCastPath from './_baseCastPath'; +import castPath from './_castPath'; import isKey from './_isKey'; import last from './last'; import parent from './_parent'; @@ -16,7 +16,7 @@ import parent from './_parent'; */ function baseInvoke(object, path, args) { if (!isKey(path, object)) { - path = baseCastPath(path); + path = castPath(path); object = parent(object, path); path = last(path); } diff --git a/_basePullAt.js b/_basePullAt.js index 470afcbcc..ecf27ccb3 100644 --- a/_basePullAt.js +++ b/_basePullAt.js @@ -1,4 +1,4 @@ -import baseCastPath from './_baseCastPath'; +import castPath from './_castPath'; import isIndex from './_isIndex'; import isKey from './_isKey'; import last from './last'; @@ -31,7 +31,7 @@ function basePullAt(array, indexes) { splice.call(array, index, 1); } else if (!isKey(index, array)) { - var path = baseCastPath(index), + var path = castPath(index), object = parent(array, path); if (object != null) { diff --git a/_baseSet.js b/_baseSet.js index 6e96a08ea..c08d7ac03 100644 --- a/_baseSet.js +++ b/_baseSet.js @@ -1,5 +1,5 @@ import assignValue from './_assignValue'; -import baseCastPath from './_baseCastPath'; +import castPath from './_castPath'; import isIndex from './_isIndex'; import isKey from './_isKey'; import isObject from './isObject'; @@ -15,7 +15,7 @@ import isObject from './isObject'; * @returns {Object} Returns `object`. */ function baseSet(object, path, value, customizer) { - path = isKey(path, object) ? [path] : baseCastPath(path); + path = isKey(path, object) ? [path] : castPath(path); var index = -1, length = path.length, diff --git a/_baseUnset.js b/_baseUnset.js index 7b937db9a..8a35e22f6 100644 --- a/_baseUnset.js +++ b/_baseUnset.js @@ -1,4 +1,4 @@ -import baseCastPath from './_baseCastPath'; +import castPath from './_castPath'; import has from './has'; import isKey from './_isKey'; import last from './last'; @@ -13,7 +13,7 @@ import parent from './_parent'; * @returns {boolean} Returns `true` if the property is deleted, else `false`. */ function baseUnset(object, path) { - path = isKey(path, object) ? [path] : baseCastPath(path); + path = isKey(path, object) ? [path] : castPath(path); object = parent(object, path); var key = last(path); return (object != null && has(object, key)) ? delete object[key] : true; diff --git a/_baseCastArrayLikeObject.js b/_castArrayLikeObject.js similarity index 78% rename from _baseCastArrayLikeObject.js rename to _castArrayLikeObject.js index 5bf6e11a1..ddea66adf 100644 --- a/_baseCastArrayLikeObject.js +++ b/_castArrayLikeObject.js @@ -7,8 +7,8 @@ import isArrayLikeObject from './isArrayLikeObject'; * @param {*} value The value to inspect. * @returns {Array|Object} Returns the cast array-like object. */ -function baseCastArrayLikeObject(value) { +function castArrayLikeObject(value) { return isArrayLikeObject(value) ? value : []; } -export default baseCastArrayLikeObject; +export default castArrayLikeObject; diff --git a/_baseCastFunction.js b/_castFunction.js similarity index 79% rename from _baseCastFunction.js rename to _castFunction.js index 169d6c3aa..f5ac5d351 100644 --- a/_baseCastFunction.js +++ b/_castFunction.js @@ -7,8 +7,8 @@ import identity from './identity'; * @param {*} value The value to inspect. * @returns {Function} Returns cast function. */ -function baseCastFunction(value) { +function castFunction(value) { return typeof value == 'function' ? value : identity; } -export default baseCastFunction; +export default castFunction; diff --git a/_baseCastPath.js b/_castPath.js similarity index 83% rename from _baseCastPath.js rename to _castPath.js index 41c7ecdd6..ffaf2b6c1 100644 --- a/_baseCastPath.js +++ b/_castPath.js @@ -8,8 +8,8 @@ import stringToPath from './_stringToPath'; * @param {*} value The value to inspect. * @returns {Array} Returns the cast property path array. */ -function baseCastPath(value) { +function castPath(value) { return isArray(value) ? value : stringToPath(value); } -export default baseCastPath; +export default castPath; diff --git a/_castSlice.js b/_castSlice.js new file mode 100644 index 000000000..4d8a7f52b --- /dev/null +++ b/_castSlice.js @@ -0,0 +1,18 @@ +import baseSlice from './_baseSlice'; + +/** + * Casts `array` to a slice if it's needed. + * + * @private + * @param {Array} array The array to inspect. + * @param {number} start The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the cast slice. + */ +function castSlice(array, start, end) { + var length = array.length; + end = end === undefined ? length : end; + return (!start && end >= length) ? array : baseSlice(array, start, end); +} + +export default castSlice; diff --git a/_createCaseFirst.js b/_createCaseFirst.js index 69684d3b8..35279b667 100644 --- a/_createCaseFirst.js +++ b/_createCaseFirst.js @@ -1,18 +1,8 @@ +import castSlice from './_castSlice'; +import reHasComplexSymbol from './_reHasComplexSymbol'; import stringToArray from './_stringToArray'; import toString from './toString'; -/** Used to compose unicode character classes. */ -var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', - rsComboSymbolsRange = '\\u20d0-\\u20f0', - rsVarRange = '\\ufe0e\\ufe0f'; - -/** Used to compose unicode capture groups. */ -var rsZWJ = '\\u200d'; - -/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ -var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); - /** * Creates a function like `_.lowerFirst`. * @@ -28,8 +18,13 @@ function createCaseFirst(methodName) { ? stringToArray(string) : undefined; - var chr = strSymbols ? strSymbols[0] : string.charAt(0), - trailing = strSymbols ? strSymbols.slice(1).join('') : string.slice(1); + var chr = strSymbols + ? strSymbols[0] + : string.charAt(0); + + var trailing = strSymbols + ? castSlice(strSymbols, 1).join('') + : string.slice(1); return chr[methodName]() + trailing; }; diff --git a/_createPadding.js b/_createPadding.js index 29d5fd138..acc7dba42 100644 --- a/_createPadding.js +++ b/_createPadding.js @@ -1,19 +1,9 @@ import baseRepeat from './_baseRepeat'; +import castSlice from './_castSlice'; +import reHasComplexSymbol from './_reHasComplexSymbol'; import stringSize from './_stringSize'; import stringToArray from './_stringToArray'; -/** Used to compose unicode character classes. */ -var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', - rsComboSymbolsRange = '\\u20d0-\\u20f0', - rsVarRange = '\\ufe0e\\ufe0f'; - -/** Used to compose unicode capture groups. */ -var rsZWJ = '\\u200d'; - -/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ -var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); - /* Built-in method references for those with the same name as other `lodash` methods. */ var nativeCeil = Math.ceil; @@ -35,7 +25,7 @@ function createPadding(length, chars) { } var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); return reHasComplexSymbol.test(chars) - ? stringToArray(result).slice(0, length).join('') + ? castSlice(stringToArray(result), 0, length).join('') : result.slice(0, length); } diff --git a/_hasPath.js b/_hasPath.js index 901750cbc..74c454216 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -1,4 +1,4 @@ -import baseCastPath from './_baseCastPath'; +import castPath from './_castPath'; import isArguments from './isArguments'; import isArray from './isArray'; import isIndex from './_isIndex'; @@ -16,7 +16,7 @@ import isString from './isString'; * @returns {boolean} Returns `true` if `path` exists, else `false`. */ function hasPath(object, path, hasFunc) { - path = isKey(path, object) ? [path] : baseCastPath(path); + path = isKey(path, object) ? [path] : castPath(path); var result, index = -1, diff --git a/_reHasComplexSymbol.js b/_reHasComplexSymbol.js new file mode 100644 index 000000000..fff4f9cbb --- /dev/null +++ b/_reHasComplexSymbol.js @@ -0,0 +1,13 @@ +/** Used to compose unicode character classes. */ +var rsAstralRange = '\\ud800-\\udfff', + rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', + rsComboSymbolsRange = '\\u20d0-\\u20f0', + rsVarRange = '\\ufe0e\\ufe0f'; + +/** Used to compose unicode capture groups. */ +var rsZWJ = '\\u200d'; + +/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ +var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); + +export default reHasComplexSymbol; diff --git a/_stringSize.js b/_stringSize.js index 82337db1a..c85c6cbcb 100644 --- a/_stringSize.js +++ b/_stringSize.js @@ -1,3 +1,5 @@ +import reHasComplexSymbol from './_reHasComplexSymbol'; + /** Used to compose unicode character classes. */ var rsAstralRange = '\\ud800-\\udfff', rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', @@ -24,9 +26,6 @@ var reOptMod = rsModifier + '?', /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ var reComplexSymbol = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); -/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ -var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); - /** * Gets the number of symbols in `string`. * diff --git a/_baseCastKey.js b/_toKey.js similarity index 51% rename from _baseCastKey.js rename to _toKey.js index cd2d475c9..4ce40d7b4 100644 --- a/_baseCastKey.js +++ b/_toKey.js @@ -1,14 +1,14 @@ import isSymbol from './isSymbol'; /** - * Casts `value` to a string if it's not a string or symbol. + * Converts `value` to a string key if it's not a string or symbol. * * @private * @param {*} value The value to inspect. - * @returns {string|symbol} Returns the cast key. + * @returns {string|symbol} Returns the key. */ -function baseCastKey(key) { +function toKey(key) { return (typeof key == 'string' || isSymbol(key)) ? key : (key + ''); } -export default baseCastKey; +export default toKey; diff --git a/at.js b/at.js index 74b5eeb9e..f0ed13489 100644 --- a/at.js +++ b/at.js @@ -10,8 +10,7 @@ import rest from './rest'; * @since 1.0.0 * @category Object * @param {Object} object The object to iterate over. - * @param {...(string|string[])} [paths] The property paths of elements to pick, - * specified individually or in arrays. + * @param {...(string|string[])} [paths] The property paths of elements to pick. * @returns {Array} Returns the new array of picked elements. * @example * diff --git a/bindAll.js b/bindAll.js index 31478b7e9..b9dec1a18 100644 --- a/bindAll.js +++ b/bindAll.js @@ -14,8 +14,7 @@ import rest from './rest'; * @memberOf _ * @category Util * @param {Object} object The object to bind and assign the bound methods to. - * @param {...(string|string[])} methodNames The object method names to bind, - * specified individually or in arrays. + * @param {...(string|string[])} methodNames The object method names to bind. * @returns {Object} Returns `object`. * @example * diff --git a/cond.js b/cond.js index 5c560ab44..eea509455 100644 --- a/cond.js +++ b/cond.js @@ -7,7 +7,7 @@ import rest from './rest'; var FUNC_ERROR_TEXT = 'Expected a function'; /** - * Creates a function that iterates over `pairs` invoking the corresponding + * Creates a function that iterates over `pairs` and invokes the corresponding * function of the first predicate to return truthy. The predicate-function * pairs are invoked with the `this` binding and arguments of the created * function. diff --git a/debounce.js b/debounce.js index f13119b66..eaeacd277 100644 --- a/debounce.js +++ b/debounce.js @@ -169,6 +169,9 @@ function debounce(func, wait, options) { timerId = setTimeout(timerExpired, wait); return invokeFunc(lastCallTime); } + if (timerId === undefined) { + timerId = setTimeout(timerExpired, wait); + } return result; } debounced.cancel = cancel; diff --git a/forEach.js b/forEach.js index 8ac8b6cf7..1ecb92922 100644 --- a/forEach.js +++ b/forEach.js @@ -4,7 +4,7 @@ import baseIteratee from './_baseIteratee'; import isArray from './isArray'; /** - * Iterates over elements of `collection` invoking `iteratee` for each element. + * Iterates over elements of `collection` and invokes `iteratee` for each element. * The iteratee is invoked with three arguments: (value, index|key, collection). * Iteratee functions may exit iteration early by explicitly returning `false`. * diff --git a/forIn.js b/forIn.js index cc773b166..30945a53a 100644 --- a/forIn.js +++ b/forIn.js @@ -4,9 +4,9 @@ import keysIn from './keysIn'; /** * Iterates over own and inherited enumerable string keyed properties of an - * object invoking `iteratee` for each property. The iteratee is invoked with - * three arguments: (value, key, object). Iteratee functions may exit iteration - * early by explicitly returning `false`. + * object and invokes `iteratee` for each property. The iteratee is invoked + * with three arguments: (value, key, object). Iteratee functions may exit + * iteration early by explicitly returning `false`. * * @static * @memberOf _ diff --git a/forOwn.js b/forOwn.js index acf1f4f53..f9631a6fc 100644 --- a/forOwn.js +++ b/forOwn.js @@ -2,10 +2,10 @@ import baseForOwn from './_baseForOwn'; import baseIteratee from './_baseIteratee'; /** - * Iterates over own enumerable string keyed properties of an object invoking - * `iteratee` for each property. The iteratee is invoked with three arguments: - * (value, key, object). Iteratee functions may exit iteration early by - * explicitly returning `false`. + * Iterates over own enumerable string keyed properties of an object and + * invokes `iteratee` for each property. The iteratee is invoked with three + * arguments: (value, key, object). Iteratee functions may exit iteration + * early by explicitly returning `false`. * * @static * @memberOf _ diff --git a/intersection.js b/intersection.js index 2e5f6b07a..ab7f50f16 100644 --- a/intersection.js +++ b/intersection.js @@ -1,6 +1,6 @@ import arrayMap from './_arrayMap'; -import baseCastArrayLikeObject from './_baseCastArrayLikeObject'; import baseIntersection from './_baseIntersection'; +import castArrayLikeObject from './_castArrayLikeObject'; import rest from './rest'; /** @@ -21,7 +21,7 @@ import rest from './rest'; * // => [2] */ var intersection = rest(function(arrays) { - var mapped = arrayMap(arrays, baseCastArrayLikeObject); + var mapped = arrayMap(arrays, castArrayLikeObject); return (mapped.length && mapped[0] === arrays[0]) ? baseIntersection(mapped) : []; diff --git a/intersectionBy.js b/intersectionBy.js index 9a298fae4..f6e8bbb7c 100644 --- a/intersectionBy.js +++ b/intersectionBy.js @@ -1,7 +1,7 @@ import arrayMap from './_arrayMap'; -import baseCastArrayLikeObject from './_baseCastArrayLikeObject'; import baseIntersection from './_baseIntersection'; import baseIteratee from './_baseIteratee'; +import castArrayLikeObject from './_castArrayLikeObject'; import last from './last'; import rest from './rest'; @@ -30,7 +30,7 @@ import rest from './rest'; */ var intersectionBy = rest(function(arrays) { var iteratee = last(arrays), - mapped = arrayMap(arrays, baseCastArrayLikeObject); + mapped = arrayMap(arrays, castArrayLikeObject); if (iteratee === last(mapped)) { iteratee = undefined; diff --git a/intersectionWith.js b/intersectionWith.js index d0543e8b5..d4fa027e5 100644 --- a/intersectionWith.js +++ b/intersectionWith.js @@ -1,6 +1,6 @@ import arrayMap from './_arrayMap'; -import baseCastArrayLikeObject from './_baseCastArrayLikeObject'; import baseIntersection from './_baseIntersection'; +import castArrayLikeObject from './_castArrayLikeObject'; import last from './last'; import rest from './rest'; @@ -27,7 +27,7 @@ import rest from './rest'; */ var intersectionWith = rest(function(arrays) { var comparator = last(arrays), - mapped = arrayMap(arrays, baseCastArrayLikeObject); + mapped = arrayMap(arrays, castArrayLikeObject); if (comparator === last(mapped)) { comparator = undefined; diff --git a/lodash.default.js b/lodash.default.js index 903a4eeab..604e265e0 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.9.0 (Custom Build) + * lodash 4.10.0 (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright jQuery Foundation and other contributors * Released under MIT license @@ -44,7 +44,7 @@ import toInteger from './toInteger'; import lodash from './wrapperLodash'; /** Used as the semantic version number. */ -var VERSION = '4.9.0'; +var VERSION = '4.10.0'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_KEY_FLAG = 2; diff --git a/lodash.js b/lodash.js index 58564153d..618aa60ab 100644 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.9.0 (Custom Build) + * lodash 4.10.0 (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright jQuery Foundation and other contributors * Released under MIT license diff --git a/map.js b/map.js index 9fb895872..888dc851f 100644 --- a/map.js +++ b/map.js @@ -14,8 +14,8 @@ import isArray from './isArray'; * The guarded methods are: * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, - * `sampleSize`, `slice`, `some`, `sortBy`, `take`, `takeRight`, `template`, - * `trim`, `trimEnd`, `trimStart`, and `words` + * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`, + * `template`, `trim`, `trimEnd`, `trimStart`, and `words` * * @static * @memberOf _ diff --git a/omit.js b/omit.js index ebcef2d53..3eeb7ca89 100644 --- a/omit.js +++ b/omit.js @@ -1,10 +1,10 @@ import arrayMap from './_arrayMap'; -import baseCastKey from './_baseCastKey'; import baseDifference from './_baseDifference'; import baseFlatten from './_baseFlatten'; import basePick from './_basePick'; import getAllKeysIn from './_getAllKeysIn'; import rest from './rest'; +import toKey from './_toKey'; /** * The opposite of `_.pick`; this method creates an object composed of the @@ -16,8 +16,7 @@ import rest from './rest'; * @memberOf _ * @category Object * @param {Object} object The source object. - * @param {...(string|string[])} [props] The property identifiers to omit, - * specified individually or in arrays. + * @param {...(string|string[])} [props] The property identifiers to omit. * @returns {Object} Returns the new object. * @example * @@ -30,7 +29,7 @@ var omit = rest(function(object, props) { if (object == null) { return {}; } - props = arrayMap(baseFlatten(props, 1), baseCastKey); + props = arrayMap(baseFlatten(props, 1), toKey); return basePick(object, baseDifference(getAllKeysIn(object), props)); }); diff --git a/over.js b/over.js index f08e5db61..1d49032a1 100644 --- a/over.js +++ b/over.js @@ -9,7 +9,8 @@ import createOver from './_createOver'; * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Function|Function[])} iteratees The iteratees to invoke. + * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} + * [iteratees=[_.identity]] The iteratees to invoke. * @returns {Function} Returns the new function. * @example * diff --git a/overArgs.js b/overArgs.js index 4e9e24ced..1e33d0279 100644 --- a/overArgs.js +++ b/overArgs.js @@ -17,8 +17,8 @@ var nativeMin = Math.min; * @memberOf _ * @category Function * @param {Function} func The function to wrap. - * @param {...(Function|Function[])} [transforms] The functions to transform. - * arguments, specified individually or in arrays. + * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} + * [transforms[_.identity]] The functions to transform. * @returns {Function} Returns the new function. * @example * diff --git a/overEvery.js b/overEvery.js index 335503d1b..c3fd2b615 100644 --- a/overEvery.js +++ b/overEvery.js @@ -9,7 +9,8 @@ import createOver from './_createOver'; * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Function|Function[])} predicates The predicates to check. + * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} + * [predicates=[_.identity]] The predicates to check. * @returns {Function} Returns the new function. * @example * diff --git a/overSome.js b/overSome.js index 9c8021f91..70aab0b8a 100644 --- a/overSome.js +++ b/overSome.js @@ -9,7 +9,8 @@ import createOver from './_createOver'; * @memberOf _ * @since 4.0.0 * @category Util - * @param {...(Function|Function[])} predicates The predicates to check. + * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} + * [predicates=[_.identity]] The predicates to check. * @returns {Function} Returns the new function. * @example * diff --git a/package.json b/package.json index 927bb673d..95f3bf0e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lodash-es", - "version": "4.9.0", + "version": "4.10.0", "description": "Lodash exported as ES modules.", "homepage": "https://lodash.com/custom-builds", "license": "MIT", diff --git a/pick.js b/pick.js index 0e1daa36c..fb587cc51 100644 --- a/pick.js +++ b/pick.js @@ -10,8 +10,7 @@ import rest from './rest'; * @memberOf _ * @category Object * @param {Object} object The source object. - * @param {...(string|string[])} [props] The property identifiers to pick, - * specified individually or in arrays. + * @param {...(string|string[])} [props] The property identifiers to pick. * @returns {Object} Returns the new object. * @example * diff --git a/pullAt.js b/pullAt.js index 2f96df516..7f22bca73 100644 --- a/pullAt.js +++ b/pullAt.js @@ -16,8 +16,7 @@ import rest from './rest'; * @since 3.0.0 * @category Array * @param {Array} array The array to modify. - * @param {...(number|number[])} [indexes] The indexes of elements to remove, - * specified individually or in arrays. + * @param {...(number|number[])} [indexes] The indexes of elements to remove. * @returns {Array} Returns the new array of removed elements. * @example * diff --git a/rearg.js b/rearg.js index 8990017c9..caaa0328b 100644 --- a/rearg.js +++ b/rearg.js @@ -16,8 +16,7 @@ var REARG_FLAG = 256; * @since 3.0.0 * @category Function * @param {Function} func The function to rearrange arguments for. - * @param {...(number|number[])} indexes The arranged argument indexes, - * specified individually or in arrays. + * @param {...(number|number[])} indexes The arranged argument indexes. * @returns {Function} Returns the new function. * @example * diff --git a/result.js b/result.js index f6d0bbb5d..8565004e4 100644 --- a/result.js +++ b/result.js @@ -1,4 +1,4 @@ -import baseCastPath from './_baseCastPath'; +import castPath from './_castPath'; import isFunction from './isFunction'; import isKey from './_isKey'; @@ -32,7 +32,7 @@ import isKey from './_isKey'; * // => 'default' */ function result(object, path, defaultValue) { - path = isKey(path, object) ? [path] : baseCastPath(path); + path = isKey(path, object) ? [path] : castPath(path); var index = -1, length = path.length; diff --git a/sortBy.js b/sortBy.js index edb45a3b9..9fe3665bc 100644 --- a/sortBy.js +++ b/sortBy.js @@ -15,8 +15,7 @@ import rest from './rest'; * @category Collection * @param {Array|Object} collection The collection to iterate over. * @param {...(Array|Array[]|Function|Function[]|Object|Object[]|string|string[])} - * [iteratees=[_.identity]] The iteratees to sort by, specified individually - * or in arrays. + * [iteratees=[_.identity]] The iteratees to sort by. * @returns {Array} Returns the new sorted array. * @example * @@ -46,7 +45,7 @@ var sortBy = rest(function(collection, iteratees) { if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) { iteratees = []; } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { - iteratees.length = 1; + iteratees = [iteratees[0]]; } return baseOrderBy(collection, baseFlatten(iteratees, 1), []); }); diff --git a/split.js b/split.js index 773ce73bc..2452e01b2 100644 --- a/split.js +++ b/split.js @@ -1,18 +1,12 @@ +import castSlice from './_castSlice'; +import isIterateeCall from './_isIterateeCall'; import isRegExp from './isRegExp'; +import reHasComplexSymbol from './_reHasComplexSymbol'; import stringToArray from './_stringToArray'; import toString from './toString'; -/** Used to compose unicode character classes. */ -var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', - rsComboSymbolsRange = '\\u20d0-\\u20f0', - rsVarRange = '\\ufe0e\\ufe0f'; - -/** Used to compose unicode capture groups. */ -var rsZWJ = '\\u200d'; - -/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ -var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); +/** Used as references for the maximum length and index of an array. */ +var MAX_ARRAY_LENGTH = 4294967295; /** * Splits `string` by `separator`. @@ -34,6 +28,13 @@ var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange * // => ['a', 'b'] */ function split(string, separator, limit) { + if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { + separator = limit = undefined; + } + limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0; + if (!limit) { + return []; + } string = toString(string); if (string && ( typeof separator == 'string' || @@ -41,8 +42,7 @@ function split(string, separator, limit) { )) { separator += ''; if (separator == '' && reHasComplexSymbol.test(string)) { - var strSymbols = stringToArray(string); - return limit === undefined ? strSymbols : strSymbols.slice(0, limit < 0 ? 0 : limit); + return castSlice(stringToArray(string), 0, limit); } } return string.split(separator, limit); diff --git a/spread.js b/spread.js index debde0b4d..94923335f 100644 --- a/spread.js +++ b/spread.js @@ -1,5 +1,6 @@ import apply from './_apply'; import arrayPush from './_arrayPush'; +import castSlice from './_castSlice'; import rest from './rest'; import toInteger from './toInteger'; @@ -50,7 +51,7 @@ function spread(func, start) { start = start === undefined ? 0 : nativeMax(toInteger(start), 0); return rest(function(args) { var array = args[start], - otherArgs = args.slice(0, start); + otherArgs = castSlice(args, 0, start); if (array) { arrayPush(otherArgs, array); diff --git a/toPath.js b/toPath.js index 4d5faee08..dc277f4cc 100644 --- a/toPath.js +++ b/toPath.js @@ -1,9 +1,9 @@ import arrayMap from './_arrayMap'; -import baseCastKey from './_baseCastKey'; import copyArray from './_copyArray'; import isArray from './isArray'; import isSymbol from './isSymbol'; import stringToPath from './_stringToPath'; +import toKey from './_toKey'; /** * Converts `value` to a property path array. @@ -33,7 +33,7 @@ import stringToPath from './_stringToPath'; */ function toPath(value) { if (isArray(value)) { - return arrayMap(value, baseCastKey); + return arrayMap(value, toKey); } return isSymbol(value) ? [value] : copyArray(stringToPath(value)); } diff --git a/toString.js b/toString.js index 989b014a7..5a3b4d7f1 100644 --- a/toString.js +++ b/toString.js @@ -9,8 +9,8 @@ var symbolProto = Symbol ? Symbol.prototype : undefined, symbolToString = symbolProto ? symbolProto.toString : undefined; /** - * Converts `value` to a string if it's not one. An empty string is returned - * for `null` and `undefined` values. The sign of `-0` is preserved. + * Converts `value` to a string. An empty string is returned for `null` + * and `undefined` values. The sign of `-0` is preserved. * * @static * @memberOf _ diff --git a/trim.js b/trim.js index eff4ec95f..2eef9e40d 100644 --- a/trim.js +++ b/trim.js @@ -1,3 +1,4 @@ +import castSlice from './_castSlice'; import charsEndIndex from './_charsEndIndex'; import charsStartIndex from './_charsStartIndex'; import stringToArray from './_stringToArray'; @@ -36,16 +37,15 @@ function trim(string, chars, guard) { if (guard || chars === undefined) { return string.replace(reTrim, ''); } - chars = (chars + ''); - if (!chars) { + if (!(chars += '')) { return string; } var strSymbols = stringToArray(string), - chrSymbols = stringToArray(chars); + chrSymbols = stringToArray(chars), + start = charsStartIndex(strSymbols, chrSymbols), + end = charsEndIndex(strSymbols, chrSymbols) + 1; - return strSymbols - .slice(charsStartIndex(strSymbols, chrSymbols), charsEndIndex(strSymbols, chrSymbols) + 1) - .join(''); + return castSlice(strSymbols, start, end).join(''); } export default trim; diff --git a/trimEnd.js b/trimEnd.js index 6eef62b7b..f3a9962ad 100644 --- a/trimEnd.js +++ b/trimEnd.js @@ -1,3 +1,4 @@ +import castSlice from './_castSlice'; import charsEndIndex from './_charsEndIndex'; import stringToArray from './_stringToArray'; import toString from './toString'; @@ -32,14 +33,13 @@ function trimEnd(string, chars, guard) { if (guard || chars === undefined) { return string.replace(reTrimEnd, ''); } - chars = (chars + ''); - if (!chars) { + if (!(chars += '')) { return string; } - var strSymbols = stringToArray(string); - return strSymbols - .slice(0, charsEndIndex(strSymbols, stringToArray(chars)) + 1) - .join(''); + var strSymbols = stringToArray(string), + end = charsEndIndex(strSymbols, stringToArray(chars)) + 1; + + return castSlice(strSymbols, 0, end).join(''); } export default trimEnd; diff --git a/trimStart.js b/trimStart.js index 26b9395a1..ddcba5d76 100644 --- a/trimStart.js +++ b/trimStart.js @@ -1,3 +1,4 @@ +import castSlice from './_castSlice'; import charsStartIndex from './_charsStartIndex'; import stringToArray from './_stringToArray'; import toString from './toString'; @@ -32,14 +33,13 @@ function trimStart(string, chars, guard) { if (guard || chars === undefined) { return string.replace(reTrimStart, ''); } - chars = (chars + ''); - if (!chars) { + if (!(chars += '')) { return string; } - var strSymbols = stringToArray(string); - return strSymbols - .slice(charsStartIndex(strSymbols, stringToArray(chars))) - .join(''); + var strSymbols = stringToArray(string), + start = charsStartIndex(strSymbols, stringToArray(chars)); + + return castSlice(strSymbols, start).join(''); } export default trimStart; diff --git a/truncate.js b/truncate.js index f93ae1e2d..a9cc9a0e1 100644 --- a/truncate.js +++ b/truncate.js @@ -1,5 +1,7 @@ +import castSlice from './_castSlice'; import isObject from './isObject'; import isRegExp from './isRegExp'; +import reHasComplexSymbol from './_reHasComplexSymbol'; import stringSize from './_stringSize'; import stringToArray from './_stringToArray'; import toInteger from './toInteger'; @@ -12,18 +14,6 @@ var DEFAULT_TRUNC_LENGTH = 30, /** Used to match `RegExp` flags from their coerced string values. */ var reFlags = /\w*$/; -/** Used to compose unicode character classes. */ -var rsAstralRange = '\\ud800-\\udfff', - rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', - rsComboSymbolsRange = '\\u20d0-\\u20f0', - rsVarRange = '\\ufe0e\\ufe0f'; - -/** Used to compose unicode capture groups. */ -var rsZWJ = '\\u200d'; - -/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ -var reHasComplexSymbol = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']'); - /** * Truncates `string` if it's longer than the given maximum string length. * The last characters of the truncated string are replaced with the omission @@ -85,7 +75,7 @@ function truncate(string, options) { return omission; } var result = strSymbols - ? strSymbols.slice(0, end).join('') + ? castSlice(strSymbols, 0, end).join('') : string.slice(0, end); if (separator === undefined) { diff --git a/update.js b/update.js index 7a7b0a1f3..ec4bbe332 100644 --- a/update.js +++ b/update.js @@ -1,5 +1,5 @@ -import baseCastFunction from './_baseCastFunction'; import baseUpdate from './_baseUpdate'; +import castFunction from './_castFunction'; /** * This method is like `_.set` except that accepts `updater` to produce the @@ -29,7 +29,7 @@ import baseUpdate from './_baseUpdate'; * // => 0 */ function update(object, path, updater) { - return object == null ? object : baseUpdate(object, path, baseCastFunction(updater)); + return object == null ? object : baseUpdate(object, path, castFunction(updater)); } export default update; diff --git a/updateWith.js b/updateWith.js index 68a571db1..528ef2f4b 100644 --- a/updateWith.js +++ b/updateWith.js @@ -1,5 +1,5 @@ -import baseCastFunction from './_baseCastFunction'; import baseUpdate from './_baseUpdate'; +import castFunction from './_castFunction'; /** * This method is like `_.update` except that it accepts `customizer` which is @@ -27,7 +27,7 @@ import baseUpdate from './_baseUpdate'; */ function updateWith(object, path, updater, customizer) { customizer = typeof customizer == 'function' ? customizer : undefined; - return object == null ? object : baseUpdate(object, path, baseCastFunction(updater), customizer); + return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer); } export default updateWith; diff --git a/words.js b/words.js index 65f297732..27ce8391f 100644 --- a/words.js +++ b/words.js @@ -1,5 +1,8 @@ import toString from './toString'; +/** Used to match non-compound words composed of alphanumeric characters. */ +var reBasicWord = /[a-zA-Z0-9]+/g; + /** Used to compose unicode character classes. */ var rsAstralRange = '\\ud800-\\udfff', rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23', @@ -38,9 +41,6 @@ var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')', rsSeq = rsOptVar + reOptMod + rsOptJoin, rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq; -/** Used to match non-compound words composed of alphanumeric characters. */ -var reBasicWord = /[a-zA-Z0-9]+/g; - /** Used to match complex or compound words. */ var reComplexWord = RegExp([ rsUpper + '?' + rsLower + '+(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', diff --git a/wrapperAt.js b/wrapperAt.js index 4eee46c87..bc82ec1b9 100644 --- a/wrapperAt.js +++ b/wrapperAt.js @@ -13,8 +13,7 @@ import thru from './thru'; * @memberOf _ * @since 1.0.0 * @category Seq - * @param {...(string|string[])} [paths] The property paths of elements to pick, - * specified individually or in arrays. + * @param {...(string|string[])} [paths] The property paths of elements to pick. * @returns {Object} Returns the new `lodash` wrapper instance. * @example *