blob: a610d135249515137e8ddf78f7840c3ff9334fe7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
|
export const bufferToBase = (buf: Uint8Array, base = 10): string => {
if (base < 2 || base > 36) {
throw new RangeError("Base must be between 2 and 36.");
}
const max = Math.ceil(8 / Math.log2(base)); // Math.log2(1 << 8) = 8
return Array.from(buf, (byte) => byte.toString(base).padStart(max, "0")).join(
"",
);
};
|