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/$2?q=function&page=2483&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 31522 results for "function"(10550ms)

linkInBioTemplatemain.tsx1 match

@awhitter•Updated 4 months ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(

steel_puppeteer_startermain.tsx1 match

@charmaine•Updated 4 months ago
12});
13
14async function main() {
15 let session;
16 let browser;

trackESMContentmain.tsx5 matches

@maxm•Updated 4 months ago
10const TABLE_NAME = `${KEY}_versions_v1`;
11
12async function fetchContent(url: string) {
13 const response = await fetch(url);
14 return await response.text();
15}
16
17async function initializeDatabase() {
18 await sqlite.execute(`
19 CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
26}
27
28export default async function(interval: Interval) {
29 await initializeDatabase();
30
56}
57
58async function sha256(message: string): Promise<string> {
59 const msgUint8 = new TextEncoder().encode(message);
60 const hashBuffer = await crypto.subtle.digest("SHA-256", msgUint8);
64}
65
66export async function getAllVersions() {
67 await initializeDatabase();
68 const versions = await sqlite.execute(`SELECT * FROM ${TABLE_NAME} ORDER BY timestamp DESC`);

steel_puppeteer_startermain.tsx1 match

@stevekrouse•Updated 4 months ago
12});
13
14async function main() {
15 let session;
16 let browser;

badgemain.tsx1 match

@stevekrouse•Updated 4 months ago
1export default function server(req: Request): Response {
2 const svg = `<svg width="140" height="35" viewBox="0 0 140 35" fill="none" xmlns="http://www.w3.org/2000/svg">
3<g clip-path="url(#clip0_0_3)">

react_client_forkmain.tsx8 matches

@johndevor•Updated 4 months ago
1<think>
2Okay, so the user provided a React application written in TypeScript, and they mentioned that the requested changes are undefined. That probably means they just want the code to be formatted or cleaned up without any functional changes.
3
4Looking at the code, I notice that it's using a mix of JavaScript and some TypeScript features, but it's not strictly typed. The initialTodos prop is defined as an array of objects with a text property, which is good. However, the state for todos and newTodo could benefit from more specific types.
6I'll start by adding explicit types to the useState hooks. For the todos state, I'll define it as an array of { text: string }, and for newTodo, it should be a string. This helps with type checking and makes the code more robust.
7
8Next, I'll format the code for better readability. I'll adjust the indentation and spacing, especially in the JSX where inline styles are applied. This makes the code cleaner and easier to read without changing any functionality.
9
10I also notice that the server function handles different routes. I'll make sure the syntax is consistent and that all possible routes are handled correctly. Since there are no requested changes, I won't alter the functionality here.
11
12Finally, I'll ensure that all imports and function calls are correctly formatted and that there are no syntax errors. This includes checking that the createRoot function is properly used and that the client-side rendering is correctly set up.
13
14In summary, the main steps are adding explicit types, improving code formatting, and ensuring consistency without changing any functionality since the requested changes were undefined.
15</think>
16
23import { blob } from "https://esm.town/v/std/blob?v=10";
24
25function App({ initialTodos }: { initialTodos: { text: string; }[]; }) {
26 const [todos, setTodos] = useState<{ text: string; }[]>(Array.isArray(initialTodos) ? initialTodos : []);
27 const [newTodo, setNewTodo] = useState<string>("");
117}
118
119function client() {
120 const fetchTodos = async () => {
121 const response = await fetch('/todos');
131if (typeof document !== "undefined") { client(); }
132
133export default async function server(request: Request) {
134 if (request.method === 'POST' && request.url.endsWith('/add-todo')) {
135 const body = await request.json();

cerebras_codermain.tsx11 matches

@Fguyu•Updated 4 months ago
24);
25
26function Hero({
27 prompt,
28 setPrompt,
45
46 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
47 Turn your ideas into fully functional apps in{" "}
48 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
49 less than a second
116}
117
118function App() {
119 const previewRef = React.useRef<HTMLDivElement>(null);
120 const [prompt, setPrompt] = useState("");
170 });
171
172 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
173 setLoading(true);
174 setTimeout(() => handleSubmit(promptItem.prompt), 0);
175 }
176
177 async function handleSubmit(e: React.FormEvent | string) {
178 if (typeof e !== "string") {
179 e.preventDefault();
226 }
227
228 function handleVersionChange(direction: "back" | "forward") {
229 const { currentVersionIndex, versions } = versionHistory;
230 if (direction === "back" && currentVersionIndex > 0) {
974);
975
976function client() {
977 const path = window.location.pathname;
978 const root = createRoot(document.getElementById("root")!);
1010}
1011
1012function extractCodeFromFence(text: string): string {
1013 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
1014 return htmlMatch ? htmlMatch[1].trim() : text;
1015}
1016
1017async function generateCode(prompt: string, currentCode: string) {
1018 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
1019 if (starterPrompt) {
1060}
1061
1062export default async function cerebras_coder(req: Request): Promise<Response> {
1063 // Dynamic import for SQLite to avoid client-side import
1064 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1163 <meta property="og:site_name" content="Cerebras Coder">
1164 <meta property="og:url" content="https://cerebrascoder.com"/>
1165 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
1166 <meta property="og:type" content="website">
1167 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">

floatingQuotaTracker_Testmain.tsx2 matches

@rozek•Updated 4 months ago
2import { floatingQuotaTracker } from 'https://esm.town/v/rozek/floatingQuotaTracker'
3
4export default async function () {
5 const TestCases = [
6 /**** test constructor with defaults ****/
243/**** removeTable ****/
244
245 async function removeTable (TableName:string):Promise<void> {
246 console.log('(cleaning up)')
247 await sqlite.execute(

floatingQuotaTracker_TestREADME.md1 match

@rozek•Updated 4 months ago
30 * tests successful increments up to the limit
31 * verifies LimitExceeded error is thrown when limit is reached
329. Reset functionality
33 * increments usage
34 * tests reset method

cerebras_codermain.tsx10 matches

@aashish•Updated 4 months ago
24);
25
26function Hero({
27 prompt,
28 setPrompt,
45
46 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
47 Turn your ideas into fully functional apps in{" "}
48 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
49 less than a second
116}
117
118function App() {
119 const previewRef = React.useRef<HTMLDivElement>(null);
120 const [prompt, setPrompt] = useState("");
170 });
171
172 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
173 setLoading(true);
174 setTimeout(() => handleSubmit(promptItem.prompt), 0);
175 }
176
177 async function handleSubmit(e: React.FormEvent | string) {
178 if (typeof e !== "string") {
179 e.preventDefault();
226 }
227
228 function handleVersionChange(direction: "back" | "forward") {
229 const { currentVersionIndex, versions } = versionHistory;
230 if (direction === "back" && currentVersionIndex > 0) {
974);
975
976function client() {
977 const path = window.location.pathname;
978 const root = createRoot(document.getElementById("root")!);
1010}
1011
1012function extractCodeFromFence(text: string): string {
1013 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
1014 return htmlMatch ? htmlMatch[1].trim() : text;
1015}
1016
1017async function generateCode(prompt: string, currentCode: string) {
1018 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
1019 if (starterPrompt) {
1059}
1060
1061export default async function server(req: Request): Promise<Response> {
1062 // Dynamic import for SQLite to avoid client-side import
1063 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
tuna

tuna9 file matches

@jxnblk•Updated 2 weeks ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
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.