2.0.0 • Published 6 years ago

base-p v2.0.0

Weekly downloads
5
License
Unlicense
Repository
gitlab
Last release
6 years ago

Install

npm install base-p

Usage

const Base = require('base-p')

base62 = new Base(62)
base62.encode(2017) // returns 'WX'
base62.decode('WX') // returns 2017

base5 = new Base('01234')
base5.encode(7)     // returns '12'
base5.decode('12')  // returns 7

Usage with BigInt

const Base = require('base-p')

base62 = new Base(62)
base62.encodeBig(2017n) // returns 'WX'
base62.decodeBig('WX')  // returns 2017n

base5 = new Base('01234')
base5.encodeBig(7n)    // returns '12'
base5.decodeBig('12')  // returns 7n

Base

The parameter for the constructor is a either a string containing the alphabet used for the conversion, or an integer representing the base for one of the predefined alphabets:

BaseAlphabet
201
801234567
110123456789a
160123456789abcdef
320123456789ABCDEFGHJKMNPQRSTVWXYZ
360123456789abcdefghijklmnopqrstuvwxyz
58123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz
620123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
64ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
67ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.!~
2.0.0

6 years ago

1.0.0

7 years ago