proposals icon indicating copy to clipboard operation
proposals copied to clipboard

New Proposal: TypeArray encoding

Open jasnell opened this issue 3 years ago • 9 comments

Proposes a new API for TypedArray to support built-in hex, base64, base64url, and base32 encoding.

Example:

const u8 = Uint8Array.fromEncodedString('abcdef', 'hex')

console.log(u8.toEncodedString('base64url'))

Currently, each runtime has to handle these differently. Node.js has it's non-standard Buffer API, Deno has its own APIs, browser developers have to choose from a variety of userland options. These encodings are common enough, however, that they warrant being built into the language.

My goal will be to present this at an upcoming TC-39, but also looking for a champion.

jasnell avatar Jan 19 '22 15:01 jasnell

What's the difference with https://github.com/tc39/proposal-arraybuffer-base64 (sure, excepting place and names of methods)?

zloirock avatar Jan 19 '22 15:01 zloirock

Key difference is the additional support of both hex and base32 and a simpler interface (no options argument with the ability to add other encoding options later)

jasnell avatar Jan 19 '22 15:01 jasnell

Typically we only put stage 0 proposals in this repo when they're presented, or planned to be presented, at a TC39 plenary - the deadline has passed for next week's meeting, which means that you can still request advancement but delegates may object solely on the basis of the deadline.

Are you planning to present next week, or in March?

ljharb avatar Jan 19 '22 15:01 ljharb

Likely in March. And there's no rush on getting this PR landed. I wanted to at least open the discussion

jasnell avatar Jan 19 '22 15:01 jasnell

@jasnell maybe it's better to propose it in the scope of the already existent proposal since they have the same target?

zloirock avatar Jan 19 '22 15:01 zloirock

@jasnell you may want to drop the proposal repo link into matrix too.

ljharb avatar Jan 19 '22 15:01 ljharb

I like the idea of adding support for base32 and hex under the ArrayBuffer proposal since it works off the same idea and is a bit farther along. Is it possible to extend the proposal (or add a new one) for ArrayBuffer? We could have additional functions like ArrayBuffer.fromBase32 and ArrayBuffer.fromHex that could follow the same pattern as ArrayBuffer.fromBase64.

kitsune7 avatar Jan 19 '22 18:01 kitsune7

@kitsune7 I intend to add support for hex, but am unconvinced by the need for base32; see https://github.com/tc39/proposal-arraybuffer-base64/issues/7#issuecomment-872536851. But let's continue the conversation on that repository rather than here.

bakkot avatar Jan 19 '22 18:01 bakkot

@jasnell the March meeting has passed; are you intending to propose this at the June meeting?

ljharb avatar Apr 02 '22 20:04 ljharb

Closing for now; happy to reopen if you plan to present it in the future.

ljharb avatar Oct 01 '23 05:10 ljharb