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/image-url.jpg%20%22Optional%20title%22?q=function&page=77&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 30366 results for "function"(2763ms)

stevensDemoApp.tsx2 matches

@swampstrathโ€ขUpdated 3 days ago
62};
63
64export function App() {
65 const [memories, setMemories] = useState<Memory[]>([]);
66 const [loading, setLoading] = useState(true);
139 const data = await response.json();
140
141 // Change the sorting function to show memories in chronological order
142 const sortedMemories = [...data].sort((a, b) => {
143 const dateA = a.createdDate || 0;

glancerContentCheckoutEmbedmain.tsx1 match

@glanceโ€ขUpdated 3 days ago
2import { useState } from "https://esm.sh/react@18.2.0";
3
4export function CheckoutContent({ data, content }) {
5 // const { content, contentURL, docsURL } = config;
6 // console.log("content: ", content);

sqliteExplorerAppREADME.md1 match

@hfmโ€ขUpdated 3 days ago
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
35- [x] add export to CSV, and JSON (CSV and JSON helper functions written in [this val](https://www.val.town/v/nbbaier/sqliteExportHelpers). Thanks to @pomdtr for merging the initial version!)
36- [x] add listener for cmd+enter to submit query
37

vtEditorFilesvaltown.mdc12 matches

@nbbaierโ€ขUpdated 3 days ago
9
10- Ask clarifying questions when requirements are ambiguous
11- Provide complete, functional solutions rather than skeleton implementations
12- Test your logic against edge cases before presenting the final solution
13- Ensure all code follows Val Town's specific platform requirements
22- **Never bake in secrets into the code** - always use environment variables
23- Include comments explaining complex logic (avoid commenting obvious operations)
24- Follow modern ES6+ conventions and functional programming practices if possible
25
26## Types of triggers
33
34```ts
35export default async function (req: Request) {
36 return new Response("Hello World");
37}
45
46```ts
47export default async function () {
48 // Scheduled task code
49}
57
58```ts
59export default async function (email: Email) {
60 // Process email
61}
65## Val Town Standard Libraries
66
67Val Town provides several hosted services and utility functions.
68
69### Blob Storage
119```
120
121## Val Town Utility Functions
122
123Val Town provides several utility functions to help with common project tasks.
124
125### Importing Utilities
181โ”‚ โ”œโ”€โ”€ database/
182โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
183โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
184โ”‚ โ”‚ โ””โ”€โ”€ README.md
185โ”‚ โ””โ”€โ”€ routes/ # Route modules
200โ””โ”€โ”€ shared/
201 โ”œโ”€โ”€ README.md
202 โ””โ”€โ”€ utils.ts # Shared types and functions
203```
204
208- Main entry point should be `backend/index.ts`
209- Do NOT use Hono serveStatic middleware
210- **Static asset serving:** Use the utility functions to read and serve project files:
211 ```ts
212 import { readFile, serveFile } from "https://esm.town/v/std/utils/index.ts";
242- Run migrations on startup or comment out for performance
243- Change table names when modifying schemas rather than altering
244- Export clear query functions with proper TypeScript typing
245
246## Common Gotchas and Solutions

vtEditorFiles.cursorrules12 matches

@nbbaierโ€ขUpdated 3 days ago
4
5- Ask clarifying questions when requirements are ambiguous
6- Provide complete, functional solutions rather than skeleton implementations
7- Test your logic against edge cases before presenting the final solution
8- Ensure all code follows Val Town's specific platform requirements
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
19- Follow modern ES6+ conventions and functional programming practices if possible
20
21## Types of triggers
28
29```ts
30export default async function (req: Request) {
31 return new Response("Hello World");
32}
42
43```ts
44export default async function () {
45 // Scheduled task code
46}
56
57```ts
58export default async function (email: Email) {
59 // Process email
60}
66## Val Town Standard Libraries
67
68Val Town provides several hosted services and utility functions.
69
70### Blob Storage
120```
121
122## Val Town Utility Functions
123
124Val Town provides several utility functions to help with common project tasks.
125
126### Importing Utilities
200โ”‚ โ”œโ”€โ”€ database/
201โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
202โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
203โ”‚ โ”‚ โ””โ”€โ”€ README.md
204โ”‚ โ””โ”€โ”€ routes/ # Route modules
219โ””โ”€โ”€ shared/
220 โ”œโ”€โ”€ README.md
221 โ””โ”€โ”€ utils.ts # Shared types and functions
222```
223
226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
229 ```ts
230 import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
262- Export clear query functions with proper TypeScript typing
263
264## Common Gotchas and Solutions

untitled-3259main.tsx2 matches

@jacklumenโ€ขUpdated 3 days ago
1export default async function(req: Request): Promise<Response> {
2 const html = <!DOCTYPE html>
3<html>
15 const { createRoot } = ReactDOM;
16
17 function BatchSubmit() {
18 const [inputData, setInputData] = useState('');
19 const [isSubmitting, setIsSubmitting] = useState(false);

goodmotorsmain.tsx30 matches

@ncfโ€ขUpdated 3 days ago
15var popupOpenTime = 0;
16
17function addToParams(k, v) {
18 sendParams[k] = v;
19 console.log(sendParams);
20}
21
22function openAppWithParams(type, path) {
23 if (type === "catalogue") {
24 const queryString = new URLSearchParams(sendParams).toString();
33}
34
35function getParams() {
36 // Get the current URL's query parameters
37 queryParams = new URLSearchParams(window.location.search);
43}
44
45function replaceParams() {
46 // Get the current URL's query parameters
47 destination = document.querySelectorAll("[query-get]");
58}
59
60function getCurrentLang() {
61 lang = Weglot.getCurrentLang();
62 const currentLang = lang;
67
68 // Remove existing language prefix from the URL
69 function cleanUrl(langCode) {
70 let path = window.location.pathname;
71
108}
109
110function insertIframe() {
111 console.log("iframe start instering");
112
129}
130
131function removeBg() {
132 console.log("removing");
133 // document.getElementById("popupContent").contentWindow.document.querySelectorAll("html")[0].style="";
134}
135
136function addDisplayMap() {
137 feedDisplayMap();
138 document.getElementById("popupContent").src = urlPopup + "&lang=" + lang + "&device=" + device + mapValue;
139 popupOpenTime = 1;
140}
141function addDisplayNoMap() {
142 removeDisplayMap();
143 document.getElementById("popupContent").src = urlPopup + "&lang=" + lang + "&device=" + device + mapValue;
145}
146
147function addMotoModel(value) {
148 document.getElementById("popupContent").src = urlPopup + "&lang=" + lang + "&device=" + device + "&model_slug="
149 + value + mapValue;
151}
152
153function addParkingId(value) {
154 document.getElementById("popupContent").src = urlPopup + "&lang=" + lang + "&parking_id=" + value + "&device="
155 + device + mapValue;
156 popupOpenTime = 1;
157}
158function addCityName(value) {
159 document.getElementById("popupContent").src = urlPopup + "&lang=" + lang + "&queryAutoFill=" + value + "&device="
160 + device + mapValue;
161 popupOpenTime = 1;
162}
163function feedDisplayMap() {
164 mapValue = "&display=map";
165 stylePopupForMapOn();
166}
167
168function stylePopupForMapOn() {
169 const container = document.getElementById(idPopupTarget);
170 container.style.height = "100%";
174 document.getElementById("closebtn").classList.add("opacity-100");
175}
176function stylePopupForMapOff() {
177 const container = document.getElementById(idPopupTarget);
178 container.style.height = "84%";
183}
184
185function removeDisplayMap() {
186 mapValue = "";
187 stylePopupForMapOff();
188}
189function calcDevice() {
190 if (window.innerWidth > 980) {
191 device = "desktop";
196}
197
198function InitPage() {
199 console.log("DOM and all resources are loaded!");
200 getParams();
223 // Ajouter un event listener ร  chaque รฉlรฉment
224 model_slug_array.forEach(element => {
225 element.addEventListener("click", function(event) {
226 const value = element.getAttribute("model_slug");
227 model_slug = value;
233 // Ajouter un event listener ร  chaque รฉlรฉment
234 parking_id_array.forEach(element => {
235 element.addEventListener("click", function(event) {
236 const value = element.getAttribute("parking_id");
237 addToParams("parking_id", value);
283 // Ajouter un event listener ร  chaque รฉlรฉment
284 change_page.forEach(element => {
285 element.addEventListener("click", function(event) {
286 openAppWithParams("moto", "/app/moto/");
287 });
293 if ((sendParams["start_date"] && sendParams["start_date"] && sendParams["parking_id"]) == true) {
294 element.textContent = "voir les dispooo";
295 element.addEventListener("click", function(event) {
296 openAppWithParams("catalogue", "/app/catalogue/?");
297 });
303}
304
305function blurNavBar(bool) {
306 // Select the div with the specific data-w-id attribute
307 const targetDiv = document.querySelector("#backdrop-blur");
348 // Check if the scroll position is at the top
349 if (window.scrollY === 0) {
350 blurNavBar(false); // Call the test function
351 } else {
352 blurNavBar(true);
355
356// On page load
357function addParamsToSrc() {
358 const pathname = window.location.pathname;
359 // Check if the URL contains "/parking/"
376
377document.querySelectorAll("[redirectTo]").forEach(element => {
378 element.addEventListener("click", function(event) {
379 event.preventDefault();
380 window.location.href = baseUrl + "/" + element.getAttribute("redirectTo") + "?lang=" + lang;
382});
383document.querySelectorAll("[redirectToMotoCommerciale]").forEach(element => {
384 element.addEventListener("click", function(event) {
385 event.preventDefault();
386 if (document.querySelectorAll("[data-parking-id]").length > 0) {
395});
396document.querySelectorAll("[redirectToCatalogue]").forEach(element => {
397 element.addEventListener("click", function(event) {
398 event.preventDefault();
399 if (element.getAttribute("parking_id")) {
406});
407
408function styleFirstCardMobile() {
409 if (
410 (window.innerWidth < 768) && (document.querySelectorAll(".motos-container > .motos-content-wrapper").length > 0)

SamuelYProfilemain.tsx2 matches

@pureheartโ€ขUpdated 3 days ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(
22 <p style='color: gray; text-align: center;'>Redirecting...</p>
23 \`;
24 setTimeout(function() {
25 window.location.href = "https://google.com";
26 }, 3000); // 3-second delay

Gemeprofilesmain.tsx2 matches

@pureheartโ€ขUpdated 3 days ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(
22 <p style='color: gray; text-align: center;'>Redirecting...</p>
23 \`;
24 setTimeout(function() {
25 window.location.href = "https://google.com";
26 }, 3000); // 3-second delay

one-netmain.tsx23 matches

@onebulaโ€ขUpdated 3 days ago
114 * @param {import("@cloudflare/workers-types").Request} request
115 */
116async function vlessOverWSHandler(request) {
117
118 /** @type {import("@cloudflare/workers-types").WebSocket[]} */
216 * @param {import("@cloudflare/workers-types").WebSocket} webSocket The WebSocket to pass the remote socket to.
217 * @param {Uint8Array} vlessResponseHeader The VLESS response header.
218 * @param {function} log The logging function.
219 * @returns {Promise<void>} The remote socket.
220 */
221async function handleTCPOutBound(remoteSocket, addressType, addressRemote, portRemote, rawClientData, webSocket, vlessResponseHeader, log,) {
222 async function connectAndWrite(address, port, socks = false) {
223 /** @type {import("@cloudflare/workers-types").Socket} */
224 const tcpSocket = socks ? await socks5Connect(addressType, address, port, log)
236
237 // if the cf connect tcp socket have no incoming data, we retry to redirect ip
238 async function retry() {
239 if (enableSocks) {
240 tcpSocket = await connectAndWrite(addressRemote, portRemote, true);
264 * @param {(info: string)=> void} log for ws 0rtt
265 */
266function makeReadableWebSocketStream(webSocketServer, earlyDataHeader, log) {
267 let readableStreamCancel = false;
268 const stream = new ReadableStream({
333 * @returns
334 */
335function processVlessHeader(
336 vlessBuffer,
337 userID
454 * @param {*} log
455 */
456async function remoteSocketToWS(remoteSocket, webSocket, vlessResponseHeader, retry, log) {
457 // remote--> ws
458 let remoteChunkCount = 0;
522 * @returns
523 */
524function base64ToArrayBuffer(base64Str) {
525 if (!base64Str) {
526 return { error: null };
541 * @param {string} uuid
542 */
543function isValidUUID(uuid) {
544 const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
545 return uuidRegex.test(uuid);
552 * @param {import("@cloudflare/workers-types").WebSocket} socket
553 */
554function safeCloseWebSocket(socket) {
555 try {
556 if (socket.readyState === WS_READY_STATE_OPEN || socket.readyState === WS_READY_STATE_CLOSING) {
566 byteToHex.push((i + 256).toString(16).slice(1));
567}
568function unsafeStringify(arr, offset = 0) {
569 return (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
570}
571function stringify(arr, offset = 0) {
572 const uuid = unsafeStringify(arr, offset);
573 if (!isValidUUID(uuid)) {
584 * @param {(string)=> void} log
585 */
586async function handleDNSQuery(udpChunk, webSocket, vlessResponseHeader, log) {
587 // no matter which DNS server client send, we alwasy use hard code one.
588 // beacsue someof DNS server is not support DNS over TCP
632 * @param {string} addressRemote
633 * @param {number} portRemote
634 * @param {function} log The logging function.
635 */
636async function socks5Connect(addressType, addressRemote, portRemote, log) {
637 const { username, password, hostname, port } = parsedSocks5Address;
638 // Connect to the SOCKS server
771 * @param {string} address
772 */
773function socks5AddressParser(address) {
774 let [latter, former] = address.split("@").reverse();
775 let username, password, hostname, port;
799}
800
801function revertFakeInfo(content, userID, hostName, isBase64) {
802 if (isBase64) content = atob(content);//Base64่งฃ็ 
803 content = content.replace(new RegExp(fakeUserID, 'g'), userID).replace(new RegExp(fakeHostName, 'g'), hostName);
807}
808
809function generateRandomNumber() {
810 let minNum = 100000;
811 let maxNum = 999999;
813}
814
815function generateRandomString() {
816 let minLength = 2;
817 let maxLength = 3;
825}
826
827function generateUUID() {
828 let uuid = '';
829 for (let i = 0; i < 32; i++) {
845 * @returns {Promise<string>}
846 */
847async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) {
848 // ๅฆ‚ๆžœsubไธบ็ฉบ๏ผŒๅˆ™ๆ˜พ็คบๅŽŸๅง‹ๅ†…ๅฎน
849 if (!sub || sub === '') {
918 `;
919 } else {
920 if (typeof fetch != 'function') {
921 return 'Error: fetch is not available in this environment.';
922 }
tuna

tuna9 file matches

@jxnblkโ€ขUpdated 1 week 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.