mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Remove getRawTag and objectToString.
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
import getRawTag from './getRawTag.js'
|
||||
import objectToString from './objectToString.js'
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
const nullTag = '[object Null]'
|
||||
const undefinedTag = '[object Undefined]'
|
||||
|
||||
/** Built-in value references. */
|
||||
const symToStringTag = Symbol ? Symbol.toStringTag : undefined
|
||||
const objectProto = Object.prototype
|
||||
const hasOwnProperty = objectProto.hasOwnProperty
|
||||
const toString = objectProto.toString
|
||||
const symToStringTag = typeof Symbol != 'undefined' ? Symbol.toStringTag : undefined
|
||||
|
||||
/**
|
||||
* The base implementation of `getTag` without fallbacks for buggy environments.
|
||||
@@ -17,11 +12,28 @@ const symToStringTag = Symbol ? Symbol.toStringTag : undefined
|
||||
*/
|
||||
function baseGetTag(value) {
|
||||
if (value == null) {
|
||||
return value === undefined ? undefinedTag : nullTag
|
||||
return value === undefined ? '[object Undefined]' : '[object Null]'
|
||||
}
|
||||
return (symToStringTag && symToStringTag in Object(value))
|
||||
? getRawTag(value)
|
||||
: objectToString(value)
|
||||
if (!(symToStringTag && symToStringTag in Object(value))) {
|
||||
return toString.call(value)
|
||||
}
|
||||
const isOwn = hasOwnProperty.call(value, symToStringTag)
|
||||
const tag = value[symToStringTag]
|
||||
let unmasked = false
|
||||
try {
|
||||
value[symToStringTag] = undefined
|
||||
unmasked = true
|
||||
} catch (e) {}
|
||||
|
||||
const result = toString.call(value)
|
||||
if (unmasked) {
|
||||
if (isOwn) {
|
||||
value[symToStringTag] = tag
|
||||
} else {
|
||||
delete value[symToStringTag]
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default baseGetTag
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/** Used for built-in method references. */
|
||||
const objectProto = Object.prototype
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
const hasOwnProperty = objectProto.hasOwnProperty
|
||||
|
||||
/**
|
||||
* Used to resolve the
|
||||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
||||
* of values.
|
||||
*/
|
||||
const nativeObjectToString = objectProto.toString
|
||||
|
||||
/** Built-in value references. */
|
||||
const symToStringTag = Symbol ? Symbol.toStringTag : undefined
|
||||
|
||||
/**
|
||||
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to query.
|
||||
* @returns {string} Returns the raw `toStringTag`.
|
||||
*/
|
||||
function getRawTag(value) {
|
||||
const isOwn = hasOwnProperty.call(value, symToStringTag)
|
||||
const tag = value[symToStringTag]
|
||||
let unmasked = false
|
||||
|
||||
try {
|
||||
value[symToStringTag] = undefined
|
||||
unmasked = true
|
||||
} catch (e) {}
|
||||
|
||||
const result = nativeObjectToString.call(value)
|
||||
if (unmasked) {
|
||||
if (isOwn) {
|
||||
value[symToStringTag] = tag
|
||||
} else {
|
||||
delete value[symToStringTag]
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export default getRawTag
|
||||
@@ -1,19 +0,0 @@
|
||||
/**
|
||||
* Used to resolve the
|
||||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
||||
* of values.
|
||||
*/
|
||||
const nativeObjectToString = Object.prototype.toString
|
||||
|
||||
/**
|
||||
* Converts `value` to a string using `Object.prototype.toString`.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to convert.
|
||||
* @returns {string} Returns the converted string.
|
||||
*/
|
||||
function objectToString(value) {
|
||||
return nativeObjectToString.call(value)
|
||||
}
|
||||
|
||||
export default objectToString
|
||||
Reference in New Issue
Block a user