Search

Results include substring matches and semantically similar vals. Learn more
easrng avatar
nodejsSample
@easrng
// run node.js code in your val
Script
import { nodejs } from "https://esm.town/v/easrng/nodejs";
// run node.js code in your val
export const nodejsSample = (async () => {
const nodeEval = await nodejs();
console.log(await nodeEval("2 + 2"));
console.log(await nodeEval("typeof require"));
pomdtr avatar
dotShortcut
@pomdtr
Dot Shortcut This val adds a github-like dot shortcut to your website, redirecting to the val.town editor. Usage Add the following script tag to your website head. <script type="module" src="https://esm.town/v/pomdtr/dotShortcut"></script>
Script
# Dot Shortcut
This val adds a github-like dot shortcut to your website, redirecting to the val.town editor.
## Usage
Add the following script tag to your website head.
```html
<script type="module" src="https://esm.town/v/pomdtr/dotShortcut"></script>
document.addEventListener("keydown", async (event) => {
if (event.key != ".") {
return;
if (document.activeElement != document.body) {
liamdanielduffy avatar
parseCalendarEventsTable
@liamdanielduffy
An interactive, runnable TypeScript val by liamdanielduffy
Script
export type TableRow = {
[key: string]: string;
export async function parseCalendarEventsTable(html: string): Promise<TableRow[]> {
const { DOMParser } = await import(
"https://deno.land/x/deno_dom/deno-dom-wasm.ts"
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
const tables = doc.querySelectorAll("table");
const result: TableRow[][] = [];
tables.forEach((table) => {
dhvanil avatar
val_RAE2AP0hsH
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export const jsonOkExample = () => Response.json({ ok: true });
neverstew avatar
markdownExample
@neverstew
An interactive, runnable TypeScript val by neverstew
HTTP
export const markdownExample = async (req: Request) => {
const marked = await import("npm:marked");
return new Response(
marked.parse(`
Using Marked, a Markdown Parser
[Marked](https://marked.js.org) is a widely used markdown parser.
Here, we've imported it using \`const marked = await import("npm:marked");\`!
{ headers: { "Content-Type": "text/html" } },
darcy avatar
feed
@darcy
An interactive, runnable TypeScript val by darcy
Cron
import { fetch } from "https://esm.town/v/std/fetch";
export function feed() {
let _feed = following.map(async (name) => {
let req = await fetch(`https://api.val.town/v1/run/${name}.posts`);
let res = (req.status === 200) ? req.json() : {};
return res;
console.log(_feed);
return _feed;
wade avatar
stirringLavenderStoat
@wade
An interactive, runnable TypeScript val by wade
HTTP
export default async function(req: Request): Promise<Response> {
if (req.method !== "POST") {
return new Response(
JSON.stringify({ error: "Only POST requests are allowed" }),
{ status: 405, headers: { "Content-Type": "application/json" } },
let body: {
sourceCurrency?: string;
sourceAmount?: string | number;
destinationCurrency?: string;
try {
janpaul123 avatar
valle_tmp_397893855838237934336717990875854
@janpaul123
// This HTTP val responds to all requests with "Hello world"
HTTP
// This HTTP val responds to all requests with "Hello world"
export default async function main(req: Request): Promise<Response> {
return new Response("Hello world", { headers: { "Content-Type": "text/plain" } });
politelyinvinciblepointer avatar
getinnerfeelingscounter
@politelyinvinciblepointer
An interactive, runnable TypeScript val by politelyinvinciblepointer
Script
import { innerfeelingscounter } from "https://esm.town/v/politelyinvinciblepointer/innerfeelingscounter";
export function getinnerfeelingscounter() {
return innerfeelingscounter;
jrmann100 avatar
pushSendNotification_negrel
@jrmann100
// https://github.com/web-push-libs/web-push/blob/v3.4.4/README.md#using-vapid-key-for-applicationserverkey
Script
// https://github.com/web-push-libs/web-push/blob/v3.4.4/README.md#using-vapid-key-for-applicationserverkey
function urlBase64ToUint8Array(b64) {
const padding = "=".repeat((4 - (b64.length % 4)) % 4);
const base64 = (b64 + padding)
.replace(/\-/g, "+")
.replace(/_/g, "/");
const rawData = globalThis.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
maksik avatar
doit
@maksik
An interactive, runnable TypeScript val by maksik
Script
export async function doit() {
console.email("Hello!", "from Val Town");
root avatar
hello
@root
An interactive, runnable TypeScript val by root
Script
export function hello(name) {
// return "wow~ your are 叼毛 open 了 Pandora" ;
return { message: "wow~ your are 叼毛 open 了 Pandora" };
// return eval("window.open('https://www.jd.com')") // 不允许
// return window.alert.call(null, '123') // nodejs 环境没有window
// return window // nodejs 环境没有window = null
stevekrouse avatar
getColor
@stevekrouse
Get common or "dominant" color from an image given a source URL
HTTP
Get common or "dominant" color from an image given a source URL
/** @jsxImportSource npm:hono@3/jsx */
const EXAMPLE_URL = "https://letsenhance.io/static/8f5e523ee6b2479e26ecc91b9c25261e/1015f/MainAfter.jpg";
const PERCENT_COVERAGE = 10; // lower is faster, but higher is more accurate
function getPixelIndex(numToRound) {
// Each pixel is 4 units long: r,g,b,a
const remainder = numToRound % 4;
if (remainder == 0) return numToRound;
return numToRound + 4 - remainder;
export async function getColor(src: string = EXAMPLE_URL): Promise<string> {
tmcw avatar
ittyRouterExample
@tmcw
itty-router This is an example of using the Val Town Web API to integrate with itty-router . Server examples Hono Peko Itty Router Nhttp
HTTP
# itty-router
This is an example of using the Val Town [Web API](https://docs.val.town/api/web) to integrate with [itty-router](https://git
### Server examples
- [Hono](https://www.val.town/v/tmcw.honoExample)
- [Peko](https://www.val.town/v/tmcw.pekoExample)
- [Itty Router](https://www.val.town/v/tmcw.ittyRouterExample)
export const ittyRouterExample = async (request: Request) => {
const { Router, json } = await import("npm:itty-router@4");
const router = Router();
router.get("/", () => "Hi");
rodrigotello avatar
FigmaAvatarsMixerTest
@rodrigotello
An interactive, runnable TypeScript val by rodrigotello
Script
import process from "node:process";
export const FigmaAvatarsMixerTest = (async () => {
const apiToken = process.env.myFigmaAPIToken;
const fileKey =
parseFigmaURL(
"https://www.figma.com/file/XqiternEMTE2Gk8jHzG4Ui/AvatarMixerFileTest?type=design&node-id=0%3A1&mode=design&t=Mpjs48FG
).key;
return fetchFigmaFile(apiToken, fileKey);