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=1490&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 17287 results for "function"(2074ms)

roseDragonmain.tsx1 match

@stevekrouse•Updated 1 year ago
1import { fetch } from "https://esm.town/v/std/fetch";
2
3export async function uploadTo0x0(data, name) {
4 const blob = new Blob([data]);
5 const formData = new FormData();

claudemain.tsx1 match

@yawnxyz•Updated 1 year ago
11};
12
13export async function prompt(
14 text,
15 { mode = "text", model = "opus", max_tokens = 1024, messages = [] } = {},

viewSourcemain.tsx1 match

@crif•Updated 1 year ago
3import { escape } from "npm:html-sloppy-escaper";
4
5export default async function viewSource(req: Request) {
6 const pathname = new URL(req.url).pathname;
7 const html = await fetchText(

telemetrymain.tsx18 matches

@saolsen•Updated 1 year ago
218];
219
220async function migrate() {
221 await std_sqlite.execute(`
222 create table if not exists tracing_schema (
369}
370
371export async function init(
372 url: string | URL,
373): Promise<void> {
394}
395
396export function tracer(): Tracer {
397 return otelTrace.getTracer("val.town");
398}
399
400export function attribute(name: string, value: string): void {
401 otelTrace.getActiveSpan()?.setAttribute(name, value);
402}
403
404export function event(name: string, attrs: Record<string, string>): void {
405 otelTrace.getActiveSpan()?.addEvent(name, attrs);
406}
407
408export function trace<
409 // deno-lint-ignore no-explicit-any
410 F extends (...args: any[]) => any,
428}
429
430export async function traceAsync<
431 // deno-lint-ignore no-explicit-any
432 F extends (...args: any[]) => any,
454}
455
456export function traced<
457 // deno-lint-ignore no-explicit-any
458 F extends (...args: any[]) => any,
459>(name: string, f: F) {
460 return async function (
461 ...args: Parameters<F>
462 ): Promise<Awaited<ReturnType<F>>> {
470 * be tied together.
471 */
472export async function fetch(
473 input: string | URL,
474 init?: RequestInit,
511}
512
513async function tracedExecute(statement: InStatement): Promise<ResultSet> {
514 return await tracer().startActiveSpan(
515 `sqlite:execute`,
544}
545
546async function tracedBatch(
547 statements: InStatement[],
548 mode?: TransactionMode,
603 * Takes an http handler and returns a new handler that
604 * traces the request.
605 * @returns {Function} A new handler that traces the request.
606 */
607export function tracedHandler(
608 handler: (req: Request) => Promise<Response>,
609): (req: Request) => Promise<Response> {
610 async function _tracedHandler(req: Request): Promise<Response> {
611 let active_context = null;
612 const prop_header = req.headers.get("b3");
930
931 const render_spans: SelectSpan[] = [];
932 function push_span(span_id: string) {
933 const span = spans_by_id.get(span_id)!;
934 render_spans.push(span);
1069
1070 const render_spans: SelectSpan[] = [];
1071 function push_span(span_id: string) {
1072 const span = spans_by_id.get(span_id)!;
1073 render_spans.push(span);
1246});
1247
1248export async function traceViewer(req: Request): Promise<Response> {
1249 await migrate();
1250 return await app.fetch(req);

message_processormain.tsx1 match

@curtcox•Updated 1 year ago
1import { command_processor } from "https://esm.town/v/curtcox/command_processor?v=14";
2
3function tail(text: string): string {
4 const trimmed = text.trimStart();
5 const index = trimmed.indexOf(" ");

telemetryREADME.md5 matches

@saolsen•Updated 1 year ago
19await init(import.meta.url);
20
21async function handler(req: Request): Promise<Response> {
22 // whatever else you do.
23 return
63```
64
65* `traced` wraps an async function in tracing.
66
67```typescript
68import { traceAsync } from "https://esm.town/v/saolsen/telemetry";
69
70const myTracedFunction: () => Promise<string> = traced(
71 "myTracedFunction",
72 async () => {
73 // await sleep(100);
77```
78
79* `fetch` is a traced version of the builtin `fetch` function that traces the request. Just import it and use it like you would use `fetch`.
80
81* `sqlite` is a traced version of the val town sqlite client. Just import it and use it like you would use [https://www.val.town/v/std/sqlite](https://www.val.town/v/std/sqlite)

valwritermain.tsx4 matches

@yawnxyz•Updated 1 year ago
9 user: "website that shows the current time",
10 content: `/** @jsxImportSource npm:react */
11export default function() {
12 return <h1>{new Date().toLocaleTimeString()}</h1>;
13}`,
66 );
67});
68export async function compile(description: string) {
69 const messages = [
70 {
74 You write Deno TypeScript.
75 Reply ONLY with valid Typescript.
76 Export the fetch function to run the server.
77 Only use web standard fetch. Export the fetch function to start the server.
78 Add extensive comments`,
79 },

discordEventReceivermain.tsx1 match

@stevekrouse•Updated 1 year ago
1export default async function handler(req: Request) {
2 if (req.method !== 'POST') {
3 return new Response('Method not allowed', { status: 405 });

TodoAppmain.tsx6 matches

@mjweaver01•Updated 1 year ago
5import { Form, hydrate } from "https://esm.town/v/stevekrouse/ssr_react_mini?v=75";
6
7export async function loader(req: Request) {
8 const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
9 const [, { columns, rows }] = await sqlite.batch([
20}
21
22export async function action(req: Request) {
23 const { sqlite } = await import("https://esm.town/v/std/sqlite?v=4");
24 const formData = await req.formData();
47}
48
49export function Component({ initialTodos, initialLogs }) {
50 const [todos, setTodos] = useState(initialTodos);
51 const [logs, setLogs] = useState(initialLogs);
54 useEffect(() => addLog(`Client rendered`), []);
55
56 function addTodo() {
57 setTodos([...todos, { text: newTodo }]);
58 setNewTodo("");
64 }
65
66 function toggleTodo(e) {
67 const formData = new FormData(e.target);
68 const id = parseInt(formData.get("id") as string);
71 }
72
73 function deleteTodo(e) {
74 const formData = new FormData(e.target);
75 const id = parseInt(formData.get("id") as string);

weatherBotmain.tsx11 matches

@jdan•Updated 1 year ago
9 "latLngOfCity": {
10 openAiTool: {
11 type: "function",
12 function: {
13 name: "latLngOfCity",
14 description: "Get the latitude and longitude of a city",
34 "weatherOfLatLon": {
35 openAiTool: {
36 type: "function",
37 function: {
38 name: "weatherOfLatLon",
39 description: "Get the latitude and longitude of a city",
61 "fetchWebpage": {
62 openAiTool: {
63 type: "function",
64 function: {
65 name: "fetchWebpage",
66 description: "Fetch the weather forecast from the contents of a forecast URL",
87];
88
89function truncate(response: string | object) {
90 const TRUNCATE_LEN = 60
91 const responseStr = typeof response === "string" ? response : JSON.stringify(response)
93}
94
95async function runConversation() {
96 const response = await openai.chat.completions.create({
97 messages: transcript,
105 if (message.tool_calls) {
106 for (let i = 0; i < message.tool_calls.length; i++) {
107 console.log("[CALLING]", message.tool_calls[i].function);
108 const tool = toolbox[message.tool_calls[i].function.name];
109 if (tool) {
110 const result = await tool.call(JSON.parse(message.tool_calls[i].function.arguments));
111 console.log("[RESULT]", truncate(result));
112 transcript.push({

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 1 week 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": "*",