npm: @voken/base32

Compute Voken flavored Base32 encoding/decoding, with auto checksum.

@voken/base32 is human-friendly – you don’t have to worry about letters/numbers that are easy to confuse, making it easier to transmit in handwriting or typing over the phone.

The encoding alphabet consists of the numerals 0-9 and the letters a-z, excluding a few letters that might look like numbers, which we simply interpret as follows:

  • i, l -> 1

  • o -> 0

  • z -> 2

const ALPHABET = '0123456789abcdefghjkmnpqrstuvwxy'

Each character corresponds to 5 bits of input.

Lexicographic order of strings is preserved through Base 32 encoding.

Install

npm i --save @voken/base32

for yarn:

yarn add @voken/base32

API

encode(input)

input must be a Buffer or an Array. Returns a String.

const base32 = require('@voken/base32')

const bytes = Buffer.from('This is a example.')
const decoded = base32.encode(bytes)
console.log(decoded)
// => AhM6jvS0d5Sj0R90CNV62UbGDHjJV

decode(input)

input must be a Base32 encoded String. Returns a Buffer.

const base32 = require('@voken/base32')

const encoded = 'AhM6jvS0d5Sj0R90CNV62UbGDHjJV'
const bytes = base32.decode(encoded)
console.log(bytes.toString())
// => This is a example.

Hack / Test

Uses JavaScript standard style. Read more:

js-standard-style

Credits

License

MIT