JSPM

crockford-base32

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6374
  • Score
    100M100P100Q129297F
  • License MIT

An implementation of Douglas Crockford's base 32 encoding algorithm

Package Exports

  • crockford-base32

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 (crockford-base32) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

crockford-base32

An implementation of Douglas Crockford's Base 32 encoding algorithm.

Installation

npm install --save crockford-base32

Usage

const { CrockfordBase32 } = require('crockford-base32');

CrockfordBase32.encode(Buffer.from('some string')); // 3KDXPPA83KEHS6JVK7
CrockfordBase32.decode('3KDXPPA83KEHS6JVK7').toString(); // some string

Encoding Options

You can pass options to the encode() method to change how it performs the encoding:

Option Type Default Description
stripLeadingZeros boolean false Returns the encoded string without any leading zeros

Example

CrockfordBase32.encode(Buffer.from('\x00test')); // 01T6AWVM
CrockfordBase32.encode(Buffer.from('\x00test'), { stripLeadingZeros: true }); // 1T6AWVM

Decoding Options

You can also pass options to decode() as follows:

Option Type Default Description
stripLeadingZeros boolean false Strips all zeros from the decoded string.
asNumber boolean false true to return the decoded output as a bigint, false to return as a Buffer.
Example
CrockfordBase32.decode('01T6AWVM').toString(); // \x00test
CrockfordBase32.decode('01T6AWVM', { stripLeadingZeros: true }).toString(); // test

CrockfordBase32.decode('CSCW'); // <Buffer 06 65 9c>
CrockfordBase32.decode('CSCW', { asNumber: true }); // 419228n