all repos — underbbs @ 9dc27a4b9a016a92b6ab8f0041e3c5319e147913

decentralized social media client

ts/util.ts (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 }