Search

Results include substring matches and semantically similar vals. Learn more
suhas avatar
htmx_test_endpoint
@suhas
An interactive, runnable TypeScript val by suhas
Script
export const htmx_test_endpoint = async (
req: express.Request,
res: express.Response
console.email(req.body);
res.set("Content-Type", "text/html");
res.send("<h1>hi</h1>");
fossforlife avatar
wiitdb_jsonl
@fossforlife
An interactive, runnable TypeScript val by fossforlife
HTTP (deprecated)
export default async function(req: Request): Promise<Response> {
try {
const xml = await fetch("https://ej-public-files.sfo3.cdn.digitaloceanspaces.com/wiitdb.xml");
const xmlInput = await xml.text();
const jsonOutput = await parseXML(xmlInput);
const jsonl = jsonArrayToJsonL(jsonOutput.datafile.game);
return new Response(jsonl);
} catch (e) {
return Response.json({ message: "Unknown error" }, {
status: 400,
xuangong avatar
testAndroidBingApps
@xuangong
An interactive, runnable TypeScript val by xuangong
Cron
export async function testAndroidBingApps() {
const { default: axios } = await import("npm:axios");
const url =
"https://sapphire.api.microsoftapp.net/config/api/v1/get?setmkt=en-us&setplatform=android&setchannel=production&settenant
try {
const response = await fetch(url, {
method: "GET",
const data = await response.json();
console.log(data);
const validate = ruleAndroidAppsCheck(data);
thesophiaxu avatar
handler
@thesophiaxu
An interactive, runnable TypeScript val by thesophiaxu
Script
export async function handler(req, res) {
console.email(JSON.stringify(req.body, null, 4), "Hello from Val.town!");
patrickjm avatar
weatherTomorrowGpt3
@patrickjm
An interactive, runnable TypeScript val by patrickjm
Script
import { simpleWeather } from "https://esm.town/v/patrickjm/simpleWeather";
export let weatherTomorrowGpt3 = (params: { openAiKey: string, city: string }) =>
simpleWeather(params.city).then((weather) =>
gpt3({
openAiKey: params.openAiKey,
prompt: `
Given a JSON sequence, give a short, plain-English summary about the weather tomorrow.
The hourly forecast uses military time, where i.e. 600 = 6 A.M. and 1500 = 3 P.M.
Here is the JSON string:
${JSON.stringify(weather.forecast[1])}
petermillspaugh avatar
sendTestEmailNewsletter
@petermillspaugh
Val Town email subscriptions: send test email Cousin Val to @petermillspaugh/emailSubscription — see docs there. When you're writing up an email to send to subscribers, it's helpful to send it to yourself ahead of time to proofread and see how it looks in different email clients etc.
Cron
# Val Town email subscriptions: send test email
Cousin Val to [@petermillspaugh/emailSubscription](https://www.val.town/v/petermillspaugh/emailSubscription) — see docs there
When you're writing up an email to send to subscribers, it's helpful to send it to yourself ahead of time to proofread and se
/** @jsxImportSource https://esm.sh/preact */
export function sendTestEmailNewsletter(interval: Interval) {
* Since this is a public Val, anyone can run it.
* This early return prevents spamming me with test emails.
* Comment out the early return to actually test.
if (interval.lastRunAt) {
return console.log("early return");
andreterron avatar
useMagicNumber
@andreterron
An interactive, runnable TypeScript val by andreterron
Script
import { magicNumber } from "https://esm.town/v/andreterron/magicNumber";
export const useMagicNumber = () => magicNumber
aeaton avatar
kpunkShowsData
@aeaton
An interactive, runnable TypeScript val by aeaton
Script
import { runVal } from "https://esm.town/v/std/runVal";
export const kpunkShowsData = runVal("aeaton.kpunkShows");
qaispalekar avatar
myApi
@qaispalekar
An interactive, runnable TypeScript val by qaispalekar
Script
export function myApi(name) {
return "hi " + name;
hetzelhouse avatar
consoleEmailEx
@hetzelhouse
// email yourself as easily as logging to the console
Script
// email yourself as easily as logging to the console
export let consoleEmailEx = (() => {
console.email("message"); // any JSON object can be the message
console.email({ html: "<h1>hello html emails!</h1>" }); // you can send HTML emails
console.email({ hi: "there" }, "Subject Line"); // optional second arg is the subject line
console.email({ html: "<b>hi!</b>", subject: "Subject accepted here too" });
doublelotus avatar
sendNotification
@doublelotus
Push Notification Sender This val can be used in other vals to send notifications to a segment using OneSignal's REST API This is really handy if you want to send push notifications to your phone without building a native app! I built a barebones React PWA that asks for a password then loads the OneSignal Web SDK that I deployed to Netlify for free. OneSignal has easy to follow docs so you can build this functionality into a React, Angular, Vue app or even Wordpress! Then install the PWA on your platform of choice and you're off to the races! Setup Save your ONESIGNAL_TOKEN and SEGMENT_APPID from OneSignal to your Val Town environment variables Import into another val! import sendNotification from "https://esm.town/v/gwoods22/sendNotification";
Script
# Push Notification Sender
This val can be used in other vals to send notifications to a segment using [OneSignal's REST API](https://documentation.ones
This is really handy if you want to send push notifications to your phone without building a native app! I built a barebones
## Setup
1. Save your `ONESIGNAL_TOKEN` and `SEGMENT_APPID` from OneSignal to your Val Town [environment variables](https://www.val.to
2. Import into another val!
axios.defaults.headers.get["User-Agent"] =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3";
async function run() {
const imageUrl =
postpostscript avatar
sqliteBackupInterval
@postpostscript
An interactive, runnable TypeScript val by postpostscript
Cron
export async function sqliteBackupWithEmail() {
const { name, content } = await sqliteBackup();
return email({
subject: "SQLite Backup",
attachments: [
content: btoa(content),
filename: name.replace(/[^\w\d]+/g, "_").replace(/_+/, "_") + ".json",
type: "json",
disposition: "attachment",
export default function() {
pomdtr avatar
http_request_example
@pomdtr
#example
Script
#example
* @title HTTP Requests
* @description This example demonstrates how to make a HTTP request to a server.
// To make a request to a server, you use the `fetch` API.
let resp = await fetch("https://example.com");
// The response is a `Response` object. This contains the status code, headers,
// and the body.
console.log(resp.status); // 200
console.log(resp.headers.get("Content-Type")); // "text/html"
console.log(await resp.text()); // "Hello, World!"
twschiller avatar
logTest
@twschiller
An interactive, runnable TypeScript val by twschiller
Script
export function logTest() {
const levels = ["info", "debug", "log", "warn", "error"];
const result = {};
for (const level of levels) {
try {
console[level](level);
result[level] = true;
catch {
result[level] = false;
return result;
pjc8889 avatar
emailRandomJoke
@pjc8889
// Fetches a random joke.
Cron
// Fetches a random joke.
async function fetchRandomJoke() {
const response = await fetch(
"https://official-joke-api.appspot.com/random_joke",
return response.json();
const randomJoke = await fetchRandomJoke();
const setup = randomJoke.setup;
const punchline = randomJoke.punchline;
// Sends an email with the joke.
export const emailRandomJoke = email({