const parseBigInt = (numberString, throwOnFail = true) => { if (!numberString) { return; } if (numberString.startsWith("$")) { return; } const keySpace = "0123456789abcdefghijklmnopqrstuvwxyz"; let result = 0n; const keySpaceLength = BigInt(keySpace.length); for (const iterator of numberString) { const value = keySpace.indexOf(iterator); if (value === -1) { if (throwOnFail) { throw new Error("invalid string"); } return; } result = result * keySpaceLength + BigInt(value); } return result; }; export class Base36 { static encode(n: number | bigint) { return BigInt(n).toString(36); } static decode(n: string, throwOnFail = true) { // pg might not accept bigint return parseBigInt(n, throwOnFail)?.toString(); } }