mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 02:17:50 +00:00
Remove toSource.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import baseGetTag from './baseGetTag.js'
|
import baseGetTag from './baseGetTag.js'
|
||||||
import toSource from './toSource.js'
|
|
||||||
|
|
||||||
/** `Object#toString` result references. */
|
/** `Object#toString` result references. */
|
||||||
const dataViewTag = '[object DataView]'
|
const dataViewTag = '[object DataView]'
|
||||||
@@ -10,11 +9,11 @@ const setTag = '[object Set]'
|
|||||||
const weakMapTag = '[object WeakMap]'
|
const weakMapTag = '[object WeakMap]'
|
||||||
|
|
||||||
/** Used to detect maps, sets, and weakmaps. */
|
/** Used to detect maps, sets, and weakmaps. */
|
||||||
const dataViewCtorString = toSource(DataView)
|
const dataViewCtorString = `${ DataView }`
|
||||||
const mapCtorString = toSource(Map)
|
const mapCtorString = `${ Map }`
|
||||||
const promiseCtorString = toSource(Promise)
|
const promiseCtorString = `${ Promise }`
|
||||||
const setCtorString = toSource(Set)
|
const setCtorString = `${ Set }`
|
||||||
const weakMapCtorString = toSource(WeakMap)
|
const weakMapCtorString = `${ WeakMap }`
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the `toStringTag` of `value`.
|
* Gets the `toStringTag` of `value`.
|
||||||
@@ -34,7 +33,7 @@ if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
|
|||||||
getTag = (value) => {
|
getTag = (value) => {
|
||||||
const result = baseGetTag(value)
|
const result = baseGetTag(value)
|
||||||
const Ctor = result == objectTag ? value.constructor : undefined
|
const Ctor = result == objectTag ? value.constructor : undefined
|
||||||
const ctorString = Ctor ? toSource(Ctor) : ''
|
const ctorString = Ctor ? `${ Ctor }` : ''
|
||||||
|
|
||||||
if (ctorString) {
|
if (ctorString) {
|
||||||
switch (ctorString) {
|
switch (ctorString) {
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
/** Used to resolve the decompiled source of functions. */
|
|
||||||
const funcToString = Function.prototype.toString
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts `func` to its source code.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Function} func The function to convert.
|
|
||||||
* @returns {string} Returns the source code.
|
|
||||||
*/
|
|
||||||
function toSource(func) {
|
|
||||||
if (func != null) {
|
|
||||||
try {
|
|
||||||
return funcToString.call(func)
|
|
||||||
} catch (e) {}
|
|
||||||
try {
|
|
||||||
return `${ func }`
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
export default toSource
|
|
||||||
11
isNative.js
11
isNative.js
@@ -1,6 +1,4 @@
|
|||||||
import isFunction from './isFunction.js'
|
|
||||||
import isObject from './isObject.js'
|
import isObject from './isObject.js'
|
||||||
import toSource from './.internal/toSource.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to match `RegExp`
|
* Used to match `RegExp`
|
||||||
@@ -8,9 +6,6 @@ import toSource from './.internal/toSource.js'
|
|||||||
*/
|
*/
|
||||||
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g
|
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g
|
||||||
|
|
||||||
/** Used to detect host constructors (Safari). */
|
|
||||||
const reIsHostCtor = /^\[object .+?Constructor\]$/
|
|
||||||
|
|
||||||
/** Used to detect if a method is native. */
|
/** Used to detect if a method is native. */
|
||||||
const reIsNative = RegExp(`^${
|
const reIsNative = RegExp(`^${
|
||||||
Function.prototype.toString.call(Object.prototype.hasOwnProperty)
|
Function.prototype.toString.call(Object.prototype.hasOwnProperty)
|
||||||
@@ -35,11 +30,7 @@ const reIsNative = RegExp(`^${
|
|||||||
* // => false
|
* // => false
|
||||||
*/
|
*/
|
||||||
function isNative(value) {
|
function isNative(value) {
|
||||||
if (!isObject(value)) {
|
return isObject(value) && reIsNative.test(value)
|
||||||
return false
|
|
||||||
}
|
|
||||||
const pattern = isFunction(value) ? reIsNative : reIsHostCtor
|
|
||||||
return pattern.test(toSource(value))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default isNative
|
export default isNative
|
||||||
|
|||||||
Reference in New Issue
Block a user