How to determine if a TypedArray is signed?

1 week ago 15
ARTICLE AD BOX

I am working on a byte editor like DataView but with more features and I was wondering how to detect if a TypedArray was signed or not.

I already have this,

const signedTypes = new Set([ Int8Array, Int16Array, Int32Array, BigInt64Array ]); function isSigned(TypedArray) { return signedTypes.has(TypedArray.constructor); }

But this seems too manual - for example, if there was a new signed TypedArray like 20 years into the future I'm going to have to go back to my source code and add it into the list.

I could also check if the name matches Int or BigInt but that feels too hacky.

Feedback is appreciated, Thanks 🙏

Read Entire Article