Search

Results include substring matches and semantically similar vals. Learn more
alp avatar
proxyFetch8
@alp
An interactive, runnable TypeScript val by alp
Script
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch8 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
antonnyman avatar
honoExample
@antonnyman
Hono Here's an example using the Hono server library with the Web API . It works great! Server examples Hono Peko Itty Router Nhttp
HTTP
# Hono
Here's an example using the [Hono](https://hono.dev/) server library with the [Web API](https://docs.val.town/api/web). It wo
### Server examples
- [Hono](https://www.val.town/v/tmcw.honoExample)
- [Peko](https://www.val.town/v/tmcw.pekoExample)
- [Itty Router](https://www.val.town/v/tmcw.ittyRouterExample)
export const honoExample = async (req: Request) => {
const { Hono } = await import("npm:hono@3");
const app = new Hono();
app.get("/", (c) => c.text("Hono?"));
stevekrouse avatar
valOutput
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export async function valOutput(req: Request) {
const url = new URL(req.url);
const pattern = /^\/([^\/]+)\/([^@]+)(?:@([^\.]+))?$/;
const match = url.pathname.match(pattern);
if (!match) {
return new Response("invalid request", { status: 400 });
const author = match[1];
const name = match[2];
const val = await fetchJSON(
`https://api.val.town/v1/alias/${author}/${name}`,
tmcw avatar
elysiaExample
@tmcw
Elysia example This is how you can use Elysia with Val Town.
HTTP
# Elysia example
This is how you can use [Elysia](https://elysiajs.com) with Val Town.
export const elysiaExample = async (req) => {
const { Elysia } = await import("https://esm.sh/elysia@0.7.15");
const app = new Elysia()
.get("/", () => "Hello Elysia");
return app.fetch(req);
curtcox avatar
_not_actually_private_so_that_you_can_see_it
@curtcox
This is public so you can see what's in it. If it had real secrets, it should be private. See https://www.val.town/v/curtcox/reply_to_slack_message
HTTP
This is public so you can see what's in it. If it had real secrets, it should be private.
See https://www.val.town/v/curtcox/reply_to_slack_message
import { reply_to_slack_message, SlackConfig } from "https://esm.town/v/curtcox/reply_to_slack_message";
// This is for informational purposes only.
// It needs real tokens to work.
export const chatio = (req: Request) => {
const config: SlackConfig = {
slackToken: "See Val Town docs for how to get this token",
slackVerificationToken: "See Val Town docs for how to get this token",
return reply_to_slack_message(req, processor, config);
byjonathanleung avatar
setZ
@byjonathanleung
An interactive, runnable TypeScript val by byjonathanleung
Script
let { Z } = await import("https://esm.town/v/byjonathanleung/Z");
export const setZ = (newValue) => {
Z = newValue;
return Z
dhvanil avatar
val_jATkKH8yPO
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export const jsonOkExample = () => Response.json({ ok: true });
dhvanil avatar
web_kH7d5ah6xz
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function web_kH7d5ah6xz(req) {
return new Response(`<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Dark Hours: Global Patterns Reveal AI's Secret Evolution</title>
<style>
body {
background-color: #000;
dhvanil avatar
val_iWH7hGnj6J
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_iWH7hGnj6J(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
const isPalindrome = (str) => {
const reversed = str.split('').reverse().join('');
return str === reversed;
const findPalindromicSubstrings = (str) => {
const palindromes = [];
for (let i = 0; i < str.length; i++) {
andreterron2 avatar
_
@andreterron2
An interactive, runnable TypeScript val by andreterron2
Script
export const _ = import("npm:lodash");
whatrocks avatar
foo
@whatrocks
// email yourself as easily as logging to the console
Script
// email yourself as easily as logging to the console
export async function foo() {
const username = "whatrocks";
const today = new Date().toDateString();
console.log("today: ", today);
const url = `https://searchcaster.xyz/api/search?text=%E2%8C%86&username=${username}`;
let old_fling = "";
const response = await fetch(url);
const jsonData = await response.json();
console.log(jsonData);
stevekrouse avatar
tealBadger
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
HTTP
export default async function(req: Request): Promise<Response> {
const openai = new OpenAI();
const stream = await openai.chat.completions.create({
stream: true,
messages: [{ role: "user", content: "Write a poem in the style of beowulf about the DMV" }],
model: "gpt-3.5-turbo",
max_tokens: 2048,
return new Response(
new ReadableStream({
async start(controller) {
pomdtr avatar
coffeeFowl
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
// Import Astral
const command = new Command().arguments("<app>").action(async (_, app) => {
// Launch the browser
const browser = await launch();
// Open a new page
const page = await browser.newPage(`https://${app}.localhost`);
// Take a screenshot of the page and save that to disk
const screenshot = await page.screenshot();
Deno.stdout.write(screenshot);
browser.close();
dhvanil avatar
val_1jzxJ5oCHe
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export const jsonOkExample = () => Response.json({ ok: true });
browserbase avatar
TopHackerNewsDailyEmail
@browserbase
Browserbase Browserbase offers a reliable, high performance serverless developer platform to run, manage, and monitor headless browsers at scale. Leverage our infrastructure to power your web automation and AI agents. Get started with Browserbase for free here . If you have any questions, reach out to developer@browserbase.com.
Cron
### Browserbase
Browserbase offers a reliable, high performance serverless developer platform to run, manage, and monitor headless browsers a
Get started with Browserbase for free [here](browserbase.com).
If you have any questions, reach out to developer@browserbase.com.
let html = await loadPageContent("https://news.ycombinator.com/", { textContent: false });
html = html.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, ""); // remove useless context
// Then, we define the shape of the data to extract
// with a `zod` schema
const schema = z.object({
top: z