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=868&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 16279 results for "function"(1343ms)

parseImportMetaproject1 match

@std•Updated 2 months ago
20}
21
22export function parseProject(url: string): Project {
23 const pattern = /^https:\/\/esm\.town\/v\/([^/]+)\/([^@]+)@(\d+)-(.+?)(\/.*)?$/;
24 const match = url.match(pattern);

mathOfTheDayvivaciousBlushMarlin1 match

@charmaine•Updated 2 months ago
1import { email } from "https://esm.town/v/std/email?v=13";
2
3export default async function(interval: Interval) {
4 console.log(`math problem`);
5 email({

b5338dba_f0ab_11ef_a041_e6cdfca9ef9fmain.tsx3 matches

@cam•Updated 2 months ago
3import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
4
5function LinkInBio() {
6 const links = [
7 {
57}
58
59function client() {
60 createRoot(document.getElementById("root")).render(<LinkInBio />);
61}
62if (typeof document !== "undefined") { client(); }
63
64export default async function server(request: Request): Promise<Response> {
65 return new Response(`
66 <html>

poe_botmain.tsx12 matches

@jeffreyyoung•Updated 2 months ago
148export interface ToolDefinition {
149 type: string;
150 function: {
151 name: string;
152 description: string;
162 id: string;
163 type: string;
164 function: {
165 name: string;
166 arguments: string;
178 id: string;
179 type: string;
180 function: {
181 name: string;
182 arguments: string;
213`;
214
215export function createBot(bot: BotBase<ValTownCtx>): { handleRequest: Handler } {
216 async function handleRequest(req: Request): Promise<Response> {
217 const reqBody = await req.json().catch(e => null);
218 if (!reqBody) {
228 let settingsResponse = await Promise.resolve()
229 .then(() => {
230 if (typeof bot.settings === "function") {
231 return bot.settings(body, { req });
232 }
244 const stream = new ReadableStream({
245 start(controller) {
246 (async function() {
247 for await (const event of bot.handleMessage(body, { req }, { events, sleep })) {
248 if (typeof event === "string") {
276}
277
278export function sleep(timeInMs: number) {
279 return new Promise(resolve => setTimeout(resolve, timeInMs));
280}
281
282function encodeEvent(event: string, data: any = {}) {
283 return new TextEncoder().encode(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`);
284}
285
286export default function serve(bot: BotBase<ValTownCtx>): Handler {
287 return createBot(bot).handleRequest;
288}
291 * Forwards a query to a poe hosted bot, like "GPT-4o"
292 */
293export async function* forward(
294 { query, toBotName, accessKey }: { query: QueryRequest; toBotName: string; accessKey: string },
295): AsyncIterable<PoeBotServerSentEvent> {
309}
310
311async function* fetchEventSource(request: Request): AsyncIterable<{ event: string; data: any }> {
312 const response = await fetch(request);
313

rumsey_roulettemain.tsx4 matches

@sammeltassen•Updated 2 months ago
45};
46
47async function getRandomObject() {
48 const result = await sqlite.execute(`
49 SELECT data FROM ${tableName} ORDER BY RANDOM() LIMIT 1
54}
55
56function parseData(ndjson: string) {
57 return ndjson.split(/[\r\n]+/)
58 .filter((line) => line)
60}
61
62function createChunks(arr: any[]) {
63 let chunks = new Array();
64 for (let i = 0; i < arr.length; i += chunkSize) {
69}
70
71export default async function(req: Request): Promise<Response> {
72 const method = req.method;
73 const searchParams = new URL(req.url).searchParams;

chatAgentWithCustomPromptmain.tsx3 matches

@mjoshimanhar•Updated 2 months ago
4import { OpenAI } from "https://esm.town/v/std/openai";
5
6export default async function chatAgentWithCustomPrompt(input?: string) {
7 const model = new ChatOpenAI({
8 temperature: 0,
31}
32
33// Test function to demonstrate usage
34export async function testChatAgent() {
35 // Test with default input
36 console.log("Default Test:");
1export default async function (interval: Interval) {
2
3}

youthfulCyanSheepmain.tsx2 matches

@alexwein•Updated 2 months ago
2import { retryFill } from "https://esm.town/v/alexwein/gridRetryFill";
3
4export async function fabw() {
5 // Import d3 and Plot with a server-side compatible approach
6 const d3 = await import("https://cdn.jsdelivr.net/npm/d3@7/+esm");
61}
62
63export default async function(request: Request) {
64 return await fabw();
65}

valentinemain.tsx3 matches

@sakura_17•Updated 2 months ago
13];
14
15function App() {
16 const [noClicks, setNoClicks] = useState(0);
17 const [isValentine, setIsValentine] = useState(false);
98}
99
100function client() {
101 createRoot(document.getElementById("root")).render(<App />);
102}
103if (typeof document !== "undefined") { client(); }
104
105export default async function server(request: Request): Promise<Response> {
106 return new Response(
107 `

valentinemain.tsx3 matches

@bogdanmoale•Updated 2 months ago
13];
14
15function App() {
16 const [noClicks, setNoClicks] = useState(0);
17 const [isValentine, setIsValentine] = useState(false);
98}
99
100function client() {
101 createRoot(document.getElementById("root")).render(<App />);
102}
103if (typeof document !== "undefined") { client(); }
104
105export default async function server(request: Request): Promise<Response> {
106 return new Response(
107 `

getFileEmail4 file matches

@shouser•Updated 1 week ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblk•Updated 1 week ago
Simple functional CSS library for Val Town
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
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": "*",