typed-array-constructor
v1.0.2
Published
Get a typed array constructor based on the hypothetical max value it could contain. Signed or unsigned.
Downloads
19
Maintainers
Readme
typed-array-constructor
Get a typed array constructor based on the hypothetical max value it could contain. Signed or unsigned.
Installation
npm install typed-array-constructor
Usage
import typedArrayConstructor from "typed-array-constructor";
new (typedArrayConstructor(255))(10);
// => Uint8Array(10)
new (typedArrayConstructor(127, true))(10);
// => Int8Array(10)
new (typedArrayConstructor(255, true))(10);
// => Int16Array(10)
new (typedArrayConstructor(-255))(10);
// => Uint8Array(10)
new (typedArrayConstructor(-255, true))(10);
// => Int16Array(10)
new (typedArrayConstructor(65535 + 1))(10);
// => Uint32Array(10)
API
typedArrayConstructor
typedArrayConstructor(maxValue, signed) ⇒ Uint8Array | Uint16Array | Uint32Array | BigInt64Array | Int8Array | Int16Array | Int32Array | BigInt64Array ⏏
Get a typed array constructor based on the hypothetical max value it could contain. Signed or unsigned.
Kind: Exported function See: MDN TypedArray objects
| Param | Type | Description | | -------- | -------------------- | ------------------------------- | | maxValue | number | The max value expected. | | signed | boolean | Get a signed or unsigned array. |
License
MIT. See license file.