Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

typed-array-constructor

dmnsgn89MIT1.0.2TypeScript support: included

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

constructor, typed-arrays, arrays, util

readme

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.

changelog

Changelog

All notable changes to this project will be documented in this file. See commit-and-tag-version for commit guidelines.

1.0.2 (2024-07-06)

1.0.1 (2023-02-08)

1.0.0 (2023-02-08)