mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Simplify isTypedArray.
This commit is contained in:
@@ -3,23 +3,8 @@ import isLength from './isLength.js';
|
|||||||
import isObjectLike from './isObjectLike.js';
|
import isObjectLike from './isObjectLike.js';
|
||||||
import nodeUtil from './.internal/nodeUtil.js';
|
import nodeUtil from './.internal/nodeUtil.js';
|
||||||
|
|
||||||
/** Used to identify `toStringTag` values of typed arrays. */
|
/** Used to match `toStringTag` values of typed arrays. */
|
||||||
const typedArrayTags = {};
|
const reTypedTag = /^\[object (?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)\]$/;
|
||||||
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. */
|
/* Node.js helper references. */
|
||||||
const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
|
const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
|
||||||
@@ -41,6 +26,6 @@ const nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
|
|||||||
*/
|
*/
|
||||||
const isTypedArray = nodeIsTypedArray
|
const isTypedArray = nodeIsTypedArray
|
||||||
? value => nodeIsTypedArray(value)
|
? 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;
|
export default isTypedArray;
|
||||||
|
|||||||
Reference in New Issue
Block a user