const BASE62_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
/**
* The input number can be a bigInt, integer number or
* a string representing a number. Non decimal strings
* need to start with a prefix 0x (hex), 0o (octal) or 0b (binary)
*
* @param {number | string} num input number
* @returns {string} encoded string
*/
export function base62encode(num) {
if ((typeof num === "number") ||
(typeof num === "string")
) num = BigInt(num);
if (typeof num !== "bigint") {
throw "Unsupported input data type";
}
if (num === 0n) return BASE62_CHARSET[0];
let result = "";
while (num > 0n) {
result = BASE62_CHARSET[num % 62n] + result;
num = num / 62n;
}
return result;
}