Simplify isType modules.

This commit is contained in:
John-David Dalton
2017-01-10 13:44:02 -08:00
parent b2f69ea36a
commit 4ecd69e4fa
24 changed files with 50 additions and 217 deletions

View File

@@ -1,6 +1,26 @@
import baseIsTypedArray from './.internal/baseIsTypedArray.js';
import baseGetTag from './.internal/baseGetTag.js';
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;
/* Node.js helper references. */
const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
@@ -21,6 +41,6 @@ const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
*/
const isTypedArray = nodeIsTypedArray
? value => nodeIsTypedArray(value)
: baseIsTypedArray;
: value => isObjectLike(value) && isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
export default isTypedArray;