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/$%7Bart_info.art.src%7D?q=function&page=1562&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 20222 results for "function"(3373ms)

readmeValsmain.tsx1 match

@janpaul123•Updated 6 months ago
2const data = await blob.getJSON("readme-vals.json");
3
4export default async function(req: Request): Promise<Response> {
5 return Response.json(data, {
6 headers: { "Content-Type": "application/json" },

prodigiousTanTurtlemain.tsx21 matches

@ocholap9•Updated 6 months ago
36
37// Main App component
38function App() {
39 const [user, setUser] = useState(null);
40
86
87// Home component
88function Home({ user }) {
89 if (!user) {
90 return <h2>Welcome! Please login or register to use the system.</h2>;
104
105// Login component
106function Login({ setUser }) {
107 const [email, setEmail] = useState('');
108 const [password, setPassword] = useState('');
138
139// Register component
140function Register() {
141 const [email, setEmail] = useState('');
142 const [password, setPassword] = useState('');
175
176// Profile component
177function Profile({ user }) {
178 const [name, setName] = useState(user.name || '');
179 const [phone, setPhone] = useState(user.phone || '');
207
208// Logout component
209function Logout({ setUser }) {
210 const navigate = useNavigate();
211
220
221// Driver Dashboard component
222function DriverDashboard({ user }) {
223 const [vehicles, setVehicles] = useState([]);
224 const [transactions, setTransactions] = useState([]);
271
272// Operator Dashboard component
273function OperatorDashboard({ user }) {
274 const [tollBooths, setTollBooths] = useState([]);
275
307
308// Admin Dashboard component
309function AdminDashboard({ user }) {
310 const [revenueReport, setRevenueReport] = useState(null);
311 const [trafficAnalytics, setTrafficAnalytics] = useState(null);
355
356// Client-side rendering
357function client() {
358 createRoot(document.getElementById("root")).render(<App />);
359}
361
362// Server-side code
363export default async function server(request: Request): Promise<Response> {
364 const { pathname } = new URL(request.url);
365
391}
392
393async function handleApiRequest(request: Request): Promise<Response> {
394 const { pathname } = new URL(request.url);
395 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
467}
468
469async function handleRegister(request: Request, sqlite, KEY, SCHEMA_VERSION) {
470 if (request.method !== 'POST') {
471 return new Response('Method Not Allowed', { status: 405 });
492}
493
494async function handleLogin(request: Request, sqlite, KEY, SCHEMA_VERSION) {
495 if (request.method !== 'POST') {
496 return new Response('Method Not Allowed', { status: 405 });
520}
521
522function generateJWT(user) {
523 // This is a simplified JWT generation.
524 // In a real application, use a proper JWT library and keep the secret secure.
529}
530
531async function handleProfile(request: Request, sqlite, KEY, SCHEMA_VERSION, jwtDecode) {
532 if (request.method !== 'PUT') {
533 return new Response('Method Not Allowed', { status: 405 });
564}
565
566async function handleVehicles(request: Request, sqlite, KEY, SCHEMA_VERSION, jwtDecode) {
567 const token = request.headers.get('Authorization')?.split(' ')[1];
568 if (!token) {
586}
587
588async function handleTransactions(request: Request, sqlite, KEY, SCHEMA_VERSION, jwtDecode) {
589 const token = request.headers.get('Authorization')?.split(' ')[1];
590 if (!token) {
610}
611
612async function handleTollBooths(request: Request, sqlite, KEY, SCHEMA_VERSION, jwtDecode) {
613 const token = request.headers.get('Authorization')?.split(' ')[1];
614 if (!token) {
637}
638
639async function handleRevenueReport(request: Request, sqlite, KEY, SCHEMA_VERSION, jwtDecode) {
640 const token = request.headers.get('Authorization')?.split(' ')[1];
641 if (!token) {
666}
667
668async function handleTrafficAnalytics(request: Request, sqlite, KEY, SCHEMA_VERSION, jwtDecode) {
669 const token = request.headers.get('Authorization')?.split(' ')[1];
670 if (!token) {

usageAlertmain.tsx1 match

@stevekrouse•Updated 6 months ago
2import { email } from "https://esm.town/v/std/email?v=13";
3
4export function usageAlert(handler: (req: Request) => Promise<Response>) {
5 const requestCounts: number[] = [];
6 const LIMIT = 1000;

usageAlertREADME.md1 match

@stevekrouse•Updated 6 months ago
9import { usageAlert } from "https://esm.town/v/stevekrouse/usageAlert"
10
11async function sampleHandler(req: Request): Promise<Response> {
12 return new Response("Hello, World!");
13}

fastCoffeeLizardmain.tsx2 matches

@mvmattgray•Updated 6 months ago
4 const secret = "cfbd87a697526bf25127f998fe6388684b80524be46062a1a79d6dd26b5a6b90";
5
6 async function verifySignature(bodyText, receivedSignature) {
7 const encoder = new TextEncoder();
8 const keyData = encoder.encode(secret);
126
127 <script>
128 async function fetchData() {
129 try {
130 const response = await fetch(window.location.href, { headers: { 'accept': 'application/json' } });

sqliteExplorerAppREADME.md1 match

@robaggio•Updated 6 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
37

whoIsHiringmain.tsx3 matches

@lowlu•Updated 6 months ago
7import About from "https://esm.town/v/vawogbemi/whoIsHiringAbout";
8
9function App() {
10 const tabs = { "/": "Home", "/about": "About" };
11 const [activeTab, setActiveTab] = useState("/");
362}
363
364function ServerApp() {
365 return (
366 <html>
385}
386
387export default async function(req: Request): Promise<Response> {
388 const url = new URL(req.url);
389 if (url.pathname === "/api/stories") {

diligentSapphireOrcamain.tsx5 matches

@gigmx•Updated 6 months ago
1export default async function(req: Request): Response {
2 const url = new URL(req.url);
3
136 const connectionStatus = document.querySelector("#connection-status");
137
138 // Dropdown menu functionality
139 const menuButton = document.getElementById('menuButton');
140 const menuDropdown = document.getElementById('menuDropdown');
209 });
210
211 function parseResponse(text) {
212 const parts = [];
213 let currentText = "";
256 });
257
258 document.getElementById("input").addEventListener("submit", async function(event) {
259 event.preventDefault();
260 const userMessage = event.target.message.value;
359
360 document.querySelectorAll(".suggestion-button").forEach((button)=>{
361 button.addEventListener("click", function() {
362 const input = document.querySelector("input[name=\\"message\\"]");
363 input.value = this.textContent;

wittyTurquoiseDovemain.tsx12 matches

@all•Updated 6 months ago
12}
13
14function QuickCommand({ label, onClick }: { label: string; onClick: () => void }) {
15 return (
16 <button className="quick-command" onClick={onClick}>
20}
21
22function App() {
23 const [prompt, setPrompt] = useState("hello llamapalooza");
24 const [code, setCode] = useState("");
104 label: "Mobile-First Layout",
105 prompt:
106 "Design a Mobile-First Layout that prioritizes mobile device usability and performance, ensuring that the design scales up effectively for larger screens while maintaining functionality and aesthetics on smaller devices.",
107 },
108 {
208 }, []);
209
210 async function fetchSavedSnippets() {
211 const response = await fetch("/snippets");
212 const snippets = await response.json();
214 }
215
216 async function handleSave() {
217 if (!code) return;
218 const response = await fetch("/snippets", {
226 }
227
228 async function handleDelete(id: number) {
229 const response = await fetch(`/snippets/${id}`, { method: "DELETE" });
230 if (response.ok) {
233 }
234
235 async function handleSubmit(e: React.FormEvent) {
236 e.preventDefault();
237 setLoading(true);
257 }
258
259 function handleBack() {
260 if (currentIndex > 0) {
261 setCurrentIndex(currentIndex - 1);
264 }
265
266 function handleForward() {
267 if (currentIndex < history.length - 1) {
268 setCurrentIndex(currentIndex + 1);
391}
392
393function client() {
394 createRoot(document.getElementById("root")!).render(<App />);
395}
399}
400
401function extractCodeFromFence(text: string): string {
402 const htmlMatch = text.match(/```html\n([\s\S]*?)\n```/);
403 return htmlMatch ? htmlMatch[1].trim() : text;
404}
405
406export default async function server(req: Request): Response {
407 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
408 const KEY = "wittyTurquoiseDove";

zwiftPortalScheduleREADME.md1 match

@dazzag24•Updated 6 months ago
47import { email } from "https://esm.town/v/std/email";
48
49export default async function sendZwiftPortalSchedule(interval: Interval) {
50 console.log("Parsing Zwift portal road schedule...");
51

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 3 weeks 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.