uint1array

1.2.0 • Public • Published

🎐 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

/uint1array/

    Package Sidebar

    Install

    npm i uint1array

    Weekly Downloads

    100

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    24.9 kB

    Total Files

    8

    Last publish

    Collaborators

    • dosy