A JavaScript Base62 encode/decoder.
Base62 encoding converts numbers to ASCII strings (0-9, a-z and A-Z) and vice versa, which typically results in comparatively short strings. Such identifiers also tend to be more readily identifiable by humans.
999->"g7"9999->"2Bh"238327->"ZZZ"
npm install base62var base62 = require("base62");
base62.encode(999); // "g7"
base62.decode("g7"); // 999Both encode and decode support BigInt for values beyond Number.MAX_SAFE_INTEGER:
base62.encode(9007199254740993n); // "FfGNdXsE9"
base62.decode("FfGNdXsE9", { bigint: true }); // 9007199254740993nYou can also use a custom character set:
var base62 = require("base62");
base62.setCharacterSet("~9876543210ABCDEFGHIJKLMNOPQRSTU$#@%!abcdefghijklmnopqrstuvw-=");
base62.encode(999); // "F3"
base62.decode("F3"); // 999setCharacterSet expects a string containing exactly 62 unique characters.
Source code is hosted on GitHub. Please report issues or feature requests in GitHub Issues.
- Fork the project.
- Make your feature addition or bug fix.
- Add tests for it.
- Send a pull request.
MIT. Copyright (c) 2026 Andrew Nesbitt. See LICENSE for details.