Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/o0101/uint1array
:wind_chime: Uint1Array - get a bit view of any ArrayBuffer
https://github.com/o0101/uint1array
Last synced: 15 days ago
JSON representation
:wind_chime: Uint1Array - get a bit view of any ArrayBuffer
- Host: GitHub
- URL: https://github.com/o0101/uint1array
- Owner: o0101
- License: mit
- Created: 2017-06-11T08:09:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-05T00:51:43.000Z (about 1 year ago)
- Last Synced: 2024-10-14T07:20:46.975Z (30 days ago)
- Language: JavaScript
- Homepage:
- Size: 577 KB
- Stars: 12
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# :wind_chime: [Uint1Array](https://github.com/crislin2046/Uint1Array) ![npm downloads](https://img.shields.io/npm/dt/uint1array) ![version](https://img.shields.io/npm/v/uint1array)
JavaScript's missing TypedArray. Bit-level view of any underlying ArrayBuffer.
## API
The API simply mirrors a regular [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray).
## Differences from the [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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 `.length`.# Get
`npm install --save uint1array`
# Using
You can use like an ordinary TypedArray:
```js
// 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
- [Typed Arrays on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)
- [Uint1Array on npm](https://www.npmjs.com/package/uint1array)