From d931d6e8e8716d32c0aed4a202d77295f77f4cc0 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Thu, 9 Feb 2017 23:14:09 -0800 Subject: [PATCH] Simplify isType methods. --- isArguments.js | 8 +++----- isSet.js | 3 +-- isString.js | 7 +++---- isSymbol.js | 7 +++---- isTypedArray.js | 6 ++---- isWeakMap.js | 3 +-- isWeakSet.js | 5 ++--- 7 files changed, 15 insertions(+), 24 deletions(-) diff --git a/isArguments.js b/isArguments.js index c69cceb69..6e2961242 100644 --- a/isArguments.js +++ b/isArguments.js @@ -1,5 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' -import isObjectLike from './isObjectLike.js' +import getTag from './.internal/getTag.js' /** * Checks if `value` is likely an `arguments` object. @@ -7,8 +6,7 @@ import isObjectLike from './isObjectLike.js' * @since 0.1.0 * @category Lang * @param {*} value The value to check. - * @returns {boolean} Returns `true` if `value` is an `arguments` object, - * else `false`. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, else `false`. * @example * * isArguments(function() { return arguments }()) @@ -18,7 +16,7 @@ import isObjectLike from './isObjectLike.js' * // => false */ function isArguments(value) { - return isObjectLike(value) && baseGetTag(value) == '[object Arguments]' + return typeof value == 'object' && value != null && getTag(value) == '[object Arguments]' } export default isArguments diff --git a/isSet.js b/isSet.js index ffdb7fb4b..6a3d21485 100644 --- a/isSet.js +++ b/isSet.js @@ -1,5 +1,4 @@ import getTag from './.internal/getTag.js' -import isObjectLike from './isObjectLike.js' import nodeUtil from './.internal/nodeUtil.js' /* Node.js helper references. */ @@ -22,6 +21,6 @@ const nodeIsSet = nodeUtil && nodeUtil.isSet */ const isSet = nodeIsSet ? value => nodeIsSet(value) - : value => isObjectLike(value) && getTag(value) == '[object Set]' + : value => typeof value == 'object' && value != null && getTag(value) == '[object Set]' export default isSet diff --git a/isString.js b/isString.js index 710f9ba36..b9ec3ae59 100644 --- a/isString.js +++ b/isString.js @@ -1,5 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' -import isObjectLike from './isObjectLike.js' +import getTag from './.internal/getTag.js' /** * Checks if `value` is classified as a `String` primitive or object. @@ -17,8 +16,8 @@ import isObjectLike from './isObjectLike.js' * // => false */ function isString(value) { - return typeof value == 'string' || - (!Array.isArray(value) && isObjectLike(value) && baseGetTag(value) == '[object String]') + const type = typeof value + return type == 'string' || (type == 'object' && value != null && !Array.isArray(value) && getTag(value) == '[object String]') } export default isString diff --git a/isSymbol.js b/isSymbol.js index f1d387fb4..8ea537f4e 100644 --- a/isSymbol.js +++ b/isSymbol.js @@ -1,5 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' -import isObjectLike from './isObjectLike.js' +import getTag from './.internal/getTag.js' /** * Checks if `value` is classified as a `Symbol` primitive or object. @@ -17,8 +16,8 @@ import isObjectLike from './isObjectLike.js' * // => false */ function isSymbol(value) { - return typeof value == 'symbol' || - (isObjectLike(value) && baseGetTag(value) == '[object Symbol]') + const type = typeof value + return type == 'symbol' || (type == 'object' && value != null && getTag(value) == '[object Symbol]') } export default isSymbol diff --git a/isTypedArray.js b/isTypedArray.js index c51f45abf..89259a189 100644 --- a/isTypedArray.js +++ b/isTypedArray.js @@ -1,6 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' -import isLength from './isLength.js' -import isObjectLike from './isObjectLike.js' +import getTag from './.internal/getTag.js' import nodeUtil from './.internal/nodeUtil.js' /** Used to match `toStringTag` values of typed arrays. */ @@ -26,6 +24,6 @@ const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray */ const isTypedArray = nodeIsTypedArray ? value => nodeIsTypedArray(value) - : value => isObjectLike(value) && isLength(value.length) && reTypedTag.test(baseGetTag(value)) + : value => typeof value == 'object' && value != null && reTypedTag.test(getTag(value)) export default isTypedArray diff --git a/isWeakMap.js b/isWeakMap.js index 0271dca45..0f9dd8163 100644 --- a/isWeakMap.js +++ b/isWeakMap.js @@ -1,5 +1,4 @@ import getTag from './.internal/getTag.js' -import isObjectLike from './isObjectLike.js' /** * Checks if `value` is classified as a `WeakMap` object. @@ -17,7 +16,7 @@ import isObjectLike from './isObjectLike.js' * // => false */ function isWeakMap(value) { - return isObjectLike(value) && getTag(value) == '[object WeakMap]' + return typeof value == 'object' && value != null && getTag(value) == '[object WeakMap]' } export default isWeakMap diff --git a/isWeakSet.js b/isWeakSet.js index d0ad9f4a8..24b1322b8 100644 --- a/isWeakSet.js +++ b/isWeakSet.js @@ -1,5 +1,4 @@ -import baseGetTag from './.internal/baseGetTag.js' -import isObjectLike from './isObjectLike.js' +import getTag from './.internal/getTag.js' /** * Checks if `value` is classified as a `WeakSet` object. @@ -17,7 +16,7 @@ import isObjectLike from './isObjectLike.js' * // => false */ function isWeakSet(value) { - return isObjectLike(value) && baseGetTag(value) == '[object WeakSet]' + return typeof value == 'object' && value != null && getTag(value) == '[object WeakSet]' } export default isWeakSet