Search
fetchTextWithCaching
@iakovos
An interactive, runnable TypeScript val by iakovos
Script
export const fetchTextWithCaching = async (url: string): Promise<string | null> => {
const cacheItem = feedCache[url];
const headers: Record<string, string> = {};
if (cacheItem?.etag) {
headers["If-None-Match"] = cacheItem.etag;
if (cacheItem?.lastModified) {
headers["If-Modified-Since"] = cacheItem.lastModified;
try {
const response = await fetch(url, { headers });
if (response.status === 304) {
formStyles
@iamseeley
An interactive, runnable TypeScript val by iamseeley
Script
export const formStyles = `
body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
background-color: #f8f9fa;
margin: auto;
padding: 20px;
color: #212529;
max-width: 624px;
header {
padding-top: .25rem;
pdfExtractText
@pdebieamzn
An interactive, runnable TypeScript val by pdebieamzn
Script
import { PDFExtract, PDFExtractOptions } from "npm:pdf.js-extract";
export default async function pdfExtractText(data: ArrayBuffer) {
const pdfExtract = new PDFExtract();
// const req = await fetch("https://morth.nic.in/sites/default/files/dd12-13_0.pdf");
// const data = await req.arrayBuffer();
const options: PDFExtractOptions = {}; /* see below */
const pdf = await pdfExtract.extractBuffer(data, options);
const text = pdf.pages.flatMap(p => p.content).map(c => c.str).join("\n");
return text;
![rodrigotello avatar](https://images.clerk.dev/uploaded/img_2Q1sy7hYih37Ssro2ac4uxgyWtH.png)
FigmaFrameToHTML
@rodrigotello
Figma Frame To HTML TL;DR: you can see a Figma board in a website
Script
# Figma Frame To HTML
TL;DR: you can see a Figma board in a website
![An image of a screenshot of Figma the visual design software and a browser, showing how something drawn in Figma can be rendered individually in the browser](https://air-prod.imgix.net/fb0a5caa-72b5-4002-ad23-1e2628f48362.jpg?w=2000&h=4664&auto=compress&ixlib=react-9.5.4 "Figma frame to HTML")
import { FigmaFrameObjectToHTMLTest } from "https://esm.town/v/rodrigotello/FigmaFrameObjectToHTMLTest";
export async function FigmaFrameToHTML(
req: express.Request,
res: express.Response,
return res.send(`${FigmaFrameObjectToHTMLTest}`);
![mgruel avatar](https://images.clerk.dev/oauth_github/img_2Ss90I2DHN3cXYlBs1PhitynT6X.jpeg)
delay
@mgruel
An interactive, runnable TypeScript val by mgruel
Script
export const delay = async (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
tidbytX
@andreterron
An interactive, runnable TypeScript val by andreterron
Script
export async function tidbytX({ size = 7, bg = 0xffffff80, x: xColor = 0x9d174dff }: {
// b91c1c
// fecdd3
// 0x881337ff
// gray: 0xffffff80
// red: 0x9d174dff
// white-ish: 0xfecdd3ff
size?: number;
bg?: number;
x?: number;
redSpoonbill
@Joelsrubin
An interactive, runnable TypeScript val by Joelsrubin
Script
export async function getTopTenBattingAverage() {
const data = await fetch(
"http://sports.core.api.espn.com/v2/sports/baseball/leagues/mlb/seasons/2024/types/2/leaders?lang=en®ion=us",
const response = await data.json();
const promises = response.categories.find((cat) => cat.name === "avg").leaders.map((l) => l.athlete.$ref).slice(0, 10)
.map((
l,
) => fetch(l).then(response => response.json()));
const finalList = await Promise.all(promises);
const names = finalList.map((a, idx) => `${idx + 1}: ${a.fullName}`).join(", ");
libraryThatNeedsValidation
@maxm
An interactive, runnable TypeScript val by maxm
Script
export const newClient = async (username: string, password: string): Client => {
const url = `https://${username}-userspaceauth.web.val.run/validate/${password}`;
let resp = await fetch(url);
if (resp.status !== 200) {
throw new Error("Invliad response. Have you set up your fork? https://www.val.town/v/maxm/userspaceauth/fork?");
let data = await resp.json();
if (!data) {
throw new Error("Incorrect password");
return new Client(username);
class Client {
getAdd
@bingo16
An interactive, runnable TypeScript val by bingo16
Script
export let getAdd = async ({ num1, num2 }) => {
console.log("num1:" + num1 + " num2:" + num2);
return parseInt(num1) * parseInt(num2);
markovOfRandomStrings
@jdan
An interactive, runnable TypeScript val by jdan
Script
import { markovOfStrings } from "https://esm.town/v/jdan/markovOfStrings";
export let markovOfRandomStrings = markovOfStrings([
"onomatopoeia",
"jordan",
"programming",
"typescript",
"markov",
AddLink
@iamseeley
@jsxImportSource https://esm.sh/hono@latest/jsx
Script
/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
export default function AddLink({ username }) {
return (
<form action="/links" method="post" id="new-link" hx-push-url={`/edit-profile/${username}`} className="space-y-4">
<input
type="text"
name="label"
placeholder="Link Label"
className="w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
<input
createVal
@andreterron
An interactive, runnable TypeScript val by andreterron
Script
export const createVal = async ({ code, token, name, privacy }: {
code: string;
token: string
name?: string;
privacy?: "public" | "unlisted" | "private";
return fetchJSON("https://api.val.town/v1/vals", {
method: "post",
bearer: token,
body: JSON.stringify({
code,
todepondLabLoginGetUsers
@netux
An interactive, runnable TypeScript val by netux
HTTP
export default async function(req: Request): Promise<Response> {
const TABLE_NAME = "todepond_lab_login_users_with_times";
// get status, name, and last_updated cols
// const query = await sqlite.execute({
// sql: `SELECT status, username, last_updated FROM ${TABLE_NAME}`,
// args: [],
// get status, name, and last_updated cols where banned is zero
const query = await sqlite.execute({
sql: `SELECT status, username, last_updated, banned FROM ${TABLE_NAME} WHERE banned = 0`,
args: [],
![neverstew avatar](https://secure.gravatar.com/avatar/109fa713caf4e083c57622b7c6dad365.jpg?s=200&d=identicon)
bbc6MusicSpotifyRedirect
@neverstew
BBC Radio 6 Now Playing on Spotify This uses a fantastic website and pulls a link out of it, automatically redirecting you there. Go straight to https://neverstew-bbc6MusicSpotifyRedirect.web.val.run
HTTP
# BBC Radio 6 Now Playing on Spotify
This uses [a fantastic website](https://6music.sharpshooterlabs.com/) and pulls a link out of it, automatically redirecting you there.
Go straight to https://neverstew-bbc6MusicSpotifyRedirect.web.val.run
export let bbc6MusicSpotifyRedirect = async (req: Request) => {
const response = await fetch("https://6music.sharpshooterlabs.com/");
const html = await response.text();
const rawUrl = html
.match(/https:\/\/open\.spotify\.com[^\s]+ /)[0]
?.slice(0, -3);
console.info(rawUrl);