This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
356 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function base64ToBytes(base64: string) { | ||
const binString = atob(base64); | ||
return Uint8Array.from(binString, (m) => m.codePointAt(0)); | ||
} | ||
|
||
function bytesToBase64(bytes: Uint8Array) { | ||
const binString = String.fromCodePoint(...bytes); | ||
return btoa(binString); | ||
} | ||
|
||
export function encodeUtf8ToBase64(utf8source: string): string { | ||
return bytesToBase64(new TextEncoder().encode(utf8source)) | ||
} | ||
|
||
export function decodeBase64ToUtf8(base64: string): string { | ||
return new TextDecoder().decode(base64ToBytes(base64)) | ||
} |
Oops, something went wrong.