From 68190b854657d074e3ebd35d70291ab4bb48fe32 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 9 Jan 2017 18:44:38 -0800 Subject: [PATCH] Use `Array.isArray`. --- _arrayLikeKeys.js | 3 +-- _baseClone.js | 3 +-- _baseGetAllKeys.js | 3 +-- _baseIsEqualDeep.js | 5 ++--- _baseMergeDeep.js | 5 ++--- _baseToString.js | 3 +-- _castPath.js | 3 +-- _createAggregator.js | 3 +-- _hasPath.js | 3 +-- _isFlattenable.js | 3 +-- _isKey.js | 3 +-- castArray.js | 3 +-- concat.js | 3 +-- every.js | 3 +-- filter.js | 3 +-- forEach.js | 3 +-- forEachRight.js | 3 +-- isEmpty.js | 3 +-- isString.js | 3 +-- map.js | 3 +-- mergeWith.js | 2 +- orderBy.js | 5 ++--- reduce.js | 3 +-- reduceRight.js | 3 +-- reject.js | 3 +-- sample.js | 3 +-- sampleSize.js | 3 +-- shuffle.js | 3 +-- some.js | 3 +-- toPath.js | 3 +-- transform.js | 3 +-- 31 files changed, 34 insertions(+), 64 deletions(-) diff --git a/_arrayLikeKeys.js b/_arrayLikeKeys.js index 6dedf128b..2c20e060a 100644 --- a/_arrayLikeKeys.js +++ b/_arrayLikeKeys.js @@ -1,6 +1,5 @@ import baseTimes from './_baseTimes.js'; import isArguments from './isArguments.js'; -import isArray from './isArray.js'; import isBuffer from './isBuffer.js'; import isIndex from './_isIndex.js'; import isTypedArray from './isTypedArray.js'; @@ -17,7 +16,7 @@ const hasOwnProperty = Object.prototype.hasOwnProperty; * @returns {Array} Returns the array of property names. */ function arrayLikeKeys(value, inherited) { - const isArr = isArray(value); + const isArr = Array.isArray(value); const isArg = !isArr && isArguments(value); const isBuff = !isArr && !isArg && isBuffer(value); const isType = !isArr && !isArg && !isBuff && isTypedArray(value); diff --git a/_baseClone.js b/_baseClone.js index f30c68fe2..0a7f13bb3 100644 --- a/_baseClone.js +++ b/_baseClone.js @@ -13,7 +13,6 @@ import getTag from './_getTag.js'; import initCloneArray from './_initCloneArray.js'; import initCloneByTag from './_initCloneByTag.js'; import initCloneObject from './_initCloneObject.js'; -import isArray from './isArray.js'; import isBuffer from './isBuffer.js'; import isObject from './isObject.js'; import keys from './keys.js'; @@ -99,7 +98,7 @@ function baseClone(value, bitmask, customizer, key, object, stack) { if (!isObject(value)) { return value; } - const isArr = isArray(value); + const isArr = Array.isArray(value); if (isArr) { result = initCloneArray(value); if (!isDeep) { diff --git a/_baseGetAllKeys.js b/_baseGetAllKeys.js index 16d8f4a85..f22dce981 100644 --- a/_baseGetAllKeys.js +++ b/_baseGetAllKeys.js @@ -1,5 +1,4 @@ import arrayPush from './_arrayPush.js'; -import isArray from './isArray.js'; /** * The base implementation of `getAllKeys` and `getAllKeysIn` which uses @@ -14,7 +13,7 @@ import isArray from './isArray.js'; */ function baseGetAllKeys(object, keysFunc, symbolsFunc) { const result = keysFunc(object); - return isArray(object) ? result : arrayPush(result, symbolsFunc(object)); + return Array.isArray(object) ? result : arrayPush(result, symbolsFunc(object)); } export default baseGetAllKeys; diff --git a/_baseIsEqualDeep.js b/_baseIsEqualDeep.js index 31814c79c..53312cc18 100644 --- a/_baseIsEqualDeep.js +++ b/_baseIsEqualDeep.js @@ -3,7 +3,6 @@ import equalArrays from './_equalArrays.js'; import equalByTag from './_equalByTag.js'; import equalObjects from './_equalObjects.js'; import getTag from './_getTag.js'; -import isArray from './isArray.js'; import isBuffer from './isBuffer.js'; import isTypedArray from './isTypedArray.js'; @@ -33,8 +32,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty; * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. */ function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { - let objIsArr = isArray(object); - const othIsArr = isArray(other); + let objIsArr = Array.isArray(object); + const othIsArr = Array.isArray(other); let objTag = objIsArr ? arrayTag : getTag(object); let othTag = othIsArr ? arrayTag : getTag(other); diff --git a/_baseMergeDeep.js b/_baseMergeDeep.js index 065169726..ebb5ae178 100644 --- a/_baseMergeDeep.js +++ b/_baseMergeDeep.js @@ -4,7 +4,6 @@ import cloneTypedArray from './_cloneTypedArray.js'; import copyArray from './_copyArray.js'; import initCloneObject from './_initCloneObject.js'; import isArguments from './isArguments.js'; -import isArray from './isArray.js'; import isArrayLikeObject from './isArrayLikeObject.js'; import isBuffer from './isBuffer.js'; import isFunction from './isFunction.js'; @@ -44,13 +43,13 @@ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, sta let isCommon = newValue === undefined; if (isCommon) { - const isArr = isArray(srcValue); + const isArr = Array.isArray(srcValue); const isBuff = !isArr && isBuffer(srcValue); const isTyped = !isArr && !isBuff && isTypedArray(srcValue); newValue = srcValue; if (isArr || isBuff || isTyped) { - if (isArray(objValue)) { + if (Array.isArray(objValue)) { newValue = objValue; } else if (isArrayLikeObject(objValue)) { diff --git a/_baseToString.js b/_baseToString.js index 43af79e95..a5f48ea16 100644 --- a/_baseToString.js +++ b/_baseToString.js @@ -1,6 +1,5 @@ import Symbol from './_Symbol.js'; import arrayMap from './_arrayMap.js'; -import isArray from './isArray.js'; import isSymbol from './isSymbol.js'; /** Used as references for various `Number` constants. */ @@ -23,7 +22,7 @@ function baseToString(value) { if (typeof value == 'string') { return value; } - if (isArray(value)) { + if (Array.isArray(value)) { // Recursively convert values (susceptible to call stack limits). return `${ arrayMap(value, baseToString) }`; } diff --git a/_castPath.js b/_castPath.js index 89aae9551..9e39448f9 100644 --- a/_castPath.js +++ b/_castPath.js @@ -1,4 +1,3 @@ -import isArray from './isArray.js'; import isKey from './_isKey.js'; import stringToPath from './_stringToPath.js'; import toString from './toString.js'; @@ -12,7 +11,7 @@ import toString from './toString.js'; * @returns {Array} Returns the cast property path array. */ function castPath(value, object) { - if (isArray(value)) { + if (Array.isArray(value)) { return value; } return isKey(value, object) ? [value] : stringToPath(toString(value)); diff --git a/_createAggregator.js b/_createAggregator.js index a5e151cb0..763dc742c 100644 --- a/_createAggregator.js +++ b/_createAggregator.js @@ -1,6 +1,5 @@ import arrayAggregator from './_arrayAggregator.js'; import baseAggregator from './_baseAggregator.js'; -import isArray from './isArray.js'; /** * Creates a function like `groupBy`. @@ -12,7 +11,7 @@ import isArray from './isArray.js'; */ function createAggregator(setter, initializer) { return (collection, iteratee) => { - const func = isArray(collection) ? arrayAggregator : baseAggregator; + const func = Array.isArray(collection) ? arrayAggregator : baseAggregator; const accumulator = initializer ? initializer() : {}; return func(collection, setter, iteratee, accumulator); }; diff --git a/_hasPath.js b/_hasPath.js index 4de656804..91394cf50 100644 --- a/_hasPath.js +++ b/_hasPath.js @@ -1,6 +1,5 @@ import castPath from './_castPath.js'; import isArguments from './isArguments.js'; -import isArray from './isArray.js'; import isIndex from './_isIndex.js'; import isLength from './isLength.js'; import toKey from './_toKey.js'; @@ -34,7 +33,7 @@ function hasPath(object, path, hasFunc) { } length = object == null ? 0 : object.length; return !!length && isLength(length) && isIndex(key, length) && - (isArray(object) || isArguments(object)); + (Array.isArray(object) || isArguments(object)); } export default hasPath; diff --git a/_isFlattenable.js b/_isFlattenable.js index 7301c81a9..96df7e753 100644 --- a/_isFlattenable.js +++ b/_isFlattenable.js @@ -1,6 +1,5 @@ import Symbol from './_Symbol.js'; import isArguments from './isArguments.js'; -import isArray from './isArray.js'; /** Built-in value references. */ const spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; @@ -13,7 +12,7 @@ const spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined; * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. */ function isFlattenable(value) { - return isArray(value) || isArguments(value) || + return Array.isArray(value) || isArguments(value) || !!(spreadableSymbol && value && value[spreadableSymbol]); } diff --git a/_isKey.js b/_isKey.js index 444c70207..fe5450ee5 100644 --- a/_isKey.js +++ b/_isKey.js @@ -1,4 +1,3 @@ -import isArray from './isArray.js'; import isSymbol from './isSymbol.js'; /** Used to match property names within property paths. */ @@ -14,7 +13,7 @@ const reIsPlainProp = /^\w*$/; * @returns {boolean} Returns `true` if `value` is a property name, else `false`. */ function isKey(value, object) { - if (isArray(value)) { + if (Array.isArray(value)) { return false; } const type = typeof value; diff --git a/castArray.js b/castArray.js index 85579eb8b..5b184e3c4 100644 --- a/castArray.js +++ b/castArray.js @@ -1,4 +1,3 @@ -import isArray from './isArray.js'; /** * Casts `value` as an array if it's not one. @@ -37,7 +36,7 @@ function castArray(...args) { return []; } const value = args[0]; - return isArray(value) ? value : [value]; + return Array.isArray(value) ? value : [value]; } export default castArray; diff --git a/concat.js b/concat.js index 914adacb1..cf4118a5a 100644 --- a/concat.js +++ b/concat.js @@ -1,7 +1,6 @@ import arrayPush from './_arrayPush.js'; import baseFlatten from './_baseFlatten.js'; import copyArray from './_copyArray.js'; -import isArray from './isArray.js'; /** * Creates a new array concatenating `array` with any additional arrays @@ -25,7 +24,7 @@ import isArray from './isArray.js'; * // => [1] */ function concat(array, ...values) { - return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); + return arrayPush(Array.isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); } export default concat; diff --git a/every.js b/every.js index b683d1624..b40f9c33e 100644 --- a/every.js +++ b/every.js @@ -1,6 +1,5 @@ import arrayEvery from './_arrayEvery.js'; import baseEvery from './_baseEvery.js'; -import isArray from './isArray.js'; import isIterateeCall from './_isIterateeCall.js'; /** @@ -27,7 +26,7 @@ import isIterateeCall from './_isIterateeCall.js'; * // => false */ function every(collection, predicate, guard) { - const func = isArray(collection) ? arrayEvery : baseEvery; + const func = Array.isArray(collection) ? arrayEvery : baseEvery; if (guard && isIterateeCall(collection, predicate, guard)) { predicate = undefined; } diff --git a/filter.js b/filter.js index 556bf82d8..3913923c5 100644 --- a/filter.js +++ b/filter.js @@ -1,6 +1,5 @@ import arrayFilter from './_arrayFilter.js'; import baseFilter from './_baseFilter.js'; -import isArray from './isArray.js'; /** * Iterates over elements of `collection`, returning an array of all elements @@ -27,7 +26,7 @@ import isArray from './isArray.js'; * // => objects for ['fred'] */ function filter(collection, predicate) { - const func = isArray(collection) ? arrayFilter : baseFilter; + const func = Array.isArray(collection) ? arrayFilter : baseFilter; return func(collection, predicate); } diff --git a/forEach.js b/forEach.js index 5df13d1c7..5d968b9b2 100644 --- a/forEach.js +++ b/forEach.js @@ -1,6 +1,5 @@ import arrayEach from './_arrayEach.js'; import baseEach from './_baseEach.js';; -import isArray from './isArray.js'; /** * Iterates over elements of `collection` and invokes `iteratee` for each element. @@ -32,7 +31,7 @@ import isArray from './isArray.js'; * // => Logs 'a' then 'b' (iteration order is not guaranteed). */ function forEach(collection, iteratee) { - const func = isArray(collection) ? arrayEach : baseEach; + const func = Array.isArray(collection) ? arrayEach : baseEach; return func(collection, iteratee); } diff --git a/forEachRight.js b/forEachRight.js index 637c1ec8f..eba21841c 100644 --- a/forEachRight.js +++ b/forEachRight.js @@ -1,6 +1,5 @@ import arrayEachRight from './_arrayEachRight.js'; import baseEachRight from './_baseEachRight.js'; -import isArray from './isArray.js'; /** * This method is like `forEach` except that it iterates over elements of @@ -22,7 +21,7 @@ import isArray from './isArray.js'; * // => Logs `2` then `1`. */ function forEachRight(collection, iteratee) { - const func = isArray(collection) ? arrayEachRight : baseEachRight; + const func = Array.isArray(collection) ? arrayEachRight : baseEachRight; return func(collection, iteratee); } diff --git a/isEmpty.js b/isEmpty.js index e80574f63..fa3a96e9f 100644 --- a/isEmpty.js +++ b/isEmpty.js @@ -1,7 +1,6 @@ import baseKeys from './_baseKeys.js'; import getTag from './_getTag.js'; import isArguments from './isArguments.js'; -import isArray from './isArray.js'; import isArrayLike from './isArrayLike.js'; import isBuffer from './isBuffer.js'; import isPrototype from './_isPrototype.js'; @@ -51,7 +50,7 @@ function isEmpty(value) { return true; } if (isArrayLike(value) && - (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || + (Array.isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || isBuffer(value) || isTypedArray(value) || isArguments(value))) { return !value.length; } diff --git a/isString.js b/isString.js index a724be5a8..d337f5a4f 100644 --- a/isString.js +++ b/isString.js @@ -1,5 +1,4 @@ import baseGetTag from './_baseGetTag.js'; -import isArray from './isArray.js'; import isObjectLike from './isObjectLike.js'; /** `Object#toString` result references. */ @@ -23,7 +22,7 @@ const stringTag = '[object String]'; */ function isString(value) { return typeof value == 'string' || - (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); + (!Array.isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); } export default isString; diff --git a/map.js b/map.js index 9e59bce8e..b3a48904d 100644 --- a/map.js +++ b/map.js @@ -1,6 +1,5 @@ import arrayMap from './_arrayMap.js'; import baseMap from './_baseMap.js'; -import isArray from './isArray.js'; /** * Creates an array of values by running each element in `collection` thru @@ -35,7 +34,7 @@ import isArray from './isArray.js'; * // => [16, 64] (iteration order is not guaranteed) */ function map(collection, iteratee) { - const func = isArray(collection) ? arrayMap : baseMap; + const func = Array.isArray(collection) ? arrayMap : baseMap; return func(collection, iteratee); } diff --git a/mergeWith.js b/mergeWith.js index 3ed4a1ccd..ed47d5133 100644 --- a/mergeWith.js +++ b/mergeWith.js @@ -20,7 +20,7 @@ import createAssigner from './_createAssigner.js'; * @example * * function customizer(objValue, srcValue) { - * if (isArray(objValue)) { + * if (Array.isArray(objValue)) { * return objValue.concat(srcValue); * } * } diff --git a/orderBy.js b/orderBy.js index e008922ed..3a4b50775 100644 --- a/orderBy.js +++ b/orderBy.js @@ -1,5 +1,4 @@ import baseOrderBy from './_baseOrderBy.js'; -import isArray from './isArray.js'; /** * This method is like `sortBy` except that it allows specifying the sort @@ -33,11 +32,11 @@ function orderBy(collection, iteratees, orders, guard) { if (collection == null) { return []; } - if (!isArray(iteratees)) { + if (!Array.isArray(iteratees)) { iteratees = iteratees == null ? [] : [iteratees]; } orders = guard ? undefined : orders; - if (!isArray(orders)) { + if (!Array.isArray(orders)) { orders = orders == null ? [] : [orders]; } return baseOrderBy(collection, iteratees, orders); diff --git a/reduce.js b/reduce.js index d29e5a309..858f3f1fe 100644 --- a/reduce.js +++ b/reduce.js @@ -1,7 +1,6 @@ import arrayReduce from './_arrayReduce.js'; import baseEach from './_baseEach.js'; import baseReduce from './_baseReduce.js'; -import isArray from './isArray.js'; /** * Reduces `collection` to a value which is the accumulated result of running @@ -40,7 +39,7 @@ import isArray from './isArray.js'; * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) */ function reduce(collection, iteratee, accumulator) { - const func = isArray(collection) ? arrayReduce : baseReduce; + const func = Array.isArray(collection) ? arrayReduce : baseReduce; const initAccum = arguments.length < 3; return func(collection, iteratee, accumulator, initAccum, baseEach); } diff --git a/reduceRight.js b/reduceRight.js index 4eb029110..1c10f8bf7 100644 --- a/reduceRight.js +++ b/reduceRight.js @@ -1,7 +1,6 @@ import arrayReduceRight from './_arrayReduceRight.js'; import baseEachRight from './_baseEachRight.js'; import baseReduce from './_baseReduce.js'; -import isArray from './isArray.js'; /** * This method is like `reduce` except that it iterates over elements of @@ -25,7 +24,7 @@ import isArray from './isArray.js'; * // => [4, 5, 2, 3, 0, 1] */ function reduceRight(collection, iteratee, accumulator) { - const func = isArray(collection) ? arrayReduceRight : baseReduce; + const func = Array.isArray(collection) ? arrayReduceRight : baseReduce; const initAccum = arguments.length < 3; return func(collection, iteratee, accumulator, initAccum, baseEachRight); } diff --git a/reject.js b/reject.js index 127323784..fd28b9b3b 100644 --- a/reject.js +++ b/reject.js @@ -1,6 +1,5 @@ import arrayFilter from './_arrayFilter.js'; import baseFilter from './_baseFilter.js'; -import isArray from './isArray.js'; import negate from './negate.js'; /** @@ -25,7 +24,7 @@ import negate from './negate.js'; * // => objects for ['fred'] */ function reject(collection, predicate) { - const func = isArray(collection) ? arrayFilter : baseFilter; + const func = Array.isArray(collection) ? arrayFilter : baseFilter; return func(collection, negate(predicate)); } diff --git a/sample.js b/sample.js index e22dff1b3..27ed1608b 100644 --- a/sample.js +++ b/sample.js @@ -1,6 +1,5 @@ import arraySample from './_arraySample.js'; import baseSample from './_baseSample.js'; -import isArray from './isArray.js'; /** * Gets a random element from `collection`. @@ -16,7 +15,7 @@ import isArray from './isArray.js'; * // => 2 */ function sample(collection) { - const func = isArray(collection) ? arraySample : baseSample; + const func = Array.isArray(collection) ? arraySample : baseSample; return func(collection); } diff --git a/sampleSize.js b/sampleSize.js index 420250e8a..ffd414dea 100644 --- a/sampleSize.js +++ b/sampleSize.js @@ -1,6 +1,5 @@ import arraySampleSize from './_arraySampleSize.js'; import baseSampleSize from './_baseSampleSize.js'; -import isArray from './isArray.js'; import isIterateeCall from './_isIterateeCall.js'; import toInteger from './toInteger.js'; @@ -29,7 +28,7 @@ function sampleSize(collection, n, guard) { } else { n = toInteger(n); } - const func = isArray(collection) ? arraySampleSize : baseSampleSize; + const func = Array.isArray(collection) ? arraySampleSize : baseSampleSize; return func(collection, n); } diff --git a/shuffle.js b/shuffle.js index eeaf104a9..2aa0e4bbc 100644 --- a/shuffle.js +++ b/shuffle.js @@ -1,6 +1,5 @@ import arrayShuffle from './_arrayShuffle.js'; import baseShuffle from './_baseShuffle.js'; -import isArray from './isArray.js'; /** * Creates an array of shuffled values, using a version of the @@ -17,7 +16,7 @@ import isArray from './isArray.js'; * // => [4, 1, 3, 2] */ function shuffle(collection) { - const func = isArray(collection) ? arrayShuffle : baseShuffle; + const func = Array.isArray(collection) ? arrayShuffle : baseShuffle; return func(collection); } diff --git a/some.js b/some.js index e379c08b5..e9847c754 100644 --- a/some.js +++ b/some.js @@ -1,6 +1,5 @@ import arraySome from './_arraySome.js'; import baseSome from './_baseSome.js'; -import isArray from './isArray.js'; import isIterateeCall from './_isIterateeCall.js'; /** @@ -22,7 +21,7 @@ import isIterateeCall from './_isIterateeCall.js'; * // => true */ function some(collection, predicate, guard) { - const func = isArray(collection) ? arraySome : baseSome; + const func = Array.isArray(collection) ? arraySome : baseSome; if (guard && isIterateeCall(collection, predicate, guard)) { predicate = undefined; } diff --git a/toPath.js b/toPath.js index 026e95ed5..e03bec443 100644 --- a/toPath.js +++ b/toPath.js @@ -1,6 +1,5 @@ import arrayMap from './_arrayMap.js'; import copyArray from './_copyArray.js'; -import isArray from './isArray.js'; import isSymbol from './isSymbol.js'; import stringToPath from './_stringToPath.js'; import toKey from './_toKey.js'; @@ -23,7 +22,7 @@ import toString from './toString.js'; * // => ['a', '0', 'b', 'c'] */ function toPath(value) { - if (isArray(value)) { + if (Array.isArray(value)) { return arrayMap(value, toKey); } return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value))); diff --git a/transform.js b/transform.js index 683bf63de..9b713f31d 100644 --- a/transform.js +++ b/transform.js @@ -2,7 +2,6 @@ import arrayEach from './_arrayEach.js'; import baseCreate from './_baseCreate.js'; import baseForOwn from './_baseForOwn.js'; import getPrototype from './_getPrototype.js'; -import isArray from './isArray.js'; import isBuffer from './isBuffer.js'; import isFunction from './isFunction.js'; import isObject from './isObject.js'; @@ -38,7 +37,7 @@ import isTypedArray from './isTypedArray.js'; * // => { '1': ['a', 'c'], '2': ['b'] } */ function transform(object, iteratee, accumulator) { - const isArr = isArray(object); + const isArr = Array.isArray(object); const isArrLike = isArr || isBuffer(object) || isTypedArray(object); if (accumulator == null) {