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=941&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 18081 results for "function"(1084ms)

tranquilPurpleMongoosemain.ts1 match

@pomdtr•Updated 2 months ago
1export default function() {
2 return new Response("Hello world!")
3}

linkInBioTemplatemain.tsx1 match

@flamingo•Updated 2 months ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(

reactHonoExampleREADME.md2 matches

@alexwein•Updated 2 months 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`. This routes are called from the React app to refresh and update data.
29
30## Errors

reactHonoExampleREADME.md2 matches

@alexwein•Updated 2 months ago
4
5* `migrations.ts` - code to set up the database tables the app needs
6* `queries.ts` - functions to run queries against those tables, which are imported and used in the main Hono server in `/backend/index.ts`
7
8## Migrations
18The queries file is where running the migrations happen in this app. It'd also be reasonable for that to happen in index.ts, or as is said above, for that line to be commented out, and only run when actual changes are made to your database schema.
19
20The queries file exports functions to get and write data. It relies on shared types and data imported from the `/shared` directory.

reactHonoExamplequeries.ts2 matches

@alexwein•Updated 2 months ago
10await createTables();
11
12export async function getMessages(limit = MESSAGE_LIMIT): Promise<Message[]> {
13 const messages = await sqlite.execute(
14 `SELECT * FROM ${tableName}
20}
21
22export async function insertMessage(content: string) {
23 await sqlite.execute(
24 `INSERT INTO ${tableName} (content)

reactHonoExamplemigrations.ts1 match

@alexwein•Updated 2 months ago
3export const tableName = "reactHonoStarter_messages";
4
5export async function createTables() {
6 await sqlite.batch([
7 `CREATE TABLE IF NOT EXISTS ${tableName} (

reactHonoExampleMessageInput.tsx1 match

@alexwein•Updated 2 months ago
3import type { Message } from "../shared/types.ts";
4
5export function MessageInput({ onSubmit }: { onSubmit: () => void }) {
6 const [message, setMessage] = React.useState("");
7

reactHonoExampleApp.tsx3 matches

@alexwein•Updated 2 months ago
4import { MessageInput } from "./MessageInput.tsx";
5
6export function App(
7 { initialMessages = [], thisProjectURL }: { initialMessages?: Message[]; thisProjectURL?: string },
8) {
41}
42
43function MessageList({ messages }: { messages: Message[] }) {
44 const displayedMessages = messages.slice(0, MESSAGE_LIMIT);
45 return (
50}
51
52function MessageItem({ message }) {
53 const formattedDate = new Date(message.timestamp).toLocaleString();
54

utilsindex.tsx7 matches

@std•Updated 2 months ago
13interface TestCase {
14 name: string;
15 function: () => void;
16}
17
18interface TestCaseResult {
19 name: string;
20 function: () => void;
21 passed: boolean;
22 duration: number;
23}
24
25async function runTest(test: TestCase) {
26 let pass, message;
27 let start = performance.now();
28 try {
29 await test.function();
30 pass = true;
31 } catch (e: any) {
40}
41
42function renderBadge({ label, passedCount, testCount }: { label?: string; passedCount: number; testCount: number }) {
43 return makeBadge({
44 label: label ?? "Tests",
48}
49
50function Badge({ label, passedCount, testCount }: { label?: string; passedCount: number; testCount: number }) {
51 const svgMarkup = renderBadge({ label, passedCount, testCount });
52 const srcDoc = `<body style="margin: 0"}>${svgMarkup}</body>`;
62}
63
64function renderTestResults(testGroups: TestGroup[], outputs: { [groupName: string]: TestOutput[] }) {
65 const totalPassed = Object.values(outputs).flat().filter((output: TestOutput) => output.pass).length;
66 const totalTests = testGroups.reduce((sum, group) => sum + group.tests.length, 0);

utilsexample.test.ts4 matches

@std•Updated 2 months ago
8 {
9 name: "no-op",
10 function: () => {
11 return true;
12 },
14 {
15 name: "passing test",
16 function: () => {
17 expect(1).toBe(1);
18 },
20 {
21 name: "Failing test",
22 function: () => {
23 expect(1).toBe(2);
24 },
31 {
32 name: "passing test 2",
33 function: () => {
34 expect(1).toBe(1);
35 },

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
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": "*",