Uint8Array Tools
This library is licensed under MIT.
Usage
Note: fromHex
and compare
mimic the Buffer.from('ff', 'hex')
and
buf1.compare(buf2)
API. Their behavior should be the same in the browser
as well as in Node.
import * as uint8arraytools from "uint8array-tools";
uint8arraytools.fromHex("ff");
uint8arraytools.toHex(Uint8Array.from([0xff]));
uint8arraytools.compare(Uint8Array.from([0xff]), Uint8Array.from([0x01]));
uint8arraytools.compare(Uint8Array.from([0xff]), Uint8Array.from([0xff]));
uint8arraytools.compare(Uint8Array.from([0x01]), Uint8Array.from([0xff]));
uint8arraytools.fromUtf8("tools");
uint8arraytools.toUtf8(Uint8Array.from([116, 111, 111, 108, 115]));
uint8arraytools.concat([Uint8Array.from([1]), Uint8Array.from([2])]);
uint8arraytools.fromBase64("dG9vbHM=");
uint8arraytools.toBase64(Uint8Array.from([116, 111, 111, 108, 115]));
const uint8array = new Uint8Array(2);
uint8arraytools.writeUInt16(uint8array, 0, 0xffff - 1, "LE");
uint8array;
uint8arraytools.readUInt16(uint8array, 0, "LE");