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=1072&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 17289 results for "function"(2103ms)

MultiImageCompressormain.tsx2 matches

@robbert_h•Updated 3 months ago
10}
11
12function ImageCompressor() {
13 const [images, setImages] = React.useState<CompressedImage[]>([]);
14 const [totalCompressed, setTotalCompressed] = React.useState(0);
324}
325
326export default async function server(request: Request): Promise<Response> {
327 return new Response(`
328 <html>

getRandomWordmain.tsx2 matches

@alexwein•Updated 3 months ago
1// Use Web Crypto API for hashing instead of Deno's standard library
2async function hashSeed(seed: string): Promise<string> {
3 const encoder = new TextEncoder();
4 const data = encoder.encode(seed);
12let wordListCache: string[] | null = null;
13
14export async function getRandomWord(
15 seed?: string,
16 min: number = 3,

tape_test_examplemain.tsx4 matches

@kucukkanat•Updated 3 months ago
1import test from "npm:tape";
2
3test("timing test", function(t) {
4 t.plan(2);
5
6 t.equal(typeof Date.now, "function");
7 var start = Date.now();
8
9 setTimeout(function() {
10 t.equal(Date.now() - start, 100);
11 }, 100);
12});
13
14test("test using promises", async function(t) {
15 const result = await someAsyncThing();
16 t.ok(result);

UImain.tsx10 matches

@gokulnpc•Updated 3 months ago
34}
35
36function ComponentGenerator() {
37 const [prompt, setPrompt] = useState("");
38 const [generatedCode, setGeneratedCode] = useState("");
62 try {
63 // eslint-disable-next-line no-new-func
64 const ComponentFunc = new Function('React', `return (${code})`)();
65 setParsedComponent(() => ComponentFunc);
66 } catch (parseError) {
103 value={prompt}
104 onChange={(e) => setPrompt(e.target.value)}
105 placeholder="Describe your React component (e.g., 'A todo list with add and delete functionality')"
106 className="flex-grow p-3 rounded-l-lg bg-gray-800 text-white"
107 />
157}
158
159function App() {
160 return <ComponentGenerator />;
161}
162
163function client() {
164 const root = document.getElementById("root");
165 if (root) {
172}
173
174export default async function server(request: Request): Promise<Response> {
175 if (request.method === "POST" && new URL(request.url).pathname === "/generate-component") {
176 const { prompt } = await request.json();
186 role: "system",
187 content: `You are an expert React component generator.
188 Generate a complete, functional React component based on the user's description.
189 - Use modern React with functional components and hooks
190 - Include necessary imports (import React from 'react')
191 - Provide a fully working component
193 - Handle basic interactions and state management
194 - Ensure the component is self-contained and renders correctly
195 - Return ONLY the component function, not the full file
196 - Wrap the function in parentheses () => { ... }`
197 },
198 {

cerebras_codermain.tsx11 matches

@gokulnpc•Updated 3 months ago
75const PoweredByInfo = "";
76
77function Hero({
78 prompt,
79 setPrompt,
96
97 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
98 Turn your ideas into fully functional apps in{" "}
99 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
100 less than a second
170}
171
172function App() {
173 const previewRef = React.useRef<HTMLDivElement>(null);
174 const [prompt, setPrompt] = useState("");
224 });
225
226 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
227 setLoading(true);
228 setTimeout(() => handleSubmit(promptItem.prompt), 0);
229 }
230
231 async function handleSubmit(e: React.FormEvent | string) {
232 if (typeof e !== "string") {
233 e.preventDefault();
280 }
281
282 function handleVersionChange(direction: "back" | "forward") {
283 const { currentVersionIndex, versions } = versionHistory;
284 if (direction === "back" && currentVersionIndex > 0) {
996);
997
998function client() {
999 const path = window.location.pathname;
1000 const root = createRoot(document.getElementById("root")!);
1032}
1033
1034function extractCodeFromFence(text: string): string {
1035 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
1036 return htmlMatch ? htmlMatch[1].trim() : text;
1037}
1038
1039async function generateCode(prompt: string, currentCode: string) {
1040 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
1041 if (starterPrompt) {
1082}
1083
1084export default async function cerebras_coder(req: Request): Promise<Response> {
1085 // Dynamic import for SQLite to avoid client-side import
1086 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1185 <meta property="og:site_name" content="Cerebras Coder">
1186 <meta property="og:url" content="https://cerebrascoder.com"/>
1187 <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."">
1188 <meta property="og:type" content="website">
1189 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">

cerebrasTemplatemain.tsx2 matches

@gokulnpc•Updated 3 months ago
242};
243
244function client() {
245 createRoot(document.getElementById("root")).render(<SubscriptionTracker />);
246}
248if (typeof document !== "undefined") { client(); }
249
250export default async function server(request: Request): Promise<Response> {
251 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
252 const KEY = "cerebrasTemplate";

cerebrasTemplatemain.tsx3 matches

@keien•Updated 3 months ago
3import React, { useState } from "https://esm.sh/react@18.2.0";
4
5function App() {
6 const [messages, setMessages] = useState([]);
7 const [input, setInput] = useState("");
71}
72
73function client() {
74 createRoot(document.getElementById("root")).render(<App />);
75}
79}
80
81export default async function server(request: Request): Promise<Response> {
82 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
83 const { messages } = await request.json();

cerebrasTemplatemain.tsx3 matches

@cory16457•Updated 3 months ago
3import React, { useState } from "https://esm.sh/react@18.2.0";
4
5function App() {
6 const [messages, setMessages] = useState([]);
7 const [input, setInput] = useState("");
71}
72
73function client() {
74 createRoot(document.getElementById("root")).render(<App />);
75}
79}
80
81export default async function server(request: Request): Promise<Response> {
82 if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
83 const { messages } = await request.json();

hopefulGoldChinchillamain.tsx11 matches

@charmaine•Updated 3 months ago
73const PoweredByInfo = "";
74
75function Hero({
76 prompt,
77 setPrompt,
94
95 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
96 Turn your ideas into fully functional apps in{" "}
97 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
98 less than a second
168}
169
170function App() {
171 const previewRef = React.useRef<HTMLDivElement>(null);
172 const [prompt, setPrompt] = useState("");
222 });
223
224 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
225 setLoading(true);
226 setTimeout(() => handleSubmit(promptItem.prompt), 0);
227 }
228
229 async function handleSubmit(e: React.FormEvent | string) {
230 if (typeof e !== "string") {
231 e.preventDefault();
278 }
279
280 function handleVersionChange(direction: "back" | "forward") {
281 const { currentVersionIndex, versions } = versionHistory;
282 if (direction === "back" && currentVersionIndex > 0) {
994);
995
996function client() {
997 const path = window.location.pathname;
998 const root = createRoot(document.getElementById("root")!);
1030}
1031
1032function extractCodeFromFence(text: string): string {
1033 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
1034 return htmlMatch ? htmlMatch[1].trim() : text;
1035}
1036
1037async function generateCode(prompt: string, currentCode: string) {
1038 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
1039 if (starterPrompt) {
1080}
1081
1082export default async function cerebras_coder(req: Request): Promise<Response> {
1083 // Dynamic import for SQLite to avoid client-side import
1084 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
1183 <meta property="og:site_name" content="Cerebras Coder">
1184 <meta property="og:url" content="https://cerebrascoder.com"/>
1185 <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."">
1186 <meta property="og:type" content="website">
1187 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">

aqimain.tsx1 match

@siddharth178•Updated 3 months ago
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=5";
3
4export async function aqi(interval: Interval) {
5 const location = "411038"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });

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": "*",