From 4d0c15b49ee1f7133a2f314b8f74e1b34559b9ac Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 8 Jan 2017 23:38:19 -0800 Subject: [PATCH] Apply more let/const transforms. --- _ListCache.js | 6 ++-- _Map.js | 2 +- _MapCache.js | 6 ++-- _Promise.js | 2 +- _arrayLikeKeys.js | 20 ++++++------ _baseClone.js | 74 +++++++++++++++++++++---------------------- _baseDifference.js | 20 ++++++------ _baseIntersection.js | 27 ++++++++-------- _baseIsEqualDeep.js | 34 ++++++++++---------- _baseIsMatch.js | 24 +++++++------- _baseIsTypedArray.js | 50 ++++++++++++++--------------- _baseMergeDeep.js | 16 +++++----- _basePickBy.js | 11 +++---- _basePullAll.js | 19 +++++------ _baseRandom.js | 4 +-- _baseRange.js | 10 +++--- _baseSet.js | 15 +++++---- _baseSlice.js | 4 +-- _baseSortedIndex.js | 13 ++++---- _baseSortedIndexBy.js | 31 +++++++++--------- _baseSortedUniq.js | 16 +++++----- _baseUniq.js | 23 +++++++------- _cloneBuffer.js | 13 ++++---- _cloneSymbol.js | 4 +-- _compareAscending.js | 16 +++++----- _compareMultiple.js | 14 ++++---- _composeArgs.js | 20 ++++++------ _composeArgsRight.js | 23 +++++++------- _countHolders.js | 4 +-- _createAggregator.js | 5 ++- _createAssigner.js | 10 +++--- _createBaseFor.js | 11 ++++--- _createBind.js | 8 ++--- _createCtor.js | 6 ++-- _createCurry.js | 15 +++++---- _createFlow.js | 29 ++++++++--------- _createHybrid.js | 42 ++++++++++++------------ _createPartial.js | 19 +++++------ _createRecurry.js | 26 +++++++-------- _createRound.js | 8 ++--- _createToPairs.js | 6 ++-- _createWrap.js | 26 +++++++-------- _equalArrays.js | 21 ++++++------ _equalByTag.js | 38 +++++++++++----------- _equalObjects.js | 38 +++++++++++----------- _getFuncName.js | 14 ++++---- _getMatchData.js | 9 +++--- _getRawTag.js | 14 ++++---- _getTag.js | 31 +++++++++--------- _getView.js | 12 +++---- _getWrapDetails.js | 6 ++-- _hasUnicodeWord.js | 2 +- _initCloneArray.js | 8 ++--- _isFlattenable.js | 2 +- _isIndex.js | 4 +-- _isIterateeCall.js | 2 +- _isKey.js | 6 ++-- _isKeyable.js | 2 +- _isMaskable.js | 2 +- _isMasked.js | 2 +- _isPrototype.js | 6 ++-- _iteratorToArray.js | 4 +-- _mapCacheDelete.js | 2 +- _mapCacheSet.js | 4 +-- _reEscape.js | 2 +- _reEvaluate.js | 2 +- _reInterpolate.js | 2 +- _realNames.js | 2 +- _setData.js | 2 +- _setToArray.js | 4 +-- _setToString.js | 2 +- _shuffleSelf.js | 10 +++--- reject.js | 2 +- rest.js | 2 +- result.js | 6 ++-- reverse.js | 4 +-- round.js | 2 +- sample.js | 2 +- sampleSize.js | 2 +- shuffle.js | 2 +- size.js | 6 ++-- slice.js | 2 +- some.js | 2 +- sortedIndexOf.js | 4 +-- sortedLastIndexOf.js | 4 +-- split.js | 2 +- spread.js | 8 ++--- startCase.js | 2 +- subtract.js | 2 +- tail.js | 2 +- takeRight.js | 2 +- template.js | 39 ++++++++++++----------- templateSettings.js | 2 +- throttle.js | 6 ++-- times.js | 12 +++---- toArray.js | 10 +++--- toFinite.js | 6 ++-- toInteger.js | 4 +-- toLength.js | 2 +- toNumber.js | 16 +++++----- toPairs.js | 2 +- toPairsIn.js | 2 +- toSafeInteger.js | 2 +- transform.js | 6 ++-- trim.js | 10 +++--- trimEnd.js | 7 ++-- trimStart.js | 7 ++-- truncate.js | 31 ++++++++++-------- unescape.js | 4 +-- unionWith.js | 7 ++-- uniqueId.js | 4 +-- unzip.js | 4 +-- unzipWith.js | 2 +- upperFirst.js | 2 +- zip.js | 2 +- 115 files changed, 621 insertions(+), 613 deletions(-) diff --git a/_ListCache.js b/_ListCache.js index bafa2afc5..88b83d973 100644 --- a/_ListCache.js +++ b/_ListCache.js @@ -12,12 +12,12 @@ import listCacheSet from './_listCacheSet.js'; * @param {Array} [entries] The key-value pairs to cache. */ function ListCache(entries) { - var index = -1, - length = entries == null ? 0 : entries.length; + let index = -1; + const length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { - var entry = entries[index]; + const entry = entries[index]; this.set(entry[0], entry[1]); } } diff --git a/_Map.js b/_Map.js index 205585046..de2ba6c53 100644 --- a/_Map.js +++ b/_Map.js @@ -2,6 +2,6 @@ import getNative from './_getNative.js'; import root from './_root.js'; /* Built-in method references that are verified to be native. */ -var Map = getNative(root, 'Map'); +const Map = getNative(root, 'Map'); export default Map; diff --git a/_MapCache.js b/_MapCache.js index deef22ed3..a3ae50727 100644 --- a/_MapCache.js +++ b/_MapCache.js @@ -12,12 +12,12 @@ import mapCacheSet from './_mapCacheSet.js'; * @param {Array} [entries] The key-value pairs to cache. */ function MapCache(entries) { - var index = -1, - length = entries == null ? 0 : entries.length; + let index = -1; + const length = entries == null ? 0 : entries.length; this.clear(); while (++index < length) { - var entry = entries[index]; + const entry = entries[index]; this.set(entry[0], entry[1]); } } diff --git a/_Promise.js b/_Promise.js index ce54b5815..00bc8e8fe 100644 --- a/_Promise.js +++ b/_Promise.js @@ -2,6 +2,6 @@ import getNative from './_getNative.js'; import root from './_root.js'; /* Built-in method references that are verified to be native. */ -var Promise = getNative(root, 'Promise'); +const Promise = getNative(root, 'Promise'); export default Promise; diff --git a/_arrayLikeKeys.js b/_arrayLikeKeys.js index c2161ea4b..8e214e84b 100644 --- a/_arrayLikeKeys.js +++ b/_arrayLikeKeys.js @@ -6,10 +6,10 @@ import isIndex from './_isIndex.js'; import isTypedArray from './isTypedArray.js'; /** Used for built-in method references. */ -var objectProto = Object.prototype; +const objectProto = Object.prototype; /** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; +const hasOwnProperty = objectProto.hasOwnProperty; /** * Creates an array of the enumerable property names of the array-like `value`. @@ -20,15 +20,15 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @returns {Array} Returns the array of property names. */ function arrayLikeKeys(value, inherited) { - var isArr = isArray(value), - isArg = !isArr && isArguments(value), - isBuff = !isArr && !isArg && isBuffer(value), - isType = !isArr && !isArg && !isBuff && isTypedArray(value), - skipIndexes = isArr || isArg || isBuff || isType, - result = skipIndexes ? baseTimes(value.length, String) : [], - length = result.length; + const isArr = isArray(value); + const isArg = !isArr && isArguments(value); + const isBuff = !isArr && !isArg && isBuffer(value); + const isType = !isArr && !isArg && !isBuff && isTypedArray(value); + const skipIndexes = isArr || isArg || isBuff || isType; + const result = skipIndexes ? baseTimes(value.length, String) : []; + const length = result.length; - for (var key in value) { + for (const key in value) { if ((inherited || hasOwnProperty.call(value, key)) && !(skipIndexes && ( // Safari 9 has enumerable `arguments.length` in strict mode. diff --git a/_baseClone.js b/_baseClone.js index d2ca075b0..61eb27c1c 100644 --- a/_baseClone.js +++ b/_baseClone.js @@ -24,36 +24,36 @@ const CLONE_FLAT_FLAG = 2; const CLONE_SYMBOLS_FLAG = 4; /** `Object#toString` result references. */ -const argsTag = '[object Arguments]', - arrayTag = '[object Array]', - boolTag = '[object Boolean]', - dateTag = '[object Date]', - errorTag = '[object Error]', - funcTag = '[object Function]', - genTag = '[object GeneratorFunction]', - mapTag = '[object Map]', - numberTag = '[object Number]', - objectTag = '[object Object]', - regexpTag = '[object RegExp]', - setTag = '[object Set]', - stringTag = '[object String]', - symbolTag = '[object Symbol]', - weakMapTag = '[object WeakMap]'; +const argsTag = '[object Arguments]'; +const arrayTag = '[object Array]'; +const boolTag = '[object Boolean]'; +const dateTag = '[object Date]'; +const errorTag = '[object Error]'; +const funcTag = '[object Function]'; +const genTag = '[object GeneratorFunction]'; +const mapTag = '[object Map]'; +const numberTag = '[object Number]'; +const objectTag = '[object Object]'; +const regexpTag = '[object RegExp]'; +const setTag = '[object Set]'; +const stringTag = '[object String]'; +const symbolTag = '[object Symbol]'; +const weakMapTag = '[object WeakMap]'; -var arrayBufferTag = '[object ArrayBuffer]', - dataViewTag = '[object DataView]', - float32Tag = '[object Float32Array]', - float64Tag = '[object Float64Array]', - int8Tag = '[object Int8Array]', - int16Tag = '[object Int16Array]', - int32Tag = '[object Int32Array]', - uint8Tag = '[object Uint8Array]', - uint8ClampedTag = '[object Uint8ClampedArray]', - uint16Tag = '[object Uint16Array]', - uint32Tag = '[object Uint32Array]'; +const arrayBufferTag = '[object ArrayBuffer]'; +const dataViewTag = '[object DataView]'; +const float32Tag = '[object Float32Array]'; +const float64Tag = '[object Float64Array]'; +const int8Tag = '[object Int8Array]'; +const int16Tag = '[object Int16Array]'; +const int32Tag = '[object Int32Array]'; +const uint8Tag = '[object Uint8Array]'; +const uint8ClampedTag = '[object Uint8ClampedArray]'; +const uint16Tag = '[object Uint16Array]'; +const uint32Tag = '[object Uint32Array]'; /** Used to identify `toStringTag` values supported by `_.clone`. */ -var cloneableTags = {}; +const cloneableTags = {}; cloneableTags[argsTag] = cloneableTags[arrayTag] = cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = cloneableTags[boolTag] = cloneableTags[dateTag] = @@ -85,10 +85,10 @@ cloneableTags[weakMapTag] = false; * @returns {*} Returns the cloned value. */ function baseClone(value, bitmask, customizer, key, object, stack) { - var result, - isDeep = bitmask & CLONE_DEEP_FLAG, - isFlat = bitmask & CLONE_FLAT_FLAG, - isFull = bitmask & CLONE_SYMBOLS_FLAG; + let result; + const isDeep = bitmask & CLONE_DEEP_FLAG; + const isFlat = bitmask & CLONE_FLAT_FLAG; + const isFull = bitmask & CLONE_SYMBOLS_FLAG; if (customizer) { result = object ? customizer(value, key, object, stack) : customizer(value); @@ -99,15 +99,15 @@ function baseClone(value, bitmask, customizer, key, object, stack) { if (!isObject(value)) { return value; } - var isArr = isArray(value); + const isArr = isArray(value); if (isArr) { result = initCloneArray(value); if (!isDeep) { return copyArray(value, result); } } else { - var tag = getTag(value), - isFunc = tag == funcTag || tag == genTag; + const tag = getTag(value); + const isFunc = tag == funcTag || tag == genTag; if (isBuffer(value)) { return cloneBuffer(value, isDeep); @@ -128,17 +128,17 @@ function baseClone(value, bitmask, customizer, key, object, stack) { } // Check for circular references and return its corresponding clone. stack || (stack = new Stack); - var stacked = stack.get(value); + const stacked = stack.get(value); if (stacked) { return stacked; } stack.set(value, result); - var keysFunc = isFull + const keysFunc = isFull ? (isFlat ? getAllKeysIn : getAllKeys) : (isFlat ? keysIn : keys); - var props = isArr ? undefined : keysFunc(value); + const props = isArr ? undefined : keysFunc(value); arrayEach(props || value, (subValue, key) => { if (props) { key = subValue; diff --git a/_baseDifference.js b/_baseDifference.js index 9916db72d..0fe5d64c2 100644 --- a/_baseDifference.js +++ b/_baseDifference.js @@ -6,7 +6,7 @@ import baseUnary from './_baseUnary.js'; import cacheHas from './_cacheHas.js'; /** Used as the size to enable large array optimizations. */ -var LARGE_ARRAY_SIZE = 200; +const LARGE_ARRAY_SIZE = 200; /** * The base implementation of methods like `_.difference` without support @@ -20,12 +20,12 @@ var LARGE_ARRAY_SIZE = 200; * @returns {Array} Returns the new array of filtered values. */ function baseDifference(array, values, iteratee, comparator) { - var index = -1, - includes = arrayIncludes, - isCommon = true, - length = array.length, - result = [], - valuesLength = values.length; + let index = -1; + let includes = arrayIncludes; + let isCommon = true; + const length = array.length; + const result = []; + const valuesLength = values.length; if (!length) { return result; @@ -44,12 +44,12 @@ function baseDifference(array, values, iteratee, comparator) { } outer: while (++index < length) { - var value = array[index], - computed = iteratee == null ? value : iteratee(value); + let value = array[index]; + const computed = iteratee == null ? value : iteratee(value); value = (comparator || value !== 0) ? value : 0; if (isCommon && computed === computed) { - var valuesIndex = valuesLength; + let valuesIndex = valuesLength; while (valuesIndex--) { if (values[valuesIndex] === computed) { continue outer; diff --git a/_baseIntersection.js b/_baseIntersection.js index dede69664..5ad0cafff 100644 --- a/_baseIntersection.js +++ b/_baseIntersection.js @@ -6,7 +6,7 @@ import baseUnary from './_baseUnary.js'; import cacheHas from './_cacheHas.js'; /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMin = Math.min; +const nativeMin = Math.min; /** * The base implementation of methods like `_.intersection`, without support @@ -19,13 +19,14 @@ var nativeMin = Math.min; * @returns {Array} Returns the new array of shared values. */ function baseIntersection(arrays, iteratee, comparator) { - var includes = comparator ? arrayIncludesWith : arrayIncludes, - length = arrays[0].length, - othLength = arrays.length, - othIndex = othLength, - caches = Array(othLength), - maxLength = Infinity, - result = []; + const includes = comparator ? arrayIncludesWith : arrayIncludes; + const length = arrays[0].length; + const othLength = arrays.length; + const caches = Array(othLength); + const result = []; + + let maxLength = Infinity; + let othIndex = othLength; while (othIndex--) { var array = arrays[othIndex]; @@ -39,13 +40,13 @@ function baseIntersection(arrays, iteratee, comparator) { } array = arrays[0]; - var index = -1, - seen = caches[0]; + let index = -1; + const seen = caches[0]; outer: while (++index < length && result.length < maxLength) { - var value = array[index], - computed = iteratee ? iteratee(value) : value; + let value = array[index]; + const computed = iteratee ? iteratee(value) : value; value = (comparator || value !== 0) ? value : 0; if (!(seen @@ -54,7 +55,7 @@ function baseIntersection(arrays, iteratee, comparator) { )) { othIndex = othLength; while (--othIndex) { - var cache = caches[othIndex]; + const cache = caches[othIndex]; if (!(cache ? cacheHas(cache, computed) : includes(arrays[othIndex], computed, comparator)) diff --git a/_baseIsEqualDeep.js b/_baseIsEqualDeep.js index d8c8bf075..c18686b88 100644 --- a/_baseIsEqualDeep.js +++ b/_baseIsEqualDeep.js @@ -8,18 +8,18 @@ import isBuffer from './isBuffer.js'; import isTypedArray from './isTypedArray.js'; /** Used to compose bitmasks for value comparisons. */ -var COMPARE_PARTIAL_FLAG = 1; +const COMPARE_PARTIAL_FLAG = 1; /** `Object#toString` result references. */ -var argsTag = '[object Arguments]', - arrayTag = '[object Array]', - objectTag = '[object Object]'; +const argsTag = '[object Arguments]'; +const arrayTag = '[object Array]'; +const objectTag = '[object Object]'; /** Used for built-in method references. */ -var objectProto = Object.prototype; +const objectProto = Object.prototype; /** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; +const hasOwnProperty = objectProto.hasOwnProperty; /** * A specialized version of `baseIsEqual` for arrays and objects which performs @@ -36,17 +36,17 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { - var objIsArr = isArray(object), - othIsArr = isArray(other), - objTag = objIsArr ? arrayTag : getTag(object), - othTag = othIsArr ? arrayTag : getTag(other); + let objIsArr = isArray(object); + const othIsArr = isArray(other); + let objTag = objIsArr ? arrayTag : getTag(object); + let othTag = othIsArr ? arrayTag : getTag(other); objTag = objTag == argsTag ? objectTag : objTag; othTag = othTag == argsTag ? objectTag : othTag; - var objIsObj = objTag == objectTag, - othIsObj = othTag == objectTag, - isSameTag = objTag == othTag; + let objIsObj = objTag == objectTag; + const othIsObj = othTag == objectTag; + const isSameTag = objTag == othTag; if (isSameTag && isBuffer(object)) { if (!isBuffer(other)) { @@ -62,12 +62,12 @@ function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack); } if (!(bitmask & COMPARE_PARTIAL_FLAG)) { - var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), - othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); + const objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'); + const othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); if (objIsWrapped || othIsWrapped) { - var objUnwrapped = objIsWrapped ? object.value() : object, - othUnwrapped = othIsWrapped ? other.value() : other; + const objUnwrapped = objIsWrapped ? object.value() : object; + const othUnwrapped = othIsWrapped ? other.value() : other; stack || (stack = new Stack); return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack); diff --git a/_baseIsMatch.js b/_baseIsMatch.js index 926e03fee..5dc19d211 100644 --- a/_baseIsMatch.js +++ b/_baseIsMatch.js @@ -2,8 +2,8 @@ import Stack from './_Stack.js'; import baseIsEqual from './_baseIsEqual.js'; /** Used to compose bitmasks for value comparisons. */ -var COMPARE_PARTIAL_FLAG = 1, - COMPARE_UNORDERED_FLAG = 2; +const COMPARE_PARTIAL_FLAG = 1; +const COMPARE_UNORDERED_FLAG = 2; /** * The base implementation of `_.isMatch` without support for iteratee shorthands. @@ -16,16 +16,18 @@ var COMPARE_PARTIAL_FLAG = 1, * @returns {boolean} Returns `true` if `object` is a match, else `false`. */ function baseIsMatch(object, source, matchData, customizer) { - var index = matchData.length, - length = index, - noCustomizer = !customizer; + let index = matchData.length; + const length = index; + const noCustomizer = !customizer; if (object == null) { return !length; } + let data; + let result; object = Object(object); while (index--) { - var data = matchData[index]; + data = matchData[index]; if ((noCustomizer && data[2]) ? data[1] !== object[data[0]] : !(data[0] in object) @@ -35,18 +37,18 @@ function baseIsMatch(object, source, matchData, customizer) { } while (++index < length) { data = matchData[index]; - var key = data[0], - objValue = object[key], - srcValue = data[1]; + const key = data[0]; + const objValue = object[key]; + const srcValue = data[1]; if (noCustomizer && data[2]) { if (objValue === undefined && !(key in object)) { return false; } } else { - var stack = new Stack; + const stack = new Stack; if (customizer) { - var result = customizer(objValue, srcValue, key, object, source, stack); + result = customizer(objValue, srcValue, key, object, source, stack); } if (!(result === undefined ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) diff --git a/_baseIsTypedArray.js b/_baseIsTypedArray.js index 0a18d1c1a..806887e01 100644 --- a/_baseIsTypedArray.js +++ b/_baseIsTypedArray.js @@ -3,34 +3,34 @@ import isLength from './isLength.js'; import isObjectLike from './isObjectLike.js'; /** `Object#toString` result references. */ -var argsTag = '[object Arguments]', - arrayTag = '[object Array]', - boolTag = '[object Boolean]', - dateTag = '[object Date]', - errorTag = '[object Error]', - funcTag = '[object Function]', - mapTag = '[object Map]', - numberTag = '[object Number]', - objectTag = '[object Object]', - regexpTag = '[object RegExp]', - setTag = '[object Set]', - stringTag = '[object String]', - weakMapTag = '[object WeakMap]'; +const argsTag = '[object Arguments]'; +const arrayTag = '[object Array]'; +const boolTag = '[object Boolean]'; +const dateTag = '[object Date]'; +const errorTag = '[object Error]'; +const funcTag = '[object Function]'; +const mapTag = '[object Map]'; +const numberTag = '[object Number]'; +const objectTag = '[object Object]'; +const regexpTag = '[object RegExp]'; +const setTag = '[object Set]'; +const stringTag = '[object String]'; +const weakMapTag = '[object WeakMap]'; -var arrayBufferTag = '[object ArrayBuffer]', - dataViewTag = '[object DataView]', - float32Tag = '[object Float32Array]', - float64Tag = '[object Float64Array]', - int8Tag = '[object Int8Array]', - int16Tag = '[object Int16Array]', - int32Tag = '[object Int32Array]', - uint8Tag = '[object Uint8Array]', - uint8ClampedTag = '[object Uint8ClampedArray]', - uint16Tag = '[object Uint16Array]', - uint32Tag = '[object Uint32Array]'; +const arrayBufferTag = '[object ArrayBuffer]'; +const dataViewTag = '[object DataView]'; +const float32Tag = '[object Float32Array]'; +const float64Tag = '[object Float64Array]'; +const int8Tag = '[object Int8Array]'; +const int16Tag = '[object Int16Array]'; +const int32Tag = '[object Int32Array]'; +const uint8Tag = '[object Uint8Array]'; +const uint8ClampedTag = '[object Uint8ClampedArray]'; +const uint16Tag = '[object Uint16Array]'; +const uint32Tag = '[object Uint32Array]'; /** Used to identify `toStringTag` values of typed arrays. */ -var typedArrayTags = {}; +const typedArrayTags = {}; typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = diff --git a/_baseMergeDeep.js b/_baseMergeDeep.js index ee8e345f9..065169726 100644 --- a/_baseMergeDeep.js +++ b/_baseMergeDeep.js @@ -29,24 +29,24 @@ import toPlainObject from './toPlainObject.js'; * counterparts. */ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { - var objValue = object[key], - srcValue = source[key], - stacked = stack.get(srcValue); + const objValue = object[key]; + const srcValue = source[key]; + const stacked = stack.get(srcValue); if (stacked) { assignMergeValue(object, key, stacked); return; } - var newValue = customizer + let newValue = customizer ? customizer(objValue, srcValue, `${ key }`, object, source, stack) : undefined; - var isCommon = newValue === undefined; + let isCommon = newValue === undefined; if (isCommon) { - var isArr = isArray(srcValue), - isBuff = !isArr && isBuffer(srcValue), - isTyped = !isArr && !isBuff && isTypedArray(srcValue); + const isArr = isArray(srcValue); + const isBuff = !isArr && isBuffer(srcValue); + const isTyped = !isArr && !isBuff && isTypedArray(srcValue); newValue = srcValue; if (isArr || isBuff || isTyped) { diff --git a/_basePickBy.js b/_basePickBy.js index f2610c599..67d04cb87 100644 --- a/_basePickBy.js +++ b/_basePickBy.js @@ -12,14 +12,13 @@ import castPath from './_castPath.js'; * @returns {Object} Returns the new object. */ function basePickBy(object, paths, predicate) { - var index = -1, - length = paths.length, - result = {}; + let index = -1; + const length = paths.length; + const result = {}; while (++index < length) { - var path = paths[index], - value = baseGet(object, path); - + const path = paths[index]; + const value = baseGet(object, path); if (predicate(value, path)) { baseSet(result, castPath(path, object), value); } diff --git a/_basePullAll.js b/_basePullAll.js index e69c1003e..e292b2fa9 100644 --- a/_basePullAll.js +++ b/_basePullAll.js @@ -5,10 +5,10 @@ import baseUnary from './_baseUnary.js'; import copyArray from './_copyArray.js'; /** Used for built-in method references. */ -var arrayProto = Array.prototype; +const arrayProto = Array.prototype; /** Built-in value references. */ -var splice = arrayProto.splice; +const splice = arrayProto.splice; /** * The base implementation of `_.pullAllBy` without support for iteratee @@ -22,10 +22,11 @@ var splice = arrayProto.splice; * @returns {Array} Returns `array`. */ function basePullAll(array, values, iteratee, comparator) { - var indexOf = comparator ? baseIndexOfWith : baseIndexOf, - index = -1, - length = values.length, - seen = array; + const indexOf = comparator ? baseIndexOfWith : baseIndexOf; + const length = values.length; + + let index = -1; + let seen = array; if (array === values) { values = copyArray(values); @@ -34,9 +35,9 @@ function basePullAll(array, values, iteratee, comparator) { seen = arrayMap(array, baseUnary(iteratee)); } while (++index < length) { - var fromIndex = 0, - value = values[index], - computed = iteratee ? iteratee(value) : value; + let fromIndex = 0; + const value = values[index]; + const computed = iteratee ? iteratee(value) : value; while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) { if (seen !== array) { diff --git a/_baseRandom.js b/_baseRandom.js index 0e6cf0302..d6a63f525 100644 --- a/_baseRandom.js +++ b/_baseRandom.js @@ -1,6 +1,6 @@ /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeFloor = Math.floor, - nativeRandom = Math.random; +const nativeFloor = Math.floor; +const nativeRandom = Math.random; /** * The base implementation of `_.random` without support for returning diff --git a/_baseRange.js b/_baseRange.js index 12e48b031..a3bb76bb9 100644 --- a/_baseRange.js +++ b/_baseRange.js @@ -1,6 +1,6 @@ /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeCeil = Math.ceil, - nativeMax = Math.max; +const nativeCeil = Math.ceil; +const nativeMax = Math.max; /** * The base implementation of `_.range` and `_.rangeRight` which doesn't @@ -14,9 +14,9 @@ var nativeCeil = Math.ceil, * @returns {Array} Returns the range of numbers. */ function baseRange(start, end, step, fromRight) { - var index = -1, - length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), - result = Array(length); + let index = -1; + let length = nativeMax(nativeCeil((end - start) / (step || 1)), 0); + const result = Array(length); while (length--) { result[fromRight ? length : ++index] = start; diff --git a/_baseSet.js b/_baseSet.js index 6cdc792c6..6e905081a 100644 --- a/_baseSet.js +++ b/_baseSet.js @@ -20,17 +20,18 @@ function baseSet(object, path, value, customizer) { } path = castPath(path, object); - var index = -1, - length = path.length, - lastIndex = length - 1, - nested = object; + const length = path.length; + const lastIndex = length - 1; + + let index = -1; + let nested = object; while (nested != null && ++index < length) { - var key = toKey(path[index]), - newValue = value; + const key = toKey(path[index]); + let newValue = value; if (index != lastIndex) { - var objValue = nested[key]; + const objValue = nested[key]; newValue = customizer ? customizer(objValue, key, nested) : undefined; if (newValue === undefined) { newValue = isObject(objValue) diff --git a/_baseSlice.js b/_baseSlice.js index bd9c69b71..da21c248c 100644 --- a/_baseSlice.js +++ b/_baseSlice.js @@ -8,7 +8,7 @@ * @returns {Array} Returns the slice of `array`. */ function baseSlice(array, start, end) { - var index = -1, + let index = -1, length = array.length; if (start < 0) { @@ -21,7 +21,7 @@ function baseSlice(array, start, end) { length = start > end ? 0 : ((end - start) >>> 0); start >>>= 0; - var result = Array(length); + const result = Array(length); while (++index < length) { result[index] = array[index + start]; } diff --git a/_baseSortedIndex.js b/_baseSortedIndex.js index c19250591..00598f98e 100644 --- a/_baseSortedIndex.js +++ b/_baseSortedIndex.js @@ -3,8 +3,8 @@ import identity from './identity.js'; import isSymbol from './isSymbol.js'; /** Used as references for the maximum length and index of an array. */ -var MAX_ARRAY_LENGTH = 4294967295, - HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; +const MAX_ARRAY_LENGTH = 4294967295; +const HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; /** * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which @@ -19,14 +19,13 @@ var MAX_ARRAY_LENGTH = 4294967295, * into `array`. */ function baseSortedIndex(array, value, retHighest) { - var low = 0, - high = array == null ? low : array.length; + let low = 0; + let high = array == null ? low : array.length; if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { while (low < high) { - var mid = (low + high) >>> 1, - computed = array[mid]; - + const mid = (low + high) >>> 1; + const computed = array[mid]; if (computed !== null && !isSymbol(computed) && (retHighest ? (computed <= value) : (computed < value))) { low = mid + 1; diff --git a/_baseSortedIndexBy.js b/_baseSortedIndexBy.js index 20a90d0ad..bf37a6c4d 100644 --- a/_baseSortedIndexBy.js +++ b/_baseSortedIndexBy.js @@ -1,12 +1,11 @@ import isSymbol from './isSymbol.js'; /** Used as references for the maximum length and index of an array. */ -var MAX_ARRAY_LENGTH = 4294967295, - MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1; +const MAX_ARRAY_LENGTH = 4294967295; +const MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1; /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeFloor = Math.floor, - nativeMin = Math.min; +const nativeFloor = Math.floor, nativeMin = Math.min; /** * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy` @@ -24,20 +23,20 @@ var nativeFloor = Math.floor, function baseSortedIndexBy(array, value, iteratee, retHighest) { value = iteratee(value); - var low = 0, - high = array == null ? 0 : array.length, - valIsNaN = value !== value, - valIsNull = value === null, - valIsSymbol = isSymbol(value), - valIsUndefined = value === undefined; + let low = 0; + let high = array == null ? 0 : array.length; + const valIsNaN = value !== value; + const valIsNull = value === null; + const valIsSymbol = isSymbol(value); + const valIsUndefined = value === undefined; while (low < high) { - var mid = nativeFloor((low + high) / 2), - computed = iteratee(array[mid]), - othIsDefined = computed !== undefined, - othIsNull = computed === null, - othIsReflexive = computed === computed, - othIsSymbol = isSymbol(computed); + const mid = nativeFloor((low + high) / 2); + const computed = iteratee(array[mid]); + const othIsDefined = computed !== undefined; + const othIsNull = computed === null; + const othIsReflexive = computed === computed; + const othIsSymbol = isSymbol(computed); if (valIsNaN) { var setLow = retHighest || othIsReflexive; diff --git a/_baseSortedUniq.js b/_baseSortedUniq.js index cb44abc14..d4bf82fad 100644 --- a/_baseSortedUniq.js +++ b/_baseSortedUniq.js @@ -10,17 +10,17 @@ import eq from './eq.js'; * @returns {Array} Returns the new duplicate free array. */ function baseSortedUniq(array, iteratee) { - var index = -1, - length = array.length, - resIndex = 0, - result = []; + let seen; + let index = -1; + let resIndex = 0; + + const length = array.length; + const result = []; while (++index < length) { - var value = array[index], - computed = iteratee ? iteratee(value) : value; - + const value = array[index], computed = iteratee ? iteratee(value) : value; if (!index || !eq(computed, seen)) { - var seen = computed; + seen = computed; result[resIndex++] = value === 0 ? 0 : value; } } diff --git a/_baseUniq.js b/_baseUniq.js index 4ca0bcdee..fde5ed1e1 100644 --- a/_baseUniq.js +++ b/_baseUniq.js @@ -6,7 +6,7 @@ import createSet from './_createSet.js'; import setToArray from './_setToArray.js'; /** Used as the size to enable large array optimizations. */ -var LARGE_ARRAY_SIZE = 200; +const LARGE_ARRAY_SIZE = 200; /** * The base implementation of `_.uniqBy` without support for iteratee shorthands. @@ -18,19 +18,20 @@ var LARGE_ARRAY_SIZE = 200; * @returns {Array} Returns the new duplicate free array. */ function baseUniq(array, iteratee, comparator) { - var index = -1, - includes = arrayIncludes, - length = array.length, - isCommon = true, - result = [], - seen = result; + let index = -1; + let includes = arrayIncludes; + let isCommon = true; + + const length = array.length; + const result = []; + let seen = result; if (comparator) { isCommon = false; includes = arrayIncludesWith; } else if (length >= LARGE_ARRAY_SIZE) { - var set = iteratee ? null : createSet(array); + const set = iteratee ? null : createSet(array); if (set) { return setToArray(set); } @@ -43,12 +44,12 @@ function baseUniq(array, iteratee, comparator) { } outer: while (++index < length) { - var value = array[index], - computed = iteratee ? iteratee(value) : value; + let value = array[index]; + const computed = iteratee ? iteratee(value) : value; value = (comparator || value !== 0) ? value : 0; if (isCommon && computed === computed) { - var seenIndex = seen.length; + let seenIndex = seen.length; while (seenIndex--) { if (seen[seenIndex] === computed) { continue outer; diff --git a/_cloneBuffer.js b/_cloneBuffer.js index 21b192e9f..5f0c5e26e 100644 --- a/_cloneBuffer.js +++ b/_cloneBuffer.js @@ -1,17 +1,16 @@ import root from './_root.js'; /** Detect free variable `exports`. */ -var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; +const freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports; /** Detect free variable `module`. */ -var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; +const freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module; /** Detect the popular CommonJS extension `module.exports`. */ -var moduleExports = freeModule && freeModule.exports === freeExports; +const moduleExports = freeModule && freeModule.exports === freeExports; /** Built-in value references. */ -var Buffer = moduleExports ? root.Buffer : undefined, - allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined; +const Buffer = moduleExports ? root.Buffer : undefined, allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined; /** * Creates a clone of `buffer`. @@ -25,8 +24,8 @@ function cloneBuffer(buffer, isDeep) { if (isDeep) { return buffer.slice(); } - var length = buffer.length, - result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length); + const length = buffer.length; + const result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length); buffer.copy(result); return result; diff --git a/_cloneSymbol.js b/_cloneSymbol.js index 357b155f4..1fa2ef75d 100644 --- a/_cloneSymbol.js +++ b/_cloneSymbol.js @@ -1,8 +1,8 @@ import Symbol from './_Symbol.js'; /** Used to convert symbols to primitives and strings. */ -var symbolProto = Symbol ? Symbol.prototype : undefined, - symbolValueOf = symbolProto ? symbolProto.valueOf : undefined; +const symbolProto = Symbol ? Symbol.prototype : undefined; +const symbolValueOf = symbolProto ? symbolProto.valueOf : undefined; /** * Creates a clone of the `symbol` object. diff --git a/_compareAscending.js b/_compareAscending.js index f4451931d..f297a0827 100644 --- a/_compareAscending.js +++ b/_compareAscending.js @@ -10,15 +10,15 @@ import isSymbol from './isSymbol.js'; */ function compareAscending(value, other) { if (value !== other) { - var valIsDefined = value !== undefined, - valIsNull = value === null, - valIsReflexive = value === value, - valIsSymbol = isSymbol(value); + const valIsDefined = value !== undefined; + const valIsNull = value === null; + const valIsReflexive = value === value; + const valIsSymbol = isSymbol(value); - var othIsDefined = other !== undefined, - othIsNull = other === null, - othIsReflexive = other === other, - othIsSymbol = isSymbol(other); + const othIsDefined = other !== undefined; + const othIsNull = other === null; + const othIsReflexive = other === other; + const othIsSymbol = isSymbol(other); if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || diff --git a/_compareMultiple.js b/_compareMultiple.js index 06e755733..4ef8281e2 100644 --- a/_compareMultiple.js +++ b/_compareMultiple.js @@ -15,19 +15,19 @@ import compareAscending from './_compareAscending.js'; * @returns {number} Returns the sort order indicator for `object`. */ function compareMultiple(object, other, orders) { - var index = -1, - objCriteria = object.criteria, - othCriteria = other.criteria, - length = objCriteria.length, - ordersLength = orders.length; + let index = -1; + const objCriteria = object.criteria; + const othCriteria = other.criteria; + const length = objCriteria.length; + const ordersLength = orders.length; while (++index < length) { - var result = compareAscending(objCriteria[index], othCriteria[index]); + const result = compareAscending(objCriteria[index], othCriteria[index]); if (result) { if (index >= ordersLength) { return result; } - var order = orders[index]; + const order = orders[index]; return result * (order == 'desc' ? -1 : 1); } } diff --git a/_composeArgs.js b/_composeArgs.js index 82643bdf0..96a4464ba 100644 --- a/_composeArgs.js +++ b/_composeArgs.js @@ -1,5 +1,5 @@ /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMax = Math.max; +const nativeMax = Math.max; /** * Creates an array that is the composition of partially applied arguments, @@ -13,14 +13,16 @@ var nativeMax = Math.max; * @returns {Array} Returns the new array of composed arguments. */ function composeArgs(args, partials, holders, isCurried) { - var argsIndex = -1, - argsLength = args.length, - holdersLength = holders.length, - leftIndex = -1, - leftLength = partials.length, - rangeLength = nativeMax(argsLength - holdersLength, 0), - result = Array(leftLength + rangeLength), - isUncurried = !isCurried; + const argsLength = args.length; + const holdersLength = holders.length; + const leftLength = partials.length; + + let argsIndex = -1; + let leftIndex = -1; + let rangeLength = nativeMax(argsLength - holdersLength, 0); + + const result = Array(leftLength + rangeLength); + const isUncurried = !isCurried; while (++leftIndex < leftLength) { result[leftIndex] = partials[leftIndex]; diff --git a/_composeArgsRight.js b/_composeArgsRight.js index 9540e39cf..34f1bc421 100644 --- a/_composeArgsRight.js +++ b/_composeArgsRight.js @@ -1,5 +1,5 @@ /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMax = Math.max; +const nativeMax = Math.max; /** * This function is like `composeArgs` except that the arguments composition @@ -13,20 +13,21 @@ var nativeMax = Math.max; * @returns {Array} Returns the new array of composed arguments. */ function composeArgsRight(args, partials, holders, isCurried) { - var argsIndex = -1, - argsLength = args.length, - holdersIndex = -1, - holdersLength = holders.length, - rightIndex = -1, - rightLength = partials.length, - rangeLength = nativeMax(argsLength - holdersLength, 0), - result = Array(rangeLength + rightLength), - isUncurried = !isCurried; + let argsIndex = -1; + let holdersIndex = -1; + let rightIndex = -1; + + const argsLength = args.length; + const holdersLength = holders.length; + const rightLength = partials.length; + const rangeLength = nativeMax(argsLength - holdersLength, 0); + const result = Array(rangeLength + rightLength); + const isUncurried = !isCurried; while (++argsIndex < rangeLength) { result[argsIndex] = args[argsIndex]; } - var offset = argsIndex; + const offset = argsIndex; while (++rightIndex < rightLength) { result[offset + rightIndex] = partials[rightIndex]; } diff --git a/_countHolders.js b/_countHolders.js index 0767946dd..c5bce50d0 100644 --- a/_countHolders.js +++ b/_countHolders.js @@ -7,8 +7,8 @@ * @returns {number} Returns the placeholder count. */ function countHolders(array, placeholder) { - var length = array.length, - result = 0; + let length = array.length; + let result = 0; while (length--) { if (array[length] === placeholder) { diff --git a/_createAggregator.js b/_createAggregator.js index b8fd331ef..37c5b1591 100644 --- a/_createAggregator.js +++ b/_createAggregator.js @@ -13,9 +13,8 @@ import isArray from './isArray.js'; */ function createAggregator(setter, initializer) { return (collection, iteratee) => { - var func = isArray(collection) ? arrayAggregator : baseAggregator, - accumulator = initializer ? initializer() : {}; - + const func = isArray(collection) ? arrayAggregator : baseAggregator; + const accumulator = initializer ? initializer() : {}; return func(collection, setter, baseIteratee(iteratee, 2), accumulator); }; } diff --git a/_createAssigner.js b/_createAssigner.js index a83e30f0f..9c71c0bbd 100644 --- a/_createAssigner.js +++ b/_createAssigner.js @@ -10,10 +10,10 @@ import isIterateeCall from './_isIterateeCall.js'; */ function createAssigner(assigner) { return baseRest((object, sources) => { - var index = -1, - length = sources.length, - customizer = length > 1 ? sources[length - 1] : undefined, - guard = length > 2 ? sources[2] : undefined; + let index = -1; + let length = sources.length; + let customizer = length > 1 ? sources[length - 1] : undefined; + const guard = length > 2 ? sources[2] : undefined; customizer = (assigner.length > 3 && typeof customizer == 'function') ? (length--, customizer) @@ -25,7 +25,7 @@ function createAssigner(assigner) { } object = Object(object); while (++index < length) { - var source = sources[index]; + const source = sources[index]; if (source) { assigner(object, source, index, customizer); } diff --git a/_createBaseFor.js b/_createBaseFor.js index 483be373b..254283a5d 100644 --- a/_createBaseFor.js +++ b/_createBaseFor.js @@ -7,13 +7,14 @@ */ function createBaseFor(fromRight) { return (object, iteratee, keysFunc) => { - var index = -1, - iterable = Object(object), - props = keysFunc(object), - length = props.length; + const iterable = Object(object); + const props = keysFunc(object); + + let index = -1; + let length = props.length; while (length--) { - var key = props[fromRight ? length : ++index]; + const key = props[fromRight ? length : ++index]; if (iteratee(iterable[key], key, iterable) === false) { break; } diff --git a/_createBind.js b/_createBind.js index ff5f7de8e..3e9b7a1f7 100644 --- a/_createBind.js +++ b/_createBind.js @@ -2,7 +2,7 @@ import createCtor from './_createCtor.js'; import root from './_root.js'; /** Used to compose bitmasks for function metadata. */ -var WRAP_BIND_FLAG = 1; +const WRAP_BIND_FLAG = 1; /** * Creates a function that wraps `func` to invoke it with the optional `this` @@ -15,11 +15,11 @@ var WRAP_BIND_FLAG = 1; * @returns {Function} Returns the new wrapped function. */ function createBind(func, bitmask, thisArg) { - var isBind = bitmask & WRAP_BIND_FLAG, - Ctor = createCtor(func); + const isBind = bitmask & WRAP_BIND_FLAG; + const Ctor = createCtor(func); function wrapper(...args) { - var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + const fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; return fn.apply(isBind ? thisArg : this, args); } return wrapper; diff --git a/_createCtor.js b/_createCtor.js index 57f32b15d..582355201 100644 --- a/_createCtor.js +++ b/_createCtor.js @@ -14,7 +14,7 @@ function createCtor(Ctor) { // Use a `switch` statement to work with class constructors. See // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist // for more details. - var args = arguments; + const args = arguments; switch (args.length) { case 0: return new Ctor; case 1: return new Ctor(args[0]); @@ -25,8 +25,8 @@ function createCtor(Ctor) { case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); } - var thisBinding = baseCreate(Ctor.prototype), - result = Ctor.apply(thisBinding, args); + const thisBinding = baseCreate(Ctor.prototype); + const result = Ctor.apply(thisBinding, args); // Mimic the constructor's `return` behavior. // See https://es5.github.io/#x13.2.2 for more details. diff --git a/_createCurry.js b/_createCurry.js index cae7f9343..07575cb48 100644 --- a/_createCurry.js +++ b/_createCurry.js @@ -16,18 +16,19 @@ import root from './_root.js'; * @returns {Function} Returns the new wrapped function. */ function createCurry(func, bitmask, arity) { - var Ctor = createCtor(func); + const Ctor = createCtor(func); function wrapper() { - var length = arguments.length, - args = Array(length), - index = length, - placeholder = getHolder(wrapper); + let length = arguments.length; + let index = length; + + const args = Array(length); + const placeholder = getHolder(wrapper); while (index--) { args[index] = arguments[index]; } - var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) + const holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) ? [] : replaceHolders(args, placeholder); @@ -37,7 +38,7 @@ function createCurry(func, bitmask, arity) { func, bitmask, createHybrid, wrapper.placeholder, undefined, args, holders, undefined, undefined, arity - length); } - var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + const fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; return apply(fn, this, args); } return wrapper; diff --git a/_createFlow.js b/_createFlow.js index 83c5b6356..180fcb797 100644 --- a/_createFlow.js +++ b/_createFlow.js @@ -6,13 +6,13 @@ import isArray from './isArray.js'; import isLaziable from './_isLaziable.js'; /** Error message constants. */ -var FUNC_ERROR_TEXT = 'Expected a function'; +const FUNC_ERROR_TEXT = 'Expected a function'; /** Used to compose bitmasks for function metadata. */ -var WRAP_CURRY_FLAG = 8, - WRAP_PARTIAL_FLAG = 32, - WRAP_ARY_FLAG = 128, - WRAP_REARG_FLAG = 256; +const WRAP_CURRY_FLAG = 8; +const WRAP_PARTIAL_FLAG = 32; +const WRAP_ARY_FLAG = 128; +const WRAP_REARG_FLAG = 256; /** * Creates a `_.flow` or `_.flowRight` function. @@ -23,9 +23,9 @@ var WRAP_CURRY_FLAG = 8, */ function createFlow(fromRight) { return flatRest(funcs => { - var length = funcs.length, - index = length, - prereq = LodashWrapper.prototype.thru; + const length = funcs.length; + const prereq = LodashWrapper.prototype.thru; + let index = length; if (fromRight) { funcs.reverse(); @@ -43,12 +43,12 @@ function createFlow(fromRight) { while (++index < length) { func = funcs[index]; - var funcName = getFuncName(func), - data = funcName == 'wrapper' ? getData(func) : undefined; + const funcName = getFuncName(func); + const data = funcName == 'wrapper' ? getData(func) : undefined; if (data && isLaziable(data[0]) && data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) && - !data[4].length && data[9] == 1 + !data[4].length && data[9] == 1 ) { wrapper = wrapper[getFuncName(data[0])](...data[3]); } else { @@ -58,14 +58,13 @@ function createFlow(fromRight) { } } return function() { - var args = arguments, - value = args[0]; + const args = arguments; + const value = args[0]; if (wrapper && args.length == 1 && isArray(value)) { return wrapper.plant(value).value(); } - var index = 0, - result = length ? funcs[index].apply(this, args) : value; + let index = 0, result = length ? funcs[index].apply(this, args) : value; while (++index < length) { result = funcs[index].call(this, result); diff --git a/_createHybrid.js b/_createHybrid.js index 300f66b1b..6a2056ef7 100644 --- a/_createHybrid.js +++ b/_createHybrid.js @@ -9,12 +9,12 @@ import replaceHolders from './_replaceHolders.js'; import root from './_root.js'; /** Used to compose bitmasks for function metadata. */ -var WRAP_BIND_FLAG = 1, - WRAP_BIND_KEY_FLAG = 2, - WRAP_CURRY_FLAG = 8, - WRAP_CURRY_RIGHT_FLAG = 16, - WRAP_ARY_FLAG = 128, - WRAP_FLIP_FLAG = 512; +const WRAP_BIND_FLAG = 1; +const WRAP_BIND_KEY_FLAG = 2; +const WRAP_CURRY_FLAG = 8; +const WRAP_CURRY_RIGHT_FLAG = 16; +const WRAP_ARY_FLAG = 128; +const WRAP_FLIP_FLAG = 512; /** * Creates a function that wraps `func` to invoke it with optional `this` @@ -36,24 +36,26 @@ var WRAP_BIND_FLAG = 1, * @returns {Function} Returns the new wrapped function. */ function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { - var isAry = bitmask & WRAP_ARY_FLAG, - isBind = bitmask & WRAP_BIND_FLAG, - isBindKey = bitmask & WRAP_BIND_KEY_FLAG, - isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG), - isFlip = bitmask & WRAP_FLIP_FLAG, - Ctor = isBindKey ? undefined : createCtor(func); + const isAry = bitmask & WRAP_ARY_FLAG; + const isBind = bitmask & WRAP_BIND_FLAG; + const isBindKey = bitmask & WRAP_BIND_KEY_FLAG; + const isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG); + const isFlip = bitmask & WRAP_FLIP_FLAG; + const Ctor = isBindKey ? undefined : createCtor(func); function wrapper() { - var length = arguments.length, - args = Array(length), - index = length; + let holderCount; + let placeholder; + let length = arguments.length; + let args = Array(length); + let index = length; while (index--) { args[index] = arguments[index]; } if (isCurried) { - var placeholder = getHolder(wrapper), - holdersCount = countHolders(args, placeholder); + placeholder = getHolder(wrapper); + holdersCount = countHolders(args, placeholder); } if (partials) { args = composeArgs(args, partials, holders, isCurried); @@ -63,14 +65,14 @@ function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, } length -= holdersCount; if (isCurried && length < arity) { - var newHolders = replaceHolders(args, placeholder); + const newHolders = replaceHolders(args, placeholder); return createRecurry( func, bitmask, createHybrid, wrapper.placeholder, thisArg, args, newHolders, argPos, ary, arity - length ); } - var thisBinding = isBind ? thisArg : this, - fn = isBindKey ? thisBinding[func] : func; + const thisBinding = isBind ? thisArg : this; + let fn = isBindKey ? thisBinding[func] : func; length = args.length; if (argPos) { diff --git a/_createPartial.js b/_createPartial.js index 851a3b6b6..07eea05b6 100644 --- a/_createPartial.js +++ b/_createPartial.js @@ -3,7 +3,7 @@ import createCtor from './_createCtor.js'; import root from './_root.js'; /** Used to compose bitmasks for function metadata. */ -var WRAP_BIND_FLAG = 1; +const WRAP_BIND_FLAG = 1; /** * Creates a function that wraps `func` to invoke it with the `this` binding @@ -18,16 +18,17 @@ var WRAP_BIND_FLAG = 1; * @returns {Function} Returns the new wrapped function. */ function createPartial(func, bitmask, thisArg, partials) { - var isBind = bitmask & WRAP_BIND_FLAG, - Ctor = createCtor(func); + const isBind = bitmask & WRAP_BIND_FLAG; + const Ctor = createCtor(func); function wrapper() { - var argsIndex = -1, - argsLength = arguments.length, - leftIndex = -1, - leftLength = partials.length, - args = Array(leftLength + argsLength), - fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + let argsIndex = -1; + let argsLength = arguments.length; + let leftIndex = -1; + + const leftLength = partials.length; + const args = Array(leftLength + argsLength); + const fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; while (++leftIndex < leftLength) { args[leftIndex] = partials[leftIndex]; diff --git a/_createRecurry.js b/_createRecurry.js index e6e2dab08..7137d5797 100644 --- a/_createRecurry.js +++ b/_createRecurry.js @@ -3,12 +3,12 @@ import setData from './_setData.js'; import setWrapToString from './_setWrapToString.js'; /** Used to compose bitmasks for function metadata. */ -var WRAP_BIND_FLAG = 1, - WRAP_BIND_KEY_FLAG = 2, - WRAP_CURRY_BOUND_FLAG = 4, - WRAP_CURRY_FLAG = 8, - WRAP_PARTIAL_FLAG = 32, - WRAP_PARTIAL_RIGHT_FLAG = 64; +const WRAP_BIND_FLAG = 1; +const WRAP_BIND_KEY_FLAG = 2; +const WRAP_CURRY_BOUND_FLAG = 4; +const WRAP_CURRY_FLAG = 8; +const WRAP_PARTIAL_FLAG = 32; +const WRAP_PARTIAL_RIGHT_FLAG = 64; /** * Creates a function that wraps `func` to continue currying. @@ -28,11 +28,11 @@ var WRAP_BIND_FLAG = 1, * @returns {Function} Returns the new wrapped function. */ function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { - var isCurry = bitmask & WRAP_CURRY_FLAG, - newHolders = isCurry ? holders : undefined, - newHoldersRight = isCurry ? undefined : holders, - newPartials = isCurry ? partials : undefined, - newPartialsRight = isCurry ? undefined : partials; + const isCurry = bitmask & WRAP_CURRY_FLAG; + const newHolders = isCurry ? holders : undefined; + const newHoldersRight = isCurry ? undefined : holders; + const newPartials = isCurry ? partials : undefined; + const newPartialsRight = isCurry ? undefined : partials; bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG); bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG); @@ -40,12 +40,12 @@ function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) { bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG); } - var newData = [ + const newData = [ func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, newHoldersRight, argPos, ary, arity ]; - var result = wrapFunc(...newData); + const result = wrapFunc(...newData); if (isLaziable(func)) { setData(result, newData); } diff --git a/_createRound.js b/_createRound.js index a8308aebf..ec2f21df1 100644 --- a/_createRound.js +++ b/_createRound.js @@ -3,7 +3,7 @@ import toNumber from './toNumber.js'; import toString from './toString.js'; /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMin = Math.min; +const nativeMin = Math.min; /** * Creates a function like `_.round`. @@ -13,15 +13,15 @@ var nativeMin = Math.min; * @returns {Function} Returns the new round function. */ function createRound(methodName) { - var func = Math[methodName]; + const func = Math[methodName]; return (number, precision) => { number = toNumber(number); precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); if (precision) { // Shift with exponential notation to avoid floating-point issues. // See [MDN](https://mdn.io/round#Examples) for more details. - var pair = `${ toString(number) }e`.split('e'), - value = func(`${ pair[0] }e${ +pair[1] + precision }`); + let pair = `${ toString(number) }e`.split('e'); + const value = func(`${ pair[0] }e${ +pair[1] + precision }`); pair = `${ toString(value) }e`.split('e'); return +`${ pair[0] }e${ +pair[1] - precision }`; diff --git a/_createToPairs.js b/_createToPairs.js index 735a3044c..72b370973 100644 --- a/_createToPairs.js +++ b/_createToPairs.js @@ -4,8 +4,8 @@ import mapToArray from './_mapToArray.js'; import setToPairs from './_setToPairs.js'; /** `Object#toString` result references. */ -var mapTag = '[object Map]', - setTag = '[object Set]'; +const mapTag = '[object Map]'; +const setTag = '[object Set]'; /** * Creates a `_.toPairs` or `_.toPairsIn` function. @@ -16,7 +16,7 @@ var mapTag = '[object Map]', */ function createToPairs(keysFunc) { return object => { - var tag = getTag(object); + const tag = getTag(object); if (tag == mapTag) { return mapToArray(object); } diff --git a/_createWrap.js b/_createWrap.js index a471c206b..9049725d1 100644 --- a/_createWrap.js +++ b/_createWrap.js @@ -10,18 +10,18 @@ import setWrapToString from './_setWrapToString.js'; import toInteger from './toInteger.js'; /** Error message constants. */ -var FUNC_ERROR_TEXT = 'Expected a function'; +const FUNC_ERROR_TEXT = 'Expected a function'; /** Used to compose bitmasks for function metadata. */ -var WRAP_BIND_FLAG = 1, - WRAP_BIND_KEY_FLAG = 2, - WRAP_CURRY_FLAG = 8, - WRAP_CURRY_RIGHT_FLAG = 16, - WRAP_PARTIAL_FLAG = 32, - WRAP_PARTIAL_RIGHT_FLAG = 64; +const WRAP_BIND_FLAG = 1; +const WRAP_BIND_KEY_FLAG = 2; +const WRAP_CURRY_FLAG = 8; +const WRAP_CURRY_RIGHT_FLAG = 16; +const WRAP_PARTIAL_FLAG = 32; +const WRAP_PARTIAL_RIGHT_FLAG = 64; /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMax = Math.max; +const nativeMax = Math.max; /** * Creates a function that either curries or invokes `func` with optional @@ -49,11 +49,11 @@ var nativeMax = Math.max; * @returns {Function} Returns the new wrapped function. */ function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { - var isBindKey = bitmask & WRAP_BIND_KEY_FLAG; + const isBindKey = bitmask & WRAP_BIND_KEY_FLAG; if (!isBindKey && typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - var length = partials ? partials.length : 0; + let length = partials ? partials.length : 0; if (!length) { bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG); partials = holders = undefined; @@ -68,9 +68,9 @@ function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arit partials = holders = undefined; } - var data = isBindKey ? undefined : getData(func); + const data = isBindKey ? undefined : getData(func); - var newData = [ + const newData = [ func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity ]; @@ -99,7 +99,7 @@ function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arit } else { result = createHybrid(...newData); } - var setter = data ? baseSetData : setData; + const setter = data ? baseSetData : setData; return setWrapToString(setter(result, newData), func, bitmask); } diff --git a/_equalArrays.js b/_equalArrays.js index 97fa24474..6052699d1 100644 --- a/_equalArrays.js +++ b/_equalArrays.js @@ -3,8 +3,8 @@ import arraySome from './_arraySome.js'; import cacheHas from './_cacheHas.js'; /** Used to compose bitmasks for value comparisons. */ -var COMPARE_PARTIAL_FLAG = 1, - COMPARE_UNORDERED_FLAG = 2; +const COMPARE_PARTIAL_FLAG = 1; +const COMPARE_UNORDERED_FLAG = 2; /** * A specialized version of `baseIsEqualDeep` for arrays with support for @@ -20,29 +20,28 @@ var COMPARE_PARTIAL_FLAG = 1, * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. */ function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { - var isPartial = bitmask & COMPARE_PARTIAL_FLAG, - arrLength = array.length, - othLength = other.length; + const isPartial = bitmask & COMPARE_PARTIAL_FLAG; + const arrLength = array.length; + const othLength = other.length; if (arrLength != othLength && !(isPartial && othLength > arrLength)) { return false; } // Assume cyclic values are equal. - var stacked = stack.get(array); + const stacked = stack.get(array); if (stacked && stack.get(other)) { return stacked == other; } - var index = -1, - result = true, - seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined; + let index = -1; + let result = true; + const seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined; stack.set(array, other); stack.set(other, array); // Ignore non-index properties. while (++index < arrLength) { - var arrValue = array[index], - othValue = other[index]; + const arrValue = array[index], othValue = other[index]; if (customizer) { var compared = isPartial diff --git a/_equalByTag.js b/_equalByTag.js index ad1200834..c42b4c3ff 100644 --- a/_equalByTag.js +++ b/_equalByTag.js @@ -6,26 +6,26 @@ import mapToArray from './_mapToArray.js'; import setToArray from './_setToArray.js'; /** Used to compose bitmasks for value comparisons. */ -var COMPARE_PARTIAL_FLAG = 1, - COMPARE_UNORDERED_FLAG = 2; +const COMPARE_PARTIAL_FLAG = 1; +const COMPARE_UNORDERED_FLAG = 2; /** `Object#toString` result references. */ -var boolTag = '[object Boolean]', - dateTag = '[object Date]', - errorTag = '[object Error]', - mapTag = '[object Map]', - numberTag = '[object Number]', - regexpTag = '[object RegExp]', - setTag = '[object Set]', - stringTag = '[object String]', - symbolTag = '[object Symbol]'; +const boolTag = '[object Boolean]'; +const dateTag = '[object Date]'; +const errorTag = '[object Error]'; +const mapTag = '[object Map]'; +const numberTag = '[object Number]'; +const regexpTag = '[object RegExp]'; +const setTag = '[object Set]'; +const stringTag = '[object String]'; +const symbolTag = '[object Symbol]'; -var arrayBufferTag = '[object ArrayBuffer]', - dataViewTag = '[object DataView]'; +const arrayBufferTag = '[object ArrayBuffer]'; +const dataViewTag = '[object DataView]'; /** Used to convert symbols to primitives and strings. */ -var symbolProto = Symbol ? Symbol.prototype : undefined, - symbolValueOf = symbolProto ? symbolProto.valueOf : undefined; +const symbolProto = Symbol ? Symbol.prototype : undefined; +const symbolValueOf = symbolProto ? symbolProto.valueOf : undefined; /** * A specialized version of `baseIsEqualDeep` for comparing objects of @@ -79,17 +79,17 @@ function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { return object == `${ other }`; case mapTag: - var convert = mapToArray; + let convert = mapToArray; case setTag: - var isPartial = bitmask & COMPARE_PARTIAL_FLAG; + const isPartial = bitmask & COMPARE_PARTIAL_FLAG; convert || (convert = setToArray); if (object.size != other.size && !isPartial) { return false; } // Assume cyclic values are equal. - var stacked = stack.get(object); + const stacked = stack.get(object); if (stacked) { return stacked == other; } @@ -97,7 +97,7 @@ function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { // Recursively compare objects (susceptible to call stack limits). stack.set(object, other); - var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack); + const result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack); stack['delete'](object); return result; diff --git a/_equalObjects.js b/_equalObjects.js index 9f304ab7a..3949864ae 100644 --- a/_equalObjects.js +++ b/_equalObjects.js @@ -1,13 +1,13 @@ import getAllKeys from './_getAllKeys.js'; /** Used to compose bitmasks for value comparisons. */ -var COMPARE_PARTIAL_FLAG = 1; +const COMPARE_PARTIAL_FLAG = 1; /** Used for built-in method references. */ -var objectProto = Object.prototype; +const objectProto = Object.prototype; /** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; +const hasOwnProperty = objectProto.hasOwnProperty; /** * A specialized version of `baseIsEqualDeep` for objects with support for @@ -23,39 +23,41 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { - var isPartial = bitmask & COMPARE_PARTIAL_FLAG, - objProps = getAllKeys(object), - objLength = objProps.length, - othProps = getAllKeys(other), - othLength = othProps.length; + const isPartial = bitmask & COMPARE_PARTIAL_FLAG; + const objProps = getAllKeys(object); + const objLength = objProps.length; + const othProps = getAllKeys(other); + const othLength = othProps.length; if (objLength != othLength && !isPartial) { return false; } - var index = objLength; + let key; + let index = objLength; while (index--) { - var key = objProps[index]; + key = objProps[index]; if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { return false; } } // Assume cyclic values are equal. - var stacked = stack.get(object); + const stacked = stack.get(object); if (stacked && stack.get(other)) { return stacked == other; } - var result = true; + let result = true; stack.set(object, other); stack.set(other, object); - var skipCtor = isPartial; + let compared; + let skipCtor = isPartial; while (++index < objLength) { key = objProps[index]; - var objValue = object[key], - othValue = other[key]; + const objValue = object[key]; + const othValue = other[key]; if (customizer) { - var compared = isPartial + compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack); } @@ -70,8 +72,8 @@ function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { skipCtor || (skipCtor = key == 'constructor'); } if (result && !skipCtor) { - var objCtor = object.constructor, - othCtor = other.constructor; + const objCtor = object.constructor; + const othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal. if (objCtor != othCtor && diff --git a/_getFuncName.js b/_getFuncName.js index fbb666182..1a3ffc140 100644 --- a/_getFuncName.js +++ b/_getFuncName.js @@ -1,10 +1,10 @@ import realNames from './_realNames.js'; /** Used for built-in method references. */ -var objectProto = Object.prototype; +const objectProto = Object.prototype; /** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; +const hasOwnProperty = objectProto.hasOwnProperty; /** * Gets the name of `func`. @@ -14,13 +14,13 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @returns {string} Returns the function name. */ function getFuncName(func) { - var result = `${ func.name }`, - array = realNames[result], - length = hasOwnProperty.call(realNames, result) ? array.length : 0; + const result = `${ func.name }`; + const array = realNames[result]; + let length = hasOwnProperty.call(realNames, result) ? array.length : 0; while (length--) { - var data = array[length], - otherFunc = data.func; + const data = array[length]; + const otherFunc = data.func; if (otherFunc == null || otherFunc == func) { return data.name; } diff --git a/_getMatchData.js b/_getMatchData.js index 545d3e89f..1aaa1123a 100644 --- a/_getMatchData.js +++ b/_getMatchData.js @@ -9,13 +9,12 @@ import keys from './keys.js'; * @returns {Array} Returns the match data of `object`. */ function getMatchData(object) { - var result = keys(object), - length = result.length; + const result = keys(object); + let length = result.length; while (length--) { - var key = result[length], - value = object[key]; - + const key = result[length]; + const value = object[key]; result[length] = [key, value, isStrictComparable(value)]; } return result; diff --git a/_getRawTag.js b/_getRawTag.js index a89a35b1c..10d9ace22 100644 --- a/_getRawTag.js +++ b/_getRawTag.js @@ -1,20 +1,20 @@ import Symbol from './_Symbol.js'; /** Used for built-in method references. */ -var objectProto = Object.prototype; +const objectProto = Object.prototype; /** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; +const hasOwnProperty = objectProto.hasOwnProperty; /** * Used to resolve the * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) * of values. */ -var nativeObjectToString = objectProto.toString; +const nativeObjectToString = objectProto.toString; /** Built-in value references. */ -var symToStringTag = Symbol ? Symbol.toStringTag : undefined; +const symToStringTag = Symbol ? Symbol.toStringTag : undefined; /** * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. @@ -24,15 +24,15 @@ var symToStringTag = Symbol ? Symbol.toStringTag : undefined; * @returns {string} Returns the raw `toStringTag`. */ function getRawTag(value) { - var isOwn = hasOwnProperty.call(value, symToStringTag), - tag = value[symToStringTag]; + const isOwn = hasOwnProperty.call(value, symToStringTag); + const tag = value[symToStringTag]; try { value[symToStringTag] = undefined; var unmasked = true; } catch (e) {} - var result = nativeObjectToString.call(value); + const result = nativeObjectToString.call(value); if (unmasked) { if (isOwn) { value[symToStringTag] = tag; diff --git a/_getTag.js b/_getTag.js index 0ccc0ee83..695a50d89 100644 --- a/_getTag.js +++ b/_getTag.js @@ -7,20 +7,19 @@ import baseGetTag from './_baseGetTag.js'; import toSource from './_toSource.js'; /** `Object#toString` result references. */ -var mapTag = '[object Map]', - objectTag = '[object Object]', - promiseTag = '[object Promise]', - setTag = '[object Set]', - weakMapTag = '[object WeakMap]'; - -var dataViewTag = '[object DataView]'; +const dataViewTag = '[object DataView]'; +const mapTag = '[object Map]'; +const objectTag = '[object Object]'; +const promiseTag = '[object Promise]'; +const setTag = '[object Set]'; +const weakMapTag = '[object WeakMap]'; /** Used to detect maps, sets, and weakmaps. */ -var dataViewCtorString = toSource(DataView), - mapCtorString = toSource(Map), - promiseCtorString = toSource(Promise), - setCtorString = toSource(Set), - weakMapCtorString = toSource(WeakMap); +const dataViewCtorString = toSource(DataView); +const mapCtorString = toSource(Map); +const promiseCtorString = toSource(Promise); +const setCtorString = toSource(Set); +const weakMapCtorString = toSource(WeakMap); /** * Gets the `toStringTag` of `value`. @@ -29,7 +28,7 @@ var dataViewCtorString = toSource(DataView), * @param {*} value The value to query. * @returns {string} Returns the `toStringTag`. */ -var getTag = baseGetTag; +let getTag = baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || @@ -38,9 +37,9 @@ if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || (Set && getTag(new Set) != setTag) || (WeakMap && getTag(new WeakMap) != weakMapTag)) { getTag = value => { - var result = baseGetTag(value), - Ctor = result == objectTag ? value.constructor : undefined, - ctorString = Ctor ? toSource(Ctor) : ''; + const result = baseGetTag(value); + const Ctor = result == objectTag ? value.constructor : undefined; + const ctorString = Ctor ? toSource(Ctor) : ''; if (ctorString) { switch (ctorString) { diff --git a/_getView.js b/_getView.js index 14fbba4d8..e48dc0546 100644 --- a/_getView.js +++ b/_getView.js @@ -1,6 +1,6 @@ /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMax = Math.max, - nativeMin = Math.min; +const nativeMax = Math.max; +const nativeMin = Math.min; /** * Gets the view, applying any `transforms` to the `start` and `end` positions. @@ -13,12 +13,12 @@ var nativeMax = Math.max, * positions of the view. */ function getView(start, end, transforms) { - var index = -1, - length = transforms.length; + let index = -1; + const length = transforms.length; while (++index < length) { - var data = transforms[index], - size = data.size; + const data = transforms[index]; + const size = data.size; switch (data.type) { case 'drop': start += size; break; diff --git a/_getWrapDetails.js b/_getWrapDetails.js index 1de838d81..54351e4be 100644 --- a/_getWrapDetails.js +++ b/_getWrapDetails.js @@ -1,6 +1,6 @@ /** Used to match wrap detail comments. */ -var reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, - reSplitDetails = /,? & /; +const reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/; +const reSplitDetails = /,? & /; /** * Extracts wrapper details from the `source` body comment. @@ -10,7 +10,7 @@ var reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, * @returns {Array} Returns the wrapper details. */ function getWrapDetails(source) { - var match = source.match(reWrapDetails); + const match = source.match(reWrapDetails); return match ? match[1].split(reSplitDetails) : []; } diff --git a/_hasUnicodeWord.js b/_hasUnicodeWord.js index b2a026093..3d4d3b634 100644 --- a/_hasUnicodeWord.js +++ b/_hasUnicodeWord.js @@ -1,5 +1,5 @@ /** Used to detect strings that need a more robust regexp to match words. */ -var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; +const reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; /** * Checks if `string` contains a word composed of Unicode symbols. diff --git a/_initCloneArray.js b/_initCloneArray.js index 599732e03..138658151 100644 --- a/_initCloneArray.js +++ b/_initCloneArray.js @@ -1,8 +1,8 @@ /** Used for built-in method references. */ -var objectProto = Object.prototype; +const objectProto = Object.prototype; /** Used to check objects for own properties. */ -var hasOwnProperty = objectProto.hasOwnProperty; +const hasOwnProperty = objectProto.hasOwnProperty; /** * Initializes an array clone. @@ -12,8 +12,8 @@ var hasOwnProperty = objectProto.hasOwnProperty; * @returns {Array} Returns the initialized clone. */ function initCloneArray(array) { - var length = array.length, - result = array.constructor(length); + const length = array.length; + const result = array.constructor(length); // Add properties assigned by `RegExp#exec`. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { diff --git a/_isFlattenable.js b/_isFlattenable.js index 3bdef9652..7301c81a9 100644 --- a/_isFlattenable.js +++ b/_isFlattenable.js @@ -3,7 +3,7 @@ import isArguments from './isArguments.js'; import isArray from './isArray.js'; /** Built-in value references. */ -var spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; +const spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; /** * Checks if `value` is a flattenable `arguments` object or array. diff --git a/_isIndex.js b/_isIndex.js index 0381ad086..9c5aa51ad 100644 --- a/_isIndex.js +++ b/_isIndex.js @@ -1,8 +1,8 @@ /** Used as references for various `Number` constants. */ -var MAX_SAFE_INTEGER = 9007199254740991; +const MAX_SAFE_INTEGER = 9007199254740991; /** Used to detect unsigned integer values. */ -var reIsUint = /^(?:0|[1-9]\d*)$/; +const reIsUint = /^(?:0|[1-9]\d*)$/; /** * Checks if `value` is a valid array-like index. diff --git a/_isIterateeCall.js b/_isIterateeCall.js index 1fb6dc93d..bf5f4686d 100644 --- a/_isIterateeCall.js +++ b/_isIterateeCall.js @@ -17,7 +17,7 @@ function isIterateeCall(value, index, object) { if (!isObject(object)) { return false; } - var type = typeof index; + const type = typeof index; if (type == 'number' ? (isArrayLike(object) && isIndex(index, object.length)) : (type == 'string' && index in object) diff --git a/_isKey.js b/_isKey.js index 3e36bce80..444c70207 100644 --- a/_isKey.js +++ b/_isKey.js @@ -2,8 +2,8 @@ import isArray from './isArray.js'; import isSymbol from './isSymbol.js'; /** Used to match property names within property paths. */ -var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, - reIsPlainProp = /^\w*$/; +const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/; +const reIsPlainProp = /^\w*$/; /** * Checks if `value` is a property name and not a property path. @@ -17,7 +17,7 @@ function isKey(value, object) { if (isArray(value)) { return false; } - var type = typeof value; + const type = typeof value; if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol(value)) { return true; diff --git a/_isKeyable.js b/_isKeyable.js index 22715962e..0931e86ef 100644 --- a/_isKeyable.js +++ b/_isKeyable.js @@ -6,7 +6,7 @@ * @returns {boolean} Returns `true` if `value` is suitable, else `false`. */ function isKeyable(value) { - var type = typeof value; + const type = typeof value; return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') ? (value !== '__proto__') : (value === null); diff --git a/_isMaskable.js b/_isMaskable.js index 4c17c1c0a..18caa73fe 100644 --- a/_isMaskable.js +++ b/_isMaskable.js @@ -9,6 +9,6 @@ import stubFalse from './stubFalse.js'; * @param {*} value The value to check. * @returns {boolean} Returns `true` if `func` is maskable, else `false`. */ -var isMaskable = coreJsData ? isFunction : stubFalse; +const isMaskable = coreJsData ? isFunction : stubFalse; export default isMaskable; diff --git a/_isMasked.js b/_isMasked.js index f66a96c65..4f0aafc63 100644 --- a/_isMasked.js +++ b/_isMasked.js @@ -1,7 +1,7 @@ import coreJsData from './_coreJsData.js'; /** Used to detect methods masquerading as native. */ -var maskSrcKey = ((() => { +const maskSrcKey = ((() => { const uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); return uid ? `Symbol(src)_1.${ uid }` : ''; })()); diff --git a/_isPrototype.js b/_isPrototype.js index f6c7660d0..40630a2d8 100644 --- a/_isPrototype.js +++ b/_isPrototype.js @@ -1,5 +1,5 @@ /** Used for built-in method references. */ -var objectProto = Object.prototype; +const objectProto = Object.prototype; /** * Checks if `value` is likely a prototype object. @@ -9,8 +9,8 @@ var objectProto = Object.prototype; * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. */ function isPrototype(value) { - var Ctor = value && value.constructor, - proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; + const Ctor = value && value.constructor; + const proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; return value === proto; } diff --git a/_iteratorToArray.js b/_iteratorToArray.js index 315bf2bfe..59fb72054 100644 --- a/_iteratorToArray.js +++ b/_iteratorToArray.js @@ -6,8 +6,8 @@ * @returns {Array} Returns the converted array. */ function iteratorToArray(iterator) { - var data, - result = []; + let data; + const result = []; while (!(data = iterator.next()).done) { result.push(data.value); diff --git a/_mapCacheDelete.js b/_mapCacheDelete.js index 1afc18fe2..4f014e047 100644 --- a/_mapCacheDelete.js +++ b/_mapCacheDelete.js @@ -10,7 +10,7 @@ import getMapData from './_getMapData.js'; * @returns {boolean} Returns `true` if the entry was removed, else `false`. */ function mapCacheDelete(key) { - var result = getMapData(this, key)['delete'](key); + const result = getMapData(this, key)['delete'](key); this.size -= result ? 1 : 0; return result; } diff --git a/_mapCacheSet.js b/_mapCacheSet.js index e757c360e..ebf879f57 100644 --- a/_mapCacheSet.js +++ b/_mapCacheSet.js @@ -11,8 +11,8 @@ import getMapData from './_getMapData.js'; * @returns {Object} Returns the map cache instance. */ function mapCacheSet(key, value) { - var data = getMapData(this, key), - size = data.size; + const data = getMapData(this, key); + const size = data.size; data.set(key, value); this.size += data.size == size ? 0 : 1; diff --git a/_reEscape.js b/_reEscape.js index cd3729b18..1063b8c5c 100644 --- a/_reEscape.js +++ b/_reEscape.js @@ -1,4 +1,4 @@ /** Used to match template delimiters. */ -var reEscape = /<%-([\s\S]+?)%>/g; +const reEscape = /<%-([\s\S]+?)%>/g; export default reEscape; diff --git a/_reEvaluate.js b/_reEvaluate.js index 563964bf8..dee63eef7 100644 --- a/_reEvaluate.js +++ b/_reEvaluate.js @@ -1,4 +1,4 @@ /** Used to match template delimiters. */ -var reEvaluate = /<%([\s\S]+?)%>/g; +const reEvaluate = /<%([\s\S]+?)%>/g; export default reEvaluate; diff --git a/_reInterpolate.js b/_reInterpolate.js index a3cdb20e9..5124ab755 100644 --- a/_reInterpolate.js +++ b/_reInterpolate.js @@ -1,4 +1,4 @@ /** Used to match template delimiters. */ -var reInterpolate = /<%=([\s\S]+?)%>/g; +const reInterpolate = /<%=([\s\S]+?)%>/g; export default reInterpolate; diff --git a/_realNames.js b/_realNames.js index df195edda..f5ae5baa9 100644 --- a/_realNames.js +++ b/_realNames.js @@ -1,4 +1,4 @@ /** Used to lookup unminified function names. */ -var realNames = {}; +const realNames = {}; export default realNames; diff --git a/_setData.js b/_setData.js index 8b6bac9a7..5de154952 100644 --- a/_setData.js +++ b/_setData.js @@ -15,6 +15,6 @@ import shortOut from './_shortOut.js'; * @param {*} data The metadata. * @returns {Function} Returns `func`. */ -var setData = shortOut(baseSetData); +const setData = shortOut(baseSetData); export default setData; diff --git a/_setToArray.js b/_setToArray.js index 2eb13f7c7..6fb730a15 100644 --- a/_setToArray.js +++ b/_setToArray.js @@ -6,8 +6,8 @@ * @returns {Array} Returns the values. */ function setToArray(set) { - var index = -1, - result = Array(set.size); + let index = -1; + const result = Array(set.size); set.forEach(value => { result[++index] = value; diff --git a/_setToString.js b/_setToString.js index db2dd26cb..cabd82c79 100644 --- a/_setToString.js +++ b/_setToString.js @@ -9,6 +9,6 @@ import shortOut from './_shortOut.js'; * @param {Function} string The `toString` result. * @returns {Function} Returns `func`. */ -var setToString = shortOut(baseSetToString); +const setToString = shortOut(baseSetToString); export default setToString; diff --git a/_shuffleSelf.js b/_shuffleSelf.js index a04ebea15..431dee6bd 100644 --- a/_shuffleSelf.js +++ b/_shuffleSelf.js @@ -9,14 +9,14 @@ import baseRandom from './_baseRandom.js'; * @returns {Array} Returns `array`. */ function shuffleSelf(array, size) { - var index = -1, - length = array.length, - lastIndex = length - 1; + let index = -1; + const length = array.length; + const lastIndex = length - 1; size = size === undefined ? length : size; while (++index < size) { - var rand = baseRandom(index, lastIndex), - value = array[rand]; + const rand = baseRandom(index, lastIndex); + const value = array[rand]; array[rand] = array[index]; array[index] = value; diff --git a/reject.js b/reject.js index f3a1c55d8..9e395bbcc 100644 --- a/reject.js +++ b/reject.js @@ -39,7 +39,7 @@ import negate from './negate.js'; * // => objects for ['barney'] */ function reject(collection, predicate) { - var func = isArray(collection) ? arrayFilter : baseFilter; + const func = isArray(collection) ? arrayFilter : baseFilter; return func(collection, negate(baseIteratee(predicate, 3))); } diff --git a/rest.js b/rest.js index c46042548..cad060b27 100644 --- a/rest.js +++ b/rest.js @@ -2,7 +2,7 @@ import baseRest from './_baseRest.js'; import toInteger from './toInteger.js'; /** Error message constants. */ -var FUNC_ERROR_TEXT = 'Expected a function'; +const FUNC_ERROR_TEXT = 'Expected a function'; /** * Creates a function that invokes `func` with the `this` binding of the diff --git a/result.js b/result.js index fe519c817..7628f5c2d 100644 --- a/result.js +++ b/result.js @@ -34,8 +34,8 @@ import toKey from './_toKey.js'; function result(object, path, defaultValue) { path = castPath(path, object); - var index = -1, - length = path.length; + let index = -1; + let length = path.length; // Ensure the loop is entered when path is empty. if (!length) { @@ -43,7 +43,7 @@ function result(object, path, defaultValue) { object = undefined; } while (++index < length) { - var value = object == null ? undefined : object[toKey(path[index])]; + let value = object == null ? undefined : object[toKey(path[index])]; if (value === undefined) { index = length; value = defaultValue; diff --git a/reverse.js b/reverse.js index 33156a237..178abbbd7 100644 --- a/reverse.js +++ b/reverse.js @@ -1,8 +1,8 @@ /** Used for built-in method references. */ -var arrayProto = Array.prototype; +const arrayProto = Array.prototype; /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeReverse = arrayProto.reverse; +const nativeReverse = arrayProto.reverse; /** * Reverses `array` so that the first element becomes the last, the second diff --git a/round.js b/round.js index f4616dc29..20caf9529 100644 --- a/round.js +++ b/round.js @@ -21,6 +21,6 @@ import createRound from './_createRound.js'; * _.round(4060, -2); * // => 4100 */ -var round = createRound('round'); +const round = createRound('round'); export default round; diff --git a/sample.js b/sample.js index bebe5699e..1276c366e 100644 --- a/sample.js +++ b/sample.js @@ -17,7 +17,7 @@ import isArray from './isArray.js'; * // => 2 */ function sample(collection) { - var func = isArray(collection) ? arraySample : baseSample; + const func = isArray(collection) ? arraySample : baseSample; return func(collection); } diff --git a/sampleSize.js b/sampleSize.js index 152bedb89..2fba70eb2 100644 --- a/sampleSize.js +++ b/sampleSize.js @@ -30,7 +30,7 @@ function sampleSize(collection, n, guard) { } else { n = toInteger(n); } - var func = isArray(collection) ? arraySampleSize : baseSampleSize; + const func = isArray(collection) ? arraySampleSize : baseSampleSize; return func(collection, n); } diff --git a/shuffle.js b/shuffle.js index 690769999..8b0a93cf9 100644 --- a/shuffle.js +++ b/shuffle.js @@ -18,7 +18,7 @@ import isArray from './isArray.js'; * // => [4, 1, 3, 2] */ function shuffle(collection) { - var func = isArray(collection) ? arrayShuffle : baseShuffle; + const func = isArray(collection) ? arrayShuffle : baseShuffle; return func(collection); } diff --git a/size.js b/size.js index b808aaac4..d62b17a20 100644 --- a/size.js +++ b/size.js @@ -5,8 +5,8 @@ import isString from './isString.js'; import stringSize from './_stringSize.js'; /** `Object#toString` result references. */ -var mapTag = '[object Map]', - setTag = '[object Set]'; +const mapTag = '[object Map]'; +const setTag = '[object Set]'; /** * Gets the size of `collection` by returning its length for array-like @@ -36,7 +36,7 @@ function size(collection) { if (isArrayLike(collection)) { return isString(collection) ? stringSize(collection) : collection.length; } - var tag = getTag(collection); + const tag = getTag(collection); if (tag == mapTag || tag == setTag) { return collection.size; } diff --git a/slice.js b/slice.js index 02d03d7ea..ef3540670 100644 --- a/slice.js +++ b/slice.js @@ -19,7 +19,7 @@ import toInteger from './toInteger.js'; * @returns {Array} Returns the slice of `array`. */ function slice(array, start, end) { - var length = array == null ? 0 : array.length; + const length = array == null ? 0 : array.length; if (!length) { return []; } diff --git a/some.js b/some.js index 27f1996e1..f998bebcb 100644 --- a/some.js +++ b/some.js @@ -41,7 +41,7 @@ import isIterateeCall from './_isIterateeCall.js'; * // => true */ function some(collection, predicate, guard) { - var func = isArray(collection) ? arraySome : baseSome; + const func = isArray(collection) ? arraySome : baseSome; if (guard && isIterateeCall(collection, predicate, guard)) { predicate = undefined; } diff --git a/sortedIndexOf.js b/sortedIndexOf.js index f9410d79a..998a00509 100644 --- a/sortedIndexOf.js +++ b/sortedIndexOf.js @@ -18,9 +18,9 @@ import eq from './eq.js'; * // => 1 */ function sortedIndexOf(array, value) { - var length = array == null ? 0 : array.length; + const length = array == null ? 0 : array.length; if (length) { - var index = baseSortedIndex(array, value); + const index = baseSortedIndex(array, value); if (index < length && eq(array[index], value)) { return index; } diff --git a/sortedLastIndexOf.js b/sortedLastIndexOf.js index 802ebe4fa..7dfa07186 100644 --- a/sortedLastIndexOf.js +++ b/sortedLastIndexOf.js @@ -18,9 +18,9 @@ import eq from './eq.js'; * // => 3 */ function sortedLastIndexOf(array, value) { - var length = array == null ? 0 : array.length; + const length = array == null ? 0 : array.length; if (length) { - var index = baseSortedIndex(array, value, true) - 1; + const index = baseSortedIndex(array, value, true) - 1; if (eq(array[index], value)) { return index; } diff --git a/split.js b/split.js index ad3681213..28fc2257d 100644 --- a/split.js +++ b/split.js @@ -7,7 +7,7 @@ import stringToArray from './_stringToArray.js'; import toString from './toString.js'; /** Used as references for the maximum length and index of an array. */ -var MAX_ARRAY_LENGTH = 4294967295; +const MAX_ARRAY_LENGTH = 4294967295; /** * Splits `string` by `separator`. diff --git a/spread.js b/spread.js index 3fb8b2388..93554d2dd 100644 --- a/spread.js +++ b/spread.js @@ -5,10 +5,10 @@ import castSlice from './_castSlice.js'; import toInteger from './toInteger.js'; /** Error message constants. */ -var FUNC_ERROR_TEXT = 'Expected a function'; +const FUNC_ERROR_TEXT = 'Expected a function'; /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMax = Math.max; +const nativeMax = Math.max; /** * Creates a function that invokes `func` with the `this` binding of the @@ -50,8 +50,8 @@ function spread(func, start) { } start = start == null ? 0 : nativeMax(toInteger(start), 0); return baseRest(function(args) { - var array = args[start], - otherArgs = castSlice(args, 0, start); + const array = args[start]; + const otherArgs = castSlice(args, 0, start); if (array) { arrayPush(otherArgs, array); diff --git a/startCase.js b/startCase.js index 95db2ec44..c4dfd36b7 100644 --- a/startCase.js +++ b/startCase.js @@ -22,6 +22,6 @@ import upperFirst from './upperFirst.js'; * _.startCase('__FOO_BAR__'); * // => 'FOO BAR' */ -var startCase = createCompounder((result, word, index) => result + (index ? ' ' : '') + upperFirst(word)); +const startCase = createCompounder((result, word, index) => result + (index ? ' ' : '') + upperFirst(word)); export default startCase; diff --git a/subtract.js b/subtract.js index dc238a551..6d84303d1 100644 --- a/subtract.js +++ b/subtract.js @@ -15,6 +15,6 @@ import createMathOperation from './_createMathOperation.js'; * _.subtract(6, 4); * // => 2 */ -var subtract = createMathOperation((minuend, subtrahend) => minuend - subtrahend, 0); +const subtract = createMathOperation((minuend, subtrahend) => minuend - subtrahend, 0); export default subtract; diff --git a/tail.js b/tail.js index d8b979616..3ed78b750 100644 --- a/tail.js +++ b/tail.js @@ -15,7 +15,7 @@ import baseSlice from './_baseSlice.js'; * // => [2, 3] */ function tail(array) { - var length = array == null ? 0 : array.length; + const length = array == null ? 0 : array.length; return length ? baseSlice(array, 1, length) : []; } diff --git a/takeRight.js b/takeRight.js index 36399de8e..1458fcb9f 100644 --- a/takeRight.js +++ b/takeRight.js @@ -27,7 +27,7 @@ import toInteger from './toInteger.js'; * // => [] */ function takeRight(array, n, guard) { - var length = array == null ? 0 : array.length; + const length = array == null ? 0 : array.length; if (!length) { return []; } diff --git a/template.js b/template.js index 6598b846f..15c1014e8 100644 --- a/template.js +++ b/template.js @@ -11,21 +11,21 @@ import templateSettings from './templateSettings.js'; import toString from './toString.js'; /** Used to match empty string literals in compiled template source. */ -var reEmptyStringLeading = /\b__p \+= '';/g, - reEmptyStringMiddle = /\b(__p \+=) '' \+/g, - reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; +const reEmptyStringLeading = /\b__p \+= '';/g; +const reEmptyStringMiddle = /\b(__p \+=) '' \+/g; +const reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; /** * Used to match * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). */ -var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; +const reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; /** Used to ensure capturing order of template delimiters. */ -var reNoMatch = /($^)/; +const reNoMatch = /($^)/; /** Used to match unescaped characters in compiled string literals. */ -var reUnescapedString = /['\n\r\u2028\u2029\\]/g; +const reUnescapedString = /['\n\r\u2028\u2029\\]/g; /** * Creates a compiled template function that can interpolate data properties @@ -135,7 +135,7 @@ function template(string, options, guard) { // Based on John Resig's `tmpl` implementation // (http://ejohn.org/blog/javascript-micro-templating/) // and Laura Doktorova's doT.js (https://github.com/olado/doT). - var settings = templateSettings.imports._.templateSettings || templateSettings; + let settings = templateSettings.imports._.templateSettings || templateSettings; if (guard && isIterateeCall(string, options, guard)) { options = undefined; @@ -143,18 +143,19 @@ function template(string, options, guard) { string = toString(string); options = assignInWith({}, options, settings, customDefaultsAssignIn); - var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn), - importsKeys = keys(imports), - importsValues = baseValues(imports, importsKeys); + const imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn); + const importsKeys = keys(imports); + const importsValues = baseValues(imports, importsKeys); - var isEscaping, - isEvaluating, - index = 0, - interpolate = options.interpolate || reNoMatch, - source = "__p += '"; + let isEscaping; + let isEvaluating; + let index = 0; + + const interpolate = options.interpolate || reNoMatch; + let source = "__p += '"; // Compile the regexp to match each delimiter. - var reDelimiters = RegExp( + const reDelimiters = RegExp( (options.escape || reNoMatch).source + '|' + interpolate.source + '|' + (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + @@ -162,7 +163,7 @@ function template(string, options, guard) { , 'g'); // Use a sourceURL for easier debugging. - var sourceURL = 'sourceURL' in options ? `//# sourceURL=${ options.sourceURL }\n` : ''; + const sourceURL = 'sourceURL' in options ? `//# sourceURL=${ options.sourceURL }\n` : ''; string.replace(reDelimiters, ( match, @@ -200,7 +201,7 @@ function template(string, options, guard) { // If `variable` is not specified wrap a with-statement around the generated // code to add the data object to the top of the scope chain. - var variable = options.variable; + const variable = options.variable; if (!variable) { source = `with (obj) {\n${ source }\n}\n`; } @@ -228,7 +229,7 @@ function template(string, options, guard) { source + 'return __p\n}'; - var result = attempt(() => Function(importsKeys, `${ sourceURL }return ${ source }`))(...importsValues); + const result = attempt(() => Function(importsKeys, `${ sourceURL }return ${ source }`))(...importsValues); // Provide the compiled function's source by its `toString` method or // the `source` property as a convenience for inlining compiled templates. diff --git a/templateSettings.js b/templateSettings.js index 5fe73e97a..296b04c42 100644 --- a/templateSettings.js +++ b/templateSettings.js @@ -12,7 +12,7 @@ import reInterpolate from './_reInterpolate.js'; * @memberOf _ * @type {Object} */ -var templateSettings = { +const templateSettings = { /** * Used to detect `data` property values to be HTML-escaped. diff --git a/throttle.js b/throttle.js index f3cf43f19..b8944a7e7 100644 --- a/throttle.js +++ b/throttle.js @@ -2,7 +2,7 @@ import debounce from './debounce.js'; import isObject from './isObject.js'; /** Error message constants. */ -var FUNC_ERROR_TEXT = 'Expected a function'; +const FUNC_ERROR_TEXT = 'Expected a function'; /** * Creates a throttled function that only invokes `func` at most once per @@ -49,8 +49,8 @@ var FUNC_ERROR_TEXT = 'Expected a function'; * jQuery(window).on('popstate', throttled.cancel); */ function throttle(func, wait, options) { - var leading = true, - trailing = true; + let leading = true; + let trailing = true; if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); diff --git a/times.js b/times.js index 910c9264a..935985a53 100644 --- a/times.js +++ b/times.js @@ -3,13 +3,13 @@ import castFunction from './_castFunction.js'; import toInteger from './toInteger.js'; /** Used as references for various `Number` constants. */ -var MAX_SAFE_INTEGER = 9007199254740991; +const MAX_SAFE_INTEGER = 9007199254740991; /** Used as references for the maximum length and index of an array. */ -var MAX_ARRAY_LENGTH = 4294967295; +const MAX_ARRAY_LENGTH = 4294967295; /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMin = Math.min; +const nativeMin = Math.min; /** * Invokes the iteratee `n` times, returning an array of the results of @@ -35,13 +35,13 @@ function times(n, iteratee) { if (n < 1 || n > MAX_SAFE_INTEGER) { return []; } - var index = MAX_ARRAY_LENGTH, - length = nativeMin(n, MAX_ARRAY_LENGTH); + let index = MAX_ARRAY_LENGTH; + const length = nativeMin(n, MAX_ARRAY_LENGTH); iteratee = castFunction(iteratee); n -= MAX_ARRAY_LENGTH; - var result = baseTimes(length, iteratee); + const result = baseTimes(length, iteratee); while (++index < n) { iteratee(index); } diff --git a/toArray.js b/toArray.js index 5afa02854..7259aabca 100644 --- a/toArray.js +++ b/toArray.js @@ -10,11 +10,11 @@ import stringToArray from './_stringToArray.js'; import values from './values.js'; /** `Object#toString` result references. */ -var mapTag = '[object Map]', - setTag = '[object Set]'; +const mapTag = '[object Map]'; +const setTag = '[object Set]'; /** Built-in value references. */ -var symIterator = Symbol ? Symbol.iterator : undefined; +const symIterator = Symbol ? Symbol.iterator : undefined; /** * Converts `value` to an array. @@ -49,8 +49,8 @@ function toArray(value) { if (symIterator && value[symIterator]) { return iteratorToArray(value[symIterator]()); } - var tag = getTag(value), - func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); + const tag = getTag(value); + const func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); return func(value); } diff --git a/toFinite.js b/toFinite.js index ac06b7c99..4e4592efb 100644 --- a/toFinite.js +++ b/toFinite.js @@ -1,8 +1,8 @@ import toNumber from './toNumber.js'; /** Used as references for various `Number` constants. */ -var INFINITY = 1 / 0, - MAX_INTEGER = 1.7976931348623157e+308; +const INFINITY = 1 / 0; +const MAX_INTEGER = 1.7976931348623157e+308; /** * Converts `value` to a finite number. @@ -33,7 +33,7 @@ function toFinite(value) { } value = toNumber(value); if (value === INFINITY || value === -INFINITY) { - var sign = (value < 0 ? -1 : 1); + const sign = (value < 0 ? -1 : 1); return sign * MAX_INTEGER; } return value === value ? value : 0; diff --git a/toInteger.js b/toInteger.js index 6d6118c92..575ed74bc 100644 --- a/toInteger.js +++ b/toInteger.js @@ -27,8 +27,8 @@ import toFinite from './toFinite.js'; * // => 3 */ function toInteger(value) { - var result = toFinite(value), - remainder = result % 1; + const result = toFinite(value); + const remainder = result % 1; return result === result ? (remainder ? result - remainder : result) : 0; } diff --git a/toLength.js b/toLength.js index 711045562..e4901d2d8 100644 --- a/toLength.js +++ b/toLength.js @@ -2,7 +2,7 @@ import baseClamp from './_baseClamp.js'; import toInteger from './toInteger.js'; /** Used as references for the maximum length and index of an array. */ -var MAX_ARRAY_LENGTH = 4294967295; +const MAX_ARRAY_LENGTH = 4294967295; /** * Converts `value` to an integer suitable for use as the length of an diff --git a/toNumber.js b/toNumber.js index 7f682ea9c..251c9e020 100644 --- a/toNumber.js +++ b/toNumber.js @@ -2,22 +2,22 @@ import isObject from './isObject.js'; import isSymbol from './isSymbol.js'; /** Used as references for various `Number` constants. */ -var NAN = 0 / 0; +const NAN = 0 / 0; /** Used to match leading and trailing whitespace. */ -var reTrim = /^\s+|\s+$/g; +const reTrim = /^\s+|\s+$/g; /** Used to detect bad signed hexadecimal string values. */ -var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; +const reIsBadHex = /^[-+]0x[0-9a-f]+$/i; /** Used to detect binary string values. */ -var reIsBinary = /^0b[01]+$/i; +const reIsBinary = /^0b[01]+$/i; /** Used to detect octal string values. */ -var reIsOctal = /^0o[0-7]+$/i; +const reIsOctal = /^0o[0-7]+$/i; /** Built-in method references without a dependency on `root`. */ -var freeParseInt = parseInt; +const freeParseInt = parseInt; /** * Converts `value` to a number. @@ -50,14 +50,14 @@ function toNumber(value) { return NAN; } if (isObject(value)) { - var other = typeof value.valueOf == 'function' ? value.valueOf() : value; + const other = typeof value.valueOf == 'function' ? value.valueOf() : value; value = isObject(other) ? `${ other }` : other; } if (typeof value != 'string') { return value === 0 ? value : +value; } value = value.replace(reTrim, ''); - var isBinary = reIsBinary.test(value); + const isBinary = reIsBinary.test(value); return (isBinary || reIsOctal.test(value)) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : (reIsBadHex.test(value) ? NAN : +value); diff --git a/toPairs.js b/toPairs.js index d3e0a2ef6..24282b61b 100644 --- a/toPairs.js +++ b/toPairs.js @@ -25,6 +25,6 @@ import keys from './keys.js'; * _.toPairs(new Foo); * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) */ -var toPairs = createToPairs(keys); +const toPairs = createToPairs(keys); export default toPairs; diff --git a/toPairsIn.js b/toPairsIn.js index 0d46b45f8..b18dc2efd 100644 --- a/toPairsIn.js +++ b/toPairsIn.js @@ -25,6 +25,6 @@ import keysIn from './keysIn.js'; * _.toPairsIn(new Foo); * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) */ -var toPairsIn = createToPairs(keysIn); +const toPairsIn = createToPairs(keysIn); export default toPairsIn; diff --git a/toSafeInteger.js b/toSafeInteger.js index 6aecc0ab0..bd87d53dd 100644 --- a/toSafeInteger.js +++ b/toSafeInteger.js @@ -2,7 +2,7 @@ import baseClamp from './_baseClamp.js'; import toInteger from './toInteger.js'; /** Used as references for various `Number` constants. */ -var MAX_SAFE_INTEGER = 9007199254740991; +const MAX_SAFE_INTEGER = 9007199254740991; /** * Converts `value` to a safe integer. A safe integer can be compared and diff --git a/transform.js b/transform.js index 05ade4c1f..ef743a3b1 100644 --- a/transform.js +++ b/transform.js @@ -40,12 +40,12 @@ import isTypedArray from './isTypedArray.js'; * // => { '1': ['a', 'c'], '2': ['b'] } */ function transform(object, iteratee, accumulator) { - var isArr = isArray(object), - isArrLike = isArr || isBuffer(object) || isTypedArray(object); + const isArr = isArray(object); + const isArrLike = isArr || isBuffer(object) || isTypedArray(object); iteratee = baseIteratee(iteratee, 4); if (accumulator == null) { - var Ctor = object && object.constructor; + const Ctor = object && object.constructor; if (isArrLike) { accumulator = isArr ? new Ctor : []; } diff --git a/trim.js b/trim.js index 11ec4d7d3..685f3871a 100644 --- a/trim.js +++ b/trim.js @@ -6,7 +6,7 @@ import stringToArray from './_stringToArray.js'; import toString from './toString.js'; /** Used to match leading and trailing whitespace. */ -var reTrim = /^\s+|\s+$/g; +const reTrim = /^\s+|\s+$/g; /** * Removes leading and trailing whitespace or specified characters from `string`. @@ -38,10 +38,10 @@ function trim(string, chars, guard) { if (!string || !(chars = baseToString(chars))) { return string; } - var strSymbols = stringToArray(string), - chrSymbols = stringToArray(chars), - start = charsStartIndex(strSymbols, chrSymbols), - end = charsEndIndex(strSymbols, chrSymbols) + 1; + const strSymbols = stringToArray(string); + const chrSymbols = stringToArray(chars); + const start = charsStartIndex(strSymbols, chrSymbols); + const end = charsEndIndex(strSymbols, chrSymbols) + 1; return castSlice(strSymbols, start, end).join(''); } diff --git a/trimEnd.js b/trimEnd.js index 4215af3d4..13f5c7c9b 100644 --- a/trimEnd.js +++ b/trimEnd.js @@ -5,7 +5,7 @@ import stringToArray from './_stringToArray.js'; import toString from './toString.js'; /** Used to match leading and trailing whitespace. */ -var reTrimEnd = /\s+$/; +const reTrimEnd = /\s+$/; /** * Removes trailing whitespace or specified characters from `string`. @@ -34,9 +34,8 @@ function trimEnd(string, chars, guard) { if (!string || !(chars = baseToString(chars))) { return string; } - var strSymbols = stringToArray(string), - end = charsEndIndex(strSymbols, stringToArray(chars)) + 1; - + const strSymbols = stringToArray(string); + const end = charsEndIndex(strSymbols, stringToArray(chars)) + 1; return castSlice(strSymbols, 0, end).join(''); } diff --git a/trimStart.js b/trimStart.js index aa00c50f3..9c3bc1202 100644 --- a/trimStart.js +++ b/trimStart.js @@ -5,7 +5,7 @@ import stringToArray from './_stringToArray.js'; import toString from './toString.js'; /** Used to match leading and trailing whitespace. */ -var reTrimStart = /^\s+/; +const reTrimStart = /^\s+/; /** * Removes leading whitespace or specified characters from `string`. @@ -34,9 +34,8 @@ function trimStart(string, chars, guard) { if (!string || !(chars = baseToString(chars))) { return string; } - var strSymbols = stringToArray(string), - start = charsStartIndex(strSymbols, stringToArray(chars)); - + const strSymbols = stringToArray(string); + const start = charsStartIndex(strSymbols, stringToArray(chars)); return castSlice(strSymbols, start).join(''); } diff --git a/truncate.js b/truncate.js index cee98d6cc..ffbbd60de 100644 --- a/truncate.js +++ b/truncate.js @@ -9,11 +9,11 @@ import toInteger from './toInteger.js'; import toString from './toString.js'; /** Used as default options for `_.truncate`. */ -var DEFAULT_TRUNC_LENGTH = 30, - DEFAULT_TRUNC_OMISSION = '...'; +const DEFAULT_TRUNC_LENGTH = 30; +const DEFAULT_TRUNC_OMISSION = '...'; /** Used to match `RegExp` flags from their coerced string values. */ -var reFlags = /\w*$/; +const reFlags = /\w*$/; /** * Truncates `string` if it's longer than the given maximum string length. @@ -53,29 +53,31 @@ var reFlags = /\w*$/; * // => 'hi-diddly-ho there, neig [...]' */ function truncate(string, options) { - var length = DEFAULT_TRUNC_LENGTH, - omission = DEFAULT_TRUNC_OMISSION; + let separator; + let length = DEFAULT_TRUNC_LENGTH; + let omission = DEFAULT_TRUNC_OMISSION; if (isObject(options)) { - var separator = 'separator' in options ? options.separator : separator; + separator = 'separator' in options ? options.separator : separator; length = 'length' in options ? toInteger(options.length) : length; omission = 'omission' in options ? baseToString(options.omission) : omission; } string = toString(string); - var strLength = string.length; + let strSymbols; + let strLength = string.length; if (hasUnicode(string)) { - var strSymbols = stringToArray(string); + strSymbols = stringToArray(string); strLength = strSymbols.length; } if (length >= strLength) { return string; } - var end = length - stringSize(omission); + let end = length - stringSize(omission); if (end < 1) { return omission; } - var result = strSymbols + let result = strSymbols ? castSlice(strSymbols, 0, end).join('') : string.slice(0, end); @@ -87,20 +89,21 @@ function truncate(string, options) { } if (isRegExp(separator)) { if (string.slice(end).search(separator)) { - var match, - substring = result; + let match; + let newEnd; + const substring = result; if (!separator.global) { separator = RegExp(separator.source, `${ toString(reFlags.exec(separator)) }g`); } separator.lastIndex = 0; while ((match = separator.exec(substring))) { - var newEnd = match.index; + newEnd = match.index; } result = result.slice(0, newEnd === undefined ? end : newEnd); } } else if (string.indexOf(baseToString(separator), end) != end) { - var index = result.lastIndexOf(separator); + const index = result.lastIndexOf(separator); if (index > -1) { result = result.slice(0, index); } diff --git a/unescape.js b/unescape.js index 86a85e493..4356439ec 100644 --- a/unescape.js +++ b/unescape.js @@ -2,8 +2,8 @@ import toString from './toString.js'; import unescapeHtmlChar from './_unescapeHtmlChar.js'; /** Used to match HTML entities and HTML characters. */ -var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, - reHasEscapedHtml = RegExp(reEscapedHtml.source); +const reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g; +const reHasEscapedHtml = RegExp(reEscapedHtml.source); /** * The inverse of `_.escape`; this method converts the HTML entities diff --git a/unionWith.js b/unionWith.js index d0c9c52e1..0cd1ec72a 100644 --- a/unionWith.js +++ b/unionWith.js @@ -1,5 +1,4 @@ import baseFlatten from './_baseFlatten.js'; -import baseRest from './_baseRest.js'; import baseUniq from './_baseUniq.js'; import isArrayLikeObject from './isArrayLikeObject.js'; import last from './last.js'; @@ -25,10 +24,10 @@ import last from './last.js'; * _.unionWith(objects, others, _.isEqual); * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] */ -var unionWith = baseRest(arrays => { - var comparator = last(arrays); +function unionWith(...arrays) { + let comparator = last(arrays); comparator = typeof comparator == 'function' ? comparator : undefined; return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator); -}); +} export default unionWith; diff --git a/uniqueId.js b/uniqueId.js index d775c7e44..1a48b2c29 100644 --- a/uniqueId.js +++ b/uniqueId.js @@ -1,7 +1,7 @@ import toString from './toString.js'; /** Used to generate unique IDs. */ -var idCounter = 0; +let idCounter = 0; /** * Generates a unique ID. If `prefix` is given, the ID is appended to it. @@ -21,7 +21,7 @@ var idCounter = 0; * // => '105' */ function uniqueId(prefix) { - var id = ++idCounter; + const id = ++idCounter; return toString(prefix) + id; } diff --git a/unzip.js b/unzip.js index db5075011..024626b7d 100644 --- a/unzip.js +++ b/unzip.js @@ -5,7 +5,7 @@ import baseTimes from './_baseTimes.js'; import isArrayLikeObject from './isArrayLikeObject.js'; /* Built-in method references for those with the same name as other `lodash` methods. */ -var nativeMax = Math.max; +const nativeMax = Math.max; /** * This method is like `_.zip` except that it accepts an array of grouped @@ -30,7 +30,7 @@ function unzip(array) { if (!(array && array.length)) { return []; } - var length = 0; + let length = 0; array = arrayFilter(array, group => { if (isArrayLikeObject(group)) { length = nativeMax(group.length, length); diff --git a/unzipWith.js b/unzipWith.js index 7006bf9e1..a4b83a8c3 100644 --- a/unzipWith.js +++ b/unzipWith.js @@ -27,7 +27,7 @@ function unzipWith(array, iteratee) { if (!(array && array.length)) { return []; } - var result = unzip(array); + const result = unzip(array); if (iteratee == null) { return result; } diff --git a/upperFirst.js b/upperFirst.js index cb288a54b..0cd614ed7 100644 --- a/upperFirst.js +++ b/upperFirst.js @@ -17,6 +17,6 @@ import createCaseFirst from './_createCaseFirst.js'; * _.upperFirst('FRED'); * // => 'FRED' */ -var upperFirst = createCaseFirst('toUpperCase'); +const upperFirst = createCaseFirst('toUpperCase'); export default upperFirst; diff --git a/zip.js b/zip.js index c91052821..ebe627aee 100644 --- a/zip.js +++ b/zip.js @@ -17,6 +17,6 @@ import unzip from './unzip.js'; * _.zip(['a', 'b'], [1, 2], [true, false]); * // => [['a', 1, true], ['b', 2, false]] */ -var zip = baseRest(unzip); +const zip = baseRest(unzip); export default zip;