5const KEY = import.meta.url.split("?")[0];
6
7export async function addComment(str) {
8 const comments = await blob.getJSON(KEY) as Array<string> ?? [];
9 comments.push(str);
11 await email({ text: "New Comment Alert!: " + str });
12}
13export async function getComments() {
14 return await blob.getJSON(KEY) as Array<string> ?? [];
15}
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI";
3
4export async function aqi(interval: Interval) {
5 const location = "brooklyn navy yard"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });
15`.trim();
16
17export default async function(req: Request): Promise<Response> {
18 return new Response(
19 appendFragment(
4const { author, name } = extractValInfo(import.meta.url);
5
6async function serveHtml(req: Request): Promise<Response> {
7 return new Response(
8 `
9 * @param val Define which val should open. Defaults to the root reference.
10 */
11export function modifyHtmlString(
12 bodyText: string,
13 { val, style }: { val?: ValRef; style?: string } = {},
40 * @param val Define which val should open
41 */
42export function modifyFetchHandler(
43 handler: RequestHandler,
44 { val, style }: { val?: ValRef; style?: string } = {},
2import ky from "npm:ky";
3
4export async function convertUrlToDataURL(url: string | URL): Promise<string> {
5 const blob = await ky.get(url).blob();
6 return convertBlobToDataURL(blob);
7}
8
9export function convertBlobToDataURL(blob: Blob): Promise<string> {
10 return new Promise((resolve, reject) => {
11 const reader = new FileReader();
6export type RequestHandler = (req?: Request) => Response | Promise<Response>;
7
8export function createWrappedHandler(
9 handler: RequestHandler,
10 ...transforms: ReadableWritablePair[]
16}
17
18export function pipeResponse(
19 res: Response,
20 ...transforms: ReadableWritablePair[]
49### Linking to the val
50
51These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the `val` argument:
52
53- `modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }})`
1import { blob } from "https://esm.town/v/std/blob?v=11";
2
3export async function deleteBlobs(prefix: string) {
4 (await blob.list(prefix)).forEach(({ key }) => blob.delete(key));
5}
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export default async function fetchBrightDataBalance(
4 token: string,
5): Promise<number> {
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": "*",