Nenhuma descrição

index.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /**
  2. * lodash 3.0.4 (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 arrayTag = '[object Array]',
  11. funcTag = '[object Function]';
  12. /** Used to detect host constructors (Safari > 5). */
  13. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  14. /**
  15. * Checks if `value` is object-like.
  16. *
  17. * @private
  18. * @param {*} value The value to check.
  19. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  20. */
  21. function isObjectLike(value) {
  22. return !!value && typeof value == 'object';
  23. }
  24. /** Used for native method references. */
  25. var objectProto = Object.prototype;
  26. /** Used to resolve the decompiled source of functions. */
  27. var fnToString = Function.prototype.toString;
  28. /** Used to check objects for own properties. */
  29. var hasOwnProperty = objectProto.hasOwnProperty;
  30. /**
  31. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  32. * of values.
  33. */
  34. var objToString = objectProto.toString;
  35. /** Used to detect if a method is native. */
  36. var reIsNative = RegExp('^' +
  37. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  38. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  39. );
  40. /* Native method references for those with the same name as other `lodash` methods. */
  41. var nativeIsArray = getNative(Array, 'isArray');
  42. /**
  43. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  44. * of an array-like value.
  45. */
  46. var MAX_SAFE_INTEGER = 9007199254740991;
  47. /**
  48. * Gets the native function at `key` of `object`.
  49. *
  50. * @private
  51. * @param {Object} object The object to query.
  52. * @param {string} key The key of the method to get.
  53. * @returns {*} Returns the function if it's native, else `undefined`.
  54. */
  55. function getNative(object, key) {
  56. var value = object == null ? undefined : object[key];
  57. return isNative(value) ? value : undefined;
  58. }
  59. /**
  60. * Checks if `value` is a valid array-like length.
  61. *
  62. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  63. *
  64. * @private
  65. * @param {*} value The value to check.
  66. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  67. */
  68. function isLength(value) {
  69. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  70. }
  71. /**
  72. * Checks if `value` is classified as an `Array` object.
  73. *
  74. * @static
  75. * @memberOf _
  76. * @category Lang
  77. * @param {*} value The value to check.
  78. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  79. * @example
  80. *
  81. * _.isArray([1, 2, 3]);
  82. * // => true
  83. *
  84. * _.isArray(function() { return arguments; }());
  85. * // => false
  86. */
  87. var isArray = nativeIsArray || function(value) {
  88. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  89. };
  90. /**
  91. * Checks if `value` is classified as a `Function` object.
  92. *
  93. * @static
  94. * @memberOf _
  95. * @category Lang
  96. * @param {*} value The value to check.
  97. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  98. * @example
  99. *
  100. * _.isFunction(_);
  101. * // => true
  102. *
  103. * _.isFunction(/abc/);
  104. * // => false
  105. */
  106. function isFunction(value) {
  107. // The use of `Object#toString` avoids issues with the `typeof` operator
  108. // in older versions of Chrome and Safari which return 'function' for regexes
  109. // and Safari 8 equivalents which return 'object' for typed array constructors.
  110. return isObject(value) && objToString.call(value) == funcTag;
  111. }
  112. /**
  113. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  114. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  115. *
  116. * @static
  117. * @memberOf _
  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(1);
  130. * // => false
  131. */
  132. function isObject(value) {
  133. // Avoid a V8 JIT bug in Chrome 19-20.
  134. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  135. var type = typeof value;
  136. return !!value && (type == 'object' || type == 'function');
  137. }
  138. /**
  139. * Checks if `value` is a native function.
  140. *
  141. * @static
  142. * @memberOf _
  143. * @category Lang
  144. * @param {*} value The value to check.
  145. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  146. * @example
  147. *
  148. * _.isNative(Array.prototype.push);
  149. * // => true
  150. *
  151. * _.isNative(_);
  152. * // => false
  153. */
  154. function isNative(value) {
  155. if (value == null) {
  156. return false;
  157. }
  158. if (isFunction(value)) {
  159. return reIsNative.test(fnToString.call(value));
  160. }
  161. return isObjectLike(value) && reIsHostCtor.test(value);
  162. }
  163. module.exports = isArray;