Multi-system (including bring-your-own) base 32 <-> binary conversion.
npm install base32-converter
var Base32Converter = ;var converter = Base32ConvertersystemRFC4648;var val = converter;console; // prints 'X'console; // prints '10111'
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.
var convert = Base32ConvertersystemCrockford;
Base32Converter also supports bringing your own system for base 32 conversion. There are two supported methods for doing this. You can either:
- Supply a string of 32 unique characters as the system parameter to the constructor.
- Create a custom system using an object hash. The parameters of the object are
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)
// ---- Using a stringvar convert = '123456789ABCDEFGHIJKLMNOPQRSTUVW';// ---- Using an objectvar convert =validCharacters: '123456789ABCDEFGHIJKLMNOPQRSTUVW'characterSubstitutions:'0': 'O'pad: '0';
This represents an enum of native supported base 32 number systems. Below are the supported systems. Click the system for more information.
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.
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.