forked from oven-sh/bun.report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.ts
42 lines (35 loc) · 1.01 KB
/
lib.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { parse, type Parse, type Remap } from './lib/parser';
export * from './lib/parser';
export * from './lib/format';
export async function remap(key: string, parse: Parse, signal?: AbortSignal): Promise<Remap> {
const response = await fetch('https://bun.report/remap', {
method: 'POST',
body: key,
headers: {
'Content-Type': 'application/json',
},
signal,
});
if (response.status !== 200) {
throw new Error(`${response.status} ${response.statusText}\nPlease try again later.`);
}
const remap = await response.json();
if (remap.error) {
throw new Error(`${remap.error}`);
}
return {
version: parse.version,
message: parse.message,
os: parse.os,
arch: parse.arch,
commit: remap.commit,
addresses: remap.addresses,
command: remap.command,
features: remap.features,
}
}
export async function parseAndRemap(str: string): Promise<Remap | null> {
const parsed = await parse(str);
if (!parsed) return null;
return remap(str, parsed);
}