mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-30 15:07:50 +00:00
49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import isFunction from './isFunction.js';
|
|
import isMasked from './_isMasked.js';
|
|
import isObject from './isObject.js';
|
|
import toSource from './_toSource.js';
|
|
|
|
/**
|
|
* Used to match `RegExp`
|
|
* [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
|
|
*/
|
|
const reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
|
|
|
/** Used to detect host constructors (Safari). */
|
|
const reIsHostCtor = /^\[object .+?Constructor\]$/;
|
|
|
|
/** Used for built-in method references. */
|
|
const funcProto = Function.prototype;
|
|
const objectProto = Object.prototype;
|
|
|
|
/** Used to resolve the decompiled source of functions. */
|
|
const funcToString = funcProto.toString;
|
|
|
|
/** Used to check objects for own properties. */
|
|
const hasOwnProperty = objectProto.hasOwnProperty;
|
|
|
|
/** Used to detect if a method is native. */
|
|
const reIsNative = RegExp(`^${
|
|
funcToString.call(hasOwnProperty)
|
|
.replace(reRegExpChar, '\\$&')
|
|
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?')
|
|
}$`);
|
|
|
|
/**
|
|
* The base implementation of `_.isNative` without bad shim checks.
|
|
*
|
|
* @private
|
|
* @param {*} value The value to check.
|
|
* @returns {boolean} Returns `true` if `value` is a native function,
|
|
* else `false`.
|
|
*/
|
|
function baseIsNative(value) {
|
|
if (!isObject(value) || isMasked(value)) {
|
|
return false;
|
|
}
|
|
const pattern = isFunction(value) ? reIsNative : reIsHostCtor;
|
|
return pattern.test(toSource(value));
|
|
}
|
|
|
|
export default baseIsNative;
|