mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-13 06:38:31 +00:00
26 lines
717 B
JavaScript
26 lines
717 B
JavaScript
export function unicodeToBase64(text) {
|
|
const utf8Bytes = new TextEncoder().encode(text);
|
|
const base64String = btoa(String.fromCharCode(...utf8Bytes));
|
|
return base64String;
|
|
}
|
|
|
|
export function base64ToUnicode(base64String) {
|
|
const utf8Bytes = new Uint8Array(
|
|
atob(base64String)
|
|
.split('')
|
|
.map((char) => char.charCodeAt(0)),
|
|
);
|
|
const decodedText = new TextDecoder().decode(utf8Bytes);
|
|
return decodedText;
|
|
}
|
|
|
|
export function code2hash(code) {
|
|
return encodeURIComponent(unicodeToBase64(code));
|
|
//return '#' + encodeURIComponent(btoa(code));
|
|
}
|
|
|
|
export function hash2code(hash) {
|
|
return base64ToUnicode(decodeURIComponent(hash));
|
|
//return atob(decodeURIComponent(codeParam || ''));
|
|
}
|