index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * lodash 3.9.1 (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modern modularize exports="npm" -o ./`
  4. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  5. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  6. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  7. * Available under MIT license <https://lodash.com/license>
  8. */
  9. /** `Object#toString` result references. */
  10. var funcTag = '[object Function]';
  11. /** Used to detect host constructors (Safari > 5). */
  12. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  13. /**
  14. * Checks if `value` is object-like.
  15. *
  16. * @private
  17. * @param {*} value The value to check.
  18. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  19. */
  20. function isObjectLike(value) {
  21. return !!value && typeof value == 'object';
  22. }
  23. /** Used for native method references. */
  24. var objectProto = Object.prototype;
  25. /** Used to resolve the decompiled source of functions. */
  26. var fnToString = Function.prototype.toString;
  27. /** Used to check objects for own properties. */
  28. var hasOwnProperty = objectProto.hasOwnProperty;
  29. /**
  30. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  31. * of values.
  32. */
  33. var objToString = objectProto.toString;
  34. /** Used to detect if a method is native. */
  35. var reIsNative = RegExp('^' +
  36. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  37. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  38. );
  39. /**
  40. * Gets the native function at `key` of `object`.
  41. *
  42. * @private
  43. * @param {Object} object The object to query.
  44. * @param {string} key The key of the method to get.
  45. * @returns {*} Returns the function if it's native, else `undefined`.
  46. */
  47. function getNative(object, key) {
  48. var value = object == null ? undefined : object[key];
  49. return isNative(value) ? value : undefined;
  50. }
  51. /**
  52. * Checks if `value` is classified as a `Function` object.
  53. *
  54. * @static
  55. * @memberOf _
  56. * @category Lang
  57. * @param {*} value The value to check.
  58. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  59. * @example
  60. *
  61. * _.isFunction(_);
  62. * // => true
  63. *
  64. * _.isFunction(/abc/);
  65. * // => false
  66. */
  67. function isFunction(value) {
  68. // The use of `Object#toString` avoids issues with the `typeof` operator
  69. // in older versions of Chrome and Safari which return 'function' for regexes
  70. // and Safari 8 equivalents which return 'object' for typed array constructors.
  71. return isObject(value) && objToString.call(value) == funcTag;
  72. }
  73. /**
  74. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  75. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  76. *
  77. * @static
  78. * @memberOf _
  79. * @category Lang
  80. * @param {*} value The value to check.
  81. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  82. * @example
  83. *
  84. * _.isObject({});
  85. * // => true
  86. *
  87. * _.isObject([1, 2, 3]);
  88. * // => true
  89. *
  90. * _.isObject(1);
  91. * // => false
  92. */
  93. function isObject(value) {
  94. // Avoid a V8 JIT bug in Chrome 19-20.
  95. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  96. var type = typeof value;
  97. return !!value && (type == 'object' || type == 'function');
  98. }
  99. /**
  100. * Checks if `value` is a native function.
  101. *
  102. * @static
  103. * @memberOf _
  104. * @category Lang
  105. * @param {*} value The value to check.
  106. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  107. * @example
  108. *
  109. * _.isNative(Array.prototype.push);
  110. * // => true
  111. *
  112. * _.isNative(_);
  113. * // => false
  114. */
  115. function isNative(value) {
  116. if (value == null) {
  117. return false;
  118. }
  119. if (isFunction(value)) {
  120. return reIsNative.test(fnToString.call(value));
  121. }
  122. return isObjectLike(value) && reIsHostCtor.test(value);
  123. }
  124. module.exports = getNative;