index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Lodash (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modularize exports="npm" -o ./`
  4. * Copyright JS Foundation and other contributors <https://js.foundation/>
  5. * Released under MIT license <https://lodash.com/license>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. */
  9. /** `Object#toString` result references. */
  10. var asyncTag = '[object AsyncFunction]',
  11. funcTag = '[object Function]',
  12. genTag = '[object GeneratorFunction]',
  13. nullTag = '[object Null]',
  14. proxyTag = '[object Proxy]',
  15. undefinedTag = '[object Undefined]';
  16. /** Detect free variable `global` from Node.js. */
  17. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  18. /** Detect free variable `self`. */
  19. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  20. /** Used as a reference to the global object. */
  21. var root = freeGlobal || freeSelf || Function('return this')();
  22. /** Used for built-in method references. */
  23. var objectProto = Object.prototype;
  24. /** Used to check objects for own properties. */
  25. var hasOwnProperty = objectProto.hasOwnProperty;
  26. /**
  27. * Used to resolve the
  28. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  29. * of values.
  30. */
  31. var nativeObjectToString = objectProto.toString;
  32. /** Built-in value references. */
  33. var Symbol = root.Symbol,
  34. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  35. /**
  36. * The base implementation of `getTag` without fallbacks for buggy environments.
  37. *
  38. * @private
  39. * @param {*} value The value to query.
  40. * @returns {string} Returns the `toStringTag`.
  41. */
  42. function baseGetTag(value) {
  43. if (value == null) {
  44. return value === undefined ? undefinedTag : nullTag;
  45. }
  46. return (symToStringTag && symToStringTag in Object(value))
  47. ? getRawTag(value)
  48. : objectToString(value);
  49. }
  50. /**
  51. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  52. *
  53. * @private
  54. * @param {*} value The value to query.
  55. * @returns {string} Returns the raw `toStringTag`.
  56. */
  57. function getRawTag(value) {
  58. var isOwn = hasOwnProperty.call(value, symToStringTag),
  59. tag = value[symToStringTag];
  60. try {
  61. value[symToStringTag] = undefined;
  62. var unmasked = true;
  63. } catch (e) {}
  64. var result = nativeObjectToString.call(value);
  65. if (unmasked) {
  66. if (isOwn) {
  67. value[symToStringTag] = tag;
  68. } else {
  69. delete value[symToStringTag];
  70. }
  71. }
  72. return result;
  73. }
  74. /**
  75. * Converts `value` to a string using `Object.prototype.toString`.
  76. *
  77. * @private
  78. * @param {*} value The value to convert.
  79. * @returns {string} Returns the converted string.
  80. */
  81. function objectToString(value) {
  82. return nativeObjectToString.call(value);
  83. }
  84. /**
  85. * Checks if `value` is classified as a `Function` object.
  86. *
  87. * @static
  88. * @memberOf _
  89. * @since 0.1.0
  90. * @category Lang
  91. * @param {*} value The value to check.
  92. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  93. * @example
  94. *
  95. * _.isFunction(_);
  96. * // => true
  97. *
  98. * _.isFunction(/abc/);
  99. * // => false
  100. */
  101. function isFunction(value) {
  102. if (!isObject(value)) {
  103. return false;
  104. }
  105. // The use of `Object#toString` avoids issues with the `typeof` operator
  106. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  107. var tag = baseGetTag(value);
  108. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  109. }
  110. /**
  111. * Checks if `value` is the
  112. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  113. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  114. *
  115. * @static
  116. * @memberOf _
  117. * @since 0.1.0
  118. * @category Lang
  119. * @param {*} value The value to check.
  120. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  121. * @example
  122. *
  123. * _.isObject({});
  124. * // => true
  125. *
  126. * _.isObject([1, 2, 3]);
  127. * // => true
  128. *
  129. * _.isObject(_.noop);
  130. * // => true
  131. *
  132. * _.isObject(null);
  133. * // => false
  134. */
  135. function isObject(value) {
  136. var type = typeof value;
  137. return value != null && (type == 'object' || type == 'function');
  138. }
  139. module.exports = isFunction;