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=2324&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 28709 results for "function"(4876ms)

tiny_jest_examplemain.tsx7 matches

@willthereader•Updated 6 months ago
4import { expect, prettify, Test } from "https://esm.sh/tiny-jest@1.1.1";
5
6function App() {
7 const [valUrl, setValUrl] = useState("");
8 const [testCode, setTestCode] = useState("");
56}
57
58function client() {
59 createRoot(document.getElementById("root")).render(<App />);
60}
64}
65
66export default async function server(request: Request): Promise<Response> {
67 if (request.method === "POST" && new URL(request.url).pathname === "/run-tests") {
68 const { valUrl, testCode } = await request.json();
70 try {
71 const userVal = await import(valUrl);
72 const userFunction = userVal.default;
73
74 const { it, run } = new Test("User Tests");
75
76 // Create a function to safely evaluate the user's test code
77 const safeEval = (code: string) => {
78 return new Function("it", "expect", "userFunction", code);
79 };
80
81 // Run the user's test code
82 safeEval(testCode)(it, expect, userFunction);
83
84 const results = await run();

fizzBuzzTestmain.tsx22 matches

@willthereader•Updated 6 months ago
4
5const fizzBuzzTest = `
6// Test the FizzBuzz function
7function runFizzBuzzTests(fizzBuzz) {
8 const tests = [
9 { name: "Return type", test: () => {
92
93try {
94 let fizzBuzzFunction;
95 if (typeof module.default === 'function') {
96 fizzBuzzFunction = module.default;
97 } else if (typeof module === 'function') {
98 fizzBuzzFunction = module;
99 } else {
100 throw new Error('The module does not export a function');
101 }
102 const testResults = runFizzBuzzTests(fizzBuzzFunction);
103 return JSON.stringify(testResults, null, 2);
104} catch (error) {
107`;
108
109function App() {
110 const [valUrl, setValUrl] = useState("");
111 const [results, setResults] = useState(null);
132 <h2>Problem Statement:</h2>
133 <p>
134 Write a function that returns an array of 100 elements (1 to 100 inclusive). The function should do the following:
135 </p>
136 <ul>
141 </ul>
142 <p>
143 Export this function as the default export of your module.
144 </p>
145 </div>
180 <li>Verify that the module is publicly accessible.</li>
181 <li>Check if there are any CORS issues preventing the module from being imported.</li>
182 <li>Make sure your function is exported as the default export or as the module itself.</li>
183 </ul>
184 )}
197}
198
199function client() {
200 createRoot(document.getElementById("root")).render(<App />);
201}
205}
206
207async function runTests(valUrl: string, testCode: string) {
208 try {
209 let module;
215 }
216
217 let testFunction;
218 try {
219 testFunction = new Function("module", testCode);
220 } catch (functionError) {
221 console.error("Function creation error:", functionError);
222 throw new Error(`Failed to create test function: ${functionError.message}`);
223 }
224
225 let testResults;
226 try {
227 testResults = testFunction(module);
228 } catch (testError) {
229 console.error("Test execution error:", testError);
250}
251
252export default async function server(request: Request): Promise<Response> {
253 if (request.method === "POST" && new URL(request.url).pathname === "/run-tests") {
254 const { valUrl, testCode } = await request.json();

fizzBuzzmain.tsx3 matches

@willthereader•Updated 6 months ago
12// check for multiples of three, five, and both.
13
14function FizzBuzz();
15{
16 let result = [];
39// FizzBuzz();
40
41// function test() {
42// let result = [];
43// let count = 0;
58// test();
59
60// function test() {
61// let result = [];
62// let count = 0;

cors_examplemain.tsx2 matches

@stevekrouse•Updated 6 months ago
5const BASE_URL = "https://stevekrouse-cors_example_backend.web.val.run";
6
7export function App() {
8 const [logs, setLogs] = useState([]);
9 async function request(url, options) {
10 try {
11 const response = await fetch(url, options);

bandcampWrappedmain.tsx1 match

@tmcw•Updated 6 months ago
1export default async function(req: Request): Promise<Response> {
2 return new Response(
3 `

bandcampWrappedScriptmain.tsx3 matches

@tmcw•Updated 6 months ago
14]
15
16function esc(string) {
17 return replacements.reduce(function(string, replacement) {
18 return string.replace(replacement[0], replacement[1])
19 }, string)
71 )
72
73 function c(tag, style) {
74 const elem = document.createElement(tag)
75 if (style) elem.style = style

AboutNoelandLiammain.tsx4 matches

@richi1969•Updated 6 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function FAQ({ question, answer }) {
6 const [isOpen, setIsOpen] = useState(false);
7
30}
31
32function GallagherArticle() {
33 const faqs = [
34 {
133}
134
135function client() {
136 createRoot(document.getElementById("root")).render(<GallagherArticle />);
137}
139if (typeof document !== "undefined") { client(); }
140
141export default async function server(request: Request): Promise<Response> {
142 return new Response(`
143 <html>

OasisDiscographymain.tsx6 matches

@richi1969•Updated 6 months ago
134];
135
136function ExternalLinks() {
137 return (
138 <div className="external-links">
159}
160
161function BandIntroduction() {
162 return (
163 <div className="band-introduction">
188}
189
190function AlbumCard({ album }) {
191 return (
192 <div className="album-card">
206}
207
208function App() {
209 return (
210 <div className="oasis-discography">
224}
225
226function client() {
227 createRoot(document.getElementById("root")).render(<App />);
228}
229if (typeof document !== "undefined") { client(); }
230
231export default async function handler(request: Request): Promise<Response> {
232 return new Response(`
233 <html>

blueskyPostButtonmain.tsx3 matches

@lukedenton•Updated 6 months ago
4import { createRoot } from "https://esm.sh/react-dom/client";
5
6function App() {
7 const [message, setMessage] = useState("");
8 const [status, setStatus] = useState("");
82}
83
84function client() {
85 createRoot(document.getElementById("root")).render(<App />);
86}
87if (typeof document !== "undefined") { client(); }
88
89export default async function server(request: Request): Promise<Response> {
90 if (request.method === "POST" && new URL(request.url).pathname === "/post-bluesky") {
91 try {

curiousCyanWalrusmain.tsx1 match

@nicosonic•Updated 6 months ago
2
3// Fetches a random joke.
4function fetchRandomJoke() {
5 const response = fetch(
6 "https://official-joke-api.appspot.com/random_joke",

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.