1import { fetch } from "https://esm.town/v/std/fetch";
2
3export let duckdbExample = (async () => {
4 async function createWorker(url: string) {
5 const workerScript = await fetch(url);
6 const workerURL = URL.createObjectURL(await workerScript.blob());
7 return new Worker(workerURL, { type: "module" });
1# DuckDB
2
3[DuckDB](https://duckdb.org/) works on Val Town, with only one small tweak! We're basically using DuckDB in the same way you'd use it with a browser - using the WASM package with its dependencies fetched from [jsdelivr](https://www.jsdelivr.com/).
4
5The only trick is to create the worker ourselves rather than using `duckdb.createWorker`. DuckDB's built-in createWorker method doesn't specify a worker type, which causes `type` to default to `classic`, and Deno (our runtime) doesn't support classic workers.
1import { discordSendDM } from "https://esm.town/v/vtdocs/discordSendDM";
2import process from "node:process";
3import { discordFetch } from "https://esm.town/v/vtdocs/discordFetch";
4import { discordDMs } from "https://esm.town/v/vtdocs/discordDMs";
5
10 const repliesToBot = [];
11 for (const channelId of discordDMs) {
12 const messages = await discordFetch(
13 process.env.discordBot,
14 // Note: not using pagination here
5It does do as much as other transpilers (such as esm.sh, such as rewriting `npm:` imports, etc). We may add that capability in the future. For now, if you want your npm imports to run in the browser, use `https://esm.sh/package` instead of `npm:package`.
6
7The below script demonstrates this transiplation behavior by fetching its own source code (`import.meta.url`) with the user agent of a browser. You can uncoment the line setting the browser agent if you want to see the difference in the output. Or you could just load this val's module URL in your browser to see the untranspiled TS.
1/** @jsxImportSource https://esm.sh/react */
2import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
3
4const browserUserAgent: string =
8
9console.log(
10 await fetchText(import.meta.url, {
11 headers: {
12 "User-Agent": browserUserAgent, // comment this line out to see untransiled code
1import { fetch as proxyFetch } from "https://esm.town/v/std/fetch";
2const Fetch = fetch;
3
4interface ShowBox {
12}
13export default async function(req: Request): Promise<Response> {
14 const showbox = await Fetch("https://www.showbox.media/index/share_link?id=55137&type=1", {
15 headers: {
16 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0",
24 const febboxUrl = `https://www.febbox.com/share/${febboxId}`;
25 console.log(febboxId);
26 const febboxItemRequest = await fetch(`https://www.febbox.com/file/file_share_list?share_key=${febboxId}`, {
27 headers: {
28 "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0",
1import { verify_discord_signature } from "https://esm.town/v/mattx/verify_discord_signature?v=8";
2import { fetch } from "https://esm.town/v/std/fetch";
3
4export type Snowflake = string;
95 (async () => {
96 const data = await response;
97 const update = await fetch(
98 `https://discord.com/api/v10/webhooks/${body.application_id}/${body.token}/messages/@original`,
99 {
62 try {
63 await sleepRand(15);
64 const response = await fetch(NOAA_URL_TKPK, {
65 headers: { "User-Agent": "https://www.val.town/v/kingishb/blackLobster" },
66 });
53
54const getNews = async ({ query }: { query: string }) => {
55 const response = await fetch(
56 getFeedUrl(query),
57 );
8
9export const detectNewWebsiteContents = async () => {
10 // Fetch contents
11 let contents;
12 try {
13 const res = await fetch(URL, { redirect: "follow" });
14 if (res.status !== 200) {
15 console.log(`bad status code: ${res.status}`);
17 contents = await res.text();
18 } catch (e) {
19 console.log(`couldn't fetch: ${e}`);
20 }
21