Simplify isTypedArray.

This commit is contained in:
John-David Dalton
2017-01-10 19:45:37 -08:00
parent b2504adb30
commit dc4671dd0d

View File

@@ -3,23 +3,8 @@ import isLength from './isLength.js';
import isObjectLike from './isObjectLike.js';
import nodeUtil from './.internal/nodeUtil.js';
/** Used to identify `toStringTag` values of typed arrays. */
const typedArrayTags = {};
typedArrayTags['[object Float32Array]'] = typedArrayTags['[object Float64Array]'] =
typedArrayTags['[object Int8Array]'] = typedArrayTags['[object Int16Array]'] =
typedArrayTags['[object Int32Array]'] = typedArrayTags['[object Uint8Array]'] =
typedArrayTags['[object Uint8ClampedArray]'] = typedArrayTags['[object Uint16Array]'] =
typedArrayTags['[object Uint32Array]'] = true;
typedArrayTags['[object AsyncFunction]'] = typedArrayTags['[object Arguments]'] =
typedArrayTags['[object Array]'] = typedArrayTags['[object ArrayBuffer]'] =
typedArrayTags['[object Boolean]'] = typedArrayTags['[object DataView]'] =
typedArrayTags['[object Date]'] = typedArrayTags['[object Error]'] =
typedArrayTags['[object Function]'] = typedArrayTags['[object GeneratorFunction]'] =
typedArrayTags['[object Map]'] = typedArrayTags['[object Number]'] =
typedArrayTags['[object Object]'] = typedArrayTags['[object Proxy]'] =
typedArrayTags['[object RegExp]'] = typedArrayTags['[object Set]'] =
typedArrayTags['[object String]'] = typedArrayTags['[object WeakMap]'] = false;
/** Used to match `toStringTag` values of typed arrays. */
const reTypedTag = /^\[object (?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)\]$/;
/* Node.js helper references. */
const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
@@ -41,6 +26,6 @@ const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
*/
const isTypedArray = nodeIsTypedArray
? value => nodeIsTypedArray(value)
: value => isObjectLike(value) && isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
: value => isObjectLike(value) && isLength(value.length) && reTypedTag.test(baseGetTag(value));
export default isTypedArray;