@std.set

Deprecated: use @std/blob now instead.

Set a val on your account to JSON, which you can use as a key-value store.

Readme
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
import { API_URL } from "https://esm.town/v/std/API_URL";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
import process from "node:process";
export async function set(key: string, value: any) {
let resp = await fetch(
`${API_URL}/v1/vals`,
{
method: "PUT",
body: JSON.stringify({
name: key,
code: `// set at ${new Date()}
export let ${key} = ${JSON.stringify(await value)};`,
}),
headers: {
"content-type": "application/json",
authorization: "Bearer " + process.env.valtown,
},
},
);
if (!resp.ok) {
let { message } = await resp.json();
throw new Error("Set Error: " + message);
}
let val = await resp.json();
if (val.error) throw new Error("Set Error: " + val.error);
return val?.output?.json;
}
πŸ‘† This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data β€” all from the browser.