Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=function&page=3&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=function

Returns an array of strings in format "username" or "username/projectName"

Found 7147 results for "function"(323ms)

Stripe714 words

https://docs.val.town/integrations/stripe/
@ts-ignore. import { Stripe } from "npm:stripe"; const stripe = new Stripe(Deno.env.get("STRIPE_TEST_API_KEY")); export default async function (req: Request): Promise<Response> { const url = new URL(req.url); if (url.pathname === "/") {

Sections

Stripe Checkout

@ts-ignore. import { Stripe } from "npm:stripe"; const stripe = new Stripe(Deno.env.get("STRIPE_TEST_API_KEY")); export default async function (req: Request): Promise<Response> { const url = new URL(req.url); if (url.pathname === "/") {

Example Val Town Stripe Webhook

from "npm:stripe"; const stripe = new Stripe( Deno.env.get("stripe_sk_customer_readonly") as string, { apiVersion: "2020-08-27", } ); function getStripeCustomer(customerId: string) { return stripe.customers.retrieve(customerId); } export let newStripeEvent = async (req: Request) =>

Upgrade Guide: Safer Val Scopes333 words

https://docs.val.town/troubleshooting/std-set-permission-error/
is deprecated and we now use blob storage with our std/blob library instead. The equivalent function to std.set() is blob.setJSON(). // Using std/set. import { set } from "https://esm.town/v/std/set"; set("createdAt",

Sections

Use Blob Storage Instead (recommended)

Use Blob Storage Instead (recommended). Std/set is deprecated and we now use blob storage with our std/blob library instead. The equivalent function to std.set() is blob.setJSON(). // Using std/set. import

Permission errors334 words

https://docs.val.town/troubleshooting/permission-errors/
to your secrets (--allow-env). Some system information (--allow-sys=osRelease,homedir,cpus,hostname) This allows you to access the following functionality: import os from "node:os"; os.cpus(); os.homedir(); Deno.osRelease(); Deno.hostname(); These values are not particularly useful,

Sections

Allowed permissions

Allowed permissions. Vals have the following permissions: Network access (--allow-net). Environment access, limited to your secrets (--allow-env). Some system information (--allow-sys=osRelease,homedir,cpus,hostname) This allows you to access the following functionality: import

Blob Storage366 words

https://docs.val.town/std/blob/
method can throw ValTownBlobError for unexpected errors. Utilities. Our Blob SDK also includes some utility functions to make working with blobs easier. Copy. Copy import { blob } from "https://esm.town/v/std/blob";

Sections

Utilities

Utilities. Our Blob SDK also includes some utility functions to make working with blobs easier.

Express402 words

https://docs.val.town/vals/express/
webhook handler to adhere to another service’s specifications (example val). The Val must be a function. It is passed two arguments, the Express req and res objects. You can use

Sections

Express

webhook handler to adhere to another service’s specifications (example val). The Val must be a function. It is passed two arguments, the Express req and res objects. You can use

JavaScript SDK414 words

https://docs.val.town/api/sdk/
to your package.json file. index.mjs import ValTown from "@valtown/sdk"; const valTown = new ValTown(); async function main() { const myProfile = await valTown.me.profile.retrieve(); console.log(myProfile); } main(); Finally, the API expects

Sections

Getting started in Node.js

to your package.json file. index.mjs import ValTown from "@valtown/sdk"; const valTown = new ValTown(); async function main() { const myProfile = await valTown.me.profile.retrieve(); console.log(myProfile); } main(); Finally, the API expects

AWS S3445 words

https://docs.val.town/integrations/s3/
Ask questions about this page. You can upload and download from AWS S3 inside val functions. In this guide, you’ll create an AWS bucket, an IAM user, and then test

Sections

AWS S3

Ask questions about this page. You can upload and download from AWS S3 inside val functions. In this guide, you’ll create an AWS bucket, an IAM user, and then test

Upgrading Legacy Vals461 words

https://docs.val.town/upgrading/legacy-vals/
Here’s how you can handle folders: Do nothing: Upgrade vals individually; they remain separate but functional. Manual consolidation: Upgrade the main val first, then manually copy & paste other vals’

Sections

Legacy Val Folders

Here’s how you can handle folders: Do nothing: Upgrade vals individually; they remain separate but functional. Manual consolidation: Upgrade the main val first, then manually copy & paste other vals’

Telegram bot546 words

https://docs.val.town/integrations/telegram/
of this guide, which makes the HTTP calls to telegram more directly with simpler helper function. 1. Create your bot. Telegram has the best bot-making experience of any messaging platform.

Sections

Introduction

of this guide, which makes the HTTP calls to telegram more directly with simpler helper function.

Google Sheets1211 words

https://docs.val.town/integrations/google-sheets/
ACCOUNT ID HERE>"; const sheetID = "<YOUR SHEET ID HERE>"; const baseURL = `https://sheets.googleapis.com/v4/spreadsheets/${sheetID}/values`; async function fetchAccessToken() { const response = await fetch( `https://api.pipedream.com/v1/accounts/${accountID}?include_credentials=1`, { headers: { Authorization: `Bearer ${Deno.env.get("pipedream_api_key")}`,

Sections

6. Fetch a Google Sheets access token and use it in your val

ACCOUNT ID HERE>"; const sheetID = "<YOUR SHEET ID HERE>"; const baseURL = `https://sheets.googleapis.com/v4/spreadsheets/${sheetID}/values`; async function fetchAccessToken() { const response = await fetch( `https://api.pipedream.com/v1/accounts/${accountID}?include_credentials=1`, { headers: { Authorization: `Bearer ${Deno.env.get("pipedream_api_key")}`,

JimeluStevensgetCalendarEvents.ts6 matches

@luke_f•Updated 13 hours ago
6const LOCAL_TIMEZONE = "Australia/Sydney";
7
8async function deleteExistingCalendarEvents() {
9 await sqlite.execute(
10 `
15}
16
17// Helper function to extract time from ISO string without timezone conversion
18function extractTimeFromISO(isoString) {
19 // Match the time portion of the ISO string
20 const timeMatch = isoString.match(/T(\d{2}):(\d{2}):/);
31}
32
33function formatEventToNaturalLanguage(event) {
34 const summary = event.summary || "Untitled event";
35
78}
79
80async function insertCalendarEvent(date, eventText) {
81 const { nanoid } = await import("https://esm.sh/nanoid@5.0.5");
82
92}
93
94export default async function getCalendarEvents() {
95 try {
96 const events = await getEvents(

JimeluStevensgenerateFunFacts.ts8 matches

@luke_f•Updated 13 hours ago
11 * @returns Array of previous fun facts
12 */
13async function getPreviousFunFacts() {
14 try {
15 const result = await sqlite.execute(
32 * @param dates Array of date strings in ISO format
33 */
34async function deleteExistingFunFacts(dates) {
35 try {
36 for (const date of dates) {
51 * @param factText The fun fact text
52 */
53async function insertFunFact(date, factText) {
54 try {
55 await sqlite.execute(
75 * @returns Array of generated fun facts
76 */
77async function generateFunFacts(previousFacts) {
78 try {
79 // Get API key from environment
193 * @returns Array of parsed facts
194 */
195function parseFallbackFacts(responseText, expectedDates) {
196 // Try to extract facts using regex
197 const factPattern = /(\d{4}-\d{2}-\d{2})["']?[,:]?\s*["']?(.*?)["']?[,}]/gs;
256
257/**
258 * Main function to generate and store fun facts for the next 7 days
259 */
260export async function generateAndStoreFunFacts() {
261 try {
262 // Get previous fun facts
297 * Intended to be used as a Val Town cron job
298 */
299export default async function() {
300 console.log("Running fun facts generation cron job...");
301 return await generateAndStoreFunFacts();

getFileEmail4 file matches

@shouser•Updated 4 days ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago