mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 17:47:49 +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 equalByTag from './equalByTag.js'
|
||||
import equalObjects from './equalObjects.js'
|
||||
import baseGetTag from './baseGetTag.js'
|
||||
import getTag from './getTag.js'
|
||||
import isBuffer from '../isBuffer.js'
|
||||
import isTypedArray from '../isTypedArray.js'
|
||||
|
||||
@@ -34,8 +34,8 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
|
||||
function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
|
||||
let objIsArr = Array.isArray(object)
|
||||
const othIsArr = Array.isArray(other)
|
||||
let objTag = objIsArr ? arrayTag : baseGetTag(object)
|
||||
let othTag = othIsArr ? arrayTag : baseGetTag(other)
|
||||
let objTag = objIsArr ? arrayTag : getTag(object)
|
||||
let othTag = othIsArr ? arrayTag : getTag(other)
|
||||
|
||||
objTag = objTag == argsTag ? objectTag : objTag
|
||||
othTag = othTag == argsTag ? objectTag : othTag
|
||||
|
||||
@@ -1,19 +1,4 @@
|
||||
import baseGetTag from './baseGetTag.js'
|
||||
|
||||
/** `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}`
|
||||
const toString = Object.prototype.toString
|
||||
|
||||
/**
|
||||
* Gets the `toStringTag` of `value`.
|
||||
@@ -22,30 +7,11 @@ const weakMapCtorString = `${WeakMap}`
|
||||
* @param {*} value The value to query.
|
||||
* @returns {string} Returns the `toStringTag`.
|
||||
*/
|
||||
let getTag = baseGetTag
|
||||
|
||||
// Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
|
||||
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
|
||||
function getTag(value) {
|
||||
if (value == null) {
|
||||
return value === undefined ? '[object Undefined]' : '[object Null]'
|
||||
}
|
||||
return toString.call(value)
|
||||
}
|
||||
|
||||
export default getTag
|
||||
|
||||
Reference in New Issue
Block a user