From 35805ec2506978c14ab04bfb8b0fc9f5644204a2 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 19 Apr 2016 22:21:01 -0700 Subject: [PATCH] Bump to v4.11.2. --- README.md | 4 ++-- _baseDifference.js | 1 + _baseExtremum.js | 4 +++- _baseGet.js | 3 ++- _baseGt.js | 14 ++++++++++++++ _baseIntersection.js | 1 + _baseInvoke.js | 3 ++- _baseLt.js | 14 ++++++++++++++ _baseMatchesProperty.js | 3 ++- _basePullAt.js | 7 ++++--- _baseSet.js | 3 ++- _baseSortedIndex.js | 4 +++- _baseSortedIndexBy.js | 23 +++++++++++++++-------- _baseSortedUniq.js | 24 ++++++++++++++++++++---- _baseSortedUniqBy.js | 33 --------------------------------- _baseToNumber.js | 24 ++++++++++++++++++++++++ _baseToString.js | 31 +++++++++++++++++++++++++++++++ _baseUniq.js | 1 + _baseUnset.js | 8 +++++--- _compareAscending.js | 32 ++++++++++++++++++++------------ _createMathOperation.js | 15 ++++++++++++++- _createPadding.js | 3 ++- _createRelationalOperation.js | 20 ++++++++++++++++++++ _createSet.js | 6 +++++- _hasPath.js | 3 ++- _isIndex.js | 5 +++-- _isKey.js | 11 +++++++---- _isKeyable.js | 5 +++-- _toKey.js | 11 +++++++++-- assign.js | 1 + assignIn.js | 1 + assignInWith.js | 1 + assignWith.js | 1 + bindAll.js | 2 ++ clone.js | 1 + cloneDeep.js | 1 + cloneDeepWith.js | 1 + cloneWith.js | 1 + defaults.js | 1 + defaultsDeep.js | 1 + difference.js | 1 + endsWith.js | 3 ++- filter.js | 1 + flow.js | 1 + flowRight.js | 3 ++- forEach.js | 1 + forEachRight.js | 1 + forIn.js | 1 + forInRight.js | 1 + forOwn.js | 1 + forOwnRight.js | 1 + functions.js | 1 + functionsIn.js | 1 + gt.js | 8 +++++--- gte.js | 7 +++++-- inRange.js | 3 ++- lodash.default.js | 4 ++-- lodash.js | 2 +- lt.js | 8 +++++--- lte.js | 7 +++++-- mapKeys.js | 1 + mapValues.js | 1 + max.js | 4 ++-- maxBy.js | 4 ++-- min.js | 4 ++-- minBy.js | 4 ++-- package.json | 8 ++++---- pick.js | 4 +++- property.js | 3 ++- pullAt.js | 12 +++++++++--- range.js | 1 + rangeRight.js | 1 + reduce.js | 1 + reduceRight.js | 1 + reject.js | 1 + result.js | 3 ++- sortedUniqBy.js | 4 ++-- split.js | 3 ++- startsWith.js | 3 ++- toString.js | 23 ++--------------------- trim.js | 8 +++----- trimEnd.js | 8 +++----- trimStart.js | 8 +++----- truncate.js | 5 +++-- without.js | 1 + words.js | 4 ++-- xor.js | 1 + 87 files changed, 342 insertions(+), 163 deletions(-) create mode 100644 _baseGt.js create mode 100644 _baseLt.js delete mode 100644 _baseSortedUniqBy.js create mode 100644 _baseToNumber.js create mode 100644 _baseToString.js create mode 100644 _createRelationalOperation.js diff --git a/README.md b/README.md index a2ecd4cfb..d969687c1 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lodash-es v4.11.1 +# lodash-es v4.11.2 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.11.1-es) for more details. +See the [package source](https://github.com/lodash/lodash/tree/4.11.2-es) for more details. diff --git a/_baseDifference.js b/_baseDifference.js index f38753b8e..46cc2ccdb 100644 --- a/_baseDifference.js +++ b/_baseDifference.js @@ -47,6 +47,7 @@ function baseDifference(array, values, iteratee, comparator) { var value = array[index], computed = iteratee ? iteratee(value) : value; + value = (comparator || value !== 0) ? value : 0; if (isCommon && computed === computed) { var valuesIndex = valuesLength; while (valuesIndex--) { diff --git a/_baseExtremum.js b/_baseExtremum.js index 78cab39c7..4fd04a025 100644 --- a/_baseExtremum.js +++ b/_baseExtremum.js @@ -1,3 +1,5 @@ +import isSymbol from './isSymbol'; + /** * The base implementation of methods like `_.max` and `_.min` which accepts a * `comparator` to determine the extremum value. @@ -17,7 +19,7 @@ function baseExtremum(array, iteratee, comparator) { current = iteratee(value); if (current != null && (computed === undefined - ? current === current + ? (current === current && !isSymbol(current)) : comparator(current, computed) )) { var computed = current, diff --git a/_baseGet.js b/_baseGet.js index a34892e8d..d2cb535cb 100644 --- a/_baseGet.js +++ b/_baseGet.js @@ -1,5 +1,6 @@ import castPath from './_castPath'; import isKey from './_isKey'; +import toKey from './_toKey'; /** * The base implementation of `_.get` without support for default values. @@ -16,7 +17,7 @@ function baseGet(object, path) { length = path.length; while (object != null && index < length) { - object = object[path[index++]]; + object = object[toKey(path[index++])]; } return (index && index == length) ? object : undefined; } diff --git a/_baseGt.js b/_baseGt.js new file mode 100644 index 000000000..a237f3dab --- /dev/null +++ b/_baseGt.js @@ -0,0 +1,14 @@ +/** + * The base implementation of `_.gt` which doesn't coerce arguments to numbers. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. + */ +function baseGt(value, other) { + return value > other; +} + +export default baseGt; diff --git a/_baseIntersection.js b/_baseIntersection.js index d64c75fd1..f301527ca 100644 --- a/_baseIntersection.js +++ b/_baseIntersection.js @@ -47,6 +47,7 @@ function baseIntersection(arrays, iteratee, comparator) { var value = array[index], computed = iteratee ? iteratee(value) : value; + value = (comparator || value !== 0) ? value : 0; if (!(seen ? cacheHas(seen, computed) : includes(result, computed, comparator) diff --git a/_baseInvoke.js b/_baseInvoke.js index a38b84a83..ebbd25656 100644 --- a/_baseInvoke.js +++ b/_baseInvoke.js @@ -3,6 +3,7 @@ import castPath from './_castPath'; import isKey from './_isKey'; import last from './last'; import parent from './_parent'; +import toKey from './_toKey'; /** * The base implementation of `_.invoke` without support for individual @@ -20,7 +21,7 @@ function baseInvoke(object, path, args) { object = parent(object, path); path = last(path); } - var func = object == null ? object : object[path]; + var func = object == null ? object : object[toKey(path)]; return func == null ? undefined : apply(func, object, args); } diff --git a/_baseLt.js b/_baseLt.js new file mode 100644 index 000000000..1ba6745a9 --- /dev/null +++ b/_baseLt.js @@ -0,0 +1,14 @@ +/** + * The base implementation of `_.lt` which doesn't coerce arguments to numbers. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. + */ +function baseLt(value, other) { + return value < other; +} + +export default baseLt; diff --git a/_baseMatchesProperty.js b/_baseMatchesProperty.js index 8728cfd08..500ca6878 100644 --- a/_baseMatchesProperty.js +++ b/_baseMatchesProperty.js @@ -4,6 +4,7 @@ import hasIn from './hasIn'; import isKey from './_isKey'; import isStrictComparable from './_isStrictComparable'; import matchesStrictComparable from './_matchesStrictComparable'; +import toKey from './_toKey'; /** Used to compose bitmasks for comparison styles. */ var UNORDERED_COMPARE_FLAG = 1, @@ -19,7 +20,7 @@ var UNORDERED_COMPARE_FLAG = 1, */ function baseMatchesProperty(path, srcValue) { if (isKey(path) && isStrictComparable(srcValue)) { - return matchesStrictComparable(path, srcValue); + return matchesStrictComparable(toKey(path), srcValue); } return function(object) { var objValue = get(object, path); diff --git a/_basePullAt.js b/_basePullAt.js index ecf27ccb3..7f7fe94ad 100644 --- a/_basePullAt.js +++ b/_basePullAt.js @@ -3,6 +3,7 @@ import isIndex from './_isIndex'; import isKey from './_isKey'; import last from './last'; import parent from './_parent'; +import toKey from './_toKey'; /** Used for built-in method references. */ var arrayProto = Array.prototype; @@ -25,7 +26,7 @@ function basePullAt(array, indexes) { while (length--) { var index = indexes[length]; - if (lastIndex == length || index != previous) { + if (length == lastIndex || index !== previous) { var previous = index; if (isIndex(index)) { splice.call(array, index, 1); @@ -35,11 +36,11 @@ function basePullAt(array, indexes) { object = parent(array, path); if (object != null) { - delete object[last(path)]; + delete object[toKey(last(path))]; } } else { - delete array[index]; + delete array[toKey(index)]; } } } diff --git a/_baseSet.js b/_baseSet.js index c08d7ac03..ebb90107e 100644 --- a/_baseSet.js +++ b/_baseSet.js @@ -3,6 +3,7 @@ import castPath from './_castPath'; import isIndex from './_isIndex'; import isKey from './_isKey'; import isObject from './isObject'; +import toKey from './_toKey'; /** * The base implementation of `_.set`. @@ -23,7 +24,7 @@ function baseSet(object, path, value, customizer) { nested = object; while (nested != null && ++index < length) { - var key = path[index]; + var key = toKey(path[index]); if (isObject(nested)) { var newValue = value; if (index != lastIndex) { diff --git a/_baseSortedIndex.js b/_baseSortedIndex.js index e3718f61a..ab5305c43 100644 --- a/_baseSortedIndex.js +++ b/_baseSortedIndex.js @@ -1,5 +1,6 @@ import baseSortedIndexBy from './_baseSortedIndexBy'; import identity from './identity'; +import isSymbol from './isSymbol'; /** Used as references for the maximum length and index of an array. */ var MAX_ARRAY_LENGTH = 4294967295, @@ -26,7 +27,8 @@ function baseSortedIndex(array, value, retHighest) { var mid = (low + high) >>> 1, computed = array[mid]; - if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) { + if (computed !== null && !isSymbol(computed) && + (retHighest ? (computed <= value) : (computed < value))) { low = mid + 1; } else { high = mid; diff --git a/_baseSortedIndexBy.js b/_baseSortedIndexBy.js index 136ae1f9f..ceec7957c 100644 --- a/_baseSortedIndexBy.js +++ b/_baseSortedIndexBy.js @@ -1,3 +1,5 @@ +import isSymbol from './isSymbol'; + /** Used as references for the maximum length and index of an array. */ var MAX_ARRAY_LENGTH = 4294967295, MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1; @@ -26,21 +28,26 @@ function baseSortedIndexBy(array, value, iteratee, retHighest) { high = array ? array.length : 0, valIsNaN = value !== value, valIsNull = value === null, - valIsUndef = value === undefined; + valIsSymbol = isSymbol(value), + valIsUndefined = value === undefined; while (low < high) { var mid = nativeFloor((low + high) / 2), computed = iteratee(array[mid]), - isDef = computed !== undefined, - isReflexive = computed === computed; + othIsDefined = computed !== undefined, + othIsNull = computed === null, + othIsReflexive = computed === computed, + othIsSymbol = isSymbol(computed); if (valIsNaN) { - var setLow = isReflexive || retHighest; + var setLow = retHighest || othIsReflexive; + } else if (valIsUndefined) { + setLow = othIsReflexive && (retHighest || othIsDefined); } else if (valIsNull) { - setLow = isReflexive && isDef && (retHighest || computed != null); - } else if (valIsUndef) { - setLow = isReflexive && (retHighest || isDef); - } else if (computed == null) { + setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull); + } else if (valIsSymbol) { + setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol); + } else if (othIsNull || othIsSymbol) { setLow = false; } else { setLow = retHighest ? (computed <= value) : (computed < value); diff --git a/_baseSortedUniq.js b/_baseSortedUniq.js index 5428bd8a8..6ea872aa2 100644 --- a/_baseSortedUniq.js +++ b/_baseSortedUniq.js @@ -1,14 +1,30 @@ -import baseSortedUniqBy from './_baseSortedUniqBy'; +import eq from './eq'; /** - * The base implementation of `_.sortedUniq`. + * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without + * support for iteratee shorthands. * * @private * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. * @returns {Array} Returns the new duplicate free array. */ -function baseSortedUniq(array) { - return baseSortedUniqBy(array); +function baseSortedUniq(array, iteratee) { + var index = -1, + length = array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + if (!index || !eq(computed, seen)) { + var seen = computed; + result[resIndex++] = value === 0 ? 0 : value; + } + } + return result; } export default baseSortedUniq; diff --git a/_baseSortedUniqBy.js b/_baseSortedUniqBy.js deleted file mode 100644 index d31384f5d..000000000 --- a/_baseSortedUniqBy.js +++ /dev/null @@ -1,33 +0,0 @@ -import eq from './eq'; - -/** - * The base implementation of `_.sortedUniqBy` without support for iteratee - * shorthands. - * - * @private - * @param {Array} array The array to inspect. - * @param {Function} [iteratee] The iteratee invoked per element. - * @returns {Array} Returns the new duplicate free array. - */ -function baseSortedUniqBy(array, iteratee) { - var index = 0, - length = array.length, - value = array[0], - computed = iteratee ? iteratee(value) : value, - seen = computed, - resIndex = 1, - result = [value]; - - while (++index < length) { - value = array[index], - computed = iteratee ? iteratee(value) : value; - - if (!eq(computed, seen)) { - seen = computed; - result[resIndex++] = value; - } - } - return result; -} - -export default baseSortedUniqBy; diff --git a/_baseToNumber.js b/_baseToNumber.js new file mode 100644 index 000000000..a062c0215 --- /dev/null +++ b/_baseToNumber.js @@ -0,0 +1,24 @@ +import isSymbol from './isSymbol'; + +/** Used as references for various `Number` constants. */ +var NAN = 0 / 0; + +/** + * The base implementation of `_.toNumber` which doesn't ensure correct + * conversions of binary, hexadecimal, or octal string values. + * + * @private + * @param {*} value The value to process. + * @returns {number} Returns the number. + */ +function baseToNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } + return +value; +} + +export default baseToNumber; diff --git a/_baseToString.js b/_baseToString.js new file mode 100644 index 000000000..02c2c1c46 --- /dev/null +++ b/_baseToString.js @@ -0,0 +1,31 @@ +import Symbol from './_Symbol'; +import isSymbol from './isSymbol'; + +/** Used as references for various `Number` constants. */ +var INFINITY = 1 / 0; + +/** Used to convert symbols to primitives and strings. */ +var symbolProto = Symbol ? Symbol.prototype : undefined, + symbolToString = symbolProto ? symbolProto.toString : undefined; + +/** + * The base implementation of `_.toString` which doesn't convert nullish + * values to empty strings. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ +function baseToString(value) { + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value == 'string') { + return value; + } + if (isSymbol(value)) { + return symbolToString ? symbolToString.call(value) : ''; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; +} + +export default baseToString; diff --git a/_baseUniq.js b/_baseUniq.js index 40e126c75..517f020fb 100644 --- a/_baseUniq.js +++ b/_baseUniq.js @@ -46,6 +46,7 @@ function baseUniq(array, iteratee, comparator) { var value = array[index], computed = iteratee ? iteratee(value) : value; + value = (comparator || value !== 0) ? value : 0; if (isCommon && computed === computed) { var seenIndex = seen.length; while (seenIndex--) { diff --git a/_baseUnset.js b/_baseUnset.js index 8a35e22f6..a9d48a19d 100644 --- a/_baseUnset.js +++ b/_baseUnset.js @@ -1,8 +1,9 @@ +import baseHas from './_baseHas'; import castPath from './_castPath'; -import has from './has'; import isKey from './_isKey'; import last from './last'; import parent from './_parent'; +import toKey from './_toKey'; /** * The base implementation of `_.unset`. @@ -15,8 +16,9 @@ import parent from './_parent'; function baseUnset(object, 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; + + var key = toKey(last(path)); + return !(object != null && baseHas(object, key)) || delete object[key]; } export default baseUnset; diff --git a/_compareAscending.js b/_compareAscending.js index 8d048f9aa..7737d0dc5 100644 --- a/_compareAscending.js +++ b/_compareAscending.js @@ -1,3 +1,5 @@ +import isSymbol from './isSymbol'; + /** * Compares values to sort them in ascending order. * @@ -8,22 +10,28 @@ */ function compareAscending(value, other) { if (value !== other) { - var valIsNull = value === null, - valIsUndef = value === undefined, - valIsReflexive = value === value; + var valIsDefined = value !== undefined, + valIsNull = value === null, + valIsReflexive = value === value, + valIsSymbol = isSymbol(value); - var othIsNull = other === null, - othIsUndef = other === undefined, - othIsReflexive = other === other; + var othIsDefined = other !== undefined, + othIsNull = other === null, + othIsReflexive = other === other, + othIsSymbol = isSymbol(other); - if ((value > other && !othIsNull) || !valIsReflexive || - (valIsNull && !othIsUndef && othIsReflexive) || - (valIsUndef && othIsReflexive)) { + if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || + (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || + (valIsNull && othIsDefined && othIsReflexive) || + (!valIsDefined && othIsReflexive) || + !valIsReflexive) { return 1; } - if ((value < other && !valIsNull) || !othIsReflexive || - (othIsNull && !valIsUndef && valIsReflexive) || - (othIsUndef && valIsReflexive)) { + if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || + (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || + (othIsNull && valIsDefined && valIsReflexive) || + (!othIsDefined && valIsReflexive) || + !othIsReflexive) { return -1; } } diff --git a/_createMathOperation.js b/_createMathOperation.js index 4b35b2cd9..ce9e2eb86 100644 --- a/_createMathOperation.js +++ b/_createMathOperation.js @@ -1,3 +1,6 @@ +import baseToNumber from './_baseToNumber'; +import baseToString from './_baseToString'; + /** * Creates a function that performs a mathematical operation on two values. * @@ -15,7 +18,17 @@ function createMathOperation(operator) { result = value; } if (other !== undefined) { - result = result === undefined ? other : operator(result, other); + if (result === undefined) { + return other; + } + if (typeof value == 'string' || typeof other == 'string') { + value = baseToString(value); + other = baseToString(other); + } else { + value = baseToNumber(value); + other = baseToNumber(other); + } + result = operator(value, other); } return result; }; diff --git a/_createPadding.js b/_createPadding.js index acc7dba42..f4e9e037a 100644 --- a/_createPadding.js +++ b/_createPadding.js @@ -1,4 +1,5 @@ import baseRepeat from './_baseRepeat'; +import baseToString from './_baseToString'; import castSlice from './_castSlice'; import reHasComplexSymbol from './_reHasComplexSymbol'; import stringSize from './_stringSize'; @@ -17,7 +18,7 @@ var nativeCeil = Math.ceil; * @returns {string} Returns the padding for `string`. */ function createPadding(length, chars) { - chars = chars === undefined ? ' ' : (chars + ''); + chars = chars === undefined ? ' ' : baseToString(chars); var charsLength = chars.length; if (charsLength < 2) { diff --git a/_createRelationalOperation.js b/_createRelationalOperation.js new file mode 100644 index 000000000..9fd7bacc9 --- /dev/null +++ b/_createRelationalOperation.js @@ -0,0 +1,20 @@ +import toNumber from './toNumber'; + +/** + * Creates a function that performs a relational operation on two values. + * + * @private + * @param {Function} operator The function to perform the operation. + * @returns {Function} Returns the new relational operation function. + */ +function createRelationalOperation(operator) { + return function(value, other) { + if (!(typeof value == 'string' && typeof other == 'string')) { + value = toNumber(value); + other = toNumber(other); + } + return operator(value, other); + }; +} + +export default createRelationalOperation; diff --git a/_createSet.js b/_createSet.js index a2f2afc68..c049bb0bb 100644 --- a/_createSet.js +++ b/_createSet.js @@ -1,5 +1,9 @@ import Set from './_Set'; import noop from './noop'; +import setToArray from './_setToArray'; + +/** Used as references for various `Number` constants. */ +var INFINITY = 1 / 0; /** * Creates a set of `values`. @@ -8,7 +12,7 @@ import noop from './noop'; * @param {Array} values The values to add to the set. * @returns {Object} Returns the new set. */ -var createSet = !(Set && new Set([1, 2]).size === 2) ? noop : function(values) { +var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { return new Set(values); }; diff --git a/_hasPath.js b/_hasPath.js index 74c454216..9dd99305c 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -5,6 +5,7 @@ import isIndex from './_isIndex'; import isKey from './_isKey'; import isLength from './isLength'; import isString from './isString'; +import toKey from './_toKey'; /** * Checks if `path` exists on `object`. @@ -23,7 +24,7 @@ function hasPath(object, path, hasFunc) { length = path.length; while (++index < length) { - var key = path[index]; + var key = toKey(path[index]); if (!(result = object != null && hasFunc(object, key))) { break; } diff --git a/_isIndex.js b/_isIndex.js index 47a4460e5..0381ad086 100644 --- a/_isIndex.js +++ b/_isIndex.js @@ -13,9 +13,10 @@ var reIsUint = /^(?:0|[1-9]\d*)$/; * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. */ function isIndex(value, length) { - value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1; length = length == null ? MAX_SAFE_INTEGER : length; - return value > -1 && value % 1 == 0 && value < length; + return !!length && + (typeof value == 'number' || reIsUint.test(value)) && + (value > -1 && value % 1 == 0 && value < length); } export default isIndex; diff --git a/_isKey.js b/_isKey.js index 664cb414f..7226c0a5e 100644 --- a/_isKey.js +++ b/_isKey.js @@ -14,13 +14,16 @@ var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, * @returns {boolean} Returns `true` if `value` is a property name, else `false`. */ function isKey(value, object) { + if (isArray(value)) { + return false; + } var type = typeof value; - if (type == 'number' || type == 'symbol') { + if (type == 'number' || type == 'symbol' || type == 'boolean' || + value == null || isSymbol(value)) { return true; } - return !isArray(value) && - (isSymbol(value) || reIsPlainProp.test(value) || !reIsDeepProp.test(value) || - (object != null && value in Object(object))); + return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || + (object != null && value in Object(object)); } export default isKey; diff --git a/_isKeyable.js b/_isKeyable.js index c78cd2c74..22715962e 100644 --- a/_isKeyable.js +++ b/_isKeyable.js @@ -7,8 +7,9 @@ */ function isKeyable(value) { var type = typeof value; - return type == 'number' || type == 'boolean' || - (type == 'string' && value != '__proto__') || value == null; + return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') + ? (value !== '__proto__') + : (value === null); } export default isKeyable; diff --git a/_toKey.js b/_toKey.js index 4ce40d7b4..358003d63 100644 --- a/_toKey.js +++ b/_toKey.js @@ -1,5 +1,8 @@ import isSymbol from './isSymbol'; +/** Used as references for various `Number` constants. */ +var INFINITY = 1 / 0; + /** * Converts `value` to a string key if it's not a string or symbol. * @@ -7,8 +10,12 @@ import isSymbol from './isSymbol'; * @param {*} value The value to inspect. * @returns {string|symbol} Returns the key. */ -function toKey(key) { - return (typeof key == 'string' || isSymbol(key)) ? key : (key + ''); +function toKey(value) { + if (typeof value == 'string' || isSymbol(value)) { + return value; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; } export default toKey; diff --git a/assign.js b/assign.js index add611ba9..b97139063 100644 --- a/assign.js +++ b/assign.js @@ -32,6 +32,7 @@ var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf'); * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. * @returns {Object} Returns `object`. + * @see _.assignIn * @example * * function Foo() { diff --git a/assignIn.js b/assignIn.js index 17cde3335..10e446b03 100644 --- a/assignIn.js +++ b/assignIn.js @@ -28,6 +28,7 @@ var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf'); * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. * @returns {Object} Returns `object`. + * @see _.assign * @example * * function Foo() { diff --git a/assignInWith.js b/assignInWith.js index 0c4f971d7..729375948 100644 --- a/assignInWith.js +++ b/assignInWith.js @@ -19,6 +19,7 @@ import keysIn from './keysIn'; * @param {...Object} sources The source objects. * @param {Function} [customizer] The function to customize assigned values. * @returns {Object} Returns `object`. + * @see _.assignWith * @example * * function customizer(objValue, srcValue) { diff --git a/assignWith.js b/assignWith.js index 8b6396d0c..1ee0df523 100644 --- a/assignWith.js +++ b/assignWith.js @@ -18,6 +18,7 @@ import keys from './keys'; * @param {...Object} sources The source objects. * @param {Function} [customizer] The function to customize assigned values. * @returns {Object} Returns `object`. + * @see _.assignInWith * @example * * function customizer(objValue, srcValue) { diff --git a/bindAll.js b/bindAll.js index b9dec1a18..30cd83d2a 100644 --- a/bindAll.js +++ b/bindAll.js @@ -2,6 +2,7 @@ import arrayEach from './_arrayEach'; import baseFlatten from './_baseFlatten'; import bind from './bind'; import rest from './rest'; +import toKey from './_toKey'; /** * Binds methods of an object to the object itself, overwriting the existing @@ -31,6 +32,7 @@ import rest from './rest'; */ var bindAll = rest(function(object, methodNames) { arrayEach(baseFlatten(methodNames, 1), function(key) { + key = toKey(key); object[key] = bind(object[key], object); }); return object; diff --git a/clone.js b/clone.js index 09a11bea7..36385ac99 100644 --- a/clone.js +++ b/clone.js @@ -17,6 +17,7 @@ import baseClone from './_baseClone'; * @category Lang * @param {*} value The value to clone. * @returns {*} Returns the cloned value. + * @see _.cloneDeep * @example * * var objects = [{ 'a': 1 }, { 'b': 2 }]; diff --git a/cloneDeep.js b/cloneDeep.js index 10ac71aa4..80281fa4d 100644 --- a/cloneDeep.js +++ b/cloneDeep.js @@ -9,6 +9,7 @@ import baseClone from './_baseClone'; * @category Lang * @param {*} value The value to recursively clone. * @returns {*} Returns the deep cloned value. + * @see _.clone * @example * * var objects = [{ 'a': 1 }, { 'b': 2 }]; diff --git a/cloneDeepWith.js b/cloneDeepWith.js index 3006df615..f8b81d0ba 100644 --- a/cloneDeepWith.js +++ b/cloneDeepWith.js @@ -10,6 +10,7 @@ import baseClone from './_baseClone'; * @param {*} value The value to recursively clone. * @param {Function} [customizer] The function to customize cloning. * @returns {*} Returns the deep cloned value. + * @see _.cloneWith * @example * * function customizer(value) { diff --git a/cloneWith.js b/cloneWith.js index 777cad37a..a98e42d5d 100644 --- a/cloneWith.js +++ b/cloneWith.js @@ -13,6 +13,7 @@ import baseClone from './_baseClone'; * @param {*} value The value to clone. * @param {Function} [customizer] The function to customize cloning. * @returns {*} Returns the cloned value. + * @see _.cloneDeepWith * @example * * function customizer(value) { diff --git a/defaults.js b/defaults.js index 24872320e..107e2f09e 100644 --- a/defaults.js +++ b/defaults.js @@ -18,6 +18,7 @@ import rest from './rest'; * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. * @returns {Object} Returns `object`. + * @see _.defaultsDeep * @example * * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); diff --git a/defaultsDeep.js b/defaultsDeep.js index 5d932c4df..0c15aea67 100644 --- a/defaultsDeep.js +++ b/defaultsDeep.js @@ -16,6 +16,7 @@ import rest from './rest'; * @param {Object} object The destination object. * @param {...Object} [sources] The source objects. * @returns {Object} Returns `object`. + * @see _.defaults * @example * * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } }); diff --git a/difference.js b/difference.js index ce49129c9..0c684897f 100644 --- a/difference.js +++ b/difference.js @@ -16,6 +16,7 @@ import rest from './rest'; * @param {Array} array The array to inspect. * @param {...Array} [values] The values to exclude. * @returns {Array} Returns the new array of filtered values. + * @see _.without, _.xor * @example * * _.difference([3, 2, 1], [4, 2]); diff --git a/endsWith.js b/endsWith.js index 726c102f5..d37e48dd8 100644 --- a/endsWith.js +++ b/endsWith.js @@ -1,4 +1,5 @@ import baseClamp from './_baseClamp'; +import baseToString from './_baseToString'; import toInteger from './toInteger'; import toString from './toString'; @@ -27,7 +28,7 @@ import toString from './toString'; */ function endsWith(string, target, position) { string = toString(string); - target = typeof target == 'string' ? target : (target + ''); + target = baseToString(target); var length = string.length; position = position === undefined diff --git a/filter.js b/filter.js index 037c99fda..f4f1ce9d7 100644 --- a/filter.js +++ b/filter.js @@ -16,6 +16,7 @@ import isArray from './isArray'; * @param {Array|Function|Object|string} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new filtered array. + * @see _.reject * @example * * var users = [ diff --git a/flow.js b/flow.js index 799b6f532..03f549cf4 100644 --- a/flow.js +++ b/flow.js @@ -11,6 +11,7 @@ import createFlow from './_createFlow'; * @category Util * @param {...(Function|Function[])} [funcs] Functions to invoke. * @returns {Function} Returns the new function. + * @see _.flowRight * @example * * function square(n) { diff --git a/flowRight.js b/flowRight.js index fe8b6b5d4..e46c205d3 100644 --- a/flowRight.js +++ b/flowRight.js @@ -5,11 +5,12 @@ import createFlow from './_createFlow'; * invokes the given functions from right to left. * * @static - * @since 0.1.0 + * @since 3.0.0 * @memberOf _ * @category Util * @param {...(Function|Function[])} [funcs] Functions to invoke. * @returns {Function} Returns the new function. + * @see _.flow * @example * * function square(n) { diff --git a/forEach.js b/forEach.js index 1ecb92922..abdf97417 100644 --- a/forEach.js +++ b/forEach.js @@ -20,6 +20,7 @@ import isArray from './isArray'; * @param {Array|Object} collection The collection to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Array|Object} Returns `collection`. + * @see _.forEachRight * @example * * _([1, 2]).forEach(function(value) { diff --git a/forEachRight.js b/forEachRight.js index b615d48f4..0b7d05894 100644 --- a/forEachRight.js +++ b/forEachRight.js @@ -15,6 +15,7 @@ import isArray from './isArray'; * @param {Array|Object} collection The collection to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Array|Object} Returns `collection`. + * @see _.forEach * @example * * _.forEachRight([1, 2], function(value) { diff --git a/forIn.js b/forIn.js index 30945a53a..d0defc737 100644 --- a/forIn.js +++ b/forIn.js @@ -15,6 +15,7 @@ import keysIn from './keysIn'; * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Object} Returns `object`. + * @see _.forInRight * @example * * function Foo() { diff --git a/forInRight.js b/forInRight.js index 66155c199..5075c1497 100644 --- a/forInRight.js +++ b/forInRight.js @@ -13,6 +13,7 @@ import keysIn from './keysIn'; * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Object} Returns `object`. + * @see _.forIn * @example * * function Foo() { diff --git a/forOwn.js b/forOwn.js index f9631a6fc..b340b3172 100644 --- a/forOwn.js +++ b/forOwn.js @@ -14,6 +14,7 @@ import baseIteratee from './_baseIteratee'; * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Object} Returns `object`. + * @see _.forOwnRight * @example * * function Foo() { diff --git a/forOwnRight.js b/forOwnRight.js index e8750ae83..68aec5b83 100644 --- a/forOwnRight.js +++ b/forOwnRight.js @@ -12,6 +12,7 @@ import baseIteratee from './_baseIteratee'; * @param {Object} object The object to iterate over. * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @returns {Object} Returns `object`. + * @see _.forOwn * @example * * function Foo() { diff --git a/functions.js b/functions.js index e13563309..9c2000c64 100644 --- a/functions.js +++ b/functions.js @@ -11,6 +11,7 @@ import keys from './keys'; * @category Object * @param {Object} object The object to inspect. * @returns {Array} Returns the new array of property names. + * @see _.functionsIn * @example * * function Foo() { diff --git a/functionsIn.js b/functionsIn.js index 12d21ee99..998e2c153 100644 --- a/functionsIn.js +++ b/functionsIn.js @@ -11,6 +11,7 @@ import keysIn from './keysIn'; * @category Object * @param {Object} object The object to inspect. * @returns {Array} Returns the new array of property names. + * @see _.functions * @example * * function Foo() { diff --git a/gt.js b/gt.js index 81934ee87..abdc8557f 100644 --- a/gt.js +++ b/gt.js @@ -1,3 +1,6 @@ +import baseGt from './_baseGt'; +import createRelationalOperation from './_createRelationalOperation'; + /** * Checks if `value` is greater than `other`. * @@ -9,6 +12,7 @@ * @param {*} other The other value to compare. * @returns {boolean} Returns `true` if `value` is greater than `other`, * else `false`. + * @see _.lt * @example * * _.gt(3, 1); @@ -20,8 +24,6 @@ * _.gt(1, 3); * // => false */ -function gt(value, other) { - return value > other; -} +var gt = createRelationalOperation(baseGt); export default gt; diff --git a/gte.js b/gte.js index 93be2aaa7..d4ee04a52 100644 --- a/gte.js +++ b/gte.js @@ -1,3 +1,5 @@ +import createRelationalOperation from './_createRelationalOperation'; + /** * Checks if `value` is greater than or equal to `other`. * @@ -9,6 +11,7 @@ * @param {*} other The other value to compare. * @returns {boolean} Returns `true` if `value` is greater than or equal to * `other`, else `false`. + * @see _.lte * @example * * _.gte(3, 1); @@ -20,8 +23,8 @@ * _.gte(1, 3); * // => false */ -function gte(value, other) { +var gte = createRelationalOperation(function(value, other) { return value >= other; -} +}); export default gte; diff --git a/inRange.js b/inRange.js index e151cd36e..66c0004dc 100644 --- a/inRange.js +++ b/inRange.js @@ -2,7 +2,7 @@ import baseInRange from './_baseInRange'; import toNumber from './toNumber'; /** - * Checks if `n` is between `start` and up to but not including, `end`. If + * Checks if `n` is between `start` and up to, but not including, `end`. If * `end` is not specified, it's set to `start` with `start` then set to `0`. * If `start` is greater than `end` the params are swapped to support * negative ranges. @@ -15,6 +15,7 @@ import toNumber from './toNumber'; * @param {number} [start=0] The start of the range. * @param {number} end The end of the range. * @returns {boolean} Returns `true` if `number` is in the range, else `false`. + * @see _.range, _.rangeRight * @example * * _.inRange(3, 2, 4); diff --git a/lodash.default.js b/lodash.default.js index 327efaa5e..ad3919ba6 100644 --- a/lodash.default.js +++ b/lodash.default.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.11.1 (Custom Build) + * lodash 4.11.2 (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.11.1'; +var VERSION = '4.11.2'; /** Used to compose bitmasks for wrapper metadata. */ var BIND_KEY_FLAG = 2; diff --git a/lodash.js b/lodash.js index 651444289..d0faeee94 100644 --- a/lodash.js +++ b/lodash.js @@ -1,6 +1,6 @@ /** * @license - * lodash 4.11.1 (Custom Build) + * lodash 4.11.2 (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright jQuery Foundation and other contributors * Released under MIT license diff --git a/lt.js b/lt.js index e8d5cb6fa..6d108d75e 100644 --- a/lt.js +++ b/lt.js @@ -1,3 +1,6 @@ +import baseLt from './_baseLt'; +import createRelationalOperation from './_createRelationalOperation'; + /** * Checks if `value` is less than `other`. * @@ -9,6 +12,7 @@ * @param {*} other The other value to compare. * @returns {boolean} Returns `true` if `value` is less than `other`, * else `false`. + * @see _.gt * @example * * _.lt(1, 3); @@ -20,8 +24,6 @@ * _.lt(3, 1); * // => false */ -function lt(value, other) { - return value < other; -} +var lt = createRelationalOperation(baseLt); export default lt; diff --git a/lte.js b/lte.js index b8c114c60..547f9167a 100644 --- a/lte.js +++ b/lte.js @@ -1,3 +1,5 @@ +import createRelationalOperation from './_createRelationalOperation'; + /** * Checks if `value` is less than or equal to `other`. * @@ -9,6 +11,7 @@ * @param {*} other The other value to compare. * @returns {boolean} Returns `true` if `value` is less than or equal to * `other`, else `false`. + * @see _.gte * @example * * _.lte(1, 3); @@ -20,8 +23,8 @@ * _.lte(3, 1); * // => false */ -function lte(value, other) { +var lte = createRelationalOperation(function(value, other) { return value <= other; -} +}); export default lte; diff --git a/mapKeys.js b/mapKeys.js index ad06c0f76..ee7ba9bc1 100644 --- a/mapKeys.js +++ b/mapKeys.js @@ -15,6 +15,7 @@ import baseIteratee from './_baseIteratee'; * @param {Array|Function|Object|string} [iteratee=_.identity] * The function invoked per iteration. * @returns {Object} Returns the new mapped object. + * @see _.mapValues * @example * * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { diff --git a/mapValues.js b/mapValues.js index 298b7ae80..a2ebcb3ca 100644 --- a/mapValues.js +++ b/mapValues.js @@ -15,6 +15,7 @@ import baseIteratee from './_baseIteratee'; * @param {Array|Function|Object|string} [iteratee=_.identity] * The function invoked per iteration. * @returns {Object} Returns the new mapped object. + * @see _.mapKeys * @example * * var users = { diff --git a/max.js b/max.js index f498ea1f9..b08649353 100644 --- a/max.js +++ b/max.js @@ -1,5 +1,5 @@ import baseExtremum from './_baseExtremum'; -import gt from './gt'; +import baseGt from './_baseGt'; import identity from './identity'; /** @@ -22,7 +22,7 @@ import identity from './identity'; */ function max(array) { return (array && array.length) - ? baseExtremum(array, identity, gt) + ? baseExtremum(array, identity, baseGt) : undefined; } diff --git a/maxBy.js b/maxBy.js index 9be271898..130c60c40 100644 --- a/maxBy.js +++ b/maxBy.js @@ -1,6 +1,6 @@ import baseExtremum from './_baseExtremum'; +import baseGt from './_baseGt'; import baseIteratee from './_baseIteratee'; -import gt from './gt'; /** * This method is like `_.max` except that it accepts `iteratee` which is @@ -28,7 +28,7 @@ import gt from './gt'; */ function maxBy(array, iteratee) { return (array && array.length) - ? baseExtremum(array, baseIteratee(iteratee), gt) + ? baseExtremum(array, baseIteratee(iteratee), baseGt) : undefined; } diff --git a/min.js b/min.js index a6f8fd3ce..d13c254a3 100644 --- a/min.js +++ b/min.js @@ -1,6 +1,6 @@ import baseExtremum from './_baseExtremum'; +import baseLt from './_baseLt'; import identity from './identity'; -import lt from './lt'; /** * Computes the minimum value of `array`. If `array` is empty or falsey, @@ -22,7 +22,7 @@ import lt from './lt'; */ function min(array) { return (array && array.length) - ? baseExtremum(array, identity, lt) + ? baseExtremum(array, identity, baseLt) : undefined; } diff --git a/minBy.js b/minBy.js index 375660824..ba0edea3b 100644 --- a/minBy.js +++ b/minBy.js @@ -1,6 +1,6 @@ import baseExtremum from './_baseExtremum'; import baseIteratee from './_baseIteratee'; -import lt from './lt'; +import baseLt from './_baseLt'; /** * This method is like `_.min` except that it accepts `iteratee` which is @@ -28,7 +28,7 @@ import lt from './lt'; */ function minBy(array, iteratee) { return (array && array.length) - ? baseExtremum(array, baseIteratee(iteratee), lt) + ? baseExtremum(array, baseIteratee(iteratee), baseLt) : undefined; } diff --git a/package.json b/package.json index 00a985812..7e8979a2f 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,20 @@ { "name": "lodash-es", - "version": "4.11.1", + "version": "4.11.2", "description": "Lodash exported as ES modules.", + "keywords": "es6, modules, stdlib, util", "homepage": "https://lodash.com/custom-builds", + "bugs": "https://github.com/lodash/lodash-cli/issues", + "repository": "lodash/lodash", "license": "MIT", "private": true, "jsnext:main": "lodash.js", "main": "lodash.js", - "keywords": "es6, modules, stdlib, util", "author": "John-David Dalton (http://allyoucanleet.com/)", "contributors": [ "John-David Dalton (http://allyoucanleet.com/)", "Blaine Bublitz (https://github.com/phated)", "Mathias Bynens (https://mathiasbynens.be/)" ], - "bugs": "https://github.com/lodash/lodash-cli/issues", - "repository": "lodash/lodash", "scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" } } diff --git a/pick.js b/pick.js index fb587cc51..4e7dfdfd4 100644 --- a/pick.js +++ b/pick.js @@ -1,6 +1,8 @@ +import arrayMap from './_arrayMap'; import baseFlatten from './_baseFlatten'; import basePick from './_basePick'; import rest from './rest'; +import toKey from './_toKey'; /** * Creates an object composed of the picked `object` properties. @@ -20,7 +22,7 @@ import rest from './rest'; * // => { 'a': 1, 'c': 3 } */ var pick = rest(function(object, props) { - return object == null ? {} : basePick(object, baseFlatten(props, 1)); + return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey)); }); export default pick; diff --git a/property.js b/property.js index 559968dd8..b7cc87595 100644 --- a/property.js +++ b/property.js @@ -1,6 +1,7 @@ import baseProperty from './_baseProperty'; import basePropertyDeep from './_basePropertyDeep'; import isKey from './_isKey'; +import toKey from './_toKey'; /** * Creates a function that returns the value at `path` of a given object. @@ -25,7 +26,7 @@ import isKey from './_isKey'; * // => [1, 2] */ function property(path) { - return isKey(path) ? baseProperty(path) : basePropertyDeep(path); + return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path); } export default property; diff --git a/pullAt.js b/pullAt.js index 7f22bca73..0ec25dc5e 100644 --- a/pullAt.js +++ b/pullAt.js @@ -3,6 +3,7 @@ import baseAt from './_baseAt'; import baseFlatten from './_baseFlatten'; import basePullAt from './_basePullAt'; import compareAscending from './_compareAscending'; +import isIndex from './_isIndex'; import rest from './rest'; /** @@ -30,10 +31,15 @@ import rest from './rest'; * // => [10, 20] */ var pullAt = rest(function(array, indexes) { - indexes = arrayMap(baseFlatten(indexes, 1), String); + indexes = baseFlatten(indexes, 1); + + var length = array ? array.length : 0, + result = baseAt(array, indexes); + + basePullAt(array, arrayMap(indexes, function(index) { + return isIndex(index, length) ? +index : index; + }).sort(compareAscending)); - var result = baseAt(array, indexes); - basePullAt(array, indexes.sort(compareAscending)); return result; }); diff --git a/range.js b/range.js index ed7de9b86..cafc6e1b9 100644 --- a/range.js +++ b/range.js @@ -17,6 +17,7 @@ import createRange from './_createRange'; * @param {number} end The end of the range. * @param {number} [step=1] The value to increment or decrement by. * @returns {Array} Returns the new array of numbers. + * @see _.inRange, _.rangeRight * @example * * _.range(4); diff --git a/rangeRight.js b/rangeRight.js index 52b746ce7..8cf15d0a5 100644 --- a/rangeRight.js +++ b/rangeRight.js @@ -12,6 +12,7 @@ import createRange from './_createRange'; * @param {number} end The end of the range. * @param {number} [step=1] The value to increment or decrement by. * @returns {Array} Returns the new array of numbers. + * @see _.inRange, _.range * @example * * _.rangeRight(4); diff --git a/reduce.js b/reduce.js index 46a78cafe..21c47b20b 100644 --- a/reduce.js +++ b/reduce.js @@ -27,6 +27,7 @@ import isArray from './isArray'; * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @param {*} [accumulator] The initial value. * @returns {*} Returns the accumulated value. + * @see _.reduceRight * @example * * _.reduce([1, 2], function(sum, n) { diff --git a/reduceRight.js b/reduceRight.js index 39567fc41..1e112a405 100644 --- a/reduceRight.js +++ b/reduceRight.js @@ -16,6 +16,7 @@ import isArray from './isArray'; * @param {Function} [iteratee=_.identity] The function invoked per iteration. * @param {*} [accumulator] The initial value. * @returns {*} Returns the accumulated value. + * @see _.reduce * @example * * var array = [[0, 1], [2, 3], [4, 5]]; diff --git a/reject.js b/reject.js index cc72e4178..a2d10fc17 100644 --- a/reject.js +++ b/reject.js @@ -15,6 +15,7 @@ import isArray from './isArray'; * @param {Array|Function|Object|string} [predicate=_.identity] * The function invoked per iteration. * @returns {Array} Returns the new filtered array. + * @see _.filter * @example * * var users = [ diff --git a/result.js b/result.js index 8565004e4..fd977d903 100644 --- a/result.js +++ b/result.js @@ -1,6 +1,7 @@ import castPath from './_castPath'; import isFunction from './isFunction'; import isKey from './_isKey'; +import toKey from './_toKey'; /** * This method is like `_.get` except that if the resolved value is a @@ -43,7 +44,7 @@ function result(object, path, defaultValue) { length = 1; } while (++index < length) { - var value = object == null ? undefined : object[path[index]]; + var value = object == null ? undefined : object[toKey(path[index])]; if (value === undefined) { index = length; value = defaultValue; diff --git a/sortedUniqBy.js b/sortedUniqBy.js index 161f8f8a6..990950e62 100644 --- a/sortedUniqBy.js +++ b/sortedUniqBy.js @@ -1,5 +1,5 @@ import baseIteratee from './_baseIteratee'; -import baseSortedUniqBy from './_baseSortedUniqBy'; +import baseSortedUniq from './_baseSortedUniq'; /** * This method is like `_.uniqBy` except that it's designed and optimized @@ -19,7 +19,7 @@ import baseSortedUniqBy from './_baseSortedUniqBy'; */ function sortedUniqBy(array, iteratee) { return (array && array.length) - ? baseSortedUniqBy(array, baseIteratee(iteratee)) + ? baseSortedUniq(array, baseIteratee(iteratee)) : []; } diff --git a/split.js b/split.js index 8d98d4053..ca8195406 100644 --- a/split.js +++ b/split.js @@ -1,3 +1,4 @@ +import baseToString from './_baseToString'; import castSlice from './_castSlice'; import isIterateeCall from './_isIterateeCall'; import isRegExp from './isRegExp'; @@ -46,7 +47,7 @@ function split(string, separator, limit) { typeof separator == 'string' || (separator != null && !isRegExp(separator)) )) { - separator += ''; + separator = baseToString(separator); if (separator == '' && reHasComplexSymbol.test(string)) { return castSlice(stringToArray(string), 0, limit); } diff --git a/startsWith.js b/startsWith.js index 9e9689a65..a8738450c 100644 --- a/startsWith.js +++ b/startsWith.js @@ -1,4 +1,5 @@ import baseClamp from './_baseClamp'; +import baseToString from './_baseToString'; import toInteger from './toInteger'; import toString from './toString'; @@ -28,7 +29,7 @@ import toString from './toString'; function startsWith(string, target, position) { string = toString(string); position = baseClamp(toInteger(position), 0, string.length); - return string.lastIndexOf(target, position) == position; + return string.lastIndexOf(baseToString(target), position) == position; } export default startsWith; diff --git a/toString.js b/toString.js index 5a3b4d7f1..6fb03c3b5 100644 --- a/toString.js +++ b/toString.js @@ -1,12 +1,4 @@ -import Symbol from './_Symbol'; -import isSymbol from './isSymbol'; - -/** Used as references for various `Number` constants. */ -var INFINITY = 1 / 0; - -/** Used to convert symbols to primitives and strings. */ -var symbolProto = Symbol ? Symbol.prototype : undefined, - symbolToString = symbolProto ? symbolProto.toString : undefined; +import baseToString from './_baseToString'; /** * Converts `value` to a string. An empty string is returned for `null` @@ -30,18 +22,7 @@ var symbolProto = Symbol ? Symbol.prototype : undefined, * // => '1,2,3' */ function toString(value) { - // Exit early for strings to avoid a performance hit in some environments. - if (typeof value == 'string') { - return value; - } - if (value == null) { - return ''; - } - if (isSymbol(value)) { - return symbolToString ? symbolToString.call(value) : ''; - } - var result = (value + ''); - return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; + return value == null ? '' : baseToString(value); } export default toString; diff --git a/trim.js b/trim.js index 2eef9e40d..b1eceec22 100644 --- a/trim.js +++ b/trim.js @@ -1,3 +1,4 @@ +import baseToString from './_baseToString'; import castSlice from './_castSlice'; import charsEndIndex from './_charsEndIndex'; import charsStartIndex from './_charsStartIndex'; @@ -31,13 +32,10 @@ var reTrim = /^\s+|\s+$/g; */ function trim(string, chars, guard) { string = toString(string); - if (!string) { - return string; - } - if (guard || chars === undefined) { + if (string && (guard || chars === undefined)) { return string.replace(reTrim, ''); } - if (!(chars += '')) { + if (!string || !(chars = baseToString(chars))) { return string; } var strSymbols = stringToArray(string), diff --git a/trimEnd.js b/trimEnd.js index f3a9962ad..5c90502b4 100644 --- a/trimEnd.js +++ b/trimEnd.js @@ -1,3 +1,4 @@ +import baseToString from './_baseToString'; import castSlice from './_castSlice'; import charsEndIndex from './_charsEndIndex'; import stringToArray from './_stringToArray'; @@ -27,13 +28,10 @@ var reTrimEnd = /\s+$/; */ function trimEnd(string, chars, guard) { string = toString(string); - if (!string) { - return string; - } - if (guard || chars === undefined) { + if (string && (guard || chars === undefined)) { return string.replace(reTrimEnd, ''); } - if (!(chars += '')) { + if (!string || !(chars = baseToString(chars))) { return string; } var strSymbols = stringToArray(string), diff --git a/trimStart.js b/trimStart.js index ddcba5d76..89df08b5f 100644 --- a/trimStart.js +++ b/trimStart.js @@ -1,3 +1,4 @@ +import baseToString from './_baseToString'; import castSlice from './_castSlice'; import charsStartIndex from './_charsStartIndex'; import stringToArray from './_stringToArray'; @@ -27,13 +28,10 @@ var reTrimStart = /^\s+/; */ function trimStart(string, chars, guard) { string = toString(string); - if (!string) { - return string; - } - if (guard || chars === undefined) { + if (string && (guard || chars === undefined)) { return string.replace(reTrimStart, ''); } - if (!(chars += '')) { + if (!string || !(chars = baseToString(chars))) { return string; } var strSymbols = stringToArray(string), diff --git a/truncate.js b/truncate.js index a9cc9a0e1..593c9369b 100644 --- a/truncate.js +++ b/truncate.js @@ -1,3 +1,4 @@ +import baseToString from './_baseToString'; import castSlice from './_castSlice'; import isObject from './isObject'; import isRegExp from './isRegExp'; @@ -58,7 +59,7 @@ function truncate(string, options) { if (isObject(options)) { var separator = 'separator' in options ? options.separator : separator; length = 'length' in options ? toInteger(options.length) : length; - omission = 'omission' in options ? toString(options.omission) : omission; + omission = 'omission' in options ? baseToString(options.omission) : omission; } string = toString(string); @@ -98,7 +99,7 @@ function truncate(string, options) { } result = result.slice(0, newEnd === undefined ? end : newEnd); } - } else if (string.indexOf(separator, end) != end) { + } else if (string.indexOf(baseToString(separator), end) != end) { var index = result.lastIndexOf(separator); if (index > -1) { result = result.slice(0, index); diff --git a/without.js b/without.js index e8ad761ab..fa222fe6b 100644 --- a/without.js +++ b/without.js @@ -14,6 +14,7 @@ import rest from './rest'; * @param {Array} array The array to filter. * @param {...*} [values] The values to exclude. * @returns {Array} Returns the new array of filtered values. + * @see _.difference, _.xor * @example * * _.without([1, 2, 1, 3], 1, 2); diff --git a/words.js b/words.js index e5febb7dc..1cf295e02 100644 --- a/words.js +++ b/words.js @@ -11,11 +11,11 @@ var rsAstralRange = '\\ud800-\\udfff', rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', - rsQuoteRange = '\\u2018\\u2019\\u201c\\u201d', + rsPunctuationRange = '\\u2000-\\u206f', rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', rsVarRange = '\\ufe0e\\ufe0f', - rsBreakRange = rsMathOpRange + rsNonCharRange + rsQuoteRange + rsSpaceRange; + rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; /** Used to compose unicode capture groups. */ var rsApos = "['\u2019]", diff --git a/xor.js b/xor.js index ecb2d861b..e2e84f64d 100644 --- a/xor.js +++ b/xor.js @@ -15,6 +15,7 @@ import rest from './rest'; * @category Array * @param {...Array} [arrays] The arrays to inspect. * @returns {Array} Returns the new array of values. + * @see _.difference, _.without * @example * * _.xor([2, 1], [4, 2]);