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//%22https:/unpkg.com/@simplewebauthn/browser/dist/bundle/index.umd.min.js/%22?q=function&page=1&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 40692 results for "function"(776ms)

flowxo-http-bot-samplescript.js7 matches

@flowxo•Updated 22 mins ago
9const userName = "Some User";
10
11function makeMessage(messageText) {
12 return {
13 channel: {
25}
26
27function sendNewMessage(message) {
28 const payload = makeMessage(message);
29 const opts = {
37}
38
39function formatMessage(payload, from) {
40 const message = JSON.stringify(payload.message.text || payload.message)
41 .replace(/(\\n)+/, "<br/>");
49}
50
51function appendNewMessage(data) {
52 const message = data.message;
53 if (!message.message || message.message_type === "action") {
59}
60
61function resetMessages() {
62 return fetch("/reset");
63}
64
65function getMessages() {
66 return fetch("/messages")
67 .then((response) => response.json())
69}
70
71function displayMessages(messages) {
72 messageList.innerHTML = "";
73 messages.forEach(appendNewMessage);
Gemini-2-5-Pro-O-01

Gemini-2-5-Pro-O-01main.tsx17 matches

@aibotcommander•Updated 24 mins ago
83].filter(Boolean);
84
85function authenticateRequest(req: Request): { isValid: boolean; error?: string } {
86 if (!BOT_ACCESS_KEY) {
87 console.warn("Warning: BOT_ACCESS_KEY is not set in environment variables");
110}
111
112function createPoeClient(apiKey: string): OpenAI {
113 return new OpenAI({
114 apiKey: apiKey || "YOUR_POE_API_KEY",
117}
118
119function selectOptimalTokens(contentLength: number, taskType: string): number {
120 if (taskType === "Image Generation") return 1024;
121 if (contentLength < 100) return 1024; // Short queries
124}
125
126async function callSinglePoeModel(
127 model: string,
128 prompt: string,
169}
170
171async function callPoeModelParallel(
172 models: string[],
173 prompt: string,
260}
261
262async function imageToBase64(imageUrl: string): Promise<{ data: string; mimeType: string }> {
263 try {
264 const response = await fetch(imageUrl, { timeout: 8000 });
276}
277
278async function callGeminiApi(
279 config: ModelConfig,
280 prompt: string,
338}
339
340async function generateImage(prompt: string, send: SendEventFn): Promise<void> {
341 let cleanPrompt = prompt;
342 if (cleanPrompt.endsWith('--image')) {
364}
365
366async function generateText(prompt: string, send: SendEventFn, useClaudeModels: boolean = false): Promise<void> {
367 send("text", { text: `💬 Processing...` });
368
391}
392
393async function analyzeFile(fileContent: string, fileName: string, userPrompt: string, send: SendEventFn): Promise<void> {
394 if (!fileContent || fileContent.trim().length === 0) {
395 send("error", {
436}
437
438async function analyzeImage(imageUrl: string, userPrompt: string, send: SendEventFn): Promise<void> {
439 let analysisPrompt: string;
440 if (!userPrompt || userPrompt.trim().length === 0) {
468}
469
470async function performSearch(query: string, send: SendEventFn): Promise<void> {
471 const searchPrompt = `Search for comprehensive, current information about: ${query}\n\nProvide detailed, accurate information with sources and references where available. Focus on the most recent and relevant information.`;
472
494}
495
496function detectIntent(content: string, hasAttachments: boolean): { intent: string; useClaudeModels: boolean } {
497 const lowerContent = content.toLowerCase();
498 let useClaudeModels = false;
541}
542
543async function getResponse(req: Query, send: SendEventFn) {
544 send("meta", { content_type: "text/markdown" });
545
649}
650
651async function getBotSettings(): Promise<BotSettings> {
652 const rateCard = "| Task Type | Price |\n" +
653 "|-----------|-------|\n" +
716) => void;
717
718function encodeEvent(event: string, data: any = {}) {
719 return new TextEncoder().encode(
720 `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`,
722}
723
724export default async function (req: Request): Promise<Response> {
725 if (req.method !== "OPTIONS") {
726 const authResult = authenticateRequest(req);

SonarMiniAppScreen.tsx6 matches

@moe•Updated 28 mins ago
8import { fetchMiniApp } from '../util/neynar.ts'
9
10export function MiniAppScreen() {
11 const { data: miniapp, isLoading } = useMiniAppFromParams()
12
29}
30
31function MiniAppNav() {
32 const { url } = useParams()
33 const encodedUrl = encodeURIComponent(url)
40}
41
42export function MiniAppManifest() {
43 const { data: miniapp } = useMiniAppFromParams()
44 if (!miniapp) return null
46}
47
48export function MiniAppEmbed() {
49 const { data: miniapp } = useMiniAppFromParams()
50 if (!miniapp) return null
52}
53
54export function MiniAppDebug() {
55 const { data: miniapp } = useMiniAppFromParams()
56 if (!miniapp) return null
58}
59
60function useMiniAppFromParams() {
61 const { url } = useParams()
62 return useQuery({ queryKey: ['mini-app', url], queryFn: () => fetchMiniApp(url), staleTime: 1000 * 60 * 5 })
Gemini-2-5-Pro-O-02

Gemini-2-5-Pro-O-02main.tsx17 matches

@aibotcommander•Updated 29 mins ago
83].filter(Boolean);
84
85function authenticateRequest(req: Request): { isValid: boolean; error?: string } {
86 if (!BOT_ACCESS_KEY) {
87 console.warn("Warning: BOT_ACCESS_KEY is not set in environment variables");
110}
111
112function createPoeClient(apiKey: string): OpenAI {
113 return new OpenAI({
114 apiKey: apiKey || "YOUR_POE_API_KEY",
117}
118
119function selectOptimalTokens(contentLength: number, taskType: string): number {
120 if (taskType === "Image Generation") return 1024;
121 if (contentLength < 100) return 1024; // Short queries
124}
125
126async function callSinglePoeModel(
127 model: string,
128 prompt: string,
169}
170
171async function callPoeModelParallel(
172 models: string[],
173 prompt: string,
260}
261
262async function imageToBase64(imageUrl: string): Promise<{ data: string; mimeType: string }> {
263 try {
264 const response = await fetch(imageUrl, { timeout: 8000 });
276}
277
278async function callGeminiApi(
279 config: ModelConfig,
280 prompt: string,
338}
339
340async function generateImage(prompt: string, send: SendEventFn): Promise<void> {
341 let cleanPrompt = prompt;
342 if (cleanPrompt.endsWith('--image')) {
364}
365
366async function generateText(prompt: string, send: SendEventFn, useClaudeModels: boolean = false): Promise<void> {
367 send("text", { text: `💬 Processing...` });
368
391}
392
393async function analyzeFile(fileContent: string, fileName: string, userPrompt: string, send: SendEventFn): Promise<void> {
394 if (!fileContent || fileContent.trim().length === 0) {
395 send("error", {
436}
437
438async function analyzeImage(imageUrl: string, userPrompt: string, send: SendEventFn): Promise<void> {
439 let analysisPrompt: string;
440 if (!userPrompt || userPrompt.trim().length === 0) {
468}
469
470async function performSearch(query: string, send: SendEventFn): Promise<void> {
471 const searchPrompt = `Search for comprehensive, current information about: ${query}\n\nProvide detailed, accurate information with sources and references where available. Focus on the most recent and relevant information.`;
472
494}
495
496function detectIntent(content: string, hasAttachments: boolean): { intent: string; useClaudeModels: boolean } {
497 const lowerContent = content.toLowerCase();
498 let useClaudeModels = false;
541}
542
543async function getResponse(req: Query, send: SendEventFn) {
544 send("meta", { content_type: "text/markdown" });
545
649}
650
651async function getBotSettings(): Promise<BotSettings> {
652 const rateCard = "| Task Type | Price |\n" +
653 "|-----------|-------|\n" +
716) => void;
717
718function encodeEvent(event: string, data: any = {}) {
719 return new TextEncoder().encode(
720 `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`,
722}
723
724export default async function (req: Request): Promise<Response> {
725 if (req.method !== "OPTIONS") {
726 const authResult = authenticateRequest(req);

SonarApp.tsx2 matches

@moe•Updated 30 mins ago
22import { UsersScreen } from './screens/UsersScreen.tsx'
23
24export function App() {
25 const navigate = useNavigate()
26
93}
94
95function About() {
96 return (
97 <Section className="flex flex-col items-start gap-3 m-5">

flowxo-http-bot-samplebot.ts4 matches

@flowxo•Updated 33 mins ago
27});
28
29app.get("/messages", function async(c) {
30 return c.json({ messages });
31});
32
33//Clear messages
34app.get("/reset", function (request, response) {
35 messages = [];
36});
37
38//Receive a message from Flow XO
39app.post("/out", async function (c) {
40 const msg = await c.req.json();
41 console.log("RECEIVED A MESSAGE", JSON.stringify(msg, null, 2));
45
46//Send a message to Flow XO
47app.post("/in", async function (c) {
48 const message = await c.req.json();
49 const url = BOT_URL;

webgpu_2main.tsx3 matches

@saolsen•Updated 34 mins ago
10import module_path from "./module_path.tsx"
11
12async function main() {
13 const grid_shader = await (await fetch(`${module_path}/grid.wgsl`)).text();
14
210 let depth_texture: GPUTexture;
211
212 function render() {
213 const fov = 60 * Math.PI / 180;
214 const aspect = canvas.width / canvas.height;
292}
293
294function fail(msg: string) {
295 alert(msg);
296}

Notesmain.tsx18 matches

@json•Updated 36 mins ago
1export default function () {
2 const body = `<!doctype html>
3<html lang="en">
101
102 /************************************************************************
103 * State: raw variables & functions, and evaluated variables
104 ************************************************************************/
105 const rawVars = new Map(); // name -> rhs string (raw)
106 const functions = new Map(); // name -> { params: [], body: "..." }
107 const computedVars = new Map(); // name -> evaluated value (primitive, array, string, etc)
108
110 * Helpers
111 ************************************************************************/
112 function isQuotedString(s) {
113 return (s.length >= 2) && ((s[0] === '"' && s[s.length-1] === '"') || (s[0] === "'" && s[s.length-1] === "'"));
114 }
115
116 function toObj(map) {
117 const o = Object.create(null);
118 for (const [k,v] of map.entries()) o[k] = v;
122 // Evaluate an expression string in a sandbox that includes:
123 // - current computedVars
124 // - user functions (as JS functions that evaluate their bodies with the same sandbox + parameters)
125 // - builtins
126 function evalWithScope(expr) {
127 // Build base scope
128 const scope = Object.assign({}, builtins, toObj(computedVars));
129 // attach user functions into scope as callables
130 for (const [name, def] of functions.entries()) {
131 scope[name] = (...args) => {
132 // local scope that includes current computedVars and builtins, plus params
135 try {
136 // Use with(scope) { return (body) } to allow body to reference names
137 return Function('scope', 'with(scope){ return (' + def.body + ') }')(local);
138 } catch (e) {
139 // propagate error
145 // Now evaluate expression in the scope
146 try {
147 return Function('scope', 'with(scope){ return (' + expr + ') }')(scope);
148 } catch (e) {
149 throw e;
153 /************************************************************************
154 * Parse the document top-down:
155 * - function defs f(a,b)=...
156 * - variable defs name = rhs (rhs may be quoted string OR an expression)
157 *
158 * We evaluate variables in document order so earlier defs are available to later ones.
159 ************************************************************************/
160 function parseDocument(doc) {
161 rawVars.clear();
162 functions.clear();
163 computedVars.clear();
164
168 if (!line) continue;
169
170 // function: name(arg1, arg2) = body
171 const fm = line.match(/^([A-Za-z_][\\w]*)\\s*\\(([^)]*)\\)\\s*=\\s*(.+)$/);
172 if (fm) {
174 const params = fm[2].split(',').map(s=>s.trim()).filter(Boolean);
175 const body = fm[3].trim();
176 functions.set(name, { params, body });
177 continue;
178 }
185 rawVars.set(name, rhs);
186
187 // attempt to evaluate using current environment (earlier vars + functions)
188 try {
189 let value;
280 }, { decorations: v => v.decorations });
281
282 function stringifyValue(v) {
283 if (v === null || v === undefined) return String(v);
284 if (typeof v === 'number') {

SonarMiniAppsScreen.tsx3 matches

@moe•Updated 38 mins ago
8import { Feed } from '../components/Post.tsx'
9
10export function MiniAppsScreen() {
11 return (
12 <div>
22}
23
24function MiniAppsList() {
25 return (
26 <Feed
33}
34
35function MiniApp({ miniapp }) {
36 const { fcsdk, context } = useFarcasterMiniApp()
37 const navigate = useNavigate()

dotcomsend.ts1 match

@petermillspaugh•Updated 40 mins ago
4import { sqlite } from "https://esm.town/v/std/sqlite";
5
6async function sendNewsletter() {
7 const newsletter = newsletters[newsletters.length - 1];
8 const { subject, jsx, webUrl } = newsletter;

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.