1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
export async function crux_add(name: string, content: string) {
const res = await fetch("https://crux.land/api/add", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
name: ["ts", "tsx", "mts", "cts", "js", "jsx", "mts", "mjs"].map((ext) =>
`.${ext}`
).some((ext) => name.endsWith(ext))
? name
: `${name}.js`,
content: btoa(String.fromCodePoint(...new TextEncoder().encode(content))),
}),
});
const json = await res.json();
if (json.error) throw new Error(json.error);
return `https://crux.land/api/get/${json.id}`;
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
v2
November 29, 2023