underbbs/frontend/ts/util.ts

24 lines
No EOL
578 B
TypeScript

function _(key: string, value: any | null | undefined = undefined): any | null {
const x = <any>window;
if (value !== undefined) {
x[key] = value;
}
return x[key];
}
function $(id: string): HTMLElement | null {
return document.getElementById(id);
}
async function authorizedFetch(method: string, uri: string, body: any): Promise<Response> {
const headers = new Headers()
headers.set('Authorization', 'Bearer ' + _("skey"))
return await fetch(uri, {
method: method,
headers: headers,
body: body,
})
}
export default { _, $, authorizedFetch }