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=1650&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 18165 results for "function"(1439ms)

testRunnermain.tsx1 match

@karfau•Updated 1 year ago
2import { sleep } from "https://esm.town/v/stevekrouse/sleep?v=1";
3
4export async function testRunner<
5 Input extends {
6 val?: Ref;

singleformulaEndpointmain.tsx24 matches

@syncretizm•Updated 1 year ago
1const functionMap = {
2 // Basic Arithmetic Operations, with checks for type as numbers
3 "add": (a, b) => typeof a === "number" && typeof b === "number" ? a + b : null,
84 "datebetween": (startDate, endDate, unit) => {
85 if (!startDate || !endDate || typeof unit !== "string") {
86 return new Response("Invalid arguments for datebetween function");
87 }
88 let difference = Math.abs(endDate - startDate);
160 // Conditional logic with checks
161 "if": (a, b, c) => {
162 console.log(`if function called with a: ${a}, b: ${b}, c: ${c}`);
163 const result = a ? b : c;
164 console.log(`if function result: ${result}`);
165 return result;
166 },
175};
176
177function tokenize(formula) {
178 const tokens = [];
179 const functionsRegex = new RegExp(`\\b(${Object.keys(functionMap).join("|")})\\b`, "g");
180 const tokenRegex = new RegExp(
181 `(\\[\\[date:\\d{4}-\\d{2}-\\d{2}\\]\\])|`
182 + `${functionsRegex.source}|`
183 + `("(?:[^"\\\\]|\\\\.)*")|` // Match double-quoted strings
184 + `(-?\\d+(?:\\.\\d+)?)|` // Match numbers (including negative and decimal numbers)
203}
204
205function parse(tokens) {
206 let position = 0;
207
208 function peek() {
209 return tokens[position];
210 }
211
212 function consume() {
213 position++;
214 }
215
216 function isNumber(token) {
217 return !isNaN(parseFloat(token)) && isFinite(token);
218 }
219
220 function isString(token) {
221 return token.startsWith("\"") && token.endsWith("\"");
222 }
223
224 function parsePrimaryExpr() {
225 const token = peek();
226 if (token === "Yes") {
239 consume();
240 return { type: "date", value: token.slice(7, -2) };
241 } else if (token && functionMap[token]) {
242 consume();
243 return { type: "function", name: token };
244 } else if (token.match(/^[a-zA-Z_]+$/)) {
245 consume();
256 }
257
258 function parseExpr() {
259 let expr = parsePrimaryExpr();
260 while (peek() === "(") {
283}
284
285function evaluate(ast) {
286 console.log(`Evaluating node: ${JSON.stringify(ast)}`);
287
288 if (typeof ast !== "object" || ast === null || typeof ast.type === "undefined") {
289 throw new Error("Invalid input to evaluate function: Input must be an AST object");
290 }
291
298 return new Date(ast.value);
299 case "call":
300 if (typeof functionMap[ast.name] !== "function") {
301 throw new Error(`Function '${ast.name}' not found in functionMap`);
302 }
303 const argsEvaluated = ast.args.map(arg => evaluate(arg));
304 const result = functionMap[ast.name](...argsEvaluated);
305 if (result === null || result === undefined) {
306 throw new Error(`Function '${ast.name}' returned null or undefined`);
307 }
308 return result;
321 }
322 } catch (error) {
323 console.error(`Error in evaluate function: ${error.message} for AST node ${JSON.stringify(ast)}`, error);
324 throw error;
325 }
326}
327
328export async function FormulaEndpoint(req) {
329 const url = new URL(req.url);
330 console.log(`Received request with URL: ${req.url}`);

twEndpointmain.tsx1 match

@syncretizm•Updated 1 year ago
2import process from "node:process";
3
4export async function extractTwitterContent(req) {
5 try {
6 console.log("Starting to extract Twitter content...");

uploadmain.tsx1 match

@garlen20o•Updated 1 year ago
1export function uploadTemp(req) {
2 return Response.json({
3 code: 200,

findIdeaListsmain.tsx1 match

@nbbaier•Updated 1 year ago
3import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
4
5export default async function() {
6 let { data: articles } = await api(`/v1/search/vals?query=${encodeURIComponent("@vtIdeas")}`);
7

valtownIdeasmain.tsx1 match

@pomdtr•Updated 1 year ago
6import { html } from "https://esm.town/v/stevekrouse/html?v=5";
7
8export async function examplePost(req: Request) {
9 const { author, name } = extractValInfo(import.meta.url);
10

emailJasonAboutValTownmain.tsx2 matches

@petermillspaugh•Updated 1 year ago
1import { email } from "https://esm.town/v/std/email?v=11";
2
3export default async function emailJasonAboutValTown(interval: Interval) {
4 // no-op if it's not 2024: I don't want to email Jason every year!
5 const is2024 = new Date().getFullYear() === 2024;
10 <p>Hey Jason, following up on our conversation back in December about getting Steve Krouse on LWJ to explore Val Town with you!</p>
11 <p>Hope all is well, Pete</p>
12 <p><em>(This email was sent programmatically via a val.town scheduled function.)</em></p>
13 </main>
14 `;

vtWishListmain.tsx1 match

@nbbaier•Updated 1 year ago
7import { html } from "https://esm.town/v/stevekrouse/html?v=5";
8
9export async function examplePost(req: Request) {
10 const { author, name } = extractValInfo(import.meta.url);
11 const { code, readme } = await api(`/v1/alias/${author}/${name}`);

vtIdeasTemplatemain.tsx1 match

@nbbaier•Updated 1 year ago
3import { html } from "https://esm.town/v/stevekrouse/html?v=5";
4
5export async function examplePost(req: Request) {
6 const { author, name } = extractValInfo(import.meta.url);
7

downloadmain.tsx1 match

@kutan•Updated 1 year ago
2import Jimp from "npm:jimp";
3
4export async function download(req: Request): Promise<Response> {
5 // Return the picture as a response
6 const searchParams = new URL(req.url).searchParams;

getFileEmail4 file matches

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

tuna8 file matches

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