Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
petamoriken committed Oct 9, 2021
1 parent 2e24437 commit 6eae403
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/_util/is.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export function isObjectLike(value) {
}

// Inspired by util.types implementation of Node.js
const TypedArrayPrototype = Reflect.getPrototypeOf(Uint8Array).prototype;
const getTypedArrayPrototypeSybolToStringTag = Reflect.getOwnPropertyDescriptor(TypedArrayPrototype, Symbol.toStringTag).get;
const getTypedArrayPrototypeSybolToStringTag = Reflect.getOwnPropertyDescriptor(Reflect.getPrototypeOf(Uint8Array).prototype, Symbol.toStringTag).get;

/**
* @param {unknown} value
Expand All @@ -34,8 +33,6 @@ export function isUint16Array(value) {
return getTypedArrayPrototypeSybolToStringTag.call(value) === "Uint16Array";
}

const toString = Object.prototype.toString;

/**
* @param {unknown} value
* @returns {value is DataView}
Expand All @@ -49,10 +46,6 @@ export function isDataView(value) {
return false;
}

if (toString.call(value) !== "[object DataView]") {
return false;
}

return true;
}

Expand All @@ -61,15 +54,15 @@ export function isDataView(value) {
* @returns {value is ArrayBuffer}
*/
export function isArrayBuffer(value) {
return isObjectLike(value) && toString.call(value) === "[object ArrayBuffer]";
return isObjectLike(value) && value[Symbol.toStringTag] === "ArrayBuffer";
}

/**
* @param {unknown} value
* @returns {value is SharedArrayBuffer}
*/
export function isSharedArrayBuffer(value) {
return isObjectLike(value) && toString.call(value) === "[object SharedArrayBuffer]";
return isObjectLike(value) && value[Symbol.toStringTag] === "SharedArrayBuffer";
}

/**
Expand All @@ -90,7 +83,7 @@ export function isOrdinaryArray(value) {
}

const iterator = value[Symbol.iterator]();
if (toString.call(iterator) !== "[object Array Iterator]") {
if (iterator[Symbol.toStringTag] !== "Array Iterator") {
return false;
}

Expand All @@ -107,7 +100,7 @@ export function isOrdinaryTypedArray(value) {
}

const iterator = value[Symbol.iterator]();
if (toString.call(iterator) !== "[object Array Iterator]") {
if (iterator[Symbol.toStringTag] !== "Array Iterator") {
return false;
}

Expand Down

0 comments on commit 6eae403

Please sign in to comment.