Encode and decode in any base, supports BigInt
npm install baseintEncode and decode strings to a custom base
Inspired by / derivative of base62.js and Base-x
WARNING: This module is **NOT RFC4648
compliant** (formerly RFC3548). Meaning base64
and base64url will not encode/decode the same as btoa() and atob() or any of the native encodings
(base16, base32)
``sh`
npm install baseint
`js
import BaseInt, {
BASE64URL,
BASE64,
BASE62,
BASE32,
BASE32HEX,
BASE16
} from "baseint";
// Supply which base you want to use (BASE62 is default)
const baseInt = new BaseInt(BASE62);
// Or supply your own base
const charset = "abcd1234";
const baseInt = new BaseInt(charset);
const encoded = baseInt.encode(numstr);
const decoded = baseInt.decode(encoded);
`
`js
const baseInt = new BaseInt();
const uuid = "b9b03417-a52a-47cf-8638-3c26b2628c98";
// Convert uuid to bigint/number/numeric string
const bn = BigInt("0x" + uuid.replace(/-/g, ""));
const encoded = baseInt.encode(bn);
// FoYGiVxbLcGdqtB3H0Qzbi
// Or encode directly
const encoded = baseInt.encodeUUID(uuid);
// FoYGiVxbLcGdqtB3H0Qzbi
const decoded = baseInt.decodeToUUID(encoded);
// b9b03417-a52a-47cf-8638-3c26b2628c98
`
| Base | Characters |
| ----------- | -------------------------------------------------------------------- |
| BASE64URL | ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ |ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
| BASE64 | |ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
| BASE62 | |0123456789abcdefghijklmnopqrstuvwxyz
| BASE36 | |ybndrfg8ejkmcpqxot1uwisza345h769
| BASE32Z | |0123456789ABCDEFGHIJKLMNOPQRSTUV
| BASE32HEX | |ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
| BASE32 | |0123456789ABCDEF
| BASE16 | |01234567
| BASE8 | |01` |
| BASE2 |