mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 16:47:49 +00:00
Bump to v4.13.0.
This commit is contained in:
47
isNative.js
47
isNative.js
@@ -1,34 +1,16 @@
|
||||
import isFunction from './isFunction';
|
||||
import isHostObject from './_isHostObject';
|
||||
import isObject from './isObject';
|
||||
import toSource from './_toSource';
|
||||
import baseIsNative from './_baseIsNative.js';
|
||||
import isMaskable from './_isMaskable.js';
|
||||
|
||||
/**
|
||||
* Used to match `RegExp`
|
||||
* [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns).
|
||||
*/
|
||||
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
|
||||
|
||||
/** Used to detect host constructors (Safari). */
|
||||
var reIsHostCtor = /^\[object .+?Constructor\]$/;
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/** Used to resolve the decompiled source of functions. */
|
||||
var funcToString = Function.prototype.toString;
|
||||
|
||||
/** Used to check objects for own properties. */
|
||||
var hasOwnProperty = objectProto.hasOwnProperty;
|
||||
|
||||
/** Used to detect if a method is native. */
|
||||
var reIsNative = RegExp('^' +
|
||||
funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
|
||||
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
|
||||
);
|
||||
|
||||
/**
|
||||
* Checks if `value` is a native function.
|
||||
* Checks if `value` is a pristine native function.
|
||||
*
|
||||
* **Note:** This method can't reliably detect native functions in the
|
||||
* presence of the `core-js` package because `core-js` circumvents this kind
|
||||
* of detection. Despite multiple requests, the `core-js` maintainer has made
|
||||
* it clear: any attempt to fix the detection will be obstructed. As a result,
|
||||
* we're left with little choice but to throw an error. Unfortunately, this
|
||||
* also affects packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
|
||||
* which rely on `core-js`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
@@ -46,11 +28,10 @@ var reIsNative = RegExp('^' +
|
||||
* // => false
|
||||
*/
|
||||
function isNative(value) {
|
||||
if (!isObject(value)) {
|
||||
return false;
|
||||
if (isMaskable(value)) {
|
||||
throw new Error('This method is not supported with `core-js`. Try https://github.com/es-shims.');
|
||||
}
|
||||
var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
|
||||
return pattern.test(toSource(value));
|
||||
return baseIsNative(value);
|
||||
}
|
||||
|
||||
export default isNative;
|
||||
|
||||
Reference in New Issue
Block a user