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=708&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 7147 results for "function"(589ms)

vblogparse1 match

@jxnblk•Updated 3 months ago
1import type { Plugin, Post } from "./types";
2
3export async function parse(post: Post, plugins: Plugin[]) {
4 return await plugins.reduce(async (acc: Promise<Post>, plugin: Plugin) => {
5 const post = await acc;

surprisingEmbeddingsembeddingGetter1 match

@tmcw•Updated 3 months ago
10const THROTTLE = 1000
11
12export default async function(req: Request): Promise<Response> {
13 if (working) {
14 return Response.json({

Prompt_ImproverPrompt_Improver_Includer1 match

@toowired•Updated 3 months ago
1export default async function(request: Request) {
2 const { prompt } = await request.json();
3

Prompt_ImproverPrompt_Improver_Clarifier1 match

@toowired•Updated 3 months ago
1export default async function (request: Request) {
2 const { prompt } = await request.json();
3

URLReceiverURLReceiverTest10 matches

@willthereader•Updated 3 months ago
22 inputs: Record<string, unknown>;
23 expectedResult: unknown;
24 function: Function;
25}
26
28
29// Create test cases by combining URLs with modifications
30function createURLTests(): TestCase[] {
31 const tests: TestCase[] = [];
32
36 inputs: { url: baseURL },
37 expectedResult: { isValid: true },
38 function: urlReceiver.receiveURL.bind(urlReceiver),
39 });
40
43 inputs: { url: TEST_MODIFICATIONS.withHTTP(baseURL) },
44 expectedResult: { isValid: true },
45 function: urlReceiver.receiveURL.bind(urlReceiver),
46 });
47
53 error: "URL must use HTTP or HTTPS protocol",
54 },
55 function: urlReceiver.receiveURL.bind(urlReceiver),
56 });
57
63 error: "Invalid URL format",
64 },
65 function: urlReceiver.receiveURL.bind(urlReceiver),
66 });
67 });
72 inputs: {},
73 expectedResult: undefined,
74 function: urlReceiver.clearHistory.bind(urlReceiver),
75 });
76
79 inputs: {},
80 expectedResult: [],
81 function: urlReceiver.getURLHistory.bind(urlReceiver),
82 });
83
86 inputs: {},
87 expectedResult: undefined,
88 function: urlReceiver.clearHistory.bind(urlReceiver),
89 });
90
97 console.log(`Running test: ${testCase.description}`);
98
99 const result = testCase.function(testCase.inputs.url);
100 console.log(`Input: ${JSON.stringify(testCase.inputs)}`);
101 console.log(`Expected result: ${JSON.stringify(testCase.expectedResult)}`);

money_countermain.tsx7 matches

@arfan•Updated 3 months ago
3 SINGLE-FILE VAL CODE
4 1) Imports React, once.
5 2) Declares CSS + server() function
6 3) Declares the <App/> React component
7 4) Declares client() to mount <App/>
298
299/* ------------------------------------------------
300 2) server() function: returns the HTML skeleton
301------------------------------------------------ */
302export default async function server(request: Request): Promise<Response> {
303 return new Response(
304 `
328 3) The React App
329------------------------------------------------ */
330function App() {
331 // States for inputs
332 const [entryName, setEntryName] = useState("#");
365
366 // Helpers
367 function formatNumber(num) {
368 return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
369 }
370 function formatCurrency(num) {
371 return `$${num.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, "$&,")}`;
372 }
897 4) Mount the React <App/> client-side
898------------------------------------------------ */
899function client() {
900 createRoot(document.getElementById("root")).render(<App />);
901}

bluesky_bot_templatemain.tsx5 matches

@alexwein•Updated 3 months ago
6});
7
8// Helper function to convert data URI to Uint8Array
9function convertDataURIToUint8Array(dataURI: string): Uint8Array {
10 const base64Data = dataURI.split(",")[1];
11 const binaryString = atob(base64Data);
17}
18
19// Helper function to fetch SVG and convert to base64
20async function fetchSVGAsBase64(url: string): Promise<string> {
21 const response = await fetch(url);
22 if (!response.ok) {
27}
28
29export default async function(interval: Interval) {
30 // Don't forget to set these environment variables in the val's settings.
31 const username = process.env.BLUESKY_USERNAME;

templateRedditAlertmain.tsx1 match

@valdottown•Updated 3 months ago
12const isProd = true;
13
14export async function redditAlert({ lastRunAt }: Interval) {
15 if (!SERP_API_KEY || !DISCORD_API_KEY) {
16 console.error("Missing SERP_API_KEY or Discord webhook URL. Exiting.");

templateTwitterAlertmain.tsx1 match

@valdottown•Updated 3 months ago
12const isProd = false;
13
14export async function twitterAlert({ lastRunAt }: Interval) {
15 // If isProd, search for tweets since that last time this interval ran
16 // if not, search for tweets since 48 hours ago for testing

templateHackerNewsAlertmain.tsx1 match

@valdottown•Updated 3 months ago
4import process from "node:process";
5
6export async function hnValTown({ lastRunAt }: Interval) {
7 // Edit to update time frame
8 const twoMonthsAgo = new Date();

getFileEmail4 file matches

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

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago