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