Search
remapEndpoint
@wolf
An interactive, runnable TypeScript val by wolf
HTTP
export default async function(req: Request): Promise<Response> {
const url = new URL(req.url);
const queryString = new URL(req.url);
const queryParams = new URLSearchParams(queryString.searchParams);
const async = queryParams.get("async") === "true" ? true : false;
return new Response(
`export default ${async ? "async " : ""} function remappedFunction (){` + queryParams.get("code") + "}",
headers: { "Content-Type": "application/javascript" },
fetchJSON
@_
An interactive, runnable TypeScript val by _
Script
import { fetchJSON as fetchJSON2 } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export let fetchJSON = fetchJSON2;
placeholderKittenImages
@shawnbasquiat
// This val creates a publicly accessible kitten image generator using the Val Town image generation API.
HTTP
// This val creates a publicly accessible kitten image generator using the Val Town image generation API.
// It supports generating square images with a single dimension parameter or rectangular images with two dimension parameters.
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);
const parts = url.pathname.split('/').filter(Boolean);
if (parts.length === 0) {
const welcomeHtml = `
<!DOCTYPE html>
<html lang="en">
<head>
valle_tmp_0849921550869434716277180134862967
@janpaul123
// Import the required modules
HTTP
// Import the required modules
// Fetch all stories or initialize an empty array if no data exists yet
export default async function main(req: Request): Promise<Response> {
let stories = await blob.getJSON("hackerNewsStories") || [];
// Check the request method to determine the action
if (req.method === "GET") {
// Return the list of stories
return new Response(JSON.stringify(stories), { headers: { "Content-Type": "application/json" }});
} else if (req.method === "POST" || req.method === "PUT") {
// Parse the request body to get the new story data
earthquakes
@fil
Earthquake map 🌏 This val loads earthquake data from USGS, a topojson file for the land shape, and supporting libraries. It then creates a map and save it as a SVG string. The result is cached for a day. Note that we must strive to keep it under val.town’s limit of 100kB, hence the heavy simplification of the land shape. (For a simpler example, see becker barley .) | | |
|-----|-----|
| Web page | https://fil-earthquakes.web.val.run/ |
| Observable Plot | https://observablehq.com/plot/ |
| linkedom | https://github.com/WebReflection/linkedom |
| topojson | https://github.com/topojson/topojson |
| earthquakes | https://earthquake.usgs.gov |
| world | https://observablehq.com/@visionscarto/world-atlas-topojson |
| css | https://milligram.io/ |
HTTP
# Earthquake map [🌏](https://fil-earthquakes.web.val.run/)
This val loads earthquake data from USGS, a topojson file for the land shape, and supporting libraries. It then creates a map and save it as a SVG string. The result is cached for a day. Note that we must strive to keep it under val.town’s limit of 100kB, hence the heavy simplification of the land shape. (For a simpler example, see [becker barley](https://www.val.town/v/fil.beckerBarley).)
![](https://fil-earthquakes.web.val.run/?svg=1)
| Web page | https://fil-earthquakes.web.val.run/ |
| Observable Plot | https://observablehq.com/plot/ |
| linkedom | https://github.com/WebReflection/linkedom |
let { earthquakes_storage } = await import("https://esm.town/v/fil/earthquakes_storage");
export async function earthquakes(req?) {
const yesterday = new Date(-24 * 3600 * 1000 + +new Date()).toISOString();
if (!(earthquakes_storage?.date > yesterday)) {
genGrid
@beneskildsen
An interactive, runnable TypeScript val by beneskildsen
Script
export const genGrid = (state) => {
const locStack = [];
let loc = { ...state.initialPosition };
let gridMap = {};
let dir = "UP";
let i = 0;
for (let c of state.grammar) {
switch (c) {
case "[":
locStack.push({ ...loc });
gfm
@nbbaier
Convert markdown to Html with Github styling
Script
# Convert markdown to Html with Github styling
export async function gfm(markdown: string, options?: { title?: string; favicon?: string }) {
const html = await unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeDocument, {
title: options?.title,
link: [
{ href: `https://fav.farm/${options?.favicon || "đź“ť"}`, rel: "icon" },
telegrambot
@begoon
This val is a demo skeleton of a telegram chat bot. It requires the BOT_TOKEN environment varialbe, which the telegram bot token. Another required variable is ME. The variable is an HTTP header to call a few extra endpoints (see the code). One of those endpoints is /webhook/set , which installs the webhook to activate the bot. The code is mostly educational. The bot echos back incoming messages. There is one command, /ai , which sends the incoming messages to Open AI and forwards the reply back to the chat.
HTTP
This val is a demo skeleton of a telegram chat bot.
It requires the BOT_TOKEN environment varialbe, which the telegram bot token.
Another required variable is ME. The variable is an HTTP header to call a few extra endpoints (see the code).
One of those endpoints is `/webhook/set`, which installs the webhook to activate the bot.
The code is mostly educational. The bot echos back incoming messages.
There is one command, `/ai`, which sends the incoming messages to Open AI and forwards the reply back to the chat.
const { BOT_TOKEN, ME } = env;
const TELEGRAM = `https://api.telegram.org`;
const BOT = `${TELEGRAM}/bot${BOT_TOKEN}`;
const VAL = thisval();
GDI_HelloWorldService
@rozek
This val is part of a series of examples to introduce "val.town" in my computer science course at
Stuttgart University of Applied Sciences . The idea is to motivate even first-semester students not to wait but to put their
ideas into practice from the very beginning and implement web apps with
frontend and backend. It contains a very simple HTTP end point responding with a static "Hello, World!".
To make it less boring, the response is rendered as ASCII art. In order to use it, send a request similar to the following https://rozek-gdi_helloworldservice.web.val.run/ The code was created using Townie - with only very few small manual corrections. This val is licensed under the MIT License.
HTTP
This val is part of a series of examples to introduce "val.town" in my computer science course at
[Stuttgart University of Applied Sciences](https://www.hft-stuttgart.com/).
The idea is to motivate even first-semester students not to wait but to put their
ideas into practice from the very beginning and implement web apps with
frontend and backend.
It contains a very simple HTTP end point responding with a static "Hello, World!".
export default async function (req: Request): Promise<Response> {
const asciiArt = `
| _ | __/ | | (_) | \\ V V / (_) | | | | (_| |_|
return new Response(asciiArt, {
weatherInCity
@jamiedubs
get weather forecast for a city. pass ?city=Cleveland,OH . e.g.: https://jamiedubs-weatherInCity.web.val.run/?city=brooklyn,ny
HTTP
get weather forecast for a city. pass `?city=Cleveland,OH`. e.g.: https://jamiedubs-weatherInCity.web.val.run/?city=brooklyn,ny
export const getWeatherForecast = async (req: Request) => {
const url = new URL(req.url);
const city = url.searchParams.get("city");
if (!city) {
return new Response("City parameter is required", {
status: 400, // Bad Request
headers: { "Content-Type": "text/plain" },
const weatherApiUrl = `https://wttr.in/${encodeURIComponent(city)}?format=j1`;
try {
val_xsF31rYfbQ
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
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++) {
testTemplating
@tmcw
An interactive, runnable TypeScript val by tmcw
Script
import { tags } from "https://esm.town/v/tmcw/tags";
export const testTemplating = (() => {
const { a } = tags();
return a({ href: "https://vanjs.org/" }, "🍦VanJS").render();
todoMarkdown
@jessmartin
An interactive, runnable TypeScript val by jessmartin
Express (deprecated)
export let todoMarkdown = (req, res) => {
res.send("- [ ] Something to do \n - [x] Something done");
valle_tmp_52909322274216213030085201031243
@janpaul123
// This val greets the user with their inputted name
HTTP
// This val greets the user with their inputted name
export default async function(req: Request): Promise<Response> {
const formData = new URLSearchParams(await req.text());
const name = formData.get("name") || "stranger";
const htmlResponse = `<h1>Hello, ${name}!</h1>`;
return new Response(htmlResponse, {
headers: { "Content-Type": "text/html" },
notify
@adjectiveallison
An interactive, runnable TypeScript val by adjectiveallison
HTTP
export async function notify(request: Request) {
if (request.method === "OPTIONS") {
return new Response("", {
headers: {
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Origin": "*",
const body = await request.json();
if (!body.message) {
return Response.error();
const resp = await fetch("https://api.pushover.net/1/messages.json", {