Readme

A helper to get the raw data of a val, using the very nice implementation from @pomdtr.raw.

Usage: https://www.val.town/v/karfau.test_getRaw

Also look at @karfau.rawUrl to just get the raw url of another val inside a val.

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
import { rawUrl } from "https://esm.town/v/karfau/rawUrl";
import { raw } from "https://esm.town/v/pomdtr/raw?v=90";
export const getRaw = async (ref: Ref, extension: Ext = "json") => {
const rawExt = ["ts", "md", "json"].includes(extension) ? extension : "json";
const res = await raw(
new Request(rawUrl(ref, rawExt)),
);
if (!res.ok || rawExt !== "json")
return res.text();
const json = await res.json();
return extension !== "json" && extension in json ? json[extension] : json;
};
type Ref = [
user: string,
valName: string,
];
type ValData = {
"id": string;
"author": {
"id": string;
"username": string;
};
"name": string;
"code": string;
"privacy": "public" | "unlisted";
"public": boolean;
"version": number;
"runStartAt": string;
"runEndAt": string;
"logs": string[];
"output": {
"type": string;
"value": string;
};
"error": string | null;
"readme": string | null;
"likeCount": number;
"referenceCount": number;
};
type Ext = "ts" | "json" | "md" | keyof ValData;
👆 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.