1export async function chocolateMeerkat(req) {
2 const body = await req.json();
3
14 }
15
16 // Function to escape special characters in a string for regex
17 function escapeRegExp(string) {
18 return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
19 }
20
21 // Function to dynamically generate the replacement string based on original casing
22 function replaceNameWithLink(match) {
23 const link = namesToLinks[match.toLowerCase()];
24 if (link) {
1export async function track(domain: string, req: Request) {
2 await fetch("https://plausible.io/api/event", {
3 method: "POST",
4import { fetch } from "https://esm.town/v/std/fetch";
5
6export async function watchWebsite(url: string) {
7 const newHtml = await fetch(url).then(r => r.text());
8
1import { Options, Parser as CsvParser } from "npm:json2csv";
2
3export default async function(req: Request): Promise<Response> {
4 const blockFeesResp = await fetch("https://mempool.space/api/v1/mining/blocks/fees/3y");
5 const blockFees = await blockFeesResp.json();
12 new Promise((resolve) => setTimeout(resolve, delay));
13
14function _foo(x: number) {
15 console.log(x);
16}
17const foo = traced("foo", _foo);
18
19function _throw() {
20 throw new Error("errr");
21}
26});
27
28async function afn(x: number): Promise<number> {
29 return x;
30}
31const tafn = traced("afn", afn);
32
33async function handler(request: Request): Promise<Response> {
34 await tracer.startActiveSpan("sub-span", async (span) => {
35 await doSomething();
1# Cli Vals
2
3Cli vals are a new type of val (same as http, email, cron and script vals). A cli val must use a function without args as it's default export.
4
5The function body will run on the user device using [deno](https://deno.com). An error message will be shown if deno is not installed.
6
7
8```typescript
9export default function() {
10 if (Deno.args.length == 0) {
11 console.error("<name> arg is required!");
30};
31
32async function get_val(
33 user: string,
34 val: string,
50}
51
52function show_val(
53 latest_version: number,
54 val: Val,
90 {html`
91 <script type="module">
92 function unescape(str) {
93 return str.replace(
94 /&|<|>|'|"/g,
164});
165
166async function handler(req: Request): Promise<Response> {
167 await track("saolsen.changes", req);
168 return await app.fetch(req);
1import { refs } from "https://esm.town/v/stevekrouse/refs";
2
3export function editRedirect() {
4 const ref = refs()[0];
5 const editURL = `https://val.town/v/${ref.userHandle}/${ref.valName}`;
1export function parseNotionDateDoc(obj): DateMeDoc {
2 return {
3 Id: obj.id,
2import { diffLines } from "https://esm.town/v/chet/diffLines";
3
4export function diffHtml(before: string, after: string) {
5 return diffLines(cleanHtml(before), cleanHtml(after));
6}
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",