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=1354&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 18949 results for "function"(1970ms)

fifteenPuzzlemain.tsx6 matches

@manyone•Updated 5 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function countInversions(board: number[]) {
6 let inversions = 0;
7 for (let i = 0; i < board.length; i++) {
15}
16
17function isSolvable(board: number[]) {
18 const emptyTileRow = Math.floor(board.indexOf(0) / 4);
19 const inversions = countInversions(board.filter(tile => tile !== 0));
26}
27
28function generateShuffledBoard() {
29 const initialTiles = Array.from({ length: 15 }, (_, i) => i + 1);
30 let board = [...initialTiles, 0];
68}
69
70function SlidingPuzzle() {
71 const [tiles, setTiles] = useState<number[]>([]);
72 const [emptyIndex, setEmptyIndex] = useState<number>(15);
210};
211
212function client() {
213 createRoot(document.getElementById("root")).render(<SlidingPuzzle />);
214}
216if (typeof document !== "undefined") { client(); }
217
218export default async function server(request: Request): Promise<Response> {
219 return new Response(`
220 <html>

zodSchemaPlaygroundmain.tsx7 matches

@feb•Updated 5 months ago
5import * as z from "https://esm.sh/zod@3.21.4";
6
7function Modal({ isOpen, onClose, children }) {
8 if (!isOpen) return null;
9
18}
19
20function App() {
21 const [zodSchema, setZodSchema] = useState(`return z.object({
22 username: z.string().min(3).max(20),
31 useEffect(() => {
32 try {
33 // Wrap the schema in a function to allow for local variables
34 const schemaFunc = new Function("z", zodSchema);
35 const schema = schemaFunc(z);
36 const { node } = zodToTs(schema);
51 <h2>Instructions</h2>
52 <p>
53 Use any zod function from the <code>z</code> object to write your schema. At the end of the input, add a{" "}
54 <code>return</code> statement of the schema you want to see rendered as a Typescript type.
55 </p>
77}
78
79function client() {
80 createRoot(document.getElementById("root")).render(<App />);
81}
85}
86
87export default function server(request: Request): Response {
88 return new Response(
89 `

syllabusmain.tsx2 matches

@rayyan•Updated 5 months ago
2import { Hono } from "npm:hono";
3
4function omit<T>(key: keyof T, obj: T) {
5 const { [key]: omitted, ...rest } = obj;
6 return rest;
7}
8
9function omitKeys<T>(keys: Array<keyof T>, obj: T) {
10 const newObj: Record<keyof T, T[keyof T]> = {};
11 for (const key in obj) {

blitheAmberGrasshoppermain.tsx1 match

@samh434•Updated 5 months ago
2
3// Fetches a random joke.
4function fetchRandomJoke() {
5 const SAMPLE_JOKE = {
6 "setup": "What do you call a group of disorganized cats?",

exaltedAmethystAntelopemain.tsx2 matches

@dcm31•Updated 5 months ago
348
349
350 // Helper function to get the supported MIME type
351 function getSupportedMimeType() {
352 const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
353 const mimeTypes = [

translatormain.tsx2 matches

@dcm31•Updated 5 months ago
291
292
293 // Helper function to get the supported MIME type
294 function getSupportedMimeType() {
295 const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
296 const mimeTypes = [

test_valmain.tsx1 match

@dcm31•Updated 5 months ago
1function main() { return "This is a test val."; }

extractValInfomain.tsx1 match

@escalona•Updated 5 months ago
1export function extractValInfo(url: string | URL) {
2 const { pathname, search } = new URL(url);
3 const [author, filename] = pathname.split("/").slice(-2);

merryOrangeEgretmain.tsx2 matches

@briannafountain•Updated 5 months ago
2
3// Fetches a random joke.
4function fetchRandomJoke() {
5 const SAMPLE_JOKE = {
6 "setup": "What do you call a group of disorganized cats?",
22
23// Fetches a random joke.
24async function fetchRandomJoke() {
25 const response = await fetch(
26 "https://official-joke-api.appspot.com/random_joke",

imaginativeLimeOcelotmain.tsx1 match

@briannafountain•Updated 5 months ago
1function fetchRandomJoke() {
2 const SAMPLE_JOKE = {
3 "setup": "What do you call a group of disorganized cats?",

getFileEmail4 file matches

@shouser•Updated 2 weeks 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
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
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": "*",