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

base32-converter

v0.0.3

Published

Multi-system base 32 <-> binary conversion.

Downloads

54

Readme

base32-converter

Multi-system (including bring-your-own) base 32 <-> binary conversion.

Install

npm install base32-converter

Usage

var Base32Converter = require('base32-converter');
var converter = new Base32Converter(Base32Converter.system.RFC4648);
var val = converter.encode('10111');
console.log(val); // prints 'X'
console.log(converter.decode(val)); // prints '10111'

Documentation

Base32Converter([system])

Generates a new instance of the Base32Converter class. The system parameter can take multiple forms. If the system parameter is not supplied, the library will default to the Havi base 32 system. To use a built-in base 32 system, pass the system constant to the constructor.

Example

var convert = new Base32Converter(Base32Converter.system.Crockford);

Base32Converter also supports bringing your own system for base 32 conversion. There are two supported methods for doing this. You can either:

  1. Supply a string of 32 unique characters as the system parameter to the constructor.
  2. Create a custom system using an object hash. The parameters of the object are validCharacters, characterSubstitutions, and pad.
  • validCharacters(string): String of 32 unique characters to use for the base 32 system. (required)
  • characterSubstituions(object): Object whose keys are characters you'd like replaced and value representing replacing characters. (optional)
  • pad(string): Character to use for padding. (optional)

Examples

// ---- Using a string
var convert = new Base32Converter('123456789ABCDEFGHIJKLMNOPQRSTUVW');

// ---- Using an object
var convert = new Base32Converter({
  validCharacters: '123456789ABCDEFGHIJKLMNOPQRSTUVW',
  characterSubstitutions: {
    '0': 'O'
  },
  pad: '0'
});

Statics

Base32Converter.system

This represents an enum of native supported base 32 number systems. Below are the supported systems. Click the system for more information.

Base32Converter.system.Havi
Base32Converter.system.RFC4648
Base32Converter.system.z-base-32
Base32Converter.system.Crockford
Base32Converter.system.base32hex

Instance Methods

Base32Converter#decode(base32String)

This method will convert the base 32 string provided as the parameter and using the supplied conversion will convert it to base 2. Any characters that are supplied as part of the string that are not part of the designated system are ignored during conversion. Padding will be applied if supported by the system.

Base32Converter#encode(binaryString)

This method will convert the binary string provided as the parameter and using the supplied conversion will convert it to base 32. All characters that are not 0 or 1 will be removed before processing the string.

Havi Base 32 System

The Havi base 32 encoding system uses characters 0-9 and A-Z excluding I, L, O, Q. The characters I, L, and O where excluded due their similarity to 1 and 0. Q was excluded due to its representation in the phonetic alphabet. This system was developed to be used as a means by which to exchange simple encoded data over phones. The letter Q is represented as Quebec which has a 'k' sound as opposed to the 'q' sound. Also, the letter Q closely represents the appearance of 0 or O. In order to prevent unnecessary confusion, this character was excluded.