mirror of
https://github.com/ershisan99/DevToysWeb.git
synced 2025-12-17 20:49:24 +00:00
perf(bundle): drop js-base64
This commit is contained in:
14
lib/base64.ts
Normal file
14
lib/base64.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export const encode = (s: string) => {
|
||||
const bytes = new TextEncoder().encode(s);
|
||||
return btoa(String.fromCharCode(...bytes));
|
||||
};
|
||||
|
||||
export const decode = (base64: string) => {
|
||||
try {
|
||||
const binString = atob(base64);
|
||||
const bytes = Uint8Array.from(binString, c => c.charCodeAt(0));
|
||||
return new TextDecoder().decode(bytes);
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user