JSPM

@niyari/base32-ts

0.0.2-0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 171
  • Score
    100M100P100Q78999F
  • License MIT

Base32 encode/decode for TypeScript.

Package Exports

  • @niyari/base32-ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@niyari/base32-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

base32-ts

Base32 encode/decode for TypeScript

Install

npm i @niyari/base32-ts

Supported Browsers

ECMAScript 2020 and later. (Using BigInt within Crockford.)

  • Chrome 89+
  • Firefox 87+
  • Safari 14+
  • Edge(Chromium) 89+

Usage

RFC4648

const base32 = new Base32();
let base32_encoded = base32.encode('foobar');
// str = "MZXW6YTBOI======"
let base32_decoded = base32.decode('MZXW6YTBOI======');
// str = "foobar"

RFC4648_HEX

const base32_hex = new Base32({ variant: 'hex'});
base32_hex.encode('foobar');
// str = "CPNMUOJ1E8======"
base32_hex.decode('CPNMUOJ1E8======');
// str = "foobar"

Clockwork Base32

const base32_clockwork = new Base32({ variant: 'clockwork' }); // Clockwork (short name 'maki')
base32_clockwork.encode('foobar');
// str = "CSQPYRK1E8"
base32_clockwork.decode('CSQPYRK1E8');
// str = "foobar"

Encoding multibyte character set

base32.encode('Tofu on Fire!📛'); // (📛 = Name Badge:for Japanese preschoolers.)
// str = "KRXWM5JAN5XCARTJOJSSD4E7SONQ===="

Options

Encode: Set padding ( = )

_ RFC4648 HEX Clockwork Crockford
default True True False -
const base32_np = new Base32({ padding: false }); // RFC4648 no padding
base32_np.encode('foobar');
// str = "MZXW6YTBOI"
const b32_cw_pad = new Base32({ variant: 'maki', padding: true }); // Clockwork use padding
b32_cw_pad.encode('foobar');
// str = "CSQPYRK1E8======"

Decode: Raw

Return Uint8Array.

_ RFC4648 HEX Clockwork Crockford
default False False False False(hexadecimal strings)
base32.decode('MZXW6YTBOI======'); // (default)
base32.decode('MZXW6YTBOI======', { raw: false });
// Return value: TextDecoder().decode(output.buffer) -> String

base32.decode('MZXW6YTBOI======', { raw: true });
// Return value: Uint8Array object

Crockford

Encode an integer into a CrockfordSymbol string.

Usage

const base32_crockford = new Base32({ variant: 'crockford' });
base32_crockford.encode(1234);
// str = "16J"
base32_crockford.decode('16J');
// str = "0x04d2" = 1234

In decoding, the misleading character "IiLl" is treated as 1 and "Oo" is treated as 0.

base32_crockford.decode('IiLl10Oo');
// str = "0x842108000"

Encode: Checksum

base32_crockford.encode(1234, { checksum: true });
// str = "16JD"
base32_crockford.decode('16JD', { checksum: true });
// str = "0x04d2" = 1234

Encode: Split

base32_crockford.encode(123456, { split: 2 });
// str = "3R-J0"
base32_crockford.encode(123456, { split: 1 });
// str = "3-R-J-0"

Decode: Raw

base32_crockford.decode(123456, { raw: true });
// Uint8Array object

TODO:

Partial support (Checking specifications): Clockwork Base32

Partial support (WIP): Crockford

License

MIT