base62.js
base62 encode/decode library
Installation
npm
$ npm install base62.jsbower
$ bower install base62Usage
node.js
var base62 = require('base62.js');browser
<script src="base62.min.js"></script>Basics
base62.encode(39134); // "abc"
base62.decode('abc'); // 39134if you want use another table:
var b62 = base62.createConverter(
'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
// or
// var b62 = new base62.Base62(
// '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
b62.encode(39134); // "ABC"
b62.decode('ABC'); // 39134Functions
createConverter([table])
tableString- base62 table string
returnBase62- Base62 instance
return Base62 instance.
Base62([table])
tableString- base62 table string
constructor of Base62 class.
use default base62 table if parameter is empty. default table is 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.
throw TypeError if table is not a String.
throw RangeError if table length is not equal 62.
Base62#decode(str)
strString- base62 string
returnNumber- decoded number
decode to integer from base62 string.
throw TypeError if str is not a String.
throw Error if str is unsupported format. str must match to /^-?[\dA-Za-z]+$/.
Base62#encode(num)
numNumber- integer
returnString- encoded string
encode to base62 string from integer.
throw TypeError if num is not an integer. (ex: NaN, Infinity, -Infinity and floating-point number)
Test
node.js
$ npm install
$ npm testbrowser
$ npm install
$ npm run bower
$ npm run testemLicense
The MIT license. Please see LICENSE file.