npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@niyari/base32-ts

v0.0.4

Published

Base32 encode/decode for TypeScript.

Downloads

288

Readme

base32-ts

Base32 encode/decode for TypeScript

Install

npm i @niyari/base32-ts

Demo

https://niyari.github.io/base32-ts/demo/

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===="

API(Options)

new Base32([{ [variant] [,padding] [,raw] [,checksum] [,split] }]);

Variant

{ variant: '<string>' }
  • RFC4648
    • 4648
    • 3548
    • (empty)
  • RFC4648_HEX
    • hex
  • Clockwork Base32
    • clockwork
    • maki
  • Crockford
    • crockford

Encode: Set padding ( = )

{ padding: <bool> }

| | 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 object.

{ raw: <bool> }

| | RFC4648 | HEX | Clockwork | Crockford ---: | :---: | :---: | :---: | :---: | default | False | False | False | False(hexadecimal string)

const base32 = new Base32();
base32.decode('MZXW6YTBOI======'); // (default)
const base32_raw0 = new Base32({ raw: false });
base32_raw0.decode('MZXW6YTBOI======');
// Return value: String

const base32_raw1 = new Base32({ raw: true });
base32_raw1.decode('MZXW6YTBOI======');
const base32_crockford_raw = new Base32({ variant: 'crockford', raw: true });
base32_crockford_raw.decode(123456);
// Return value: Uint8Array object

Crockford

Encode an integer into a Crockford Symbol 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"

API(Options)

{ variant: 'crockford' }

Checksum

{ variant: 'crockford', checksum: <bool> }

| | RFC4648 | HEX | Clockwork | Crockford ---: | :---: | :---: | :---: | :---: | default | - | - | - | False

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

Encode: Split

{ variant: 'crockford', split: <unsigned integer> }

| | RFC4648 | HEX | Clockwork | Crockford ---: | :---: | :---: | :---: | :---: | default | - | - | - | 0

const base32_crockford = new Base32({ variant: 'crockford', split: 2 });
base32_crockford.encode(123456);
// str = "3R-J0"
const base32_crockford_s1 = new Base32({ variant: 'crockford', split: 1 });
base32_crockford_s1.encode(123456);
// str = "3-R-J-0"

See Also:

Clockwork Base32

Crockford

License

MIT