Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Uint8Array to/from base64 and hex #25051

Open
dbushell opened this issue Aug 15, 2024 · 3 comments
Open

add Uint8Array to/from base64 and hex #25051

dbushell opened this issue Aug 15, 2024 · 3 comments
Labels
feat new feature (which has been agreed to/accepted) upstream Changes in upstream are required to solve these issues

Comments

@dbushell
Copy link

The tc39 Uint8Array to/from base64 and hex proposal is stage 3.

Support for this would significantly reduce boilerplate code.

Examples:

let arr = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]);
console.log(arr.toBase64());
// 'SGVsbG8gV29ybGQ='
console.log(arr.toHex());
// '48656c6c6f20576f726c64'
let string = 'SGVsbG8gV29ybGQ=';
console.log(Uint8Array.fromBase64(string));
// Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])

string = '48656c6c6f20576f726c64';
console.log(Uint8Array.fromHex(string));
// Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])

Full spec.

@littledivy
Copy link
Member

This needs to be implemented upstream in V8.

Here's the V8 tracking issue: https://issues.chromium.org/issues/42204568

@littledivy littledivy added feat new feature (which has been agreed to/accepted) upstream Changes in upstream are required to solve these issues labels Aug 15, 2024
@BlackAsLight
Copy link

Out of curiosity, what boilerplate would it decrease? Or really, what do you mean by boilerplate here.

@dbushell
Copy link
Author

Maybe "boilerplate" is the wrong word. I mean just having built-in methods would be less of a chore than importing from @std/encoding. Especially when writing temporary code in the REPL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted) upstream Changes in upstream are required to solve these issues
Projects
None yet
Development

No branches or pull requests

3 participants