What is any-base?
The any-base npm package allows you to convert numbers between different bases. It supports conversions between any two bases ranging from binary (base 2) to base 62.
What are any-base's main functionalities?
Convert from one base to another
This feature allows you to convert a number from one base to another. In this example, a binary number ('1010') is converted to a hexadecimal number ('A').
const anyBase = require('any-base');
const base2ToBase16 = anyBase(anyBase.BIN, anyBase.HEX);
console.log(base2ToBase16('1010')); // Outputs 'A'
Custom base conversion
This feature allows you to define custom bases for conversion. In this example, a decimal number ('255') is converted to a hexadecimal number ('ff') using custom base definitions.
const anyBase = require('any-base');
const customBase = anyBase('0123456789', '0123456789abcdef');
console.log(customBase('255')); // Outputs 'ff'
Other packages similar to any-base
base-x
The base-x package provides a way to encode and decode between various bases. It supports custom alphabets and is highly performant. Compared to any-base, base-x is more focused on performance and flexibility with custom alphabets.
big-integer
The big-integer package allows for arbitrary-precision arithmetic in JavaScript, including base conversions. It is more comprehensive in terms of mathematical operations compared to any-base, which is specialized in base conversions.
bignumber.js
The bignumber.js package provides arbitrary-precision decimal and non-decimal arithmetic. It includes base conversion functionalities but is more focused on precision and mathematical operations, making it more versatile than any-base.
README
The library allows you to convert any large numbers in any number base to another number base. The base is determined by specifying the alphabet. So is full freedom

Installation
npm install any-base --save
API
AnyBase()
converterFunction = anyBase(sourceAlphabet, destinationAlphabet);
Parameters
- {String} sourceAlphabet digits from smallest to the largest
- {String} destinationAlphabet digits from smallest to the largest
Return Values
Returns function that converts the number of source base to the destination
Convert()
converterFunction(number)
Parameters
- {String} number number of source base
Return Values
Returns number of destonation base
Example
var anyBase = require('any-base'),
dec2hex = anyBase(anyBase.DEC, anyBase.HEX),
shortId = anyBase(anyBase.DEC, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+!@#$^'),
longId = anyBase('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+!@#$^', anyBase.DEC);
dec2hex('123456');
shortId('1234567890');
longId('PtmIa');