Skip to content

Commit

Permalink
Replace getTag implementation by the one from baseGetTag (remove work…
Browse files Browse the repository at this point in the history
…arounds) (lodash#4115)
  • Loading branch information
blikblum authored and jdalton committed Dec 11, 2018
1 parent c77650a commit aa1d7d8
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 83 deletions.
17 changes: 0 additions & 17 deletions .internal/baseGetTag.js

This file was deleted.

6 changes: 3 additions & 3 deletions .internal/baseIsEqualDeep.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down
44 changes: 5 additions & 39 deletions .internal/getTag.js
Original file line number Diff line number Diff line change
@@ -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`.
Expand All @@ -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
4 changes: 2 additions & 2 deletions isArguments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike'

/**
Expand All @@ -17,7 +17,7 @@ import isObjectLike from './isObjectLike'
* // => false
*/
function isArguments(value) {
return isObjectLike(value) && baseGetTag(value) == '[object Arguments]'
return isObjectLike(value) && getTag(value) == '[object Arguments]'
}

export default isArguments
4 changes: 2 additions & 2 deletions isArrayBuffer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'
import nodeTypes from './.internal/nodeTypes.js'

Expand All @@ -22,6 +22,6 @@ const nodeIsArrayBuffer = nodeTypes && nodeTypes.isArrayBuffer
*/
const isArrayBuffer = nodeIsArrayBuffer
? (value) => nodeIsArrayBuffer(value)
: (value) => isObjectLike(value) && baseGetTag(value) == '[object ArrayBuffer]'
: (value) => isObjectLike(value) && getTag(value) == '[object ArrayBuffer]'

export default isArrayBuffer
4 changes: 2 additions & 2 deletions isBoolean.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'

/**
Expand All @@ -18,7 +18,7 @@ import isObjectLike from './isObjectLike.js'
*/
function isBoolean(value) {
return value === true || value === false ||
(isObjectLike(value) && baseGetTag(value) == '[object Boolean]')
(isObjectLike(value) && getTag(value) == '[object Boolean]')
}

export default isBoolean
4 changes: 2 additions & 2 deletions isDate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'
import nodeTypes from './.internal/nodeTypes.js'

Expand All @@ -22,6 +22,6 @@ const nodeIsDate = nodeTypes && nodeTypes.isDate
*/
const isDate = nodeIsDate
? (value) => nodeIsDate(value)
: (value) => isObjectLike(value) && baseGetTag(value) == '[object Date]'
: (value) => isObjectLike(value) && getTag(value) == '[object Date]'

export default isDate
4 changes: 2 additions & 2 deletions isError.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'
import isPlainObject from './isPlainObject.js'

Expand All @@ -22,7 +22,7 @@ function isError(value) {
if (!isObjectLike(value)) {
return false
}
const tag = baseGetTag(value)
const tag = getTag(value)
return tag == '[object Error]' || tag == '[object DOMException]' ||
(typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value))
}
Expand Down
4 changes: 2 additions & 2 deletions isFunction.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObject from './isObject.js'

/**
Expand All @@ -22,7 +22,7 @@ function isFunction(value) {
}
// The use of `Object#toString` avoids issues with the `typeof` operator
// 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]' ||
tag == '[object GeneratorFunction]' || tag == '[object Proxy]'
}
Expand Down
4 changes: 2 additions & 2 deletions isNumber.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'

/**
Expand Down Expand Up @@ -28,7 +28,7 @@ import isObjectLike from './isObjectLike.js'
*/
function isNumber(value) {
return typeof value == 'number' ||
(isObjectLike(value) && baseGetTag(value) == '[object Number]')
(isObjectLike(value) && getTag(value) == '[object Number]')
}

export default isNumber
4 changes: 2 additions & 2 deletions isPlainObject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'

/**
Expand Down Expand Up @@ -28,7 +28,7 @@ import isObjectLike from './isObjectLike.js'
* // => true
*/
function isPlainObject(value) {
if (!isObjectLike(value) || baseGetTag(value) != '[object Object]') {
if (!isObjectLike(value) || getTag(value) != '[object Object]') {
return false
}
if (Object.getPrototypeOf(value) === null) {
Expand Down
4 changes: 2 additions & 2 deletions isRegExp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import isObjectLike from './isObjectLike.js'
import nodeTypes from './.internal/nodeTypes.js'

Expand All @@ -22,6 +22,6 @@ const nodeIsRegExp = nodeTypes && nodeTypes.isRegExp
*/
const isRegExp = nodeIsRegExp
? (value) => nodeIsRegExp(value)
: (value) => isObjectLike(value) && baseGetTag(value) == '[object RegExp]'
: (value) => isObjectLike(value) && getTag(value) == '[object RegExp]'

export default isRegExp
4 changes: 2 additions & 2 deletions isString.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -17,7 +17,7 @@ import baseGetTag from './.internal/baseGetTag.js'
*/
function isString(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
4 changes: 2 additions & 2 deletions isSymbol.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -17,7 +17,7 @@ import baseGetTag from './.internal/baseGetTag.js'
*/
function isSymbol(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
4 changes: 2 additions & 2 deletions isTypedArray.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import baseGetTag from './.internal/baseGetTag.js'
import getTag from './.internal/getTag.js'
import nodeTypes from './.internal/nodeTypes.js'
import isObjectLike from './isObjectLike'

Expand All @@ -25,6 +25,6 @@ const nodeIsTypedArray = nodeTypes && nodeTypes.isTypedArray
*/
const isTypedArray = nodeIsTypedArray
? (value) => nodeIsTypedArray(value)
: (value) => isObjectLike(value) && reTypedTag.test(baseGetTag(value))
: (value) => isObjectLike(value) && reTypedTag.test(getTag(value))

export default isTypedArray

0 comments on commit aa1d7d8

Please sign in to comment.