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/$%7Burl%7D?q=function&page=28&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 19142 results for "function"(957ms)

markdownBlogStarterLayout.tsx1 match

@dev223•Updated 2 days ago
2import type { ReactNode } from "npm:react@18.2.0";
3
4export function Layout({ children }: { children: ReactNode }) {
5 return (
6 <html lang="en">

markdownBlogStarterindex.tsx3 matches

@dev223•Updated 2 days ago
5import { Layout } from "./Layout.tsx";
6
7function PostComponent({ markdown, link }: { markdown: string; link?: string }) {
8 return (
9 <div style={{ border: "1px solid gray", padding: "10px", marginBottom: "20px", borderRadius: "5px" }}>
14}
15
16export default async function(req: Request): Promise<Response> {
17 const url = new URL(req.url);
18 if (url.pathname === "/") {
44}
45
46function html(children: React.ReactNode) {
47 return new Response(
48 renderToString(

reactHonoStarterApp.tsx3 matches

@texoport•Updated 2 days ago
2import { useState } from "https://esm.sh/react@18.2.0";
3
4function add(a: number, b: number) {
5 return a + b;
6}
7
8function subtract(a: number, b: number) {
9 return a - b;
10}
12const result = add(1, 2);
13
14export function App() {
15 const [clicked, setClicked] = useState(0);
16 return (

untitled-6985index.tsx1 match

@texoport•Updated 2 days ago
1/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
2
3export default function Something() {
4 return <div>hi</div>;
5}

French_Bulldogmain.tsx1 match

@ynonp•Updated 2 days ago
33
34
35async function translateWithOpenAI(text: string) {
36 const openai = new OpenAI();
37 const completion = await openai.chat.completions.create({

Mili_Botmain.tsx1 match

@ynonp•Updated 2 days ago
33
34
35async function translateWithOpenAI(text: string) {
36 const openai = new OpenAI();
37 const completion = await openai.chat.completions.create({

gordwameSVGComponent.tsx1 match

@alexwein•Updated 2 days ago
3import React, { useEffect, useRef, useState } from "https://esm.sh/react@18.2.0";
4
5export function SVGComponent({
6 width,
7 height,

RedditScrappermain.js4 matches

@hoangtongvu•Updated 2 days ago
6const clientSecret = "iE3aFgBYsZvCZmyLWOlAhI9pFAQ2-g";
7
8// Function to get the access token
9async function getAccessToken() {
10 const response = await axios.post(
11 "https://www.reddit.com/api/v1/access_token",
51// Fetch all subreddit data
52const results = {};
53async function fetchSubredditData() {
54 const accessToken = await getAccessToken(); // Get access token
55 console.log(accessToken);
79const date = now.tz(timezone).format("DD-MM-YYYY");
80
81(async function main() {
82 await fetchSubredditData();
83

esmtimeouttestmain.tsx1 match

@hacksore•Updated 2 days ago
1export default async function(req: Request): Promise<Response> {
2 const MAX_TIMEOUT = 60_000;
3 const wait = new Promise((resolve) => setTimeout(resolve, MAX_TIMEOUT));

gordwameREADME.md2 matches

@alexwein•Updated 2 days ago
16In a normal server environment, you would likely use a middleware [like this one](https://hono.dev/docs/getting-started/nodejs#serve-static-files) to serve static files. Some frameworks or deployment platforms automatically make any content inside a `public/` folder public.
17
18However in Val Town you need to handle this yourself, and it can be suprisingly difficult to read and serve files in a Val Town Project. This template uses helper functions from [stevekrouse/utils/serve-public](https://www.val.town/x/stevekrouse/utils/branch/main/code/serve-public/README.md), which handle reading project files in a way that will work across branches and forks, automatically transpiles typescript to javascript, and assigns content-types based on the file's extension.
19
20### `index.html`
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors

getFileEmail4 file matches

@shouser•Updated 2 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
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": "*",