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/$%7Bart_info.art.src%7D?q=function&page=2453&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 28331 results for "function"(6251ms)

servermain.tsx3 matches

@stevekrouse•Updated 9 months ago
4import { Tldraw } from "https://esm.sh/@tldraw/tldraw@2.3.0";
5
6function App() {
7 const [savedDrawings, setSavedDrawings] = useState([]);
8
42}
43
44function client() {
45 createRoot(document.getElementById("root")).render(<App />);
46}
51 handleRequest(req);
52
53async function handleRequest(req: Request): Promise<Response> {
54 const { blob } = await import("https://esm.town/v/std/blob");
55 const url = new URL(req.url);

excalidrawPassmain.tsx2 matches

@all•Updated 9 months ago
1// This approach adds Lucia authentication with signup to the existing Excalidraw implementation.
2// We'll use the luciaMiddleware to handle authentication and redirect unauthenticated users.
3// The Excalidraw functionality will only be accessible to authenticated users.
4
5import { html } from "https://esm.sh/common-tags@1.8.2";
28});
29
30export default luciaMiddleware(async function server(request: Request): Promise<Response> {
31 const username = request.headers.get("X-Lucia-Username");
32 const url = new URL(request.url);

excalidrawPassmain.tsx1 match

@maxm•Updated 9 months ago
1// This approach adds Lucia authentication with signup to the existing Excalidraw implementation.
2// We'll use the luciaMiddleware to handle authentication and redirect unauthenticated users.
3// The Excalidraw functionality will only be accessible to authenticated users.
4
5import { html } from "https://esm.sh/common-tags@1.8.2";

calendlyThisWeekEventsmain.tsx1 match

@ejfox•Updated 9 months ago
7
8// Server-side code
9async function server(request: Request): Promise<Response> {
10 const calendlyToken = Deno.env.get('CALENDLY_TOKEN');
11 if (!calendlyToken) {

sqlitemain.tsx7 matches

@heaversm•Updated 9 months ago
31
32// ------------
33// Functions
34// ------------
35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
49}
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
64}
65
66function createResError(body: string) {
67 try {
68 const e = zLibsqlError.parse(JSON.parse(body));
85}
86
87function normalizeStatement(statement: InStatement, args?: InArgs) {
88 if (Array.isArray(statement)) {
89 // for the case of an array of arrays
107}
108
109function upgradeResultSet(results: ImpoverishedResultSet): ResultSet {
110 return {
111 ...results,
116// adapted from
117// https://github.com/tursodatabase/libsql-client-ts/blob/17dd996b840c950dd22b871adfe4ba0eb4a5ead3/packages/libsql-client/src/sqlite3.ts#L314C1-L337C2
118function rowFromSql(
119 sqlRow: Array<unknown>,
120 columns: Array<string>,

googleCalendarWeekEndpointmain.tsx1 match

@ejfox•Updated 9 months ago
10const SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"];
11
12export default async function server(request: Request): Promise<Response> {
13 const url = new URL(request.url);
14 const path = url.pathname;

valleBlogV0main.tsx4 matches

@heaversm•Updated 9 months ago
8import _ from "npm:lodash@4";
9
10async function main(req: Request): Promise<Response> {
11 const { readable, writable } = new TransformStream();
12 const writer = writable.getWriter();
20 <script>
21 // Scroll to the bottom of the page when the page changes.
22 (new MutationObserver(function (mutationsList, observer) {
23 window.scrollTo({ left: 0, top: document.body.scrollHeight, behavior: "instant" });
24 })).observe(document, { childList: true, characterData: true, subtree: true });
47 Your response should start with \`\`\`ts and end with \`\`\`, so full code fences.
48 There should be no comments like "more content here", it should be complete and directly runnable.
49 The val should have an "export default async function main". The val should return a valid HTML website.
50 Prefer using Tailwind. Put frontend functions in a <script> tag, using dangerouslySetInnerHTML. Don't use Hono. Don't use Response.redirect.
51 `.replace("\n", " "),
52 },

ReactStreamREADME.md4 matches

@lisardo•Updated 9 months ago
7import { render, React } from "https://esm.town/v/jxnblk/ReactStream";
8
9function App() {
10 const [count, setCount] = React.useState(0);
11 return (
62```tsx
63// example middleware
64async function api (req: Request, res: Response, next): Promise<Response> {
65 if (req.pathname !== "/api") return next();
66 if (req.method === "POST") {
78```tsx
79// example middleware
80async function getInitialProps (req: Request, res: Response, next) {
81 // fetch data or do async work to pass as props to the component
82 req.data = {
95import { render } from "https://esm.town/v/jxnblk/ReactStream";
96
97function App () {
98 return (
99 <html>

ReactStreammain.tsx3 matches

@lisardo•Updated 9 months ago
22}
23
24export function render<T>(
25 /** Root-level React component that renders an entire <html> element
26 * including the head and body tags.
41 }
42
43 return async function handler(request: Request): Promise<Response> {
44 const main = reactStream(Component, module);
45 const middleware: Middleware[] = [
76 module: string | false,
77): Middleware =>
78 async function(req: DataRequest, res: Response): Promise<Response> {
79 const { renderToReadableStream } = await import("https://esm.sh/react-dom@18.3.1/server");
80

supremeRedCranemain.tsx1 match

@mvmattgray•Updated 9 months ago
2
3export default async (request) => {
4 // Function to create a standard response with CORS headers
5 const createResponse = (body, status = 200) => {
6 return new Response(body, {

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblk•Updated 1 month ago
Simple functional CSS library for Val Town
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.