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
import { api } from "https://esm.town/v/pomdtr/api";
type Module = {
slug: string;
id: string;
websiteUrl: string;
category: string | null;
};
export async function getReverseDependencies(valUrlOrSlug: string): Promise<Module[]> {
// clean the url or slug
const initialSlug = valUrlOrSlug.includes("/v/")
? valUrlOrSlug.split("/v/")[1]
: valUrlOrSlug;
// we leave the trailing quote off, in case its imported with a "?v=X" version string
// this does leave open the possibility of capturing vals that have this val as a
// prefix like (bob/getData and bob/getData). Search also returns vals where the
// search appears in the readme. We'll filter all these out later.
const searchString = ` from "https://esm.town/v/${initialSlug}`;
const { data } = await api(`/v1/search/vals?query=${encodeURI(searchString)}&offset=0&limit=100`);
return data
.map(d => {
const slug = d.author.username.replace("@", "") + "/" + d.name;
return {
slug,
id: "https://esm.town/v/" + slug,
websiteUrl: "https://www.val.town/v/" + slug,
category: "valtown",
};
});
}
👆 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.