1.0.1 • Published 1 year ago

typed-array-constructor v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

typed-array-constructor

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Get a typed array constructor based on the hypothetical max value it could contain. Signed or unsigned.

paypal coinbase twitter

npm.io

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

ParamTypeDescription
maxValuenumberThe max value expected.
signedbooleanGet a signed or unsigned array.

License

MIT. See license file.