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=706&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"(527ms)

1export default async function (interval: Interval) {
2
3}

URLReceivermainFunctionTest2 matches

@willthereader•Updated 2 months ago
1import { expect } from "jsr:@std/expect";
2import { checkWebsite } from "./mainFunctionURLReciver2";
3
4console.log("Starting Website Checker Tests");
12];
13
14async function runTests() {
15 console.log("\nTesting valid website URL");
16 let result = await checkWebsite(TEST_URLS[0]);

URLReceiversummaryURLReceiverTest7 matches

@willthereader•Updated 2 months ago
47interface TestCase {
48 description: string;
49 function: Function;
50 expectedBehavior: string;
51}
52
53function logTestInfo(message: string) {
54 console.log(` ${message}`);
55}
59 description: "Initialize generator",
60 expectedBehavior: "Should start with empty state",
61 function: () => {
62 console.log("\nTEST: Initialize generator");
63 console.log("Expected: Should start with no URLs processed\n");
83 description: "Process test URLs",
84 expectedBehavior: "Should identify working and broken URLs",
85 function: () => {
86 console.log("\nTEST: Processing multiple URLs");
87 console.log("Expected: Should correctly identify good and bad URLs\n");
124 description: "Test error handling",
125 expectedBehavior: "Should handle different types of errors",
126 function: () => {
127 console.log("\nTEST: Error handling");
128 console.log("Expected: Should identify and explain different errors\n");
182];
183
184async function runTests() {
185 console.log("Starting test run...\n");
186 let passed = 0;
189 for (const test of tests) {
190 try {
191 await test.function();
192 console.log("\nāœ… TEST PASSED");
193 passed++;

URLReceiverurlCrawlerTests8 matches

@willthereader•Updated 2 months ago
17 inputs: Record<string, unknown>;
18 expectedBehavior: string;
19 function: Function;
20}
21
27 inputs: {},
28 expectedBehavior: "should return initial progress state",
29 function: () => {
30 crawler.reset();
31 const progress = crawler.getProgress();
41 inputs: { url: TEST_URLS[0] },
42 expectedBehavior: "should not crawl beyond specified depth",
43 function: async (inputs) => {
44 // Create mock URLs with known depths
45 const baseUrl = inputs.url;
105 inputs: { url: TEST_URLS[0] },
106 expectedBehavior: "should only crawl URLs from the same domain",
107 function: async (inputs) => {
108 const result = await crawler.crawl(inputs.url);
109
133 },
134 expectedBehavior: "should normalize URLs consistently",
135 function: async (inputs) => {
136 const results = await Promise.all(
137 inputs.testUrls.map(url => crawler.crawl(url)),
157 },
158 expectedBehavior: "should properly categorize different errors",
159 function: async (inputs) => {
160 const results = await Promise.all(
161 inputs.testUrls.map(url => crawler.crawl(url)),
177];
178
179async function runTests() {
180 console.log("\nStarting enhanced test suite...");
181 let passed = 0;
187
188 try {
189 await test.function(test.inputs);
190 console.log("āœ… Test passed\n");
191 passed++;

OpenTowniegenerateCode.ts2 matches

@pomdtr•Updated 2 months ago
1import OpenAI from "https://esm.sh/openai";
2
3function parseValResponse(response: string) {
4 const codeBlockRegex = /```val type=(\w+)\n([\s\S]*?)```/;
5 const match = response.match(codeBlockRegex);
25}
26
27export async function generateCodeAnthropic(messages: Message[]): Promise<ValResponse | null> {
28 const system = await (await fetch(`${import.meta.url.split("/").slice(0, -1).join("/")}/system_prompt.txt`)).text();
29

userEnrichmentserver.ts1 match

@charmaine•Updated 2 months ago
11let { query, dataRoutes } = createStaticHandler(routes);
12
13export async function handler(request: Request) {
14 // 1. run actions/loaders to get the routing context with `query`
15 let context = await query(request);

userEnrichmenthome.tsx1 match

@charmaine•Updated 2 months ago
1/** @jsxImportSource https://esm.sh/react@18.2.0 */
2
3export default function Home() {
4 return <h1>This is just a test!</h1>;
5}

OpenTownieindex.tsx4 matches

@pomdtr•Updated 2 months ago
5import { generateCodeAnthropic, makeFullPrompt } from "./backend/generateCode";
6
7function App() {
8 const [messages, setMessages] = useState<{ content: string; role: string }[]>([]);
9 const [inputMessage, setInputMessage] = useState("make a todo app");
11 const [bearerToken, _setBearerToken] = useState(localStorage.getItem("val-town-bearer"));
12
13 function setBearerToken(token: string) {
14 _setBearerToken(token);
15 localStorage.setItem("val-town-bearer", token);
79}
80
81function client() {
82 createRoot(document.getElementById("root")).render(<App />);
83}
84if (typeof document !== "undefined") { client(); }
85
86export default async function server(req: Request): Promise<Response> {
87 // console.log(req);
88 if (req.method === "POST") {

OpenTowniesystem_prompt.txt17 matches

@pomdtr•Updated 2 months ago
10 1. `http`: http vals export a default server request handler.
11 2. `script`: script vals can be imported into other vals, similar to an npm package.
12 3. `cron`: cron vals export a function that can automatically run at user-set intervals, similar to a cron command.
13 4. `email`: email vals export a function that runs when its associated email address receives an email.
14
15Follow these requirements for Val Town when generating code.
49</requirements>
50
51If the user asks for specific functionality, the Val Town standard library includes the following:
52
53<libraries>
63 ```
64
65 Blob storage only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
66 `const { blob } = await import("https://esm.town/v/std/blob");`
67 </library>
78 If you are changing a SQLite table's schema, you should also change the table's name so it creates a fresh table, ie by adding _2 or _3 after it everywhere. Ensure that tables are created before they are used.
79
80 SQLite storage only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
81 `const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");`
82 </library>
99 ```
100
101 OpenAI only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
102 `const { OpenAI } = await import "https://esm.town/v/std/openai");`
103 </library>
113 ```
114
115 Email only works on the server. If the val includes client-side code, use dynamic imports to import this module in the server function, e.g.:
116 `const { email } = await import "https://esm.town/v/std/email");`
117 </library>
131 Write the code in ```val code fences.
132 Include the val type as metadata on the code fence, e.g.: ```val type=script
133 If this is a new val, decide what val type is appropriate based on the user's prompt. Default to choosing http type vals unless the user has requested specific functionality that requires a different type.
134
135 * If the user requests diff format in their prompt, follow these steps:
157 * Use fetch to communicate with the backend server portion.
158 */
159function App() {
160 return (
161 <div>
167/**
168 * Client-only code
169 * Any code that makes use of document or window should be scoped to the `client()` function.
170 * This val should not cause errors when imported as a module in a browser.
171 */
172function client() {
173 createRoot(document.getElementById("root")).render(<App />);
174}
177/**
178 * Server-only code
179 * Any code that is meant to run on the server should be included in the server function.
180 * This can include endpoints that the client side component can send fetch requests to.
181 */
182export default async function server(request: Request): Promise<Response> {
183 /** If needed, blob storage or sqlite can be imported as a dynamic import in this function.
184 * Blob storage should never be used in the browser directly.
185 * Other server-side specific modules can be imported in a similar way.
232 ```val type=script
233 /** Use this template for creating script vals only */
234 export default function () {
235 return "Hello, world";
236 }
243 ```val type=cron
244 /** Use this template for creating cron vals only */
245 export default async function (interval: Interval) {
246 // code will run at an interval set by the user
247 console.log(`Hello, world: ${Date.now()}`);
270 // The email address for this val will be `<username>.<valname>@valtown.email` which can be derived from:
271 // const emailAddress = new URL(import.meta.url).pathname.split("/").slice(-2).join(".") + "@valtown.email";
272 export default async function (e: Email) {
273 console.log("Email received!", email.from, email.subject, email.text);
274 }

vbloghono-adapter6 matches

@jxnblk•Updated 3 months ago
7const app = new Hono();
8
9function Style() {
10 return <style>{`body{margin:0;padding:32px;font-family:Menlo, monospace}`}</style>;
11}
12
13function Home(data: Data, c: Context) {
14 return (
15 <div>
29}
30
31function Post(data: Data, c: Context) {
32 const name = c.req.param("post");
33 const post = data.posts.find(p => p.name === name);
46}
47
48function NotFound(data: Data, c: Context) {
49 const name = c.req.param("post");
50 return (
59type RouteComponent = (data: Data, context: Context<any, any, {}>) => JSX.Element;
60
61function route(Component: RouteComponent, data: Data) {
62 return async (c) => c.html(Component(data, c));
63}
64
65export default function honoAdapter(data: Data) {
66 app.get("/", route(Home, data));
67 app.get("/posts/:post", route(Post, data));

getFileEmail4 file matches

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

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago