This is a function that can convert between arbitrary bases implemented in both Javascript and Python.
Many existing implementations, such as https://rot47.net/base.html or https://gist.github.com/inflammable/2929362 use a number as the internal representation, and thus can't safely encode/decode more than 8 letters of Base64 encoded text, or 9 letters of Base58 text (which isn't enough for parsing a Bitcoin address).
Other implementations rely on complicated third party libraries for bignum (e.g. https://rosettacode.org/wiki/Non-decimal_radices/Convert#JavaScript).
Several implementations required converting to Uint8Arrays (Base 256) as an intermediate. Others were essentially ports of complicated C implementations (see https://github.com/cryptocoinjs/base-x/blob/master/src/index.js).
This implementation works for arbitrary base conversions, such as Binary to Hexadecimal, Octal to Decimal, Binary to Octal, Octal to Hexadecimal, Hexadecimal to Base 36, Ternary to Binary, Ternary to Quadranary, Base 26, Base 32, Base 64, Base 58, Base 57, Base 62, Base 256, Base 512, etc. I believe it should work up until Base 94906265, which should even be enough to encode data into an alphabet consisting of all 1,112,064 valid UTF-8 code points.
Keep in mind that this algorithm is approximately O(n^2*log(srcb)/log(destb))
. In practice this isn't noticable until you're processing tens of thousands of digits.
There's additionally an implementation here that uses native ES2020 BigInt, which is still ultimately O(n^2) but for larger strings a bit faster than the standard JS implementation.