Search

Results include substring matches and semantically similar vals. Learn more
samk avatar
btcPriceAlert
@samk
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", "eth");
trob avatar
cardSortDragDropApp
@trob
@jsxImportSource https://esm.sh/react
HTTP
return this.props.children;
function App() {
console.log("Rendering App component");
</div>
function client() {
try {
if (typeof document !== "undefined") { setTimeout(client, 0); }
export default async function server(request: Request): Promise<Response> {
const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
<div id="root"></div>
<script>window.onerror = function(message, source, lineno, colno, error) { console.error("Global error:", message,
<script src="https://esm.town/v/std/catch"></script>
twschiller avatar
communityBoatingFlag
@twschiller
Fetch the sailing flag color from https://www.community-boating.org/
Script
import { fetch } from "https://esm.town/v/std/fetch";
export async function communityBoatingFlag() {
const response = await fetch("https://api.community-boating.org/api/flag");
const text = await response.text();
agmm avatar
sslCertificates
@agmm
What is this for? To get a list of all the SSL certificates that have been issued for a particular domain. Usage import { getCertificates } from "https://esm.town/v/agmm/sslCertificates"; const results = await getCertificates("agmm.xyz"); console.log(results)
Script
serial_number: string;
result_count: number;
export async function getCertificates(domain: string) {
const url = `https://crt.sh/json?q=${domain}`;
const response = await fetch(url);
stevekrouse avatar
blob_delete_by_prefix
@stevekrouse
Delete blobs by prefix Utility to delete your blobs by prefix
Script
import { blob } from "https://esm.town/v/std/blob?v=11";
export async function deleteBlobs(prefix: string) {
(await blob.list(prefix)).forEach(({ key }) => blob.delete(key));
stevekrouse avatar
groupBy
@stevekrouse
! * Group items from an array together by some criteria or value. * (c) 2019 Tom Bremmer (https://tbremer.com/) and Chris Ferdinandi (https://gomakethings.com), MIT License, * @param {Array} arr The array to group items from * @param {String|Function} criteria The criteria to group by * @return {Object} The grouped object
Script
* @param {Array} arr The array to group items from
* @param {String|Function} criteria The criteria to group by
* @return {Object} The grouped object
export function groupBy<A>(arr: A[], criteria: ((a: A) => string) | string) {
return arr.reduce(function (obj, item) {
// Check if the criteria is a function to run on the item or a property of it
var key = typeof criteria === "function" ? criteria(item) : item[criteria];
// If the key doesn't exist yet, create it
jxnblk avatar
valTownBadgeSVG
@jxnblk
SVG Val Town badge image service
HTTP
const rounded = 8;
const padLeft = 48;
export function Badge({
scale = 1,
label = "View source on",
fill="#fff"
</svg>
export default async function(req: Request): Promise<Response> {
const svg = renderToStaticMarkup(
<Badge scale={1} />,
stevekrouse avatar
stormyCyanLeopon
@stevekrouse
Send Chunked Discord Message This function is used to send a message to a Discord webhook. If the message exceeds the maximum character limit (2000 characters), it will be divided into chunks and sent as multiple messages. Parameters message (string): The message to be sent to the Discord webhook. Return Value This function does not return any value. Example Usage: const message = "This is a long message that needs to be sent to Discord. It may exceed the character limit, so it will be divided into smaller chunks."; await @ktodaz.sendDiscordMessage(message); In the above example, the sendDiscordMessage function is used to send the message to the Discord webhook. If the message exceeds 2000 characters, it will be split into smaller chunks and sent as separate messages. Required Secrets: Ensure you have added the secret for discord_webhook in your val.town secrets settings (Profile -> Secrets)
Script
# Send Chunked Discord Message
This function is used to send a message to a Discord webhook. If the message exceeds the maximum character limit (2000 charac
### Parameters
### Return Value
This function does not return any value.
## Example Usage:
await @ktodaz.sendDiscordMessage(message);
In the above example, the sendDiscordMessage function is used to send the message to the Discord webhook. If the message exce
## Required Secrets:
webhook_url: string = process.env.discord_webhook,
function chunkString(str) {
const chunks = [];
petermillspaugh avatar
unsubscribeFromNewsletter
@petermillspaugh
Val Town email subscriptions: unsubscribe Cousin Val to @petermillspaugh/emailSubscription — see docs there.
HTTP
import { email as sendEmail } from "https://esm.town/v/std/email?v=11";
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
export async function unsubscribe(req: Request) {
const searchParams = new URL(req.url).searchParams;
const emailAddress = searchParams.get("email");
xkonti avatar
weekday
@xkonti
An interactive, runnable TypeScript val by xkonti
Script
Fri: 5,
Sat: 6,
export function getWeekdaysInMonth(year: number, month: number, weekday: Weekday): Date[] {
const dates: Date[] = [];
const date = new Date(year, month, 1);
samk avatar
grayLimpet
@samk
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");
nthypes avatar
setCorsHeaders
@nthypes
An interactive, runnable TypeScript val by nthypes
Script
"Access-Control-Allow-Methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
} as const;
export default function setCorsHeaders(
response: Response,
headers: Partial<typeof DEFAULT_CORS_HEADERS> = DEFAULT_CORS_HEADERS,
postpostscript avatar
abortable
@postpostscript
// SPDX-License-Identifier: Apache-2.0
Script
// SPDX-License-Identifier: Apache-2.0
import type { MaybePromise } from "./types/util.ts";
export function abortable<T>(promise: MaybePromise<T>, signal?: AbortSignal): Promise<T> {
if (signal?.aborted) {
return Promise.reject(
new AbortError("signal aborted", {
cause: signal,
function cleanup() {
signal!.removeEventListener("abort", handler);
signal.addEventListener("abort", handler);
tempdev avatar
probableMaroonGuan
@tempdev
An interactive, runnable TypeScript val by tempdev
Script
[key: string]: string | Function;
setItem: Function;
setItem: function(item: string, value: string) {
function get(index: number) {
function getMemBuff(): Uint8Array {
const encode = function(text: string, array: Uint8Array) {
function parse(text: string, func: Function, func2: Function) {
function isNull(test: any) {
function getArr32() {
function shift(QP: number) {
jkbno avatar
type_Capitalize_Uppercase
@jkbno
// Basic recursion type
Script
// ReturnType is a utility type that extracts the return type of a function.
// In this definition, T is a function type that takes any number of arguments and returns any type.
, we create a temporary type variable R to represent the return type of the function. If T is a function, TypeScript infers t
function greet(name: string): string {
// Here, ReturnType is used to infer the return type of the greet function, which is string.
// This type extracts the parameter types of a function as a tuple. The definition of Parameters is as follows:
// In this example, we create a temporary type variable P to represent the parameter types of the function.
// If T is a function, TypeScript infers the parameter types and assigns them to P as a tuple.
function add(a: number, b: number): number {
// Here, Parameters is used to infer the parameter types of the add function, which is a tuple [number, number].