base62.js
base62 encode/decode library
Installation
from npm
$ npm install base62-node
from bower
$ bower install base62
Usage
for node.js
var Base62 = ;
for the browser
basic usage
var base62 = ; base62; // "abc"base62; // 39134
var base62 = '09AZaz'; base62; // "ABC"base62; // 39134
Functions
constructor(tableKeyStr)
tableKeyStr
string - base62 convert table key
tableKeyStr
can set values below.
- "09azAZ"
- "09AZaz"
if not parameter, value is "09azAZ".
if parameter is not string types, throws TypeError.
if unknown tableKey, throws Error.
; // use "09azAZ" table'09azAZ'; // use "09azAZ" table'09AZaz'; // use "09AZaz" table 12345678; // throws TypeError'AZaz09'; // throws Error
decode(str)
str
string - base62 string
convert to decimal number from base62 string.
if parameter is not string types, throws TypeError.
if unsupported string format, throws Error.
string format should be match for regexp of ^-?[\da-zA-Z]+$
.
// "09azAZ" tablebase62; // 61base62; // 62base62; // -62 base62; // throws TypeErrorbase62; // throws Error
encode(num)
num
number - number value
convert to base62 string from decimal number.
if parameter is not number types, throws TypeError.
if not a finite number(NaN, Infinity, -Infinity), throws Error.
// "09azAZ" tablebase62; // "Z"base62; // "10"base62; // "-10" base62; // throws TypeErrorbase62; // throws Error
Test
$ npm install
$ npm test
License
The MIT License. Please see LICENSE file.