mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Simplify isType methods.
This commit is contained in:
@@ -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
|
||||
|
||||
3
isSet.js
3
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user