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/image-url.jpg%20%22Image%20title%22?q=function&page=69&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 40410 results for "function"(1818ms)

slackbotdebug.tsx15 matches

@maxm•Updated 6 days ago
6import urlSigning from "./url-signing.ts";
7await migrateDB();
8async function foo(req: Request): Promise<Response> {
9 const url = new URL(req.url);
10 const ts = await urlSigning.verify(url.pathname.slice(1));
76};
77
78function Header() {
79 return (
80 <div
100}
101
102function formatTimestamp(timestamp: number): string {
103 return new Date(timestamp).toLocaleString();
104}
105
106function parseMessageData(data: string, eventType: string): any {
107 try {
108 return JSON.parse(data);
112}
113
114function ToolTimestamp({ timestamp }: { timestamp: number }) {
115 return (
116 <div style={styles.toolTimestamp}>
120}
121
122function SlackMessage({ message }: { message: any }) {
123 const parsedData = parseMessageData(message.data, message.event_type);
124
143}
144
145function ClaudeMessage({ message }: { message: any }) {
146 const parsedData = parseMessageData(message.data, message.event_type);
147 const cleanMessage = parsedData.raw
170}
171
172function Timestamp(
173 { timestamp, style = {} }: { timestamp: number; style?: any },
174) {
194}
195
196function ToolCall({ message }: { message: any }) {
197 return (
198 <div style={styles.centerMessageContainer}>
213}
214
215function ToolResult({ message }: { message: any }) {
216 return (
217 <div style={styles.centerMessageContainer}>
234}
235
236function UnknownEvent({ message }: { message: any }) {
237 return (
238 <div style={styles.centerMessageContainer}>
254}
255
256function MessagesContainer({ children }: { children: any }) {
257 return (
258 <div
267}
268
269function MessageBubble({ message }: { message: any }) {
270 switch (message.event_type) {
271 case "slack_message":
282}
283
284function Footer({ conversationData }: { conversationData: any }) {
285 return (
286 <div
320};
321
322function renderError(e: unknown) {
323 const error = e instanceof Error ? e : new Error(String(e));
324

slackbotreply.ts4 matches

@maxm•Updated 6 days ago
23}).catch(() => {});
24
25export async function reply(
26 event: GenericMessageEvent,
27 messages: Anthropic.MessageParam[],
43 });
44
45 const function_calls = response.content.filter(
46 (block) => block.type === "tool_use",
47 );
66
67 // If were no more tool calls, we're done, return
68 if (!function_calls.length) return;
69
70 // Append the assistant message once per step
72
73 // Run every tool call the model requested
74 for (const call of function_calls) {
75 if (call.type !== "tool_use") continue;
76

exampleindex.http.tsx1 match

@tmcw•Updated 6 days ago
1export default async function (req) {
2 return new Response("Hello there. This is live-updating, and live-deployed.");
3}

Electricmisc.ts2 matches

@psuechti•Updated 6 days ago
9 * @returns A promise that resolves when all files have been uploaded.
10 */
11export async function uploadDir(dir: string) {
12 const uploadPromises: Promise<void>[] = [];
13
32 * @param dir The directory to save the files in.
33 */
34export async function downloadDir(dir: string) {
35 const response = await client.files.list.$get();
36 const { files } = await response.json();

Electricblobs.ts6 matches

@psuechti•Updated 6 days ago
8 * @returns A promise that resolves to the path of the blob.
9 */
10export async function setBlobContent(path: string, content: string | ArrayBuffer): Promise<string> {
11 const key = env.STORAGE_PREFIX + path;
12 await blob.set(key, content);
20 * @returns A promise that resolves to the content of the blob as a string.
21 */
22export async function getBlobContent(path: string): Promise<string> {
23 const key = env.STORAGE_PREFIX + path;
24 return await blob.get(key).then((resp) => resp.text());
30 * @returns {Promise<string[]>} A promise that resolves to an array of blob keys, with the storage prefix removed.
31 */
32export async function listBlobs(): Promise<string[]> {
33 const files = await blob.list(env.STORAGE_PREFIX);
34 return files.map(({ key }) => key.replace(env.STORAGE_PREFIX, ""));
41 * @returns A promise that resolves when the blob is successfully deleted.
42 */
43export async function deleteBlob(path: string): Promise<void> {
44 const key = env.STORAGE_PREFIX + path;
45 await blob.delete(key);
52 * representing the keys of the deleted blobs, with the storage prefix removed.
53 */
54export async function deleteAllBlobs(): Promise<string[]> {
55 const allFiles = await blob.list(env.STORAGE_PREFIX);
56
72 * @returns A promise that resolves to true if the blob exists, false otherwise.
73 */
74export async function blobExists(path: string): Promise<boolean> {
75 const key = env.STORAGE_PREFIX + path;
76 try {

test-appnew-file-774.js1 match

@psuechti•Updated 6 days ago
1// Learn more: https://docs.val.town/vals/http/
2export default async function (req: Request): Promise<Response> {
3 return Response.json({ ok: true })
4}

slackbotdb.ts7 matches

@maxm•Updated 6 days ago
9};
10
11function parseModuleUrl(url: string) {
12 // Match the pattern: /p/{username}/{name}@{version}-{branch}/events/db.ts
13 const regex = /\/p\/[^\/]+\/([^@]+)@\d+-([^\/]+)\//;
24}
25
26export async function migrateDB() {
27 await sqlite.batch([
28 `
39}
40
41export async function getAll({ ts }: {
42 ts?: string;
43}) {
54}
55
56export async function writeSlackMessage({ event }: {
57 event: AppMentionEvent | GenericMessageEvent;
58}) {
70}
71
72export async function writeClaudeMessage({ channel, ts, msg }: {
73 channel: string;
74 ts: string;
88}
89
90export async function writeToolCall({ channel, ts, data }: {
91 channel: string;
92 ts: string;
106}
107
108export async function writeToolResult({ channel, ts, result }: {
109 channel: string;
110 ts: string;

slackbotindex.ts1 match

@maxm•Updated 6 days ago
5import { writeSlackMessage } from "../util/db.ts";
6
7export async function handleSlackEvent(event: SlackEvent) {
8 if (
9 event.type === "message" && !event.subtype && !event.bot_id &&

slackboturl-signing.ts2 matches

@maxm•Updated 6 days ago
2
3// Sign a value
4async function sign(value: string) {
5 const encoder = new TextEncoder();
6 const key = await crypto.subtle.importKey(
26
27// Verify a signed value
28async function verify(signedValue: string) {
29 const lastDotIndex = signedValue.lastIndexOf(".");
30 if (lastDotIndex === -1) return null;

my-first-val04_email.ts1 match

@joeson_marlin•Updated 6 days ago
2// Click "Run", copy and paste the email address and send an email to it.
3// This example will log the email details received.
4export default async function emailHandler(email: Email){
5 console.log("Email received!", email.from, email.subject, email.text);
6 for (const file of email.attachments) {

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.