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=689&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 7308 results for "function"(653ms)

parseImportMetaproject1 match

@std•Updated 2 months ago
20}
21
22export function parseProject(url: string): Project {
23 const pattern = /^https:\/\/esm\.town\/v\/([^/]+)\/([^@]+)@(\d+)-(.+?)(\/.*)?$/;
24 const match = url.match(pattern);

mathOfTheDayvivaciousBlushMarlin1 match

@charmaine•Updated 2 months ago
1import { email } from "https://esm.town/v/std/email?v=13";
2
3export default async function(interval: Interval) {
4 console.log(`math problem`);
5 email({
1export default async function (interval: Interval) {
2
3}

queuedb13 matches

@maxm•Updated 2 months ago
8const makeTableName = (name: string): string => `${DB_TABLE_PREFIX}${name}`;
9
10export async function addTaskToQueue({ name, args }: { name: string; args: any[] }, options?: {
11 scheduledFor?: Date;
12}) {
17}
18
19export async function getPendingTasks() {
20 return await tasksQuery(
21 `
28}
29
30async function claimTask(id: number) {
31 return await tasksQuery(
32 `UPDATE ${makeTableName("tasks")} SET status = 'processing' WHERE status = 'pending' AND id = ? RETURNING *`,
35}
36
37async function reportError(id: number, error: string) {
38 return await tasksQuery(
39 `UPDATE ${
44}
45
46export async function getTasks() {
47 return await tasksQuery(`SELECT * FROM ${makeTableName("tasks")}`);
48}
49
50export async function markTaskAsCompleted(id: number, result: any) {
51 return await tasksQuery(`UPDATE ${makeTableName("tasks")} SET status = 'completed', result = ? WHERE id = ?`, [
52 JSON.stringify(result),
55}
56
57async function tasksQuery(query: string, args?: InArgs) {
58 const rows = await sqlite.execute(query, args);
59 return (rows.rows as unknown as TaskRow[]).map(taskRowMap);
81};
82
83function taskRowMap(row: TaskRow): Task {
84 return {
85 id: row.id,
92}
93
94export async function runMigrations() {
95 await sqlite.batch([
96 // `DROP TABLE IF EXISTS ${makeTableName("tasks")}`,
109}
110
111export function serializeError(error: unknown): string {
112 // Handle null or undefined
113 if (error === null) return "Error: null";
149// console.log(await getPendingTasks());
150
151async function getUserId() {
152 const resp = await fetch("https://api.val.town/v1/me", {
153 headers: {
166 #startupComplete: boolean = false;
167 #userId: string | undefined;
168 #tasks: Record<string, Function>;
169 #error: Error | undefined;
170
171 #httpEndpoint: string;
172
173 constructor({ httpEndpoint, tasks }: { httpEndpoint: string; tasks: Record<string, Function> }) {
174 this.#tasks = tasks;
175 this.#startupPromise = (async () => {

stevekrouse_dot_comproposal.tsx1 match

@stevekrouse•Updated 2 months ago
3import { Link } from "../helpers.tsx";
4
5export default async function(request: Request) {
6 return new Response(
7 renderToString(

retoolRpchttp1 match

@maxm•Updated 2 months ago
1export default async function(req: Request): Promise<Response> {
2 const url = new URL(req.url);
3 const path = url.pathname.slice(1);

retoolRpcrpcCron1 match

@maxm•Updated 2 months ago
1export default async function (interval: Interval) {
2
3}

retoolRpcfunctions0 matches

@maxm•Updated 2 months ago

rpc_examplesoaringFuchsiaEmu1 match

@charmaine•Updated 2 months ago
1export default async function(interval: Interval) {
2 // this is running rpc register etc. keep it open
3}

rpc_examplehandler4 matches

@charmaine•Updated 2 months ago
1// @val/function
2import { RetoolRPC } from "npm:retoolrpc";
3
4export default async function startRetoolRPC(req) {
5 const rpc = new RetoolRPC({
6 apiToken: Deno.env.get("RETOOL_API_TOKEN"),
26 });
27
28 // Handle function discovery request
29 if (req.method === "GET") {
30 return new Response(
32 status: "success",
33 result: {
34 functionName: "helloWorld",
35 params: {
36 name: { type: "string", description: "Your name", required: true },

getFileEmail4 file matches

@shouser•Updated 5 days ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago