Gathering detailed insights and metrics for buff-commonjs
Gathering detailed insights and metrics for buff-commonjs
Gathering detailed insights and metrics for buff-commonjs
Gathering detailed insights and metrics for buff-commonjs
npm install buff-commonjs
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
22
Cross-platform utility library for working with byte-arrays and moving between formats.
1<script src="https://unpkg.com/@cmdcode/bytes-utils">
1yarn add @cmdcode/bytes-utils | npm install @cmdcode/bytes-utils
1/* Buff class extends Uint8Array object 2 * and provides simple format conversion. 3 */ 4import { Buff } from '@cmdcode/bytes-utils' 5 6Buff 7 .str(strData) => Buff<Uint8Array> 8 .hex(hexData) => Buff<Uint8Array> 9 .num(numData) => Buff<Uint8Array> 10 .big(bigData) => Buff<Uint8Array> 11 .buff(buffer) => Buff<Uint8Array> 12 .json(jsonData) => Buff<Uint8Array> 13 .bech32(strData) => Buff<Uint8Array> 14 .base58(strData) => Buff<Uint8Array> 15 .base64(strData) => Buff<Uint8Array> 16 17new Buff(data: ArrayBufferLike, size: number) 18 .toStr() => string 19 .toHex() => hexstring 20 .toNum() => number 21 .toBig() => bigint 22 .toBytes() => Uint8Array 23 .toJson() => object 24 .toBech32() => b32string 25 .toBase58() => b58string 26 .toBase64() => b64string
1/* Bytes class extends the Buff object 2 * even further, adds byte manipualtion. 3 */ 4import { Bytes } from '@cmdcode/bytes-utils' 5 6Bytes 7 .varint(num: number) => bytes // Returns a byte array of the varint. 8 .join(arr: Uint8Array[]) => bytes // Returns a concatenated byte array. 9 10new Bytes(data: ArrayBufferLike, size: number) 11 .prepend(bytes: Uint8Array) => bytes // Returns prepended byte array. 12 .append(bytes: Uint8Array) => bytes // Returns appended byte array. 13 .varint(num: number) => bytes // Returns appended byte array.
1/* Stream class reads from a Uint8Array, 2 * and consumes the data on each read. 3 */ 4import { Stream } from '@cmdcode/bytes-utils' 5 6new Stream(data: ArrayBufferLike) 7 .peek(len: number) => bytes // Reads the array, does not consume. 8 .read(len: number) => bytes // Reads the array, shrinks the array. 9 .varint() => number // Reads the next byte as varint, returns number.
1/* Type class is an extention of 'typeof', 2 * tries to determine a 'type' to any data. 3 */ 4import { Type } from '@cmdcode/bytes-utils' 5 6Type.of(data: any) => string [ 7 'undefined' 8 'infinity' 9 'null' 10 'hex' 11 'string' 12 'bigint' 13 'number' 14 'array' 15 'uint8' 16 'uint16' 17 'uint32' 18 'buffer' 19 'object' 20 'unknown' 21]
Please feel free to post any questions or bug reports on the issues page!
This library is currently in heavy development. Watch out for dragons!
This project uses tape for writing unit tests. I have a script that scans the API of each library and tries to import tests dynamically. The benefit of this is I can run the same tests on any bundle of the source code, so all bundle targets are tested (except cjs, gotta figure out one out).
There's also a test/index.html that will launch testing for the browser bundle, and test within the browser. Pretty neat!
This project uses the following development tools:
It should be straight-forward to setup a development environment:
1yarn install | npm install
All contributions are welcome!
No vulnerabilities found.
No security vulnerabilities found.