Search
val_M2RuLeNjIx
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_M2RuLeNjIx(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
const generateRandomSequence = (length) => {
const sequence = [];
for (let i = 0; i < length; i++) {
sequence.push(Math.random());
return sequence;
const analyzeDistribution = (sequence) => {
Nav
@iamseeley
@jsxImportSource https://esm.sh/hono@latest/jsx
Script
/** @jsxImportSource https://esm.sh/hono@latest/jsx */
export default function Nav({ currentPath }) {
const isEditProfilePath = currentPath && currentPath.startsWith('/edit-profile/');
return (
<nav className="flex flex-row justify-between items-center">
<a className="" href="/"><h2 style={{ fontFamily: '"Jaro", sans-serif' }} className="text-4xl text-neutral-800">/now</h2></a>
<div className="flex flex-row gap-2 mt-1">
{isEditProfilePath ? (
<button
hx-post="/logout"
deno_server
@pomdtr
An interactive, runnable TypeScript val by pomdtr
Script
export function denoServer(handler: (req: Request) => Response | Promise<Response>, thisArg?: any) {
if (thisArg) {
handler = handler.bind(thisArg);
return Object.assign(handler, {
fetch: (req) => handler(req),
SSEDemo
@maxm
Server-Sent Events Demo
HTTP
# Server-Sent Events Demo
const msg = new TextEncoder().encode("data: hello\r\n\r\n");
export default async function(req: Request): Promise<Response> {
let timerId: number | undefined;
const body = new ReadableStream({
start(controller) {
controller.enqueue(msg);
timerId = setInterval(() => {
controller.enqueue(msg);
}, 1000);
njuskaloIndex
@tvalincic
An interactive, runnable TypeScript val by tvalincic
HTTP
export async function njuskaloIndex(req: express.Request, res: express.Response) {
let len = 3; // default number of elements, can be overrun on frontend
let keywords: string[] = [];
let { data, emptyDetails, fillEmpty, newKeywords, defaultData } =
njuskaloCreateDataWithInterfaces(
njuskaloData,
// 1. check incomming values
const k: unknown = req.query.keywords;
if (Array.isArray(k) && k.every((i) => typeof i === "string"))
keywords = req.query.keywords as string[];
htmlExample
@olpy
An interactive, runnable TypeScript val by olpy
Script
export const htmlExample = () =>
new Response("<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Post HTTP Webhooks</title>
<style>
body {
font-family: sans-serif;
.container {
honoZodSwaggerUi
@stevekrouse
@jsxImportSource https://esm.sh/hono@3.9.2/jsx
HTTP
/** @jsxImportSource https://esm.sh/hono@3.9.2/jsx **/
const ParamsSchema = z.object({
id: z
.string()
.min(3)
.openapi({
param: {
name: "id",
in: "path",
example: "1212121",
websiteHitCounter
@healeycodes
// Tiny web page with a hit counter
Script
let { _hits } = await import("https://esm.town/v/healeycodes/_hits");
// Tiny web page with a hit counter
export let websiteHitCounter = (
req: express.Request,
res: express.Response
// track hits
if (_hits === undefined) {
_hits = 1;
} else {
_hits++;
TanaInOutSandbox
@bikefixe
An interactive, runnable TypeScript val by bikefixe
Script
export let TanaInOutSandbox = (req: express.Request, res: express.Response) => {
//res.json({ data: `Hello + ${req.body}` });
res.send(req.body.key);
mockToApi
@nbbaier
This val demonstrates the creation of an API with a programmatically generated set of data instead of an existing Val Town lowdb instance.
HTTP
This val demonstrates the [creation of an API](https://www.val.town/v/nbbaier/dbToAPI) with a programmatically generated set of data instead of an existing Val Town [lowdb](https://www.val.town/v/pomdtr/lowdb) instance.
const mock = () => {
const data = { users: [], posts: [], random: {} };
for (let i = 0; i < 25; i++) {
const user: string = faker.person.fullName(); // Rowan Nikolaus
const userSplit: string[] = user.split(" ");
const email: string = userSplit[0].endsWith(".")
? userSplit[1].toLowerCase() + "." + userSplit[2].toLowerCase() + "@"
+ faker.internet.domainName()
: userSplit[0].toLowerCase() + "." + user.split(" ")[1].toLowerCase() + "@"
date_me_form
@vawogbemi
@jsxImportSource npm:hono@3/jsx
HTTP
/** @jsxImportSource npm:hono@3/jsx */
const Link = ({ href, children }) => {
return <a href={href} class="text-sky-600 hover:text-sky-500" target="_blank">{children}</a>;
export const Form = (c) =>
c.html(
<Layout activeTab={"/submit"}>
<form class="max-w-xl mx-auto bg-white p-6" method="post">
<h2 class="text-2xl mb-4 font-semibold text-gray-800">I am a Man In Finance!</h2>
<div class="mb-4">
<label for="Name" class="block text-gray-700 font-bold mb-2">
valle_tmp_82429476471184249764330565705816
@janpaul123
// This val will respond with a styled HTML form for users to input their name
HTTP
// This val will respond with a styled HTML form for users to input their name
export default async function (req: Request): Promise<Response> {
if (req.method === "POST") {
const formData = new URLSearchParams(await req.text());
const name = formData.get("name") ?? "Stranger"; // Default to "Stranger" if no name provided
return new Response(`<h1 style="color: #333; text-align: center;">Hello, ${name}!</h1>`, { headers: { "Content-Type": "text/html" } });
return new Response(`
<html>
<head>
<title>Greetings Form</title>
valle_tmp_205899010159034569576183049286815
@janpaul123
// This val serves an HTML page with a form to enter your name.
HTTP
// This val serves an HTML page with a form to enter your name.
// When the form is submitted, it greets you with "Hello, <name>!".
export default async function(req: Request): Promise<Response> {
let name = "";
if (req.method === "POST") {
const formData = await req.formData();
name = formData.get("name") as string || "";
const html = `
<!DOCTYPE html>
<html lang="en">
generativeFill
@jeffreyyoung
An interactive, runnable TypeScript val by jeffreyyoung
HTTP
const replicate = new Replicate({
auth: Deno.env.get("REPLICATE_API_KEY"),
export default serve({
async *handleMessage(req) {
const lastMsg = req.query.at(-1);
if (lastMsg && lastMsg.attachments.length !== 2) {
yield events.replace("No image recieved");
yield html;
yield events.done();
return;