1.2.0 • Published 4 years ago

uint1array v1.2.0

Weekly downloads
23
License
MIT
Repository
github
Last release
4 years ago

:wind_chime: Uint1Array npm downloads version

JavaScript's missing TypedArray. Bit-level view of any underlying ArrayBuffer.

API

The API simply mirrors a regular TypedArray.

Differences from the TypedArray API

The only two differences are that Uint1Array has special cases of the following standard TypedArray properties:

Uint1Array.BYTES_PER_ELEMENT

Returns a number value of the element size.

BYTES_PER_ELEMENT equals 0.125 in the case of an Uint1Array.

Uint1Array.length

Static length property.

Static class member length value is 0 in the case of Uint1Array. For the actual length (number of bits), use <Uint1Array>.length.

Get

npm install --save uint1array

Using

You can use like an ordinary TypedArray:

// pick an import style, either ESM or CommonJS

// ESM
// import Uint1Array from 'uint1array';

// CommonJS
// const Uint1Array = require('uint1array').default;

const message = "JAVASCRIPT ROCKS";
const chars = message.split('').map( c => c.charCodeAt(0) );

const buf = new ArrayBuffer(chars.length);
const bytes = new Uint8Array(buf);
const bits = new Uint1Array(buf);

bytes.set(chars);

console.log(`${bits}`); // Uint1Array [ 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0 ]

More Information

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.6

6 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago