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

feat: added atob and btoa polyfills #4548

Merged
merged 2 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/react-native-compat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ if (typeof Buffer === "undefined") {
global.Buffer = require("buffer").Buffer;
}

// Polyfill btoa
if (typeof btoa === "undefined") {
global.btoa = function (str) {
return Buffer.alloc(str.length, str, "binary").toString("base64");
};
}

// Polyfill atob
if (typeof atob === "undefined") {
global.atob = function (b64Encoded) {
return Buffer.alloc(
Buffer.from(b64Encoded, "base64").length,
Buffer.from(b64Encoded, "base64"),
"binary",
).toString("binary");
};
}

if (typeof global?.Linking === "undefined") {
try {
global.Linking = require("react-native").Linking;
Expand Down