Built-in Base64 and Hex encode / decode

ArrayBuffer.from(input: string, type: "base64" | "hex"): ArrayBuffer
ArrayBuffer.toString(input: ArrayBuffer, type: "base64" | "hex"): string

but i need re-define ArrayBuffer.prototype.toString, the is break the web.

it is type checking method, buffer.toString() === "[object ArrayBuffer]"

2 Likes

I would love this. I always wondered why JS only has atob and btoa but no hex conversion

JS doesn't have those; those are in HTML.

True, I was quite surprised when I read the spec now. It would be nice if the ES spec had these (but named better)

It doesn't cover hex, but there is already a stage 1 proposal for Base64 array buffer support.