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=2536&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 28783 results for "function"(1845ms)

beigeMandrillmain.tsx1 match

@iamseeley•Updated 10 months ago
1export default async function (req: Request): Promise<Response> {
2 const { searchParams } = new URL(req.url);
3

upgradeHTTPPreviewValsmain.tsx4 matches

@stevekrouse•Updated 10 months ago
3import OpenAI from "npm:openai";
4
5async function getVals(username, type, limit) {
6 const res = await db.execute({
7 sql: `
21}
22
23async function checkHTTPPreviewUpgrade(code) {
24 const openai = new OpenAI();
25 const completion = await openai.chat.completions.create({
53 content: `const number = Math.random();
54
55 export default function(req: Request) {
56 return Response.json(number);
57 }`,
80
81/* This example will return the contents of a documentID passed in as the path as JSON. */
82export default async function(req: Request): Promise<Response> {
83 const docId = new URL(req.url).pathname.substring(1);
84

upgradeHTTPPreviewValsREADME.md5 matches

@stevekrouse•Updated 10 months ago
16 "name": "harlequinChickadee",
17 "probabilityUpgradeNeeded": true,
18 "reason": "The current code structure has several functions and program logic outside the main handler, including word selection, game state management, and SVG generation. These parts would not re-run with the new runtime, potentially affecting functionality. They need to be moved inside the handler to ensure consistent behavior across requests."
19 },
20 {
31 "name": "untitled_pinkRoundworm",
32 "probabilityUpgradeNeeded": true,
33 "reason": "The functions `addComment` and `getComments` as well as the initialization \nof the KEY variable perform actions that are intended to be run per request. These need to be moved \ninside the relevant HTTP handler to ensure the behavior remains consistent in the new runtime."
34 },
35 {
46 "name": "untitled_maroonSwallow",
47 "probabilityUpgradeNeeded": false,
48 "reason": "All the code, including the check for authentication,\n is inside the handler function. This means the behavior will stay \n the same with the new runtime."
49 },
50 {
51 "name": "wikiOG",
52 "probabilityUpgradeNeeded": true,
53 "reason": "The function `getWikipediaInfo` defined outside of the handler makes network requests and processes data for each request. In the new runtime, this function would only be executed once and cached. To ensure the same behavior in the new runtime, this function should be moved into the handler."
54 },
55 {
61 "name": "discordEventReceiver",
62 "probabilityUpgradeNeeded": false,
63 "reason": "All the relevant code for handling requests and logging input is inside the handler.\n No code needs to be moved for the new runtime to function correctly."
64 }
65]

sqliteExplorerAppREADME.md1 match

@alongwill•Updated 10 months 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

pinkEgretmain.tsx1 match

@maxm•Updated 10 months ago
1// import { Request, Response } from "./node_modules/express/index.js";
2export default async function(req: Request): Promise<Response> {
3 console.log("Request received:", req);
4

stitchValmain.tsx9 matches

@smca•Updated 10 months ago
89 <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
90 <script>
91 document.addEventListener('DOMContentLoaded', function () {
92 if (typeof THREE === 'undefined') {
93 console.error('THREE is not defined. Make sure Three.js is loaded correctly.');
106 const debugElement = document.getElementById('debug');
107
108 function createTextureCanvas() {
109 const canvas = document.createElement('canvas');
110 const ctx = canvas.getContext('2d');
130 }
131
132 function init() {
133 scene = new THREE.Scene();
134 camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
163 }
164
165 function onMouseMove(event) {
166 currentPoint.set(event.clientX, window.innerHeight - event.clientY);
167 if (isPressed) {
172 }
173
174 function onMouseDown(event) {
175 isPressed = true;
176 clickPoint.set(event.clientX, window.innerHeight - event.clientY);
181 }
182
183 function onMouseUp() {
184 isPressed = false;
185 }
186
187 function updateUniforms() {
188 if (material) {
189 material.uniforms.uClickPoint.value = clickPoint;
194 }
195
196 function onWindowResize() {
197 const width = window.innerWidth;
198 const height = window.innerHeight;
204 }
205
206 function animate() {
207 requestAnimationFrame(animate);
208

SagaImmoScrapermain.tsx2 matches

@matthiasraimann•Updated 10 months ago
3import { JSDOM } from "npm:jsdom";
4
5export async function scrapeSAGA(
6 areas: Area[],
7 maxPrice: number,
59}
60
61function parsePriceToNumber(priceString: string): number {
62 const val = +priceString.replace(/[^0-9,]/g, "").replace(",", ".");
63 return isNaN(val) ? 0 : val;

videoStoragemain.tsx6 matches

@mux•Updated 10 months ago
22)`);
23
24export function rowObjects(data) {
25 return data.rows.map(row => {
26 return data.columns.reduce((obj, column, index) => {
37}
38
39export async function createVideo(webhook: Mux.Webhooks.VideoUploadCreatedWebhookEvent) {
40 const {
41 environment,
65}
66
67export async function updateVideoCreated(webhook: Mux.Webhooks.VideoUploadAssetCreatedWebhookEvent) {
68 const sql = `
69 UPDATE videos
89
90// Just returns the sql statement itself so that we can use `batch` in our backfill script.
91export function backfillVideo(asset: Mux.Video.Asset) {
92 const sql = `
93 INSERT OR IGNORE INTO videos (
156// This is just an upsert in case somehow we get an asset created webhook from something other
157// than our direct upload process.
158export async function updateVideoReady(webhook: Mux.Webhooks.VideoAssetReadyWebhookEvent) {
159 const sql = `
160 INSERT INTO videos (
243}
244
245export async function getAllVideos() {
246 const data = await sqlite.execute(`select * from videos`);
247

stitchValmain.tsx9 matches

@yawnxyz•Updated 10 months ago
89 <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
90 <script>
91 document.addEventListener('DOMContentLoaded', function () {
92 if (typeof THREE === 'undefined') {
93 console.error('THREE is not defined. Make sure Three.js is loaded correctly.');
106 const debugElement = document.getElementById('debug');
107
108 function createTextureCanvas() {
109 const canvas = document.createElement('canvas');
110 const ctx = canvas.getContext('2d');
130 }
131
132 function init() {
133 scene = new THREE.Scene();
134 camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
163 }
164
165 function onMouseMove(event) {
166 currentPoint.set(event.clientX, window.innerHeight - event.clientY);
167 if (isPressed) {
172 }
173
174 function onMouseDown(event) {
175 isPressed = true;
176 clickPoint.set(event.clientX, window.innerHeight - event.clientY);
181 }
182
183 function onMouseUp() {
184 isPressed = false;
185 }
186
187 function updateUniforms() {
188 if (material) {
189 material.uniforms.uClickPoint.value = clickPoint;
194 }
195
196 function onWindowResize() {
197 const width = window.innerWidth;
198 const height = window.innerHeight;
204 }
205
206 function animate() {
207 requestAnimationFrame(animate);
208
31the simplest way to achieve the goal, though you can add some inline comments to explain your
32reasoning (not for every line, but for major groups of lines). Don't use any environment variables
33unless strictly necessary, for example use APIs that don't require a key, prefer internal function
34imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
35functions where possible. Unless specified, don't add error handling,
36make sure that errors bubble up to the caller.
37There should be no comments like "more content here", it should be complete and directly runnable.
38The val should create a "export default async function main" which is the main function that gets
39executed on every HTTP request.
40`.replace("\n", " ");
41
42// Your response should start with \`\`\`ts and end with \`\`\`.
43// The val should create a "export default async function main() {" which
44// is the main function that gets executed, without any arguments. Don't return a Response object,
45// just return a plain Javascript object, array, or string.
46
83 const writer = writable.getWriter();
84 const textEncoder = new TextEncoder();
85 function write(text) {
86 writer.write(textEncoder.encode(text));
87 }
149 </div>
150 <script>
151 function updateValName(valName) {
152 const valUrl = valName ? \`https://val.town/v/${username}/\${valName}\` : "";
153 const previewUrl = valName ? \`https://${username}-\${valName}.web.val.run\` : "";
157 document.getElementById('open-link').href = previewUrl;
158 }
159 function saveVal() {
160 if (window.codeMirrorEditor) {
161 document.getElementById("save-icon").classList.remove("hidden");
177 return false;
178 })
179 function openTab(tab) {
180 const tabButtonCode = document.getElementById("tab-button-code");
181 const tabButtonPreview = document.getElementById("tab-button-preview");
197 }
198 }
199 function toggleTab() {
200 openTab(document.getElementById("tab-panel-code").style.visibility === "visible" ? "preview" : "code");
201 }
255 (() => {
256 const scrollingElement = document.getElementById("conversation-container");
257 const callback = function (mutationsList, observer) {
258 scrollingElement.scrollTo({ left: 0, top: scrollingElement.scrollHeight, behavior: "instant" });
259 };
328 window.setCodeMirrorContent({ doc: '', old: ''});
329 let fullStr = "";
330 window.addToken = function(str) {
331 fullStr += str;
332 const code = fullStr.replaceAll("\`\`\`ts\\n", "").replaceAll("\`\`\`", "");

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 1 month ago
Simple functional CSS library for Val Town
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.