_baseIsTypedArray.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var baseGetTag = require('./_baseGetTag'),
  2. isLength = require('./isLength'),
  3. isObjectLike = require('./isObjectLike');
  4. /** `Object#toString` result references. */
  5. var argsTag = '[object Arguments]',
  6. arrayTag = '[object Array]',
  7. boolTag = '[object Boolean]',
  8. dateTag = '[object Date]',
  9. errorTag = '[object Error]',
  10. funcTag = '[object Function]',
  11. mapTag = '[object Map]',
  12. numberTag = '[object Number]',
  13. objectTag = '[object Object]',
  14. regexpTag = '[object RegExp]',
  15. setTag = '[object Set]',
  16. stringTag = '[object String]',
  17. weakMapTag = '[object WeakMap]';
  18. var arrayBufferTag = '[object ArrayBuffer]',
  19. dataViewTag = '[object DataView]',
  20. float32Tag = '[object Float32Array]',
  21. float64Tag = '[object Float64Array]',
  22. int8Tag = '[object Int8Array]',
  23. int16Tag = '[object Int16Array]',
  24. int32Tag = '[object Int32Array]',
  25. uint8Tag = '[object Uint8Array]',
  26. uint8ClampedTag = '[object Uint8ClampedArray]',
  27. uint16Tag = '[object Uint16Array]',
  28. uint32Tag = '[object Uint32Array]';
  29. /** Used to identify `toStringTag` values of typed arrays. */
  30. var typedArrayTags = {};
  31. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  32. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  33. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  34. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  35. typedArrayTags[uint32Tag] = true;
  36. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  37. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  38. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  39. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  40. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  41. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  42. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  43. typedArrayTags[weakMapTag] = false;
  44. /**
  45. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  46. *
  47. * @private
  48. * @param {*} value The value to check.
  49. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  50. */
  51. function baseIsTypedArray(value) {
  52. return isObjectLike(value) &&
  53. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  54. }
  55. module.exports = baseIsTypedArray;