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=13&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 30427 results for "function"(2236ms)

chatExampleApp.tsx3 matches

@laurynas•Updated 23 hours ago
5import { useMessages } from "../lib/queries.ts";
6
7export function App(
8 { initialMessages = [], thisProjectURL }: { initialMessages?: Message[]; thisProjectURL?: string },
9) {
75}
76
77function MessageList({ messages }: { messages: Message[] }) {
78 const displayedMessages = messages.slice(0, MESSAGE_LIMIT);
79 return (
84}
85
86function MessageItem({ message }: { message: Message }) {
87 const isUser = message.role === 'user';
88 const formattedDate = message.createdAt

chatExamplerouter.tsx1 match

@laurynas•Updated 23 hours ago
60
61// Export the RouterProvider component with QueryClient
62export function RouterApp() {
63 return (
64 <QueryClientProvider client={queryClient}>

web_iFSIroaOdKmain.tsx1 match

@dhvanil•Updated 23 hours ago
1
2export default async function(req) {
3 return new Response(`undefined`, {
4 headers: { 'Content-Type': 'text/html' }

chatExampleMessageInput.tsx1 match

@laurynas•Updated 23 hours ago
3import { usePostMessage } from "../lib/queries.ts";
4
5export function MessageInput() {
6 const [message, setMessage] = React.useState("");
7 const postMessage = usePostMessage();

web_cc0ooufPcemain.tsx1 match

@dhvanil•Updated 23 hours ago
1
2export default async function(req) {
3 return new Response(`undefined`, {
4 headers: { 'Content-Type': 'text/html' }

aimain.tsx1 match

@quartex•Updated 1 day ago
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true })
3}

chatExampleREADME.md1 match

@laurynas•Updated 1 day ago
65### Query
66```tsx
67export function usePostMessage() {
68 return useMutation({
69 mutationFn: (content: string) => postMessage(content),

chatExampleREADME.md2 matches

@laurynas•Updated 1 day 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

chatExampleREADME.md2 matches

@laurynas•Updated 1 day 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.

chatExamplequeries.ts2 matches

@laurynas•Updated 1 day ago
3
4// Fetch messages query
5export function useMessages(initialData?: Message[]) {
6 return useQuery({
7 queryKey: ["messages"],
20
21// Post message mutation
22export function usePostMessage() {
23 const queryClient = useQueryClient();
24
tuna

tuna9 file matches

@jxnblk•Updated 1 week ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
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.