Skip to content

Extend atob and btoa to support non-ASCII strings #6779

@ethanresnick

Description

@ethanresnick

This is a feature request. Apologies if this is the wrong forum.

My basic proposal is to add an optional second argument to atob and btoa, which would take an options bag allowing the developer to describe the binary encoding to use if the string contains non-ASCII bytes, as in:

btoa("🚀", { encoding: "utf-8" /* utf-8 or utf-16 for now */ })

This would convert the string to UTF-8 and then encode those bytes, rather than throwing an InvalidCharacterError. Decoding would be similar:

atob("🚀", { encoding: "utf-8" })

This would make these functions less bug-prone in practice, and better support non-English/multi-lingual use cases. It also seems like it could be a web-compatible change, given that it'd just be adding an argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addition/proposalNew features or enhancementsneeds implementer interestMoving the issue forward requires implementers to express interest

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions