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=790&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 8390 results for "function"(498ms)

niceTodoListmain.tsx1 match

@maxmUpdated 8 months ago
8
9// Server-side only code
10export default async function server(request: Request): Promise<Response> {
11 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
12 const SCHEMA_VERSION = 1

test_migratedmain.tsx5 matches

@jxnblkUpdated 8 months ago
2import { render } from "npm:preact-render-to-string";
3
4export function it(name, fn) {
5 const ok = "✅ [OK]: ";
6 const fail = "❌ [FAIL]: ";
15}
16
17export function describe(name, run) {
18 console.log(name);
19 return async function(req: Request): Promise<Response> {
20 await run();
21 return Response.json({ ok: true, status: 200 });
34};
35
36function Badge({ status }: BadgeProps) {
37 const color = colors[status];
38 const label = status ? status.toUpperCase() : "N/A";
68}
69
70export default async function(req: Request): Promise<Response> {
71 const params = new URL(req.url).searchParams;
72 const valURL = params.get("url");

memeGeneratormain.tsx4 matches

@stevekrouseUpdated 8 months ago
21}
22
23function App() {
24 const [templates, setTemplates] = useState<MemeTemplate[]>([]);
25 const [selectedTemplate, setSelectedTemplate] = useState<string>("");
94 const [topPosition, bottomPosition] = getTextPositions(image.width, image.height, selectedTemplate);
95
96 // Function to draw text with word wrap
97 const drawText = (text: string, position: TextPosition) => {
98 ctx.fillStyle = position.color;
172}
173
174function client() {
175 createRoot(document.getElementById("root")).render(<App />);
176}
178if (typeof document !== "undefined") { client(); }
179
180async function server(request: Request): Promise<Response> {
181 const url = new URL(request.url);
182

zod_demo_frontendmain.tsx1 match

@stevekrouseUpdated 8 months ago
4import type { User } from "https://esm.town/v/stevekrouse/zod_demo_shared";
5
6export function App() {
7 const [user, setUser] = useState<User>({ username: "", email: "", age: 0 });
8 const [errors, setErrors] = useState<Partial<User>>({});

zod_demo_httpmain.tsx1 match

@stevekrouseUpdated 8 months ago
2import { UserSchema } from "https://esm.town/v/stevekrouse/zod_demo_shared";
3
4async function server(request: Request): Promise<Response> {
5 if (request.method === "POST" && new URL(request.url).pathname === "/register") {
6 try {

hnmain.tsx3 matches

@maxmUpdated 8 months ago
16`);
17
18function createErrorPage(title: string, message: string): string {
19 return `
20 <html>
108};
109
110function injectNotificationIndicator(html: string): string {
111 const notificationCount = 21; // Hardcoded for now
112 const notificationIndicator = `
125}
126
127export default async function(req: Request): Promise<Response> {
128 const url = new URL(req.url);
129 let userCookie: string | undefined;

emailmain.tsx1 match

@shouserUpdated 8 months ago
12 * The email address(es) to send the email to. Only available to Val Town Pro subscribers.
13 * Can be a single string, IAddress object, or an array of strings/IAddress objects.
14 * @default the email of the logged user calling this function.
15 */
16 to?: (IAddress | string)[] | IAddress | string;

egoBoostermain.tsx3 matches

@stevekrouseUpdated 8 months ago
10import { marked } from "https://esm.sh/marked";
11
12function App() {
13 const [compliments, setCompliments] = useState<string>("");
14 const [isLoading, setIsLoading] = useState(false);
160}
161
162function client() {
163 console.log("Client-side rendering started");
164 createRoot(document.getElementById("root")!).render(<App />);
171}
172
173async function server(request: Request): Promise<Response> {
174 console.log("Server received request:", request.method, new URL(request.url).pathname);
175

lucia_sqlitemain.tsx5 matches

@stevekrouseUpdated 8 months ago
4import { generateId, Scrypt } from "npm:lucia";
5
6export async function createTables(userTable: string, sessionTable: string) {
7 return sqlite.batch([
8 `CREATE TABLE ${userTable} (
20}
21
22async function safeExecute({ userTable, sessionTable, query, error }: {
23 userTable: string;
24 sessionTable: string;
38}
39
40export async function createUser({ userTable, sessionTable, username, password }: {
41 userTable: string;
42 sessionTable: string;
58}
59
60export async function getUser(
61 { userTable, sessionTable, username },
62): Promise<{ id: string; username: string; hashed_password: string } | null> {
74}
75
76export async function verifyPassword(hashed_password: string, password: string): Promise<boolean> {
77 return new Scrypt().verify(hashed_password, password);
78}

dateme_browse_reactmain.tsx7 matches

@stevekrouseUpdated 8 months ago
5import { nominatimSearch } from "https://esm.town/v/stevekrouse/nominatimSearch";
6
7function absoluteURL(url) {
8 if (url.startsWith("http://") || url.startsWith("https://"))
9 return url;
25let linkClass = "text-sky-600 hover:text-sky-500";
26
27function httpsIfy(url: string) {
28 if (!url.startsWith("http://") && !url.startsWith("https://")) {
29 return `https://${url}`;
33
34// TODO - refactor this into a Cell React component
35function renderCell(header, row) {
36 let data = row[header];
37 if (header === "Name") {
47}
48
49function convertParams(url) {
50 const params = new URL(url).searchParams;
51 const search = {
62const metersInMile = 1609.34;
63
64function withinRadius(
65 profileLocation: string[],
66 searchLocation: { lat: number; lon: number },
75}
76
77export async function loader({ request }) {
78 "use server"; // this is not a real feature; just me reminding myself I'm on the server
79 const { zip } = await import("npm:lodash-es");
117}
118
119export function Browse() {
120 const search = convertParams(window.location.href);
121 const { profiles } = useLoaderData() as any; // TODO - get good typing

getFileEmail4 file matches

@shouserUpdated 1 week ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemiUpdated 2 months ago