Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / isNative.js
1 var isFunction = require('./isFunction'),
2     isHostObject = require('./internal/isHostObject'),
3     isObjectLike = require('./isObjectLike');
4
5 /** Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns). */
6 var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
7
8 /** Used to detect host constructors (Safari > 5). */
9 var reIsHostCtor = /^\[object .+?Constructor\]$/;
10
11 /** Used for built-in method references. */
12 var objectProto = global.Object.prototype;
13
14 /** Used to resolve the decompiled source of functions. */
15 var funcToString = global.Function.prototype.toString;
16
17 /** Used to check objects for own properties. */
18 var hasOwnProperty = objectProto.hasOwnProperty;
19
20 /** Used to detect if a method is native. */
21 var reIsNative = RegExp('^' +
22   funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
23   .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
24 );
25
26 /**
27  * Checks if `value` is a native function.
28  *
29  * @static
30  * @memberOf _
31  * @category Lang
32  * @param {*} value The value to check.
33  * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
34  * @example
35  *
36  * _.isNative(Array.prototype.push);
37  * // => true
38  *
39  * _.isNative(_);
40  * // => false
41  */
42 function isNative(value) {
43   if (value == null) {
44     return false;
45   }
46   if (isFunction(value)) {
47     return reIsNative.test(funcToString.call(value));
48   }
49   return isObjectLike(value) &&
50     (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
51 }
52
53 module.exports = isNative;