base-62

Base 62 encoder / decoder written for node.js

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
base-62
1.0.17 years ago7 years agoMinified + gzip package size for base-62 in KB

Readme

Base62
!travistravis-imagetravis-url !javascript style guidestandard-imagestandard-url !npmnpm-imagenpm-url !downloadsdownloads-imagedownloads-url

Install

npm install base-62

How to use

base62 = require('base-62')
base62.encode(1234) // 'jU'
base62.decode('jU') // 1234

Custom Character Set Example

The default base 62 alphabet is 0-9a-zA-Z. This can be updated to a custom character set. Naturally, it must be 62 characters long.
Instead of the character set 0-9a-zA-Z you want to use 0-9A-Za-z, call the setAlphabet() method on the Base62 object passing in the string "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz". Note that all characters must be unique.
base62 = require('base-62')
base62.setAlphabet('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')
base62.encode(1234) // 'Ju'
base62.decode('Ju') // 1234

License

MIT. Copyright (c) Nicolas Lecoy.