Search
val_dO1pTtU7X9
@dhvanil
An interactive, runnable TypeScript val by dhvanil
Script
export default async function handler(req) {
try {
const result = await (async () => {
function isPrime(num) {
if (num <= 1) return false;
for (let i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) return false;
return true;
function findLowestThreeDigitPrime() {
for (let num = 100; num < 1000; num++) {

sqliteServer
@vladimyr
An interactive, runnable TypeScript val by vladimyr
Script
export type SQLiteDB = ReturnType<typeof createSqlite>;
export const createServer = (dbFactory: () => Promise<SQLiteDB>) => new SQLiteServer(dbFactory);
export class SQLiteServer {
constructor(
private dbFactory: () => Promise<SQLiteDB>,
handleExecute = async (req: Request) => {
const { statement } = await req.json<any>();
const sqlite = await this.dbFactory();
const res = await sqlite.execute(statement);
return Response.json(res);
emailAPI
@agmm
// https://username-valname.web.val.run?k=myKey&s=mySubject&m=myMessage
HTTP
// Usage exmaple:
// https://username-valname.web.val.run?k=myKey&s=mySubject&m=myMessage
const app = new Hono();
app.get("/", async (c) => {
const now = new Date();
let { to, s, m, k } = c.req.query();
s = s || "message from api";
m = m || "<empty>";
const checks = [
c.req.header("cf-ipcountry") === "US",
embedBirdSound
@crsven
An interactive, runnable TypeScript val by crsven
HTTP
export let embedBirdSound = async (req, res) => {
const [title, file, image] = req.query.args.split(",");
res.send(
`<div style="text-align: center;"><h3 style="font-size: 5rem; margin: 5rem auto;">${title}</h3><img style="display: block; width: 50vw; margin: 0 auto;" src="${image}" /><audio controls src="${file}" style="width: 50vw; margin: 0 auto 5rem;"></audio></div>`
saveFormData
@rafter
// Forked from @vtdocs.saveFormData
Express (deprecated)
import { testFormData } from "https://esm.town/v/rafter/testFormData";
export const saveFormData = (req: express.Request, res: express.Response) => {
// Pick out the form data
const formData = req.body;
testFormData.push(formData);
return res.send(`Thanks you submitted ${Object.keys(req.body)}`);
// Forked from @vtdocs.saveFormData
todepondLabLoginBanUser
@netux
An interactive, runnable TypeScript val by netux
HTTP
export default async function(req: Request): Promise<Response> {
const TABLE_NAME = "todepond_lab_login_users_with_times";
const body = await req.json();
const { username, password, type, target } = body;
const tpUserQuery = await sqlite.execute({
sql: `SELECT * FROM ${TABLE_NAME} WHERE username = ?`,
args: ["TodePond"],
if (tpUserQuery.rows.length === 0) {
return new Response(JSON.stringify({ error: "admin user not found" }), { status: 404 });
const tpUser = tpUserQuery.rows[0];

vt_playground_demo
@pomdtr
An interactive, runnable TypeScript val by pomdtr
HTTP
const body = `<!doctype html>
<html>
<head>
<title>VT Playground</title>
<script
type="module"
src="https://raw.esm.sh/vt-playground@0.1.8/dist/vt-playground.js"
></script>
</head>
<body>
aqi
@zbeastly1
An interactive, runnable TypeScript val by zbeastly1
Script
export let aqi = async () => {
return await fetchJSON(
"https://api.openaq.org/v2/latest?" +
new URLSearchParams({
limit: "10",
page: "1",
location_id: "61498",
offset: "0",
sort: "desc",
radius: "100000",
impressiveAzureJellyfish
@felixnordgren
An interactive, runnable TypeScript val by felixnordgren
HTTP
export default async function(req: Request): Promise<Response> {
// Setup CORS Headers
const headers = new Headers();
headers.set("Access-Control-Allow-Origin", "*");
headers.set("Access-Control-Allow-Methods", "GET, PUT, DELETE, OPTIONS");
headers.set("Access-Control-Allow-Headers", "Content-Type");
// List of image URLs
const images = [
"https://i.postimg.cc/QxpJhDB5/01.png",
"https://i.postimg.cc/9XwBgZCL/02.png",
tldraw_computer_example
@sparker
tldraw computer custom endpoint example This val is an example custom endpoint for tldraw computer 's data component. Usage To use this val with tldraw.computer, follow these steps: Fork this Val. Click the Copy endpoint button on your new Val. Open a project on tldraw.computer Create a Data component in your tldraw computer project In the Source dropdown, select Custom and the POST method Paste the endpoint into Data component's the HTTP Endpoint input. Run the component. To see the output, connect the Data component to a Text component. How it works In tldraw computer, you can configure a Data component to use a custom HTTP endpoint as its data source. You can also configure the request method, either GET or POST. If a Data component's request method is POST, then when the component next updates, it will send a POST request to the endpoint. The request's body will contain an array of the Data objects that the component had received as inputs. If the request method if GET, then the component will only make the request—its body will be empty. In both cases, the component will expect back a response that includes an array of Data objects these objects will be passed along as the data component's outputs. The endpoint (your forked version of this Val) can do whatever it likes between the request and response, but the response must include data in the correct format. If the format is wrong, the computer app will create a text data object instead that includes the response as plain text. Support If you're running into any difficulties, check out the #tldraw-computer channel on the tldraw discord.
HTTP
# tldraw computer custom endpoint example
This val is an example custom endpoint for [tldraw computer](tldraw.computer)'s data component.
### Usage
To use this val with tldraw.computer, follow these steps:
1. Fork this Val.
2. Click the **Copy endpoint** button on your new Val.
// This endpoint accepts and returns data.
type BooleanData = {
type: "boolean";
text: "true" | "false" | "maybe";

lucia_sqlite
@yawnxyz
An interactive, runnable TypeScript val by yawnxyz
Script
export async function createTables(userTable: string, sessionTable: string) {
return sqlite.batch([
`CREATE TABLE ${userTable} (
id TEXT NOT NULL PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
hashed_password TEXT,
github_id INTEGER UNIQUE,
google_id TEXT UNIQUE
`CREATE TABLE ${sessionTable} (
id TEXT NOT NULL PRIMARY KEY,
htmlExample
@summerboys
HTML example This is an example of how to return an HTML response. You can also preview it at https://andreterron-htmlExample.web.val.run?name=Andre
HTTP
# HTML example
This is an example of how to return an HTML response.
You can also preview it at https://andreterron-htmlExample.web.val.run?name=Andre
// View at https://andreterron-htmlExample.web.val.run?name=Andre
export default async function(req: Request): Promise<Response> {
const query = new URL(req.url).searchParams;
// Read name from the querystring or body. Defaults to "you" if not present.
const name = query.get("name") || (await req.json().catch(() => ({}))).name || "you";
// Returns the HTML response
return new Response(`<h1>Hi summer ${name}!</h1>`, {

kpunkShows
@aeaton
An interactive, runnable TypeScript val by aeaton
Script
import { fetchHtmlDom } from "https://esm.town/v/aeaton/fetchHtmlDom";
export async function kpunkShows() {
const url = "https://kpunk.libsyn.com/";
const dom = await fetchHtmlDom(url);
const items = dom.querySelectorAll(".leftnav a[href^='/webpage']");
const regex = /^\/webpage\/\d{4}\/\d{2}$/;
return [...items].map((link) => link.getAttribute("href")).filter((link) =>
regex.test(link)
).map((link) => new URL(link, url).toString());
browserbase
@kora
my own library to use it easily by just import { browser, page } from "./browserbase"; Do I need to call page.close() and browser.close()? Maybe it's already automatic
Script
my own library to use it easily by just
```js
Do I need to call page.close() and browser.close()? Maybe it's already automatic
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://connect.browserbase.com?apiKey=${Deno.env.get("BROWSERBASE_API_KEY")}`,
const pages = await browser.pages();
const page = pages[0];
// await page.goto("https://www.val.town");
// const el = await page.waitForSelector("h1");
// const title = await el?.evaluate(el => el.textContent);