mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Replace getTag implementation by the one from baseGetTag (remove workarounds) (#4115)
This commit is contained in:
committed by
John-David Dalton
parent
c77650a17b
commit
aa1d7d870d
@@ -1,17 +0,0 @@
|
|||||||
const toString = Object.prototype.toString
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The base implementation of `getTag` without fallbacks for buggy environments.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {*} value The value to query.
|
|
||||||
* @returns {string} Returns the `toStringTag`.
|
|
||||||
*/
|
|
||||||
function baseGetTag(value) {
|
|
||||||
if (value == null) {
|
|
||||||
return value === undefined ? '[object Undefined]' : '[object Null]'
|
|
||||||
}
|
|
||||||
return toString.call(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default baseGetTag
|
|
||||||
@@ -2,7 +2,7 @@ import Stack from './Stack.js'
|
|||||||
import equalArrays from './equalArrays.js'
|
import equalArrays from './equalArrays.js'
|
||||||
import equalByTag from './equalByTag.js'
|
import equalByTag from './equalByTag.js'
|
||||||
import equalObjects from './equalObjects.js'
|
import equalObjects from './equalObjects.js'
|
||||||
import baseGetTag from './baseGetTag.js'
|
import getTag from './getTag.js'
|
||||||
import isBuffer from '../isBuffer.js'
|
import isBuffer from '../isBuffer.js'
|
||||||
import isTypedArray from '../isTypedArray.js'
|
import isTypedArray from '../isTypedArray.js'
|
||||||
|
|
||||||
@@ -34,8 +34,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
|
|||||||
function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
||||||
let objIsArr = Array.isArray(object)
|
let objIsArr = Array.isArray(object)
|
||||||
const othIsArr = Array.isArray(other)
|
const othIsArr = Array.isArray(other)
|
||||||
let objTag = objIsArr ? arrayTag : baseGetTag(object)
|
let objTag = objIsArr ? arrayTag : getTag(object)
|
||||||
let othTag = othIsArr ? arrayTag : baseGetTag(other)
|
let othTag = othIsArr ? arrayTag : getTag(other)
|
||||||
|
|
||||||
objTag = objTag == argsTag ? objectTag : objTag
|
objTag = objTag == argsTag ? objectTag : objTag
|
||||||
othTag = othTag == argsTag ? objectTag : othTag
|
othTag = othTag == argsTag ? objectTag : othTag
|
||||||
|
|||||||
@@ -1,19 +1,4 @@
|
|||||||
import baseGetTag from './baseGetTag.js'
|
const toString = Object.prototype.toString
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
|
||||||
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. */
|
|
||||||
const dataViewCtorString = `${DataView}`
|
|
||||||
const mapCtorString = `${Map}`
|
|
||||||
const promiseCtorString = `${Promise}`
|
|
||||||
const setCtorString = `${Set}`
|
|
||||||
const weakMapCtorString = `${WeakMap}`
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the `toStringTag` of `value`.
|
* Gets the `toStringTag` of `value`.
|
||||||
@@ -22,30 +7,11 @@ const weakMapCtorString = `${WeakMap}`
|
|||||||
* @param {*} value The value to query.
|
* @param {*} value The value to query.
|
||||||
* @returns {string} Returns the `toStringTag`.
|
* @returns {string} Returns the `toStringTag`.
|
||||||
*/
|
*/
|
||||||
let getTag = baseGetTag
|
function getTag(value) {
|
||||||
|
if (value == null) {
|
||||||
// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
|
return value === undefined ? '[object Undefined]' : '[object Null]'
|
||||||
if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
|
||||||
(getTag(new Map) != mapTag) ||
|
|
||||||
(getTag(Promise.resolve()) != promiseTag) ||
|
|
||||||
(getTag(new Set) != setTag) ||
|
|
||||||
(getTag(new WeakMap) != weakMapTag)) {
|
|
||||||
getTag = (value) => {
|
|
||||||
const result = baseGetTag(value)
|
|
||||||
const Ctor = result == objectTag ? value.constructor : undefined
|
|
||||||
const ctorString = Ctor ? `${Ctor}` : ''
|
|
||||||
|
|
||||||
if (ctorString) {
|
|
||||||
switch (ctorString) {
|
|
||||||
case dataViewCtorString: return dataViewTag
|
|
||||||
case mapCtorString: return mapTag
|
|
||||||
case promiseCtorString: return promiseTag
|
|
||||||
case setCtorString: return setTag
|
|
||||||
case weakMapCtorString: return weakMapTag
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
return toString.call(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getTag
|
export default getTag
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike'
|
import isObjectLike from './isObjectLike'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +17,7 @@ import isObjectLike from './isObjectLike'
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isArguments(value) {
|
function isArguments(value) {
|
||||||
return isObjectLike(value) && baseGetTag(value) == '[object Arguments]'
|
return isObjectLike(value) && getTag(value) == '[object Arguments]'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isArguments
|
export default isArguments
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
import isObjectLike from './isObjectLike.js'
|
||||||
import nodeTypes from './.internal/nodeTypes.js'
|
import nodeTypes from './.internal/nodeTypes.js'
|
||||||
|
|
||||||
@@ -22,6 +22,6 @@ const nodeIsArrayBuffer = nodeTypes && nodeTypes.isArrayBuffer
|
|||||||
*/
|
*/
|
||||||
const isArrayBuffer = nodeIsArrayBuffer
|
const isArrayBuffer = nodeIsArrayBuffer
|
||||||
? (value) => nodeIsArrayBuffer(value)
|
? (value) => nodeIsArrayBuffer(value)
|
||||||
: (value) => isObjectLike(value) && baseGetTag(value) == '[object ArrayBuffer]'
|
: (value) => isObjectLike(value) && getTag(value) == '[object ArrayBuffer]'
|
||||||
|
|
||||||
export default isArrayBuffer
|
export default isArrayBuffer
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
import isObjectLike from './isObjectLike.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +18,7 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
*/
|
*/
|
||||||
function isBoolean(value) {
|
function isBoolean(value) {
|
||||||
return value === true || value === false ||
|
return value === true || value === false ||
|
||||||
(isObjectLike(value) && baseGetTag(value) == '[object Boolean]')
|
(isObjectLike(value) && getTag(value) == '[object Boolean]')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isBoolean
|
export default isBoolean
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
import isObjectLike from './isObjectLike.js'
|
||||||
import nodeTypes from './.internal/nodeTypes.js'
|
import nodeTypes from './.internal/nodeTypes.js'
|
||||||
|
|
||||||
@@ -22,6 +22,6 @@ const nodeIsDate = nodeTypes && nodeTypes.isDate
|
|||||||
*/
|
*/
|
||||||
const isDate = nodeIsDate
|
const isDate = nodeIsDate
|
||||||
? (value) => nodeIsDate(value)
|
? (value) => nodeIsDate(value)
|
||||||
: (value) => isObjectLike(value) && baseGetTag(value) == '[object Date]'
|
: (value) => isObjectLike(value) && getTag(value) == '[object Date]'
|
||||||
|
|
||||||
export default isDate
|
export default isDate
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
import isObjectLike from './isObjectLike.js'
|
||||||
import isPlainObject from './isPlainObject.js'
|
import isPlainObject from './isPlainObject.js'
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ function isError(value) {
|
|||||||
if (!isObjectLike(value)) {
|
if (!isObjectLike(value)) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const tag = baseGetTag(value)
|
const tag = getTag(value)
|
||||||
return tag == '[object Error]' || tag == '[object DOMException]' ||
|
return tag == '[object Error]' || tag == '[object DOMException]' ||
|
||||||
(typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value))
|
(typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObject from './isObject.js'
|
import isObject from './isObject.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,7 +22,7 @@ function isFunction(value) {
|
|||||||
}
|
}
|
||||||
// The use of `Object#toString` avoids issues with the `typeof` operator
|
// The use of `Object#toString` avoids issues with the `typeof` operator
|
||||||
// in Safari 9 which returns 'object' for typed arrays and other constructors.
|
// in Safari 9 which returns 'object' for typed arrays and other constructors.
|
||||||
const tag = baseGetTag(value)
|
const tag = getTag(value)
|
||||||
return tag == '[object Function]' || tag == '[object AsyncFunction]' ||
|
return tag == '[object Function]' || tag == '[object AsyncFunction]' ||
|
||||||
tag == '[object GeneratorFunction]' || tag == '[object Proxy]'
|
tag == '[object GeneratorFunction]' || tag == '[object Proxy]'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
import isObjectLike from './isObjectLike.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,7 +28,7 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
*/
|
*/
|
||||||
function isNumber(value) {
|
function isNumber(value) {
|
||||||
return typeof value == 'number' ||
|
return typeof value == 'number' ||
|
||||||
(isObjectLike(value) && baseGetTag(value) == '[object Number]')
|
(isObjectLike(value) && getTag(value) == '[object Number]')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isNumber
|
export default isNumber
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
import isObjectLike from './isObjectLike.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,7 +28,7 @@ import isObjectLike from './isObjectLike.js'
|
|||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
function isPlainObject(value) {
|
function isPlainObject(value) {
|
||||||
if (!isObjectLike(value) || baseGetTag(value) != '[object Object]') {
|
if (!isObjectLike(value) || getTag(value) != '[object Object]') {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (Object.getPrototypeOf(value) === null) {
|
if (Object.getPrototypeOf(value) === null) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import isObjectLike from './isObjectLike.js'
|
import isObjectLike from './isObjectLike.js'
|
||||||
import nodeTypes from './.internal/nodeTypes.js'
|
import nodeTypes from './.internal/nodeTypes.js'
|
||||||
|
|
||||||
@@ -22,6 +22,6 @@ const nodeIsRegExp = nodeTypes && nodeTypes.isRegExp
|
|||||||
*/
|
*/
|
||||||
const isRegExp = nodeIsRegExp
|
const isRegExp = nodeIsRegExp
|
||||||
? (value) => nodeIsRegExp(value)
|
? (value) => nodeIsRegExp(value)
|
||||||
: (value) => isObjectLike(value) && baseGetTag(value) == '[object RegExp]'
|
: (value) => isObjectLike(value) && getTag(value) == '[object RegExp]'
|
||||||
|
|
||||||
export default isRegExp
|
export default isRegExp
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as a `String` primitive or object.
|
* Checks if `value` is classified as a `String` primitive or object.
|
||||||
@@ -17,7 +17,7 @@ import baseGetTag from './.internal/baseGetTag.js'
|
|||||||
*/
|
*/
|
||||||
function isString(value) {
|
function isString(value) {
|
||||||
const type = typeof value
|
const type = typeof value
|
||||||
return type == 'string' || (type == 'object' && value != null && !Array.isArray(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,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if `value` is classified as a `Symbol` primitive or object.
|
* Checks if `value` is classified as a `Symbol` primitive or object.
|
||||||
@@ -17,7 +17,7 @@ import baseGetTag from './.internal/baseGetTag.js'
|
|||||||
*/
|
*/
|
||||||
function isSymbol(value) {
|
function isSymbol(value) {
|
||||||
const type = typeof value
|
const type = typeof value
|
||||||
return type == 'symbol' || (type == 'object' && value != null && baseGetTag(value) == '[object Symbol]')
|
return type == 'symbol' || (type == 'object' && value != null && getTag(value) == '[object Symbol]')
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isSymbol
|
export default isSymbol
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import baseGetTag from './.internal/baseGetTag.js'
|
import getTag from './.internal/getTag.js'
|
||||||
import nodeTypes from './.internal/nodeTypes.js'
|
import nodeTypes from './.internal/nodeTypes.js'
|
||||||
import isObjectLike from './isObjectLike'
|
import isObjectLike from './isObjectLike'
|
||||||
|
|
||||||
@@ -25,6 +25,6 @@ const nodeIsTypedArray = nodeTypes && nodeTypes.isTypedArray
|
|||||||
*/
|
*/
|
||||||
const isTypedArray = nodeIsTypedArray
|
const isTypedArray = nodeIsTypedArray
|
||||||
? (value) => nodeIsTypedArray(value)
|
? (value) => nodeIsTypedArray(value)
|
||||||
: (value) => isObjectLike(value) && reTypedTag.test(baseGetTag(value))
|
: (value) => isObjectLike(value) && reTypedTag.test(getTag(value))
|
||||||
|
|
||||||
export default isTypedArray
|
export default isTypedArray
|
||||||
|
|||||||
Reference in New Issue
Block a user