Skip to content

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

License

Notifications You must be signed in to change notification settings

dmnsgn/typed-array-constructor

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

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.

About

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

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published