Search
val_hdOGrceY7V
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export const jsonOkExample = () => Response.json({ ok: true });
pug
@wilt
Pug HTML Template Renderer This function is equivalent to pug.render - it takes a Pug template string and renders it to an HTML string. import(npm:pug) doesn't work in Val.Town due to Pug's usage of new Function , which is forbidden for security reasons, so this function uses Val.Town's eval API instead. Example const myEndpoint = async (req: express.Request, res: express.Response) => {
const html = await @wilt.pug("p Hello #{name}!", {name: "Pug"});
res.status(200);
res.send(html);
}
Script
# Pug HTML Template Renderer
This function is equivalent to [`pug.render`](https://pugjs.org/api/reference.html#pugrendersource-options-callback) - it takes a Pug template string and renders it to an HTML string. `import(npm:pug)` doesn't work in Val.Town due to Pug's usage of `new Function`, which is forbidden for security reasons, so this function uses Val.Town's `eval` API instead.
## Example
```javascript
const myEndpoint = async (req: express.Request, res: express.Response) => {
const html = await @wilt.pug("p Hello #{name}!", {name: "Pug"});
export async function pug(
templateStr: string,
args = {},
// Not sure why anyone would use this callback, but it's included for compatibility with pug.render
valle_tmp_50644780717275968385591250334155
@janpaul123
// The simplest approach to fulfill this request is to create an HTTP handler that responds to all requests with "Hello world" using the built-in Response class in TypeScript.
HTTP
// The simplest approach to fulfill this request is to create an HTTP handler that responds to all requests with "Hello world" using the built-in Response class in TypeScript.
* HTTP Val: Hello World Example
* This script will respond with "Hello world" to any incoming HTTP request.
export default async function(req: Request): Promise<Response> {
return new Response("Hello world", {
headers: { "Content-Type": "text/plain" },
jsr
@vladimyr
Try on Val Town This service enables quick generation of new val with specified jsr package.
Package authors can provide custom examples by setting either: valtownExample property of jsr.json / deno.json to contain example js/ts code valtownExampleFilename property of jsr.json / deno.json to point to the file with example js/ts code If no example is found val will be created with the default snippet, using @luca/flag as an example : import * as flag from "jsr:@luca/flag"; Go ahead āļø try it (on Val Town) ! š Additionally, the service supports ?code=<base64code> query param that allows overriding extracted/generated example code.
For example one might want to override @luca/flag 's snippet with: import { printProgress } from "jsr:@luca/flag@1";
printProgress(); In order to do so first you need to convert it to base64: $ printf 'import { printProgress } from "jsr:@luca/flag@1";\n\nprintProgress();' | base64 -w0
# ==> aW1wb3J0IHsgcHJpbnRQcm9ncmVzcyB9IGZyb20gImpzcjpAbHVjYS9mbGFnQDEiOwoKcHJpbnRQcm9ncmVzcygpOw== Then you simply construct the URL by setting the returned value to code query param: āļø https://vladimyr-jsr.web.val.run?code=aW1wb3J0IHsgcH... Usage https://vladimyr-jsr.web.val.run/<scope>/<name>[@<version>] https://vladimyr-jsr.web.val.run?code=<base64code> Example https://vladimyr-jsr.web.val.run/@luca/flag https://vladimyr-jsr.web.val.run/@std/assert@0.220.1 https://vladimyr-jsr.web.val.run/@mark/html@latest
HTTP
# Try on Val Town
[![](https://vladimyr-licensebadge.web.val.run/v/vladimyr/jsr)](https://spdx.org/licenses/0BSD.html)
This service enables quick generation of new val with specified [jsr](https://jsr.io) package.
Package authors can provide custom examples by setting either:
- `valtownExample` property of [`jsr.json`](https://jsr.io/docs/package-configuration)/[`deno.json`](https://docs.deno.com/runtime/manual/getting_started/configuration_file) to contain example js/ts code
- `valtownExampleFilename` property of [`jsr.json`](https://jsr.io/docs/package-configuration)/[`deno.json`](https://docs.deno.com/runtime/manual/getting_started/configuration_file) to point to the file with example js/ts code
// SPDX-License-Identifier: 0BSD
export default async function(req: Request, options?: {
transformReadme: HtmlProcessor;
}): Promise<Response> {
easyAQIExample
@dharmatech
An interactive, runnable TypeScript val by dharmatech
Script
import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=3";
export const easyAQIExample = easyAQI({
location: "brooklyn navy yard",
retroVisitCounter
@maxm
Retro Visit Counter You are visitor number: How special! Want a retro visitor counter for your myspace page or geocities website? Fork this val and add the image link to your website: <img src="https://maxm-retrovisitcounter.web.val.run/counter.png">
<!-- Make sure you swap this subdomain out with the subdomain of your forked val -->
<img src="https://[CHANGE ME!].web.val.run/counter.png">
HTTP
# Retro Visit Counter
You are visitor number: ![](https://maxm-retrovisitcounter.web.val.run/counter.png)
How special!
Want a retro visitor counter for your myspace page or geocities website? Fork this val and add the image link to your website:
<img src="https://maxm-retrovisitcounter.web.val.run/counter.png">
<!-- Make sure you swap this subdomain out with the subdomain of your forked val -->
await sqlite.execute(`create table if not exists counter(
name text,
counter integer
async function getCurrentCount(): Promise<number> {
pipeSampleLLMBind
@webup
An interactive, runnable TypeScript val by webup
Script
export const pipeSampleLLMBind = (async () => {
const { PromptTemplate } = await import("npm:langchain/prompts");
const prompt = PromptTemplate.fromTemplate(`Tell me a joke about {subject}`);
const mb = await getModelBuilder({
type: "chat",
provider: "openai",
const model = await mb();
const tb = await getLangSmithBuilder();
const tracer = await tb();
const functionSchema = [
ping2
@simonharrisco
An interactive, runnable TypeScript val by simonharrisco
Cron
import { fetchHTML } from "https://esm.town/v/stevekrouse/fetchHTML?v=9";
export function ping2() {
fetchHTML("https://simonharrisco-site.vercel.app/");
similarSites
@qiangua
Find similar pages on HN and return a streaming markdown summary. Powered by Exa and Substrate . šŖ© To fork, sign up for Substrate to get your own API key and $50 free credits.
HTTP
Find similar pages on HN and return a streaming markdown summary.
Powered by [Exa](https://exa.ai/) and [Substrate](https://substrate.run).
šŖ© To fork, [sign up for Substrate](https://substrate.run/signin) to get your own API key and $50 free credits.
const exa = new Exa(Deno.env.get("EXA_API_KEY"));
const substrate = new Substrate({ apiKey: Deno.env.get("SUBSTRATE_API_KEY") });
export default async function handler(req: Request): Promise<Response> {
const url = new URL(req.url).searchParams.get("url") || "https://thesephist.com/posts/synth/";
const searchResults = await exa.findSimilarAndContents(url, {
text: { maxCharacters: 1000 },
category: "personal site",
animateElement
@iamseeley
An interactive, runnable TypeScript val by iamseeley
Script
export function animateElement(element, delay) {
return new Promise(resolve => {
setTimeout(() => {
element.classList.add('in-view');
resolve();
}, delay);
export async function animateElementsSimultaneously(elements, initialDelay) {
const promises = elements.map(element => animateElement(element, initialDelay));
await Promise.all(promises);
runGET
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
export let runGET = fetchJSON(
`https://api.val.town/v1/run/stevekrouse.add?args=${JSON.stringify([1, 2])}`,
examplebotendpoint
@mattx
An interactive, runnable TypeScript val by mattx
Express (deprecated)
export let examplebotendpoint = async (req: Request) => {
const headers = { "Content-type": "application/json" };
const text = await req.text();
const body = JSON.parse(text);
if (
!req.headers.get("X-Signature-Timestamp") ||
!req.headers.get("X-Signature-Ed25519")
return Response.json({ error: "bad request" }, { status: 400 });
const verified = await verify_discord_signature(
process.env.discord_pubkey,
endpointCalculator
@ejfox
* This program creates a basic calculator endpoint that accepts and returns data in the specified format.
* It uses a RESTful API approach where the operation is specified in the URL path.
* The numbers to operate on are passed as query parameters.
* The result is returned as JSON.
HTTP
* This program creates a basic calculator endpoint that accepts and returns data in the specified format.
* It uses a RESTful API approach where the operation is specified in the URL path.
* The numbers to operate on are passed as query parameters.
* The result is returned as JSON.
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);
const operation = url.pathname.split('/').pop();
const numbers = url.searchParams.getAll('num').map(Number);
if (!operation || numbers.length === 0) {
return new Response(JSON.stringify({ error: "Invalid request" }), {
thisWebEndpoint
@neverstew
// Forked from @stevekrouse.thisEmail
Script
import { parentReference } from "https://esm.town/v/stevekrouse/parentReference?v=3";
export let thisWebEndpoint = () => {
let { userHandle, valName } = parentReference();
return `https://${userHandle}-${valName}.web.val.run`;
// Forked from @stevekrouse.thisEmail