@chunklab/hexparse
v1.1.7
Published
Uint8Array hex/base64/base64url codec with endianness helpers
Maintainers
Readme
hexparse
A small library providing reasonably fast implementations of:
- Base64 Standard Encoding
- Base64 URL Encoding
- Base64 Standard Decoding
- Base64 URL Decoding
- Hex / Base16 Encoding
- Hex / Base16 Decoding
Where decoding functions take strings and output a Uint8Arrays, and encoding
functions take any buffer type (ArrayBuffer, Uint8Array, other typed arrays,
and DataViews) and output a string.
This library follows the byte order of the host, this means that typed arrays
such as Uint32Array will be encoded in the byte order in its underlying memory
buffer which is host specific. If platform compatibility is required for
multi-byte buffers, see arrayToEndian and arrayFromEndian.
Example
import { decodeBase64, encodeHex } from "@chunklab/hexparse";
decodeBase64("SGVsbG8gd29ybGQ=");
// returns a Uint8Array with the bytes for "Hello world"
encodeHex(new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
// returns "DEADBEEF"Endianness
import { arrayToEndian, encodeHex } from "@chunklab/hexparse";
const words = new Uint32Array([0x11223344]);
const bigEndian = arrayToEndian(words, "big");
encodeHex(bigEndian);
// returns "11223344" regardless of host byte orderInstall
npm install @chunklab/hexparse