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//%22?q=function&page=2&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 40465 results for "function"(1579ms)

Early Return497 words

https://docs.val.town/vals/http/early-return/
Section titled “How to return early, and process after” early-returning.tsRun in Val Town ↗ async function handle(req: Request) { const new = new URL(req.url). if (url.path === '/') { //

Sections

How to return early, and process after

How to return early, and process after. Section titled “How to return early, and process after” early-returning.tsRun in Val Town ↗ async function handle(req: Request) { const new = new

Promises should otherwise be awaited

to use await with Promises, errors that occur in promises won’t be properly handled and functions may run out-of-order. For example, if you use fetch to request some resource, but

Deno LSP1413 words

https://docs.val.town/reference/deno-lsp/
currently loading your Val and downloading its dependencies. The LSP will be functional in this state but its functionality will be degraded — you may see “unresolved import” errors, for

Sections

Deno LSP

currently loading your Val and downloading its dependencies. The LSP will be functional in this state but its functionality will be degraded — you may see “unresolved import” errors, for

Features

a symbol). Signature reference (a box indicating the arguments a function takes that shows up when you are typing a function invocation). Deno supports a top level deno.json file to

Multi Tab Editing

to the return type of a function in one tab, and you have a file open in another tab that imports and uses that function, that tab may see red

Receiving a GitHub Webhook369 words

https://docs.val.town/integrations/github/receiving-a-github-webhook/
of your webhook. Securing GitHub Webhooks. Section titled “Securing GitHub Webhooks” Once public, your val function will listen for any payload sent to its endpoint. For security reasons, you probably

Sections

Securing GitHub Webhooks

GitHub Webhooks” Once public, your val function will listen for any payload sent to its endpoint. For security reasons, you probably want to limit requests to those coming from GitHub.

Send Discord message via webhook129 words

https://docs.val.town/integrations/discord/send-message/
body: JSON.stringify({ content }), }); if (text.length) throw Error("Discord Webhook error: " + text); }; You can browse example usages of this function here. Example Integration. Section titled “Example Integration”

Sections

Send Discord message via webhook

throw Error("Discord Webhook error: " + text); }; You can browse example usages of this function here.

RSS153 words

https://docs.val.town/guides/rss/
"https://esm.town/v/std/email?v=9"; import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems"; import { rssFeeds } from "https://esm.town/v/stevekrouse/rssFeeds"; export async function pollRSSFeeds({ lastRunAt }: Interval) { return Promise.all( Object.entries(rssFeeds).map(async ([name, url]) => { let items

Sections

Polling RSS

"https://esm.town/v/std/email?v=9"; import { newRSSItems } from "https://esm.town/v/stevekrouse/newRSSItems"; import { rssFeeds } from "https://esm.town/v/stevekrouse/rssFeeds"; export async function pollRSSFeeds({ lastRunAt }: Interval) { return Promise.all( Object.entries(rssFeeds).map(async ([name, url]) => { let items

ORMs206 words

https://docs.val.town/std/sqlite/orms/
Prisma. Section titled “Prisma” 🚫 Prisma isn’t supported in Val Town because it relies on functionality that only exists in a classic server environment. Sequelize. Section titled “Sequelize” 🚫 Sequelize

Sections

Prisma

Prisma. Section titled “Prisma” 🚫 Prisma isn’t supported in Val Town because it relies on functionality that only exists in a classic server environment.

Importing674 words

https://docs.val.town/reference/import/
mind, and won’t work with Deno. While Deno implements most of the functionality of Node.js and some of the functionality of browsers - so many modules will “just work” in

Sections

Look for Deno compatibility

mind, and won’t work with Deno. While Deno implements most of the functionality of Node.js and some of the functionality of browsers - so many modules will “just work” in

Stripe741 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) =>

Permission errors345 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

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,

Upgrade Guide: Safer Val Scopes378 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). Section titled “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

TopTenVideosoutput-generator.js7 matches

@pmapower•Updated 4 hours ago
261
262 // Show video details
263 function showVideoDetails(videoId) {
264 const video = videos.find(v => v.id === videoId);
265 if (!video) return;
305
306 // Track ad clicks
307 function trackAdClick(adId, url) {
308 analytics.clicks[adId] = (analytics.clicks[adId] || 0) + 1;
309 updateAnalytics();
312
313 // Track ad impressions
314 function trackAdImpression(adId) {
315 analytics.impressions[adId] = (analytics.impressions[adId] || 0) + 1;
316 updateAnalytics();
319
320 // Update analytics display
321 function updateAnalytics() {
322 const totalImpressions = Object.values(analytics.impressions).reduce((a, b) => a + b, 0);
323 const totalClicks = Object.values(analytics.clicks).reduce((a, b) => a + b, 0);
358 js += `
359 // Initialize page
360 document.addEventListener('DOMContentLoaded', function() {
361 // Auto-select first video
362 if (videos.length > 0) {
390
391 // Display single ad
392 function displayAd(ad) {
393 const content = document.getElementById('advertisementContent');
394 if (!content) return;
431
432 // Start ad rotation
433 function startAdRotation() {
434 if (weightedAds.length === 0) return;
435

TopTenVideospremium-input-iframe.html10 matches

@pmapower•Updated 4 hours ago
234 }
235
236 function getNextWeekReset() {
237 const now = new Date();
238 const nextWeek = new Date(now);
242 }
243
244 function updateDashboard() {
245 const resetDate = new Date(premiumData.weeklyReset);
246 const now = new Date();
293
294 // Handle main niche selection
295 nicheSelect.addEventListener('change', function() {
296 const selectedValue = this.value;
297
319
320 // Ad slot management
321 document.getElementById('addAdSlot').addEventListener('click', function() {
322 if (adSlotCounter >= 5) {
323 alert('Maximum 5 ad slots allowed');
332 });
333
334 function createAdSlot(slotNumber) {
335 const slotDiv = document.createElement('div');
336 slotDiv.className = 'ad-slot mb-4 p-3 border border-gray-200 rounded-lg';
364 `;
365
366 // Add remove functionality
367 slotDiv.querySelector('.remove-ad-slot').addEventListener('click', function() {
368 slotDiv.remove();
369 updateRemoveButtons();
374 }
375
376 function updateRemoveButtons() {
377 const slots = document.querySelectorAll('.ad-slot');
378 slots.forEach(slot => {
383
384 // Handle form submission
385 form.addEventListener('submit', function(e) {
386 e.preventDefault();
387
460
461 // Auto-resize iframe
462 function resizeIframe() {
463 const height = document.body.scrollHeight;
464 parent.postMessage({

ratelimit4 file matches

@unkey•Updated 1 month ago
Rate limit your serverless functions

discordWebhook2 file matches

@stevekrouse•Updated 2 months ago
Helper function to send Discord messages
lost1991
import { OpenAI } from "https://esm.town/v/std/openai"; export default async function(req: Request): Promise<Response> { if (req.method === "OPTIONS") { return new Response(null, { headers: { "Access-Control-Allow-Origin": "*",
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.