Search

Results include substring matches and semantically similar vals. Learn more
vtdocs avatar
githubPayloadStringToNormalizedJSON
@vtdocs
An interactive, runnable TypeScript val by vtdocs
Script
export function githubPayloadStringToNormalizedJSON(payload: string) {
const payloadObject = JSON.parse(payload);
// GitHub sends its JSON with an indentation of 2 spaces and a line break at the end
vladimyr avatar
podcast
@vladimyr
An interactive, runnable TypeScript val by vladimyr
Script
import { parseFeed } from "https://deno.land/x/rss@1.0.0/mod.ts";
export async function getLastEpisode(xml: string) {
const { entries } = await parseFeed(xml);
return entries
.sort((entry1, entry2) => entry2.published.getTime() - entry1.published.getTime())
.at(0);
export async function getLastPubDate(xml: string) {
const lastEpisode = await getLastEpisode(xml);
return lastEpisode.published;
Gcoxy avatar
adaptableAmberDonkey
@Gcoxy
@jsxImportSource https://esm.sh/react
HTTP
return <img src={qrDataUrl} width={size} height={size} alt="QR Code" />;
function PrintableLabel({ label }: { label: LabelResponse['label'] }) {
if (!label) return null;
</div>
function PrintModal({ label, onClose }: { label: LabelResponse['label']; onClose: () => void }) {
const printRef = React.useRef<HTMLDivElement>(null);
</div>
function LandingPage({ onNavigate }: { onNavigate: (page: string) => void }) {
return (
</Card.Root>
function CSVUploadPage() {
const [file, setFile] = React.useState<File | null>(null);
</Card.Root>
function App() {
const [currentPage, setCurrentPage] = React.useState('landing');
return <div className="content-container">Page not found</div>;
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
return new Response(`
stevekrouse avatar
stripHTML
@stevekrouse
Strip HTML Remove HTML tags from a string by parsing the HTML. There are certainly faster ways of doing this, ie html.replace(/<\/[^>]+(>|$)/g, "") // source https://stackoverflow.com/a/5002161 but this way is likely the most correct in that you're using a proper HTML parser.
Script
import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
export function stripHTML(html: string) {
const doc = new DOMParser().parseFromString(html, "text/html");
return doc.body.textContent;
browserbase avatar
hasWebsiteChanged
@browserbase
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.
Script
import { PNG } from "npm:pngjs";
import slugify from "npm:slugify";
export async function hasWebsiteChanged(url: string, threshold = 0.5) {
const slug = slugify(url);
const buffer = await screenshotPage(url);
peterqliu avatar
generateString
@peterqliu
An interactive, runnable TypeScript val by peterqliu
Script
import * as crypto from "node:crypto";
export function generateString(bytes: number = 64): string {
const randomString = crypto.randomBytes(bytes).toString("hex");
return randomString;
rejetto avatar
checkHfs
@rejetto
An interactive, runnable TypeScript val by rejetto
Script
import { fetch } from "https://esm.town/v/std/fetch";
export async function checkHfs(url: string) {
const res = await (await fetch(url)).text();
return res.includes("HFS");
loading avatar
waka
@loading
@jsxImportSource https://esm.sh/react
HTTP
RowVariant = "#475569",
function roundRect(
ctx: any,
return ctx;
function roundRectTop(
ctx: any,
hours: number;
function App() {
const [chartUrl, setChartUrl] = useState<string | null>(null);
</div>
function client() {
createRoot(document.getElementById("root")!).render(<App />);
client();
async function fetchWakaTimeData(): Promise<DataPoint[]> {
const response = await fetch("https://wakatime.com/share/@load1n9/899abefd-d814-4e99-b603-e94af0305d4a.json");
hours: parseFloat(item.grand_total.decimal),
async function generateChart(data: DataPoint[]): Promise<string> {
const width = 1000;
return canvas.toBuffer();
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);
jxnblk avatar
svg_favicon
@jxnblk
SVG favicon service, with support for custom text/letters and colors <img src="https://jxnblk-svg_favicon.web.val.run?text=Hi&color=000&bg=f0f" />
HTTP
const HEXRE = /^[A-Fa-f0-9]{3,6}$/;
const toHex = (str) => HEXRE.test(str) ? "#" + str : str;
function SVG({
text = "Aa",
bg = "000",
</text>
</svg>
export default function favicon(req: Request): Response {
const params = Object.fromEntries(new URL(req.url).searchParams);
const svg = render(<SVG {...params} />);
syncretizm avatar
fsrsEndpoint
@syncretizm
An interactive, runnable TypeScript val by syncretizm
HTTP
* Math.exp((1 - r) * this.p.w[14])
function formatDate(date, timeZone = "Asia/Singapore") {
if (!(date instanceof Date) || isNaN(date.getTime())) {
return `${year}-${month}-${day}T${hour}:${minute}`;
function serverToTimeZone(timeZoneOffset) {
const nowUTC = new Date();
return dateInTimeZone;
function getRatingKey(grade) {
const ratingKeys = ["Again", "Hard", "Good", "Easy"]; // Array of keys in the Rating object
// FSRS API Handler
export async function fsrsEndpoint(req) {
// difficulty = 0, stability = 0, state = 0, reps = 0, lapses = 0, scheduled_days = 0, elapsed_days = 0;
const formattedDueDate = formatDate(dueDate, timeZone);
function ldp(num, decimalPlaces, defaultvalue) {
if (typeof num === "number" && !isNaN(num)) {
std avatar
linkify
@std
linkify This is a client-side helper for linkifying URLs in error pages
Script
const MODULE_URL = "https://esm.town/";
const APP_URL = "https://val.town/";
export function formatHref(href: string) {
if (href.startsWith(MODULE_URL)) {
const redirected = href.replace(MODULE_URL, APP_URL);
rwev avatar
polygonEmailTickerSummary
@rwev
An interactive, runnable TypeScript val by rwev
Script
import { toPercentChange } from "https://esm.town/v/rwev/toPercentChange";
import { polygonTickerSummary } from "https://esm.town/v/rwev/polygonTickerSummary";
export async function polygonEmailTickerSummary(ticker) {
const summary = await polygonTickerSummary(ticker);
const message = `${ticker} closed at ${
mgruel avatar
exchangeCurrency
@mgruel
Calls https://www.exchangerate-api.com to retrieve the currency exchange rates * for the provided base currency or "eur" if undefined * @param {string} desired - The desired currency convert to * @param {number} amount - The amount of target currency * @param {string} base - The base currency, from which the exchange should be calculated
Script
* @param {number} amount - The amount of target currency
* @param {string} base - The base currency, from which the exchange should be calculated
export async function exchangeCurrency(
desired: string,
amount = 1,
donmccurdy avatar
bandcampWrappedScript
@donmccurdy
An interactive, runnable TypeScript val by donmccurdy
Script
[/\|/g, "\\|"],
function esc(string) {
return replacements.reduce(function(string, replacement) {
return string.replace(replacement[0], replacement[1])
c("div", "display:grid;grid-template-columns:1fr 1fr 1fr;gap:10px;"),
function c(tag, style) {
const elem = document.createElement(tag)
pomdtr avatar
hono_counter
@pomdtr
Hono Counter Component
Script
/** @jsxImportSource https://esm.sh/hono/jsx */
import { useState } from "https://esm.sh/hono/jsx/dom";
export default function Counter(props: { initialCount?: number }) {
const [count, setCount] = useState(props.initialCount || 0);
return (