typed-array-constructor
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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.

Package Sidebar

Install

npm i typed-array-constructor

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

7.97 kB

Total Files

6

Last publish

Collaborators

  • dmnsgn