Sin descripción

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**
  2. * lodash (Custom Build) <https://lodash.com/>
  3. * Build: `lodash modularize exports="npm" -o ./`
  4. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  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. /** Used as references for various `Number` constants. */
  10. var MAX_SAFE_INTEGER = 9007199254740991;
  11. /** `Object#toString` result references. */
  12. var argsTag = '[object Arguments]',
  13. funcTag = '[object Function]',
  14. genTag = '[object GeneratorFunction]';
  15. /** Used for built-in method references. */
  16. var objectProto = Object.prototype;
  17. /** Used to check objects for own properties. */
  18. var hasOwnProperty = objectProto.hasOwnProperty;
  19. /**
  20. * Used to resolve the
  21. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  22. * of values.
  23. */
  24. var objectToString = objectProto.toString;
  25. /** Built-in value references. */
  26. var propertyIsEnumerable = objectProto.propertyIsEnumerable;
  27. /**
  28. * Checks if `value` is likely an `arguments` object.
  29. *
  30. * @static
  31. * @memberOf _
  32. * @since 0.1.0
  33. * @category Lang
  34. * @param {*} value The value to check.
  35. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  36. * else `false`.
  37. * @example
  38. *
  39. * _.isArguments(function() { return arguments; }());
  40. * // => true
  41. *
  42. * _.isArguments([1, 2, 3]);
  43. * // => false
  44. */
  45. function isArguments(value) {
  46. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  47. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  48. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  49. }
  50. /**
  51. * Checks if `value` is array-like. A value is considered array-like if it's
  52. * not a function and has a `value.length` that's an integer greater than or
  53. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  54. *
  55. * @static
  56. * @memberOf _
  57. * @since 4.0.0
  58. * @category Lang
  59. * @param {*} value The value to check.
  60. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  61. * @example
  62. *
  63. * _.isArrayLike([1, 2, 3]);
  64. * // => true
  65. *
  66. * _.isArrayLike(document.body.children);
  67. * // => true
  68. *
  69. * _.isArrayLike('abc');
  70. * // => true
  71. *
  72. * _.isArrayLike(_.noop);
  73. * // => false
  74. */
  75. function isArrayLike(value) {
  76. return value != null && isLength(value.length) && !isFunction(value);
  77. }
  78. /**
  79. * This method is like `_.isArrayLike` except that it also checks if `value`
  80. * is an object.
  81. *
  82. * @static
  83. * @memberOf _
  84. * @since 4.0.0
  85. * @category Lang
  86. * @param {*} value The value to check.
  87. * @returns {boolean} Returns `true` if `value` is an array-like object,
  88. * else `false`.
  89. * @example
  90. *
  91. * _.isArrayLikeObject([1, 2, 3]);
  92. * // => true
  93. *
  94. * _.isArrayLikeObject(document.body.children);
  95. * // => true
  96. *
  97. * _.isArrayLikeObject('abc');
  98. * // => false
  99. *
  100. * _.isArrayLikeObject(_.noop);
  101. * // => false
  102. */
  103. function isArrayLikeObject(value) {
  104. return isObjectLike(value) && isArrayLike(value);
  105. }
  106. /**
  107. * Checks if `value` is classified as a `Function` object.
  108. *
  109. * @static
  110. * @memberOf _
  111. * @since 0.1.0
  112. * @category Lang
  113. * @param {*} value The value to check.
  114. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  115. * @example
  116. *
  117. * _.isFunction(_);
  118. * // => true
  119. *
  120. * _.isFunction(/abc/);
  121. * // => false
  122. */
  123. function isFunction(value) {
  124. // The use of `Object#toString` avoids issues with the `typeof` operator
  125. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  126. var tag = isObject(value) ? objectToString.call(value) : '';
  127. return tag == funcTag || tag == genTag;
  128. }
  129. /**
  130. * Checks if `value` is a valid array-like length.
  131. *
  132. * **Note:** This method is loosely based on
  133. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  134. *
  135. * @static
  136. * @memberOf _
  137. * @since 4.0.0
  138. * @category Lang
  139. * @param {*} value The value to check.
  140. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  141. * @example
  142. *
  143. * _.isLength(3);
  144. * // => true
  145. *
  146. * _.isLength(Number.MIN_VALUE);
  147. * // => false
  148. *
  149. * _.isLength(Infinity);
  150. * // => false
  151. *
  152. * _.isLength('3');
  153. * // => false
  154. */
  155. function isLength(value) {
  156. return typeof value == 'number' &&
  157. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  158. }
  159. /**
  160. * Checks if `value` is the
  161. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  162. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  163. *
  164. * @static
  165. * @memberOf _
  166. * @since 0.1.0
  167. * @category Lang
  168. * @param {*} value The value to check.
  169. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  170. * @example
  171. *
  172. * _.isObject({});
  173. * // => true
  174. *
  175. * _.isObject([1, 2, 3]);
  176. * // => true
  177. *
  178. * _.isObject(_.noop);
  179. * // => true
  180. *
  181. * _.isObject(null);
  182. * // => false
  183. */
  184. function isObject(value) {
  185. var type = typeof value;
  186. return !!value && (type == 'object' || type == 'function');
  187. }
  188. /**
  189. * Checks if `value` is object-like. A value is object-like if it's not `null`
  190. * and has a `typeof` result of "object".
  191. *
  192. * @static
  193. * @memberOf _
  194. * @since 4.0.0
  195. * @category Lang
  196. * @param {*} value The value to check.
  197. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  198. * @example
  199. *
  200. * _.isObjectLike({});
  201. * // => true
  202. *
  203. * _.isObjectLike([1, 2, 3]);
  204. * // => true
  205. *
  206. * _.isObjectLike(_.noop);
  207. * // => false
  208. *
  209. * _.isObjectLike(null);
  210. * // => false
  211. */
  212. function isObjectLike(value) {
  213. return !!value && typeof value == 'object';
  214. }
  215. module.exports = isArguments;