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=1191&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 18261 results for "function"(3340ms)

audioManagermain.tsx8 matches

@Foji•Updated 3 months ago
43
44export class AudioManager {
45 constructor(apiKey=null, uploadFunction = null, downloadFunction = null) {
46 this.openai = new OpenAI(apiKey);
47 this.uploadFunction = uploadFunction || this.blobUpload;
48 }
49
50 // valtown blob upload function
51 async blobUpload(buffer, key) {
52 try {
111 console.log(blob instanceof Blob); // Should be true
112 console.log(typeof blob); // Should be true
113 console.log(typeof blob.arrayBuffer); // Should be "function"
114 return blob;
115 }
164
165 async uploadAudio(blob, key) {
166 if (!this.uploadFunction) {
167 console.error("No upload function provided to upload audio");
168 return null;
169 }
170
171 // const buffer = await blob.arrayBuffer();
172 const res = await this.uploadFunction(blob, key);
173 if (res) {
174 return res;
180
181
182 // Function to fetch audio data and return as ArrayBuffer
183 async getAudioBuffer(url) {
184 const response = await fetch(url);

btcPriceAlertmain.tsx2 matches

@bhavesh108•Updated 3 months ago
6const THRESHOLD = 0.1; // 10 %
7
8async function welcome(btcPrice: number) {
9 let formattedBtcPrice = formatAsCurrency(btcPrice);
10 let text = `The BTC price is now ${formattedBtcPrice}.
18}
19
20export async function btcPriceAlert() {
21 let btcPrice = await currency("usd", "btc");
22 const lastBtcPrice: number | undefined = await blob.getJSON("lastBtcPrice");

filemain.tsx4 matches

@loading•Updated 3 months ago
22}
23
24function getFileEmote(file: RTCFile) {
25 const fileType = file.type.split("/")[0];
26 switch (fileType) {
59const buttonHover = Object.values(ButtonHover)[randomIndex];
60
61function App() {
62 const [showModal, setShowModal] = useState(false);
63 const [peerId, setPeerId] = useState("");
376}
377
378function client() {
379 render(<App />, document.getElementById("root")!);
380}
415`;
416
417export default async function server(request: Request): Promise<Response> {
418 const url = new URL(request.url);
419

bombCycloneOutageTrackermain.tsx7 matches

@andreterron•Updated 3 months ago
16import { PSE_OUTAGES_TABLE_NAME } from "https://esm.town/v/andreterron/PSEoutages";
17
18function formatXAxis(tickItem: number | Date) {
19 return format(tickItem, "MMM d h:mmaaa");
20}
21
22function App() {
23 const [outageData, setOutageData] = useState([]);
24 // const [regressionData, setRegressionData] = useState<any[]>([]);
25
26 useEffect(() => {
27 async function fetchData() {
28 const response = await fetch("/outages");
29 const json = await response.json();
46 });
47 });
48 function timeToX(time: number) {
49 return (time - firstEntry.time) / 1000 / 60 / 60 / 24;
50 }
51 function xToTime(x: number) {
52 return x * 60 * 60 * 24 * 1000 + firstEntry.time;
53 }
188}
189
190async function client() {
191 const ReactDOM = await import("https://esm.sh/react-dom@18");
192 console.log(ReactDOM);
196if (typeof document !== "undefined") { client(); }
197
198export default async function server(request: Request): Promise<Response> {
199 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
200

website_Summarizermain.tsx9 matches

@arfan•Updated 3 months ago
4import { createRoot } from "https://esm.sh/react-dom/client";
5
6function ProgressBar({ progress }) {
7 return (
8 <div className="w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700 mb-4">
16}
17
18function SiteDetails({ siteInfo }) {
19 if (!siteInfo) return null;
20
38}
39
40function App() {
41 const [siteUrl, setSiteUrl] = useState("");
42 const [siteInfo, setSiteInfo] = useState(null);
178}
179
180function client() {
181 console.log("Client function called");
182 const root = document.getElementById("root");
183 if (root) {
207}
208
209export default async function server(request: Request): Promise<Response> {
210 console.log("Server function called", request.method, request.url);
211 const { pathname, searchParams } = new URL(request.url);
212
243 <script>
244 console.log("Inline script executed");
245 window.addEventListener('load', function() {
246 console.log("Window load event fired");
247 setTimeout(function() {
248 var loadingMessage = document.getElementById('loading-message');
249 if (loadingMessage) {

epgmain.tsx5 matches

@taoji•Updated 3 months ago
8const EPG_CACHE = new Map();
9
10async function timeoutFetch(request, timeout = Config.FETCH_TIMEOUT) {
11 const controller = new AbortController();
12 const timeoutId = setTimeout(() => controller.abort(), timeout);
28}
29
30function makeRes(body, status = 200, headers = { 'access-control-allow-origin': '*' }) {
31 return new Response(body, {
32 status,
38}
39
40function formatDateTime(time = '') {
41 const now = new Date();
42 const year = now.getFullYear();
54}
55
56async function diypHandle(channel, date, request) {
57 const cacheKey = `${channel}_${date}`;
58 const cachedData = EPG_CACHE.get(cacheKey);
106}
107
108export default async function server(request: Request) {
109 const url = new URL(request.url);
110

geminicodermain.tsx10 matches

@arfan•Updated 3 months ago
23);
24
25function Hero({
26 prompt,
27 setPrompt,
44
45 <p className="text-[#bababa] text-center max-w-[25ch] mx-auto my-4 font-dm-sans">
46 Turn your ideas into fully functional apps in{" "}
47 <span className="relative w-fit text-fuchsia-400 z-10 italic font-semibold rounded-full">
48 less than a second
115}
116
117function App() {
118 const previewRef = React.useRef<HTMLDivElement>(null);
119 const [prompt, setPrompt] = useState("");
169 });
170
171 function handleStarterPromptClick(promptItem: typeof prompts[number]) {
172 setLoading(true);
173 setTimeout(() => handleSubmit(promptItem.prompt), 0);
174 }
175
176 async function handleSubmit(e: React.FormEvent | string) {
177 if (typeof e !== "string") {
178 e.preventDefault();
225 }
226
227 function handleVersionChange(direction: "back" | "forward") {
228 const { currentVersionIndex, versions } = versionHistory;
229 if (direction === "back" && currentVersionIndex > 0) {
928);
929
930function client() {
931 const path = window.location.pathname;
932 const root = createRoot(document.getElementById("root")!);
964}
965
966function extractCodeFromFence(text: string): string {
967 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
968 return htmlMatch ? htmlMatch[1].trim() : text;
969}
970
971async function generateCode(prompt: string, currentCode: string) {
972 const starterPrompt = STARTER_PROMPTS.find(p => p.prompt === prompt);
973 if (starterPrompt) {
1004}
1005
1006export default async function gemini_coder(req: Request): Promise<Response> {
1007 // Dynamic import for SQLite to avoid client-side import
1008 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");

blog_test_25_1_11main.tsx8 matches

@arfan•Updated 3 months ago
15}
16
17function App() {
18 const [posts, setPosts] = useState<BlogPost[]>([]);
19 const [selectedPost, setSelectedPost] = useState<BlogPost | null>(null);
107}
108
109function Sidebar({ posts, onSelectPost, onNewPost }: {
110 posts: BlogPost[];
111 onSelectPost: (post: BlogPost) => void;
156}
157
158function HomePage({ posts }: { posts: BlogPost[] }) {
159 return (
160 <div>
173}
174
175function BlogPost({ post, onEdit }: { post: BlogPost; onEdit: () => void }) {
176 useEffect(() => {
177 Prism.highlightAll();
213}
214
215function PostForm({ post, onSubmit, onClose }: {
216 post?: BlogPost;
217 onSubmit: (post: Omit<BlogPost, "id" | "date">) => void;
267}
268
269function client() {
270 createRoot(document.getElementById("root")).render(<App />);
271}
275}
276
277export default async function server(request: Request): Promise<Response> {
278 const { blob } = await import("https://esm.town/v/std/blob");
279 const url = new URL(request.url);
364 <script type="module" src="${import.meta.url}"></script>
365 <script>
366 function copyToClipboard(text) {
367 navigator.clipboard.writeText(text).then(() => {
368 alert("Copied to clipboard!");

buildWebsitemain.tsx4 matches

@abidiqrar•Updated 3 months ago
10};
11
12function PortfolioApp() {
13 const [activeSection, setActiveSection] = useState("about");
14 const [menuOpen, setMenuOpen] = useState(false);
20 <p>
21 A passionate developer creating beautiful digital experiences.
22 I love turning ideas into elegant, functional solutions.
23 </p>
24 <div className="skills-preview">
100}
101
102function client() {
103 createRoot(document.getElementById("root")).render(<PortfolioApp />);
104}
105if (typeof document !== "undefined") { client(); }
106
107export default async function server(request: Request): Promise<Response> {
108 return new Response(`
109 <html>

beautifulColorfulPortfolioWebsitemain.tsx4 matches

@abidiqrar•Updated 3 months ago
10};
11
12function PortfolioApp() {
13 const [activeSection, setActiveSection] = useState("about");
14 const [menuOpen, setMenuOpen] = useState(false);
20 <p>
21 A passionate developer creating beautiful digital experiences.
22 I love turning ideas into elegant, functional solutions.
23 </p>
24 <div className="skills-preview">
100}
101
102function client() {
103 createRoot(document.getElementById("root")).render(<PortfolioApp />);
104}
105if (typeof document !== "undefined") { client(); }
106
107export default async function server(request: Request): Promise<Response> {
108 return new Response(`
109 <html>

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 2 weeks 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": "*",