typed-array-constructor
Version:
Get a typed array constructor based on the hypothetical max value it could contain. Signed or unsigned.
75 lines (51 loc) • 3.5 kB
Markdown
# typed-array-constructor
[](https://www.npmjs.com/package/typed-array-constructor)
[](https://www.npmjs.com/package/typed-array-constructor)
[](https://bundlephobia.com/package/typed-array-constructor)
[](https://github.com/dmnsgn/typed-array-constructor/blob/main/package.json)
[](https://github.com/microsoft/TypeScript)
[](https://conventionalcommits.org)
[](https://github.com/prettier/prettier)
[](https://github.com/eslint/eslint)
[](https://github.com/dmnsgn/typed-array-constructor/blob/main/LICENSE.md)
Get a typed array constructor based on the hypothetical max value it could contain. Signed or unsigned.
[](https://paypal.me/dmnsgn)
[](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3)
[](https://twitter.com/dmnsgn)

## Installation
```bash
npm install typed-array-constructor
```
## Usage
```js
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
<!-- api-start -->
<a name="module_typedArrayConstructor"></a>
## typedArrayConstructor
<a name="exp_module_typedArrayConstructor--typedArrayConstructor"></a>
### typedArrayConstructor(maxValue, signed) ⇒ <code>Uint8Array</code> \| <code>Uint16Array</code> \| <code>Uint32Array</code> \| <code>BigInt64Array</code> \| <code>Int8Array</code> \| <code>Int16Array</code> \| <code>Int32Array</code> \| <code>BigInt64Array</code> ⏏
Get a typed array constructor based on the hypothetical max value it could contain. Signed or unsigned.
**Kind**: Exported function
**See**: [MDN TypedArray objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#typedarray_objects)
| Param | Type | Description |
| -------- | -------------------- | ------------------------------- |
| maxValue | <code>number</code> | The max value expected. |
| signed | <code>boolean</code> | Get a signed or unsigned array. |
<!-- api-end -->
## License
MIT. See [license file](https://github.com/dmnsgn/typed-array-constructor/blob/main/LICENSE.md).