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> {
8const USERNAME = extractValInfo(import.meta.url).author;
9
10export async function createInjectMyFooterStream(logo = valTownLogoAuto) {
11 const footer = await MyFooter(logo);
12 return new InjectHTMLElementStream(footer.toString());
13}
14
15export async function MyFooter(logo = valTownLogoAuto) {
16 const recommendation = rootValRef().handle === USERNAME
17 ? html`<span class="recommends">${await recommends()}</span>`
41}
42
43export default async function(req) {
44 const { Layout } = await import("https://esm.town/v/postpostscript/Layout");
45 return htmlResponse`${Layout`
Simple functional CSS library for Val Town
A helper function to build a file's email
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": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.