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/image-url.jpg%20%22Image%20title%22?q=function&page=1981&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 30747 results for "function"(4435ms)

OpenTownieButton.tsx1 match

@loading•Updated 2 months ago
177
178// For HTTP vals, render the component
179export default function() {
180 const html = `
181<!DOCTYPE html>

OpenTownieApp.tsx4 matches

@loading•Updated 2 months ago
6import { Projects } from "./Projects.tsx";
7
8function safeParse(s: string) {
9 try {
10 return JSON.parse(s);
14}
15
16export function App() {
17 const [bearerToken, setBearerToken] = useLocalStorage("bearer", "");
18 const [anthropicApiKey, setAnthropicApiKey] = useLocalStorage("anthropic_api_key", "");
20 const [project, setProject_] = useState(safeParse(projectJSON));
21
22 function setProject(p: any) {
23 setProject_(p);
24 setProjectJSON(JSON.stringify(p));
25 }
26
27 function handleLogout() {
28 setBearerToken("");
29 // Keep the anthropic API key in case the user wants to reuse it

OpenTowniefile-editing.ts6 matches

@loading•Updated 2 months ago
2import { ValTown } from "npm:@valtown/sdk@0.37.0";
3
4async function view(
5 vt: ValTown,
6 project: any,
40}
41
42async function str_replace(
43 vt: ValTown,
44 project: any,
78}
79
80async function create(vt: ValTown, project: any, branch_id: string | undefined, path: string, file_text?: string) {
81 let type_: "file" | "http" | "script";
82 if (path.includes("backend/index.ts")) type_ = "http";
99}
100
101async function insert(
102 vt: ValTown,
103 project: any,
135 }
136}
137async function undo_edit(vt: ValTown, project: any, branch_id: string | undefined, path: string) {
138 try {
139 // Get file history
172}
173
174export function getTextEditorTool(bearerToken: string, project: any, branch_id: string | undefined) {
175 const vt = new ValTown({ bearerToken });
176 return anthropic.tools.textEditor_20250124({

wondrousCyanRodentApp.tsx4 matches

@loading•Updated 2 months ago
17
18// Layout component with header and footer
19function Layout() {
20 return (
21 <div className="min-h-screen flex flex-col">
71
72// Home page component
73function HomePage() {
74 const [links, setLinks] = useState<Link[]>([]);
75 const [isLoading, setIsLoading] = useState(true);
124
125// Redirect component
126function RedirectPage() {
127 const { shortId } = useParams<{ shortId: string }>();
128 const navigate = useNavigate();
199
200// Main App component
201export function App() {
202 return <RouterProvider router={router} />;
203}

wondrousCyanRodentNotFound.tsx1 match

@loading•Updated 2 months ago
2import { Link } from "https://esm.sh/react-router-dom@7.0.0-rc.0?deps=react@18.2.0,react-dom@18.2.0";
3
4export function NotFound() {
5 return (
6 <div className="flex flex-col items-center justify-center py-12">

wondrousCyanRodentLinkList.tsx1 match

@loading•Updated 2 months ago
7}
8
9export function LinkList({ links }: LinkListProps) {
10 const [copiedId, setCopiedId] = useState<string | null>(null);
11

accuratePinkPtarmiganmain.tsx3 matches

@toowired•Updated 2 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 const vals = [
7 { name: "notUber", url: "https://www.val.town/embed/vawogbemi/notUber" },
52}
53
54function client() {
55 createRoot(document.getElementById("root")).render(<App />);
56}
60}
61
62export default async function server(request: Request): Promise<Response> {
63 return new Response(`
64 <html>

wondrousCyanRodentCreateLink.tsx1 match

@loading•Updated 2 months ago
7}
8
9export function CreateLink({ onLinkCreated }: CreateLinkProps) {
10 const [url, setUrl] = useState("");
11 const [customShortId, setCustomShortId] = useState("");

wondrousCyanRodentqueries.ts5 matches

@loading•Updated 2 months ago
5
6// Generate a short ID for the URL
7export function generateShortId(length = 6): string {
8 return nanoid(length);
9}
10
11// Create a new shortened link
12export async function createLink(originalUrl: string, customShortId?: string): Promise<Link> {
13 const shortId = customShortId || generateShortId();
14 const createdAt = Date.now();
37
38// Get a link by its short ID
39export async function getLinkByShortId(shortId: string): Promise<Link | null> {
40 const result = await sqlite.execute(
41 `SELECT id, short_id, original_url, created_at, click_count FROM ${LINKS_TABLE} WHERE short_id = ?`,
58
59// Increment the click count for a link
60export async function incrementClickCount(shortId: string): Promise<void> {
61 await sqlite.execute(
62 `UPDATE ${LINKS_TABLE} SET click_count = click_count + 1 WHERE short_id = ?`,
66
67// Get all links
68export async function getAllLinks(): Promise<Link[]> {
69 const result = await sqlite.execute(
70 `SELECT id, short_id, original_url, created_at, click_count FROM ${LINKS_TABLE} ORDER BY created_at DESC`

wondrousCyanRodentmigrations.ts1 match

@loading•Updated 2 months ago
4export const LINKS_TABLE = 'link_shortener_links_v1';
5
6export async function setupDatabase() {
7 // Create the links table if it doesn't exist
8 await sqlite.execute(`
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.