Search

Results include substring matches and semantically similar vals. Learn more
malloc avatar
examplebot_endpoint
@malloc
An interactive, runnable TypeScript val by malloc
Script
export let examplebot_endpoint = (
req: express.Request,
res: express.Response,
console.log(res);
if (!req.get("X-Signature-Timestamp") || !req.get("X-Signature-Ed25519")) {
res.status(400);
res.end("Signature headers missing");
verify_discord_signature(
process.env.discord_pubkey,
JSON.stringify(req.body),
pomdtr avatar
evalPost1
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
console.log(
await fetchJSON(
"https://api.val.town/v1/eval",
method: "POST",
body: JSON.stringify({ code: "1+1" }),
pomdtr avatar
staticChess
@pomdtr
An interactive, runnable TypeScript val by pomdtr
HTTP
import { pwa } from "https://esm.town/v/pomdtr/pwa";
export default pwa(handler, {
name: "Static Chess",
display: "standalone",
background_color: "#ffffff",
start_url: "/",
ftlsid avatar
likePost
@ftlsid
An interactive, runnable TypeScript val by ftlsid
Script
import { ftlsid_com_likes } from "https://esm.town/v/ftlsid/ftlsid_com_likes";
export async function likePost(req, res) {
const ip = req.ip;
const postURL = req.query.url;
if (ftlsid_com_likes[postURL]) {
const likes = ftlsid_com_likes[postURL];
likes[ip] = true;
else {
const likes = { [ip]: true };
ftlsid_com_likes[postURL] = likes;
u avatar
fetcher
@u
An interactive, runnable TypeScript val by u
Script
export async function fetcher() {}
stevekrouse avatar
nakedAPIEx
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export function nakedAPIEx(req, res) {
res.send("my returned srting");
pomdtr avatar
brownBoar
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
export default function(req) {
return new Response("Hello from sandbox");
jhildenbiddle avatar
mergician_demo
@jhildenbiddle
// ES module shown. CommonJS module also available.
Script
// ES module shown. CommonJS module also available.
import { mergician } from "https://cdn.jsdelivr.net/npm/mergician@2";
const obj1 = { a: [1, 1], b: { c: 1, d: 1 } };
const clonedObj = mergician({}, obj1);
// Results
console.log(clonedObj); // { a: [1, 1], b: { c: 1, d: 1 } }
console.log(clonedObj === obj1); // false
console.log(clonedObj.a === obj1.a); // false
console.log(clonedObj.b === obj1.b); // false
mittzy avatar
loginredux_login
@mittzy
An interactive, runnable TypeScript val by mittzy
HTTP
export default async function(req: Request): Promise<Response> {
const body = await req.json();
let { username, password } = body;
if (!username || !password) {
return new Response(JSON.stringify({ error: "Missing username or password" }), { status: 400 });
if (password.length > 50) {
return new Response(JSON.stringify({ error: "Password too long" }), { status: 400 });
if (username.length > 50) {
return new Response(JSON.stringify({ error: "Username too long" }), { status: 400 });
const TABLE_NAME = "loginredux_users";
stevekrouse avatar
lucia_sqlite
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
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 NOT NULL
`CREATE TABLE ${sessionTable} (
id TEXT NOT NULL PRIMARY KEY,
expires_at INTEGER NOT NULL,
user_id TEXT NOT NULL,
ajax avatar
explain_like_im_150
@ajax
An interactive, runnable TypeScript val by ajax
HTTP
export default async function(req: Request): Promise<Response> {
if (req.method !== "POST") {
return Response.json({ message: "This function responds to POST requests only." }, {
status: 400,
try {
const body = await req.json();
const topic = body?.topic ?? "the modern world";
const currentYear = new Date().getFullYear();
const birthYear = currentYear - 150;
const prompt = `
vladimyr avatar
appendFragment_example
@vladimyr
An interactive, runnable TypeScript val by vladimyr
HTTP
const { author, name } = extractValInfo(import.meta.url);
const html = `<html>
<head>
<title>test</title>
</head>
<body>
<p><code>@vladimyr/appendFragment</code> test</p>
</body>
</html>
`.trim();
dglazkov avatar
googletrends
@dglazkov
An interactive, runnable TypeScript val by dglazkov
HTTP
NodeDescriberResult,
service,
} from "https://esm.town/v/dglazkov/servicefactory";
parseXml,
XmlCdata,
XmlComment,
XmlDocument,
XmlElement,
XmlText,
} from "npm:@rgrove/parse-xml";
slowchaz avatar
grotesqueAquamarineShrew
@slowchaz
An interactive, runnable TypeScript val by slowchaz
HTTP
const KEY = "views";
interface StoredData {
pageViews: number;
export default async function handler(req: Request): Promise<Response> {
const headers = new Headers({
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Authorization",
if (req.method === "OPTIONS") {
return new Response(null, { headers });
nimalu avatar
viewMailbox
@nimalu
// https://api.val.town/express/@nimalu.viewMailbox
Script
// https://api.val.town/express/@nimalu.viewMailbox
export const viewMailbox = (req, res) => {
const messages = mailbox
.map(
({ message, sender }) =>
`<li><span class="font-semibold text-gray-900">${sender}: </span>${message}</li>`
.join("");
res.set("Content-Type", "text/html");
res.send(`
<!doctype html>