mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Simplify isType methods.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is likely an `arguments` object.
|
* Checks if `value` is likely an `arguments` object.
|
||||||
@@ -7,8 +6,7 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
* @since 0.1.0
|
* @since 0.1.0
|
||||||
* @category Lang
|
* @category Lang
|
||||||
* @param {*} value The value to check.
|
* @param {*} value The value to check.
|
||||||
* @returns {boolean} Returns `true` if `value` is an `arguments` object,
|
* @returns {boolean} Returns `true` if `value` is an `arguments` object, else `false`.
|
||||||
* else `false`.
|
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* isArguments(function() { return arguments }())
|
* isArguments(function() { return arguments }())
|
||||||
@@ -18,7 +16,7 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isArguments(value) {
|
function isArguments(value) {
|
||||||
return isObjectLike(value) && baseGetTag(value) == '[object Arguments]'
|
return typeof value == 'object' && value != null && getTag(value) == '[object Arguments]'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isArguments
|
export default isArguments
|
||||||
|
|||||||
3
isSet.js
3
isSet.js
@@ -1,5 +1,4 @@
|
|||||||
import getTag from './.internal/getTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
|
||||||
import nodeUtil from './.internal/nodeUtil.js'
|
import nodeUtil from './.internal/nodeUtil.js'
|
||||||
|
|
||||||
/* Node.js helper references. */
|
/* Node.js helper references. */
|
||||||
@@ -22,6 +21,6 @@ const nodeIsSet = nodeUtil && nodeUtil.isSet
|
|||||||
*/
|
*/
|
||||||
const isSet = nodeIsSet
|
const isSet = nodeIsSet
|
||||||
? value => nodeIsSet(value)
|
? value => nodeIsSet(value)
|
||||||
: value => isObjectLike(value) && getTag(value) == '[object Set]'
|
: value => typeof value == 'object' && value != null && getTag(value) == '[object Set]'
|
||||||
|
|
||||||
export default isSet
|
export default isSet
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as a `String` primitive or object.
|
* Checks if `value` is classified as a `String` primitive or object.
|
||||||
@@ -17,8 +16,8 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isString(value) {
|
function isString(value) {
|
||||||
return typeof value == 'string' ||
|
const type = typeof value
|
||||||
(!Array.isArray(value) && isObjectLike(value) && baseGetTag(value) == '[object String]')
|
return type == 'string' || (type == 'object' && value != null && !Array.isArray(value) && getTag(value) == '[object String]')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isString
|
export default isString
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as a `Symbol` primitive or object.
|
* Checks if `value` is classified as a `Symbol` primitive or object.
|
||||||
@@ -17,8 +16,8 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isSymbol(value) {
|
function isSymbol(value) {
|
||||||
return typeof value == 'symbol' ||
|
const type = typeof value
|
||||||
(isObjectLike(value) && baseGetTag(value) == '[object Symbol]')
|
return type == 'symbol' || (type == 'object' && value != null && getTag(value) == '[object Symbol]')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isSymbol
|
export default isSymbol
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isLength from './isLength.js'
|
|
||||||
import isObjectLike from './isObjectLike.js'
|
|
||||||
import nodeUtil from './.internal/nodeUtil.js'
|
import nodeUtil from './.internal/nodeUtil.js'
|
||||||
|
|
||||||
/** Used to match `toStringTag` values of typed arrays. */
|
/** Used to match `toStringTag` values of typed arrays. */
|
||||||
@@ -26,6 +24,6 @@ const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray
|
|||||||
*/
|
*/
|
||||||
const isTypedArray = nodeIsTypedArray
|
const isTypedArray = nodeIsTypedArray
|
||||||
? value => nodeIsTypedArray(value)
|
? 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
|
export default isTypedArray
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import getTag from './.internal/getTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as a `WeakMap` object.
|
* Checks if `value` is classified as a `WeakMap` object.
|
||||||
@@ -17,7 +16,7 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isWeakMap(value) {
|
function isWeakMap(value) {
|
||||||
return isObjectLike(value) && getTag(value) == '[object WeakMap]'
|
return typeof value == 'object' && value != null && getTag(value) == '[object WeakMap]'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isWeakMap
|
export default isWeakMap
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as a `WeakSet` object.
|
* Checks if `value` is classified as a `WeakSet` object.
|
||||||
@@ -17,7 +16,7 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isWeakSet(value) {
|
function isWeakSet(value) {
|
||||||
return isObjectLike(value) && baseGetTag(value) == '[object WeakSet]'
|
return typeof value == 'object' && value != null && getTag(value) == '[object WeakSet]'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isWeakSet
|
export default isWeakSet
|
||||||
|
|||||||
Reference in New Issue
Block a user