-
Notifications
You must be signed in to change notification settings - Fork 97
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
Remove Buffer usage for Browser Environments #423
Conversation
Are there concerns with |
That would be great to add test cases for. For example const str = "Hello, world! 😊 Привет, мир! こんにちは世界"; Here's one way that could be solved. export const stringToBase64 =
typeof Buffer !== 'undefined'
? (str: string) => Buffer.from(str).toString('base64')
: (str: string) => btoa(new TextEncoder().encode(str).reduce((acc, byte) => acc + String.fromCharCode(byte), ''));
export const base64ToString =
typeof Buffer !== 'undefined'
? (str: string) => Buffer.from(str, 'base64').toString()
: (str: string) => new TextDecoder().decode(Uint8Array.from(atob(str), c => c.charCodeAt(0))); In order to actually test that code path, the tests would need to run in a browser environment. |
Co-authored-by: Simon H <[email protected]>
Buffer
usage for Browser Environments
Buffer
usage for Browser Environments
I added the handling of non-ASCII characters. I haven't tested this yet in an actual browser environment. I hope to do that soon. |
It works! Before After I tested it by merging the browser build branch and this one into a local build, then used Thanks all for the reviews and comments. This is the magic of open source right here. |
I've addressed all the feedback and I believe this is ready to go. Thanks! |
Some alternative implementations:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
My pleasure! Thanks for reviewing and merging! |
Closes #418