Search

Results include substring matches and semantically similar vals. Learn more
just_be avatar
highlightExample
@just_be
Highlight Example This is an example of my highlight val.
HTTP
# Highlight Example
This is an example of my [highlight](https://www.val.town/v/just_be/highlight) val.
export default async function(req: Request): Promise<Response> {
const { searchParams } = new URL(req.url);
const code = await searchParams.get("code") ?? "let builder = WebViewBuilder::new(&window);";
const lang = searchParams.get("lang") ?? "rust";
const theme = searchParams.get("theme") ?? "nord";
return fetch(`https://just_be-highlight.web.val.run?lang=${lang}&theme=${theme}`, {
method: "POST",
body: code,
stevekrouse avatar
myExpressApi
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Express (deprecated)
import { set } from "https://esm.town/v/std/set?v=11";
export async function myExpressApi(req: express.Request, res: express.Response) {
res.json({
count: await set(
"myState",
myState + 1,
dhvanil avatar
val_0rFpB1L3Tu
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export const jsonOkExample = () => Response.json({ ok: true });
runningj avatar
foo
@runningj
An interactive, runnable TypeScript val by runningj
Script
import { fetch } from "https://esm.town/v/std/fetch";
export const foo = () => {
fetch("ipinfo.io")
.then((res) => {
console.log("ok");
console.log(res);
console.email("runningj@duck.com");
.catch((e) => {
console.log("error");
console.error(e);
dhvanil avatar
val_i4JBy56gt2
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_i4JBy56gt2(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
// Let's explore L-Systems to model organic growth and emergent complexity
// This demonstrates how simple rules can create complex, meaningful patterns
function createLSystem(axiom, rules, iterations) {
let result = axiom;
// Apply rules iteratively
for(let i = 0; i < iterations; i++) {
qqyule avatar
honoExample
@qqyule
An interactive, runnable TypeScript val by qqyule
HTTP
import { Hono } from "npm:hono@3";
const app = new Hono();
app.get("/", (c) => c.text("Hello from Hono!"));
app.get("/yeah", (c) => c.text("Routing!"));
app.post("/json", async (c) => {
const body = await c.req.json();
return c.json(body);
export default app.fetch;
spurushottam13 avatar
isSupported
@spurushottam13
An interactive, runnable TypeScript val by spurushottam13
Script
export async function isSupported(jsInterface) {
const caniuse = await import("npm:caniuse-api");
return caniuse.getSupport("border-radius");
dvdsgl avatar
val
@dvdsgl
Val Effects Effects for Val Town. HTTP Easily create effect-based HTTP Vals. import { Effect } from "npm:effect"; import * as Val from "https://esm.town/v/dvdsgl/val"; export default Val.http(req => Effect.gen(function*(){ return Response.json({ ok: true, love: "effect" }); }));
Script
# Val Effects
`Effects` for Val Town.
## HTTP
Easily create effect-based HTTP Vals.
```ts
export default Val.http(req => Effect.gen(function*(){
type Handler<T> = (req: Request) => T;
export function http<E>(effect: Handler<Effect.Effect<Response, E>>): Handler<Promise<Response>> {
return async req => {
const exit = await Effect.runPromiseExit(effect(req));
tmcw avatar
npmExample
@tmcw
An interactive, runnable TypeScript val by tmcw
Script
export let npmExample = (async () => {
const { DOMParser } = await import(
"https://deno.land/x/deno_dom/deno-dom-wasm.ts"
return typeof DOMParser;
ridge avatar
fetchProxy
@ridge
// intended for GET requests to bypass some CORS problems.
Script
import { fetch } from "https://esm.town/v/std/fetch";
// intended for GET requests to bypass some CORS problems.
export async function fetchProxy(url) {
let response = await fetch(url);
return response.ok ? response.text() : "";
stevekrouse avatar
basicAuth
@stevekrouse
Val Town Basic Auth Add basic auth on top of any http val Usage Wrap your HTTP handler in the basicAuth middleware. import { basicAuth } from "https://esm.town/v/pomdtr/basicAuth"; function handler(req: Request) { return new Response("You are authenticated!"); } export default basicAuth(handler); To authenticate, paste an api token in the password prompt.
Script
# Val Town Basic Auth
Add basic auth on top of any http val
## Usage
Wrap your HTTP handler in the `basicAuth` middleware.
```typescript
function handler(req: Request) {
function extractToken(authorization) {
const parts = authorization.split(" ");
if (parts[0] == "Bearer") {
return parts[1];
janpaul123 avatar
valle_tmp_42249988258651369468890296933772
@janpaul123
// Initialize sample stories and store them in blob storage
HTTP
Here's the updated code to make the HN clone look exactly like Hacker News:
ts
// Initialize sample stories and store them in blob storage
const SAMPLE_STORIES_KEY = "hn_realistic_sample_stories";
async function initializeSampleStories() {
const existingStories = await blob.getJSON(SAMPLE_STORIES_KEY);
if (!existingStories) {
const sampleStories = Array.from({ length: 30 }).map((_, idx) => ({
id: idx + 1,
title: faker.company.catchPhrase(),
dhvanil avatar
val_0dtPQXGmvn
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export const jsonOkExample = () => Response.json({ ok: true });
jeffreyyoung avatar
bot1
@jeffreyyoung
a simple poe bot things to note: don't put underscores (_) in the name, it stops working
HTTP
a simple poe bot
things to note:
- don't put underscores (_) in the name, it stops working
* Returns a response to the user's query
async function getResponse(req: Query, send: SendEventFn) {
send("meta", { content_type: "text/markdown" });
const lastMessage = req.query.at(-1);
const attachment = lastMessage.attachments.at(0)?.parsed_content;
if (!attachment) {
send("text", { text: "no attachments" });
dhvanil avatar
val_jkgkaOKFzC
@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++) {