Search

Results include substring matches and semantically similar vals. Learn more
crsven avatar
renderAnimalWidgetJson
@crsven
An interactive, runnable TypeScript val by crsven
Express
import { animalWidgetJson } from "https://esm.town/v/crsven/animalWidgetJson";
export let renderAnimalWidgetJson = async (req: Request, res: Response) => {
res.json(animalWidgetJson);
yawnxyz avatar
demoSDK
@yawnxyz
An interactive, runnable TypeScript val by yawnxyz
Script
import ValTown from "npm:@valtown/sdk";
const vt = new ValTown({ bearerToken: Deno.env.get("valtown") });
console.log(await vt.me.profile.retrieve());
console.log(await vt.blobs.list());
console.log(await vt.vals.runAnonymous({ code: "export const x = 1+1" }));
pomdtr avatar
serveCommand
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
export type CommandOptions = {
args?: string[];
type ServeCommandParams = {
* The command to run.
command: string;
* The environment variables to set.
env?: Record<string, string>;
* The arguments to pass to the command.
* If `true`, the arguments will be taken from the request path and query parameters.
* if `false`, the arguments will be empty.
pomdtr avatar
protected_website
@pomdtr
An interactive, runnable TypeScript val by pomdtr
HTTP (deprecated)
import { basicAuth } from "https://esm.town/v/pomdtr/basicAuthV2";
export default basicAuth(() => {
return new Response("You're in!");
userTable: "user",
saolsen avatar
gfm
@saolsen
Convert markdown to Html with Github styling Forked to add light mode
Script
# Convert markdown to Html with Github styling
*Forked to add light mode*
// This is kind of a pain, but the existing remark/rehype mermaid plugins
// use playwright internally for some reason, which is a non-starter here
// in good ol' valtown!
const addMermaidScript = () => (tree) => {
const body = select("body", tree);
console.log(body);
const script = `
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.esm.min.mjs';
stevekrouse avatar
expressContentTypeTest
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export function expressContentTypeTest(req, res) {
res.send(req.body.a.b);
janpaul123 avatar
valle_tmp_348423812438495525540884526013663
@janpaul123
// This val will respond with "Hello World" to any incoming HTTP request
HTTP (deprecated)
// This val will respond with "Hello World" to any incoming HTTP request
export default async function(req: Request): Promise<Response> {
return new Response("Hello World");
jeffreyyoung avatar
CodeRunner
@jeffreyyoung
A simple poe bot
HTTP (deprecated)
A simple poe bot
const { loadPyodide } = pyodideModule;
const pyodide = await loadPyodide();
export default serve({
async *handleMessage(req) {
const lastMessage = req.query.at(-1)?.content;
const supportedCodeBlocks: {
type: "python";
content: string;
marked.use({
unflat avatar
joinWaitingList
@unflat
An interactive, runnable TypeScript val by unflat
Script
let { waitingList } = await import("https://esm.town/v/unflat/waitingList");
export const joinWaitingList = (req, res) => {
const emailAddress = `${req.query.email}`.toLowerCase();
const emailRegexp =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-z
if (emailRegexp.test(emailAddress) === false) return;
if (waitingList.indexOf(emailAddress) !== -1) return;
waitingList = `${waitingList},${emailAddress}`;
res.set({ "Content-Type": "application/json" });
res.send({ success: true });
nbbaier avatar
cachedResponseExample
@nbbaier
An interactive, runnable TypeScript val by nbbaier
HTTP (deprecated)
export const cachedResponseExample = () => {
const date = new Date().toISOString();
return new Response("This is the cached response", {
headers: {
"Cache-Control": "public, max-age=3600",
kayla_lin avatar
getYenPriceCron
@kayla_lin
An interactive, runnable TypeScript val by kayla_lin
Cron
async function fetchHistoricData() {
const currentDate = new Date();
const promises = [];
for (let i = 0; i < 30; i++) {
const date = new Date();
date.setDate(currentDate.getDate() - i);
const formattedDate = date.toISOString().split("T")[0];
const url =
`https://www.floatrates.com/historical-exchange-rates.html?operation=rates&pb_id=1462&page=historical&currency_date=${f
const fetchPromise = fetch(url)
valTownTrpc avatar
autocomplete
@valTownTrpc
An interactive, runnable TypeScript val by valTownTrpc
Script
import { getValTownTrpc } from "https://esm.town/v/easrng/getValTownTrpc?v=5";
export const autocomplete = async ({ name, handle }) => {
const trpc = await getValTownTrpc();
return await trpc.autocomplete.query({
name,
handle,
marianoguerra avatar
testcase1
@marianoguerra
// export state = () => {
Script
import { fetchJSON } from "https://esm.town/v/swyx/fetchJSON";
export let testcase1 = fetchJSON('https://api.val.town/eval/@stevekrouse.messages')
// export state = () => {
// const h = (new Date()).getHours()
// if (h > 7 && h < 12) {
// return "Good morning"
// } else if (h >= 12 && h < 20) {
// return "Busy"
// } else {
// return "Tired"
agmm avatar
teapot
@agmm
An interactive, runnable TypeScript val by agmm
HTTP (deprecated)
export default async function(req: Request): Promise<Response> {
const statusDoc = "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418";
const text = `I am a teapot 🫖\n\n${statusDoc}`;
return new Response(text, { status: 418 });
sboesen avatar
password_auth
@sboesen
Password Auth Middleware Protect your vals behind a password. Use session cookies to persist authentication. Demo See @pomdtr/password_auth_test Usage import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth?v=84"; export default passwordAuth(() => { return new Response("OK"); }, { verifyPassword: (password) => password == Deno.env.get("VAL_PASSWORD") }); If you want to use an api token to authenticate: import { passwordAuth } from "https://esm.town/v/pomdtr/password_auth?v=84"; import { verifyToken } from "https://esm.town/v/pomdtr/verifyToken"; export default passwordAuth(() => { return new Response("OK"); }, { verifyPassword: verifyToken }); TODO [x] allow to authenticate using a val town token [ ] add a way to send an email to ask a password from the val owner [ ] automatically extend the session [ ] automatically remove expired sessions FAQ How to sign out ? Navigate to <your-site>/signout .
Script
# Password Auth Middleware
Protect your vals behind a password. Use session cookies to persist authentication.
![6ed0648ae8813e958dbe79468572cb52f578239c0fae55857a13660beebdc5fd.png](https://imagedelivery.net/iHX6Ovru0O7AjmyT5yZRoA/36c1
## Demo
See @pomdtr/password_auth_test
## Usage
type Session = {
id: string;
expiresAt: number;
async function createSessionTable(tableName: string) {