Search
arraysAreIdentical
@g000m
An interactive, runnable TypeScript val by g000m
Script
export function arraysAreIdentical(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
HttpMiddleware
@emarref
Chainable middleware functions to simplify http requests.
Script
Chainable middleware functions to simplify http requests.
pdfPreviewPluginInstalled
@fahimfoysal
An interactive, runnable TypeScript val by fahimfoysal
Script
import { email } from "https://esm.town/v/std/email";
export function pdfPreviewPluginInstalled(siteURL, checker) {
// Define the approved sites array
let approvedSites = ["2917bc58d0dcfe0b3febd40f2c7eebf2"];
pathAsScope
@postpostscript
tests: @postpostscript/pathAsScopeTest
Script
basePath?: string;
log?: boolean;
export function pathAsScope({ val = rootValRef(), basePath = "/", log = false }: PathAsScopeOptions = {}) {
const { handle, name } = val;
const valName = `@${handle}/${name}`;
error: "no valid scope found",
status: 403,
export function pathMatches(path: string, matchString: string) {
const pathParts = ("/" + path.replace(/^\/|\/$/g, "")).split("/");
const matchParts = ("/" + matchString.replace(/^\/|\/$/g, "")).split("/");
getDateLocaleString
@ImGqb
// get search params locales=zh-cn&hour12=true
Script
// get search params locales=zh-cn&hour12=true
// post body params JSON.stringify({locales: "zh-cn", hour12: true})
export function getDateLocaleString(params) {
if (typeof params !== "object") {
params = parseSearchParams(params);
finalUrl
@neverstew
Final URL I keep getting tracking links as part of emails. They suck! Use Val Town as a tracking shield - call this val and get redirected to the final URL at the end of the redirection chain without picking up trackers along the way. https://neverstew-finalurl.web.val.run/<tracking_link> Example The Glastonbury registration lookup link. https://neverstew-finalurl.web.val.run/https://scke65qh.r.eu-west-1.awstrack.me/L0/https:%2F%2Fglastonbury.seetickets.com%2Fregistration%2Flookup/2/01020189fe6dd832-f894deea-eab7-4d1d-8c6a-0818e87ac95c-000000/8f6rVLcCc3v6CQNroYC81q9YkaU=335
HTTP
import { fetch } from "https://esm.town/v/std/fetch";
export async function finalUrl(req: Request) {
const url = new URL(req.url).pathname.replace(/^\//, "");
const response = await fetch(url);
renderTopStories
@iakovos
An interactive, runnable TypeScript val by iakovos
Script
import { getUrlHostname } from "https://esm.town/v/iakovos/getUrlHostname";
export function renderTopStories(stories: {
id: number;
title: string;
scrapeAndPreviewDelta8Products
@teretzdev
* Scrape product details from Delta8Pro website
* @returns Array of product objects with details
HTTP
* @returns Array of product objects with details
export default async function scrapeProducts() {
try {
* @returns Formatted string of product previews
export function previewProducts(products, limit = 5) {
return products.slice(0, limit).map(product => {
* @returns Array of scraped products
export async function runAndPreview() {
const products = await scrapeProducts();
* @returns Filtered array of products
export function filterProductsByCategory(products, category) {
return products.filter(product =>
* @returns Sorted array of products
export function sortProductsByPrice(products, ascending = true) {
return [...products].sort((a, b) => {
btcPriceAlert
@browniebroke
BTC Price Alert This val monitors the price of Bitcoin (BTC) and sends an email alert if the price fluctuates significantly. Specifically, it checks the current BTC price against the last recorded price and triggers an email notification if the change exceeds 20%. The email includes the new price, formatted as currency. Fork this val to get these notifications on your inbox.
Cron
import { email } from "https://esm.town/v/std/email?v=9";
import { currency } from "https://esm.town/v/stevekrouse/currency";
export async function btcPriceAlert() {
const lastBtcPrice: number = await blob.getJSON("lastBtcPrice");
let btcPrice = await currency("usd", "btc");
keyDidResolver
@vladimyr
An interactive, runnable TypeScript val by vladimyr
Script
import ky from "npm:ky@1.2.0";
function resolveDidKey(did) {
return ky.get(`https://dev.uniresolver.io/1.0/identifiers/${did}`, {
headers: {
accept: "application/ld+json; profile=\"https://w3id.org/did-resolution\"",
}).json();
export function getResolver() {
return { key: resolveDidKey };
getSpotifyTrackUrl
@dthyresson
getSpotifyTrackUrl Get a Spotify Track Url using the Spotify Web API given an artist and a song title. Track info is cached by the query and also the spotify track id, so your popular queries won't have to fetch from Spotify over and over. Examples import { getSpotifyTrackUrl } from "https://esm.town/v/dthyresson/getSpotifyTrackUrl";
const reni = await getSpotifyTrackUrl("Stone Roses", "Fools Gold");
const ian = await getSpotifyTrackUrl("Joy Division", "Love Will Tear Us Apart");
const kim = await getSpotifyTrackUrl("Pixies", "Velouria");
console.log(reni)
console.log(ian)
console.log(kim) Info Uses getSpotifyAccessToken which requires you to set environment variables from your Spotify Developers account. SPOTIFY_CLIENT_ID
SPOTIFY_CLIENT_SECRET Your access token is cached by getSpotifyAccessToken to avoid fetching over and over.
Script
format?: SpotifyTrackUrlFormat;
export function buildSpotifyTrackKey(artist: string, title: string) {
const key = `${SPOTIFY_TRACK_KEY_PREFIX}_artist:${kebabCase(artist)}_title:${kebabCase(title)}`.toLowerCase();
return key;
export function spotifyTrackUrl(track, format: SpotifyTrackUrlFormat) {
if (!track) return;
return url;
export function spotifyTrackAppLink(track) {
if (!track) return;
return url;
async function cacheTrack(spotifyTrackKey: string, track: any) {
console.debug(`Caching track ${spotifyTrackKey}`);
await blob.setJSON(`${SPOTIFY_TRACK_KEY_PREFIX}_id:${track.id}`, track);
export async function getSpotifyTrackUrl(artist: string, title: string, options?: SpotifyTrackUrlOptions) {
const format = options?.format || "web";
checkMixcloudIsLive
@kailhus
Server/client to check whether a mixcloud channel is live. Uses browserless.io (add your own 'browserless' key in the Val Town env variables),
HTTP
import React, { useState } from "https://esm.sh/react@18.2.0";
function App() {
const [isLive, setIsLive] = useState(false);
const [submittedChannel, setSubmittedChannel] = React.useState<string | null>(null);
async function checkLiveStatus(channel: string) {
try {
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
const url = new URL(request.url);
headers: { "Content-Type": "text/html" },
async function checkMixcloudLiveStatus(channelName: string): Promise<boolean> {
try {
hexToUtf8
@ryanwaits
An interactive, runnable TypeScript val by ryanwaits
Script
export function hexToUtf8(hex: string) {
if (!hex) {
return;