-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use and improve existing atou and utoa functions for unicode handling…
… in course information (#219) Co-authored-by: Philip Prinz <[email protected]>
- Loading branch information
Showing
2 changed files
with
16 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
export function atou(b64) { | ||
return decodeURIComponent(escape(atob(b64))); | ||
export function atou(b64Str: string) { | ||
const text = atob(b64Str); | ||
const length = text.length; | ||
const bytes = new Uint8Array(length); | ||
for (let i = 0; i < length; i++) { | ||
bytes[i] = text.charCodeAt(i); | ||
} | ||
const decoder = new TextDecoder(); // default is utf-8 | ||
return decoder.decode(bytes); | ||
} | ||
|
||
export function utoa(data) { | ||
return btoa(unescape(encodeURIComponent(data))); | ||
} | ||
return btoa(unescape(encodeURIComponent(data))); | ||
} |