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/$2?q=function&page=2472&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 28557 results for "function"(6738ms)

valledrawclientmain.tsx6 matches

@roadlabs•Updated 9 months ago
19// console.log(ret.url);
20
21export default function({ iframeSrc }) {
22 return async (req) => {
23 const { extractValInfo } = await import("https://esm.town/v/pomdtr/extractValInfo");
52
53if (typeof document !== "undefined") {
54 (window as any).makeValleDrawClient = async function({ iframeSrc, model }) {
55 const ret = { url: "https://esm.sh/~ae19cbe7d55c481140f1002355f248f335382639" };
56
81 } = tldraw;
82
83 function MakeRealButton() {
84 const editor = useEditor();
85 const { addToast } = useToasts();
91 const { maxX, midY } = editor.getSelectionPageBounds();
92
93 const text = `export default async function main(req: Request): Promise<Response> {
94 return new Response("Hello, World!", {
95 headers: { "Content-Type": "text/plain" },
154 }
155
156 function App() {
157 return (
158 <>
298 ];
299
300 function getRotatedBoxShadow(rotation: number) {
301 const cssStrings = ROTATING_BOX_SHADOWS.map((shadow) => {
302 const { offsetX, offsetY, blur, spread, color } = shadow;

CoverLetterGeneratormain.tsx4 matches

@shawnbasquiat•Updated 9 months ago
4import { OpenAI } from "https://esm.town/v/std/openai";
5
6export default async function server(req: Request): Promise<Response> {
7 console.log("Request method:", req.method);
8
91}
92
93async function extractTextFromPDF(file: File): Promise<string | null> {
94 try {
95 const { default: pdfjs } = await import("https://esm.sh/pdfjs-dist@3.4.120/build/pdf.min.js");
109}
110
111async function generateCoverLetter(resume: string, jobDescription: string): Promise<string> {
112 console.log("Entering generateCoverLetter function");
113 const openai = new OpenAI();
114 console.log("OpenAI instance created");

fetchTwitterUserInfoBrokenmain.tsx2 matches

@shawnbasquiat•Updated 9 months ago
4import cheerio from "https://esm.sh/cheerio@1.0.0-rc.12";
5
6export default async function server(req: Request): Promise<Response> {
7 const url = new URL(req.url);
8 const formData = await req.formData().catch(() => null);
139}
140
141function parseFollowerCount(followerText: string): number {
142 const cleanText = followerText.replace(/,/g, '').toLowerCase();
143 const num = parseFloat(cleanText);

emailListManagermain.tsx8 matches

@shawnbasquiat•Updated 9 months ago
1// This val creates a mailing list manager using blob storage for persistence.
2// It provides functions to add and remove emails, and to send emails to all subscribers.
3// The email list is stored as a JSON array in a blob.
4
8const BLOB_KEY = "emailListManager" + "_email_list";
9
10async function getEmailList(): Promise<string[]> {
11 return await blob.getJSON(BLOB_KEY) || [];
12}
13
14async function saveEmailList(list: string[]): Promise<void> {
15 await blob.setJSON(BLOB_KEY, list);
16}
17
18async function addEmail(newEmail: string): Promise<string> {
19 const list = await getEmailList();
20 if (!list.includes(newEmail)) {
26}
27
28async function removeEmail(emailToRemove: string): Promise<string> {
29 const list = await getEmailList();
30 const updatedList = list.filter(email => email !== emailToRemove);
36}
37
38async function sendEmailToAll(subject: string, content: string): Promise<string> {
39 const list = await getEmailList();
40 if (list.length === 0) {
54}
55
56export default async function server(req: Request): Promise<Response> {
57 const url = new URL(req.url);
58 const path = url.pathname;
97 // }).then(response => response.text()).then(result => console.log(result));
98
99 function exportCSV() {
100 const emails = ${JSON.stringify(emailList)};
101 const csvContent = "data:text/csv;charset=utf-8," + emails.join("\\n");

longOliveGuppymain.tsx3 matches

@sharanbabu•Updated 9 months ago
7import { createRoot } from "https://esm.sh/react-dom/client";
8
9function App() {
10 const [messages, setMessages] = useState([]);
11 const [input, setInput] = useState("");
60}
61
62function client() {
63 createRoot(document.getElementById("root")).render(<App />);
64}
65if (typeof document !== "undefined") { client(); }
66
67async function server(request: Request): Promise<Response> {
68 const Cerebras = await import("https://esm.sh/@cerebras/cerebras_cloud_sdk");
69 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");

iangac_validatormain.tsx1 match

@pfeffunit•Updated 9 months ago
4const app = new Hono();
5
6function analyzeJSON(jsonData) {
7 const images = jsonData.images;
8 const allIds = new Set(images.map(img => img.id));

globalIncrementmain.tsx6 matches

@benjiwheeler•Updated 9 months ago
1// This val uses Val Town's Blob storage to maintain a shared global integer value.
2// We'll use the val's URL as the storage key for consistency.
3// The main function handles both GET requests to retrieve the current value
4// and POST requests to increment the value.
5// We're using Promises with .then() instead of async/await for asynchronous operations.
10const KEY = "Ben Wheeler globalIncrement test key";
11
12export function getValue(): Promise<number> {
13 return blob.getJSON(KEY)
14 .then(value => typeof value === "number" ? value : 0)
16}
17
18export function increment(): Promise<number> {
19 return getValue()
20 .then(currentValue => {
28}
29
30export default async function(req: Request): Promise<Response> {
31 if (req.method === "POST") {
32 return increment()
39}
40
41export function checkIfWorking(req: Request): Promise<Response> {
42 console.log("working");
43}
44
45// export function main(req: Request): Promise<Response> {
46// }

sqlitemain.tsx7 matches

@nkohari•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>,

webhook1main.tsx1 match

@benjiwheeler•Updated 9 months ago
3};
4
5export function webhook2(a, b) {
6 return a + b;
7}

pglitemain.tsx1 match

@iamseeley•Updated 9 months ago
11`);
12
13export default async function(req: Request): Promise<Response> {
14 const res = await db.query(`
15 UPDATE test

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.