Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80742 views
1
var escapeRegExp = require('../string/escapeRegExp'),
2
isObjectLike = require('../internal/isObjectLike');
3
4
/** `Object#toString` result references. */
5
var funcTag = '[object Function]';
6
7
/** Used to detect host constructors (Safari > 5). */
8
var reIsHostCtor = /^\[object .+?Constructor\]$/;
9
10
/** Used for native method references. */
11
var objectProto = Object.prototype;
12
13
/** Used to resolve the decompiled source of functions. */
14
var fnToString = Function.prototype.toString;
15
16
/** Used to check objects for own properties. */
17
var hasOwnProperty = objectProto.hasOwnProperty;
18
19
/**
20
* Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring)
21
* of values.
22
*/
23
var objToString = objectProto.toString;
24
25
/** Used to detect if a method is native. */
26
var reIsNative = RegExp('^' +
27
escapeRegExp(fnToString.call(hasOwnProperty))
28
.replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
29
);
30
31
/**
32
* Checks if `value` is a native function.
33
*
34
* @static
35
* @memberOf _
36
* @category Lang
37
* @param {*} value The value to check.
38
* @returns {boolean} Returns `true` if `value` is a native function, else `false`.
39
* @example
40
*
41
* _.isNative(Array.prototype.push);
42
* // => true
43
*
44
* _.isNative(_);
45
* // => false
46
*/
47
function isNative(value) {
48
if (value == null) {
49
return false;
50
}
51
if (objToString.call(value) == funcTag) {
52
return reIsNative.test(fnToString.call(value));
53
}
54
return isObjectLike(value) && reIsHostCtor.test(value);
55
}
56
57
module.exports = isNative;
58
59