2021-06-19 17:37:12 -04:00
|
|
|
export function urlBase64ToUint8Array(base64String: string) {
|
2021-07-05 06:25:20 -04:00
|
|
|
const padding = "=".repeat((4 - (base64String.length % 4)) % 4);
|
|
|
|
const base64 = (base64String + padding)
|
2021-08-05 09:47:00 -04:00
|
|
|
.replace(/-/g, "+")
|
2021-07-05 06:25:20 -04:00
|
|
|
.replace(/_/g, "/");
|
|
|
|
const rawData = window.atob(base64);
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0)));
|
2021-06-19 17:37:12 -04:00
|
|
|
}
|
2021-12-11 11:24:23 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|