mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-30 02:40:58 -05:00
17 lines
547 B
TypeScript
17 lines
547 B
TypeScript
export function urlBase64ToUint8Array(base64String: string) {
|
|
const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
|
|
const base64 = (base64String + padding)
|
|
.replace(/-/g, "+")
|
|
.replace(/_/g, "/");
|
|
const rawData = window.atob(base64);
|
|
|
|
return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0)));
|
|
}
|
|
|
|
export function mapToRecord<K extends symbol | string | number, V>(
|
|
map: Map<K, V>,
|
|
) {
|
|
let record = {} as Record<K, V>;
|
|
map.forEach((v, k) => (record[k] = v));
|
|
return record;
|
|
}
|