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=1375&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 18366 results for "function"(1424ms)

reqEvaltownmain.tsx4 matches

@maxm•Updated 6 months ago
1import net, { AddressInfo } from "node:net";
2
3export default async function(req: Request): Promise<Response> {
4 return serveRequest(
5 req,
6 `data:text/tsx,${
7 encodeURIComponent(`
8export default async function(req: Request): Promise<Response> {
9 return Response.json("I am within a worker!")
10}
14}
15
16export async function serveRequest(req: Request, importUrl: string): Promise<Response> {
17 let port = await getFreePort();
18 const worker = new Worker(`https://esm.town/v/maxm/evaltownWorker?cachebust=${crypto.randomUUID()}`, {
55 });
56
57export async function isPortListening(port: number): Promise<boolean> {
58 let isListening = false;
59 const maxWaitTime = 2000; // ms

valtowntownmain.tsx5 matches

@maxm•Updated 6 months ago
48await contentStore.init();
49
50function Town() {
51 return (
52 <div
69}
70
71function HomePage() {
72 return (
73 <html>
82 <form method="POST" action="/submit">
83 <textarea name="handler" rows={10} cols={50} autoFocus>
84 {`export default async function(req: Request) {
85 return Response.json("Hello, world!");
86}`}
95}
96
97function ContentPage({ handler, id }: { handler: string; id: string }) {
98 return (
99 <html>
122 let originalContent = textarea.value;
123
124 textarea.addEventListener('input', function() {
125 if (textarea.value !== originalContent) {
126 submitButton.style.display = 'inline-block';

ethereumAddressGeneratormain.tsx4 matches

@alfongj•Updated 6 months ago
4import { ethers } from "https://esm.sh/ethers@5.7.2";
5
6function CopyableField({ label, value }) {
7 const copyToClipboard = () => {
8 navigator.clipboard.writeText(value).then(() => {
22}
23
24function App() {
25 const [wallet, setWallet] = useState(null);
26
51}
52
53function client() {
54 createRoot(document.getElementById("root")).render(<App />);
55}
57if (typeof document !== "undefined") { client(); }
58
59export default async function server(request: Request): Promise<Response> {
60 return new Response(`
61 <html>

impressiveAzureJellyfishmain.tsx1 match

@felixnordgren•Updated 6 months ago
1export default async function(req: Request): Promise<Response> {
2 // Setup CORS Headers
3 const headers = new Headers();

discordActivityClientmain.tsx5 matches

@neverstew•Updated 6 months ago
11});
12
13async function setupDiscordSdk() {
14 await discordSdk.ready();
15
73
74/**
75 * This function fetches the current voice channel over RPC. It then creates a
76 * text element that displays the voice channel's name
77 */
78async function appendVoiceChannelName() {
79 const app = document.querySelector("#app");
80 if (!app) {
104
105/**
106 * This function utilizes RPC and HTTP apis, in order show the current guild's avatar
107 * Here are the steps:
108 * 1. From RPC fetch the currently selected voice channel, which contains the voice channel's guild id
111 * 4. Append to the UI an img tag with the related information
112 */
113async function appendGuildAvatar() {
114 const app = document.querySelector("#app");
115 if (!app) {

blobbyFacemain.tsx4 matches

@yawnxyz•Updated 6 months ago
26
27
28async function streamToBuffer(stream) {
29 const chunks = [];
30 const reader = stream.getReader();
41}
42
43async function detectFileType(buffer) {
44 const type = await fileTypeFromBuffer(buffer);
45 // return type ? type.mime : 'unknown';
51
52
53export async function get(key, c) {
54 let result = await blobby.get(key);
55 // console.log('raw result for key:', result, typeof result);
211 newKeyName: '',
212
213 init: async function() {
214 console.log('blobby:', this.blobby);
215 },

arcGISHonoMiddlewaremain.tsx8 matches

@wilt•Updated 6 months ago
6 * for use with Hono instead of Express
7 */
8export function authorize(
9 options: IOAuth2Options,
10 c: Context,
41 * @returns Query string with key and value pairs separated by "&"
42 */
43export function encodeParam(key: string, value: any): string {
44 // For array of arrays, repeat key=value for each element of containing array
45 if (Array.isArray(value) && value[0] && Array.isArray(value[0])) {
58 * @returns An encoded query string.
59 */
60export function encodeQueryString(params: any): string {
61 const newParams = processParams(params);
62 return Object.keys(newParams)
72 * @return A boolean indicating if FormData will be required.
73 */
74export function requiresFormData(params: any) {
75 return Object.keys(params).some((key) => {
76 let value = params[key];
93 case "Date":
94 return false;
95 case "Function":
96 return false;
97 case "Boolean":
112 * @return A new object with properly encoded values.
113 */
114export function processParams(params: any): any {
115 const newParams: any = {};
116
138 // ported from https://github.com/Esri/esri-leaflet/blob/master/src/Request.js#L22-L30
139 // also see https://github.com/Esri/arcgis-rest-js/issues/18:
140 // null, undefined, function are excluded. If you want to send an empty key you need to send an empty string "".
141 switch (type) {
142 case "Array":
157 value = param.valueOf();
158 break;
159 case "Function":
160 value = null;
161 break;

evalUImain.tsx1 match

@maxm•Updated 6 months ago
5import safeJsonValue from "npm:safe-json-value";
6
7export default async function(req: Request): Promise<Response> {
8 if (req.method === "GET") {
9 return new Response(indexHTML, {

evalmain.tsx2 matches

@maxm•Updated 6 months ago
1import safeJsonValue from "npm:safe-json-value";
2
3export async function evalCode(
4 code: string,
5): Promise<{ error: { message: string; name: string; stack: string } } | any> {
43}
44
45function getMainExport(
46 mod: any,
47): { ok: true; value: any } | { ok: false; error: Error } {

fearlessVioletAnteatermain.tsx9 matches

@vawogbemi•Updated 6 months ago
5import confetti from "https://esm.sh/canvas-confetti";
6
7function Instructions() {
8 return (
9 <div className="bg-gray-100 p-4 rounded-xl mb-6">
31}
32
33function TippingForm({ onPaymentSuccess }) {
34 const [amount, setAmount] = useState(20);
35 const [name, setName] = useState("");
148}
149
150function Leaderboard({ payments }) {
151 return (
152 <div className="bg-white p-8 rounded-3xl shadow-md w-full">
165}
166
167function Confetti() {
168 useEffect(() => {
169 const duration = 15 * 1000;
171 const defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 0 };
172
173 function randomInRange(min, max) {
174 return Math.random() * (max - min) + min;
175 }
176
177 const interval = setInterval(function() {
178 const timeLeft = animationEnd - Date.now();
179
200}
201
202function App() {
203 const [payments, setPayments] = useState([]);
204 const [showConfetti, setShowConfetti] = useState(false);
233}
234
235function client() {
236 createRoot(document.getElementById("root")).render(<App />);
237}
241}
242
243export default async function server(req: Request): Promise<Response> {
244 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
245 const SCHEMA_VERSION = 1;

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
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.