Trending Vals
122
stevekrouse
getDayName
Script
Get the day of week name JavaScript's Date.prototype.getDay() returns a number that represents the day of the week, 0 for Sunday, 1 for Monday, etc. This function returns the name of the week, ie "Sunday" , "Monday" , etc. The function optionally inputs a Date object, but will default to the current time if none is provided.
0
125
pomdtr
lastloginHono
Script
See @pomdtr/lastlogin for more informations about the middleware Example /** @jsxImportSource npm:hono@3/jsx */
import { lastlogin } from "https://esm.town/v/pomdtr/lastloginHono";
import { verifyUserEmail } from "https://esm.town/v/pomdtr/verifyUserEmail"
import { Hono } from "npm:hono";
const app = new Hono();
const lastloginMiddleware = lastlogin({
verifyEmail: verifyUserEmail
});
// required for the auth pages to work
app.use("/auth/*", lastloginMiddleware);
// this page is public
app.get("/", async (c) => {
return c.html(
<div>
There is a secret message for you if you{" "}<a href="/secret">login</a>
</div>,
);
});
// this page requires the user to signup
app.get("/secret", lastloginMiddleware, async (c) => {
const email = c.req.header("X-User-Email");
return c.html(
<div>
I think {email} is a really silly email address, actually.
</div>,
);
});
export default app.fetch;
1
131
132
tmcw
bandcampWrapped
HTTP
Bandcamp Wrapped It's Spotify Wrapped, but for Bandcamp! . Bandcamp is for people who buy their music and probably most of them hoard MP3s. Like me. And this val helps those people
turn their Bandcamp purchases of 2024 into HTML or Markdown suitable for blog posts on their blogs, which is probably a segment that has some overlap with the people who are
wacky enough to buy their music instead of streaming it from some service. Because Bandcamp doesn't have an API, this hinges on you going to your purchases page, copying the purchases, and pasting it in. Thanks to
the ability of the system clipboard to contain HTML , the same technology that makes
copy-and-pasted text have unpredictable and annoying font and boldness choices also lets this parse and reformat that purchases page into something
shareable. I would love for this to support embeds as well, but I haven't found a strategy yet:
Bandcamp embeds use album IDs in the URLs,
which are not exposed in the content on the purchases page. I'd have to scrape Bandcamp for that, which
would probably inevitably be blocked by some 'bot protection' system. Also read about this on macwright.com .
1
136
stevekrouse
cors_example
HTTP
CORS issues are the bane of frontend engineers. In Val Town, if you don't customize any CORS headers, we add these defaults: Access-Control-Allow-Origin: "*"
Access-Control-Allow-Methods: "GET,HEAD,PUT,PATCH,POST,DELETE" You can override them if you wish to disallow CORS. This val is a client-side-rendered React app that makes requests to @stevekrouse/cors_example_backend. The backend is in a different val because CORS applies to requests on different domains. The backend has examples of the default permissive CORS behavior and disabled CORS.
1
137
138
prashamtrivedi
icsviewer
HTTP
ICS Calendar Viewer A web-based calendar application for viewing ICS (iCalendar) files, deployed as a Val Town HTTP val. Features 📅 Monthly calendar view 📤 ICS file upload support 📋 ICS content paste support 🌓 Dark/Light mode 🎨 Automatic event coloring Usage Access the calendar through your Val Town HTTP val URL Upload ICS files or paste ICS content View your events on the calendar Toggle dark/light mode as needed Navigate between months Technical Details Built with React 18.2.0 and TailwindCSS Handles ICS file parsing and display No data persistence (events are stored in memory only) Fork and Modify Fork this val Make your changes Save to automatically deploy your version
1
139
stevekrouse
openai
Script
OpenAI ChatGPT helper function This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free. import { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat("Hello, GPT!");
console.log(content); import { chat } from "https://esm.town/v/stevekrouse/openai";
const { content } = await chat(
[
{ role: "system", content: "You are Alan Kay" },
{ role: "user", content: "What is the real computer revolution?"}
],
{ max_tokens: 50, model: "gpt-4o" }
);
console.log(content);
1
142
pomdtr
fetchValInfo
Script
Usage import { fetchValInfo } from "https://esm.town/v/pomdtr/fetchValInfo"
const val = await fetchValInfo(import.meta.url)
console.log(val.id) What's the difference with extractValInfo ? @pomdtr/extractValInfo get metadata synchronously by analysing the val import url, while @pomdtr/fetchValInfo perform an http call to the val.town REST api. Only use fetchValInfo if you need some metadata that are not available from extractValInfo .
1
143
browserbase
browserbaseUtils
Script
Utils to loadPageContent() and screenshotPage() . Browserbase Browserbase offers a reliable, high performance serverless developer platform to run, manage, and monitor headless browsers at scale. Leverage our infrastructure to power your web automation and AI agents. Get started with Browserbase for free here . If you have any questions, reach out to developer@browserbase.com.
1
144
pomdtr
http_client
HTTP
HTTP Client Attach a postman-like http client to your vals, with bookmarks and history support Usage Wrap your http handler in an the httpClient middleware. import {httpClient} from "https://esm.town/v/pomdtr/http_client"
export default httpClient((req) => {
return new Response("Hello World!")
}) The http client will be shown on the root. Adding bookmarks You might want to bookmark some requests you need often. You can do it by passing a bookmark list as a middleware option: import {httpClient} from "https://esm.town/v/pomdtr/http_client"
export default httpClient((req) => {
return new Response("Hello World!")
}, {
bookmarks: [
{
"label": "Dummy Request",
"request": new Request("https://dummyjson.com/products")
}
]}) Customizing the client path import {httpClient} from "https://esm.town/v/pomdtr/http_client"
export default httpClient((req) => {
return new Response("Hello World!")
}, {
path: "/http-client"
}) TODO [ ] fix syntax highlighting on successive request [ ] allow to prefill the initial request
7