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=787&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 8323 results for "function"(617ms)

codeOnValTownmain.tsx2 matches

@stevekrouse•Updated 9 months ago
9 * @param val Define which val should open. Defaults to the root reference
10 */
11export function modifyHtmlString(
12 bodyText: string,
13 { val, style }: { val?: ValRef; style?: string } = {},
40 * @param val Define which val should open
41 */
42export function modifyFetchHandler(
43 handler: (req: Request) => Response | Promise<Response>,
44 { val, style }: { val?: ValRef; style?: string } = {},

codeOnValTownREADME.md1 match

@stevekrouse•Updated 9 months ago
49### Linking to the val
50
51These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the `val` argument:
52
53- `modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }})`

twitterAlertmain.tsx1 match

@tmcw•Updated 9 months ago
3const query = "\"val.town\" OR \"val town\" -_ValTown_ -is:retweet"
4
5export async function twitterAlert({ lastRunAt }: Interval) {
6 const results = await twitterSearch({
7 query,

valTownBadgeSVGmain.tsx2 matches

@jxnblk•Updated 9 months ago
9const padLeft = 48;
10
11export function Badge({
12 scale = 1,
13 label = "View source on",
66}
67
68export default async function(req: Request): Promise<Response> {
69 const svg = renderToStaticMarkup(
70 <Badge scale={1} />,

gitReleaseNotesmain.tsx10 matches

@stevekrouse•Updated 9 months ago
16}
17
18// Function to fetch package info from NPM registry
19async function fetchPackageInfo(packageName: string) {
20 const url = `https://registry.npmjs.org/${packageName}`;
21 const response = await fetch(url);
26}
27
28// Function to extract GitHub repo URL from package info
29function extractGitHubRepoUrl(packageInfo: any): string | null {
30 const repository = packageInfo.repository;
31 if (repository && repository.url) {
38}
39
40// Function to get the GitHub repository path (owner/repo) from the URL
41function getGithubRepoPath(repoUrl: string): string | null {
42 const match = repoUrl.match(/github\.com\/([^\/]+\/[^\/]+)/);
43 return match ? match[1] : null;
44}
45
46async function getGithubReleases(repo: string): Promise<GithubRelease[]> {
47 const response = await fetch(`https://api.github.com/repos/${repo}/releases`);
48 if (!response.ok) {
52}
53
54function compareVersions(version1: string, version2: string): number {
55 const v1 = version1.replace(/^v/, "").split(".").map(Number);
56 const v2 = version2.replace(/^v/, "").split(".").map(Number);
63}
64
65async function getReleaseNotesBetweenVersions(repo: string, currentVersion: string): Promise<GithubRelease[]> {
66 const releases = await getGithubReleases(repo);
67
74}
75
76async function checkNpmUpdates(packageJsonUrl: string): Promise<string> {
77 try {
78 const response = await fetch(packageJsonUrl);

stripHTMLmain.tsx1 match

@stevekrouse•Updated 9 months ago
1import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
2
3export function stripHTML(html: string) {
4 const doc = new DOMParser().parseFromString(html, "text/html");
5 return doc.body.textContent;

similarSitesmain.tsx1 match

@stevekrouse•Updated 9 months ago
4const exa = new Exa(exaSecret);
5
6const similarSites = async function(url: string) {
7 const results = await exa.findSimilar(url);
8 if (results.results) {

upgradeHTTPPreviewValsmain.tsx4 matches

@stevekrouse•Updated 9 months ago
3import OpenAI from "npm:openai";
4
5async function getVals(username, type, limit) {
6 const res = await db.execute({
7 sql: `
21}
22
23async function checkHTTPPreviewUpgrade(code) {
24 const openai = new OpenAI();
25 const completion = await openai.chat.completions.create({
53 content: `const number = Math.random();
54
55 export default function(req: Request) {
56 return Response.json(number);
57 }`,
80
81/* This example will return the contents of a documentID passed in as the path as JSON. */
82export default async function(req: Request): Promise<Response> {
83 const docId = new URL(req.url).pathname.substring(1);
84

upgradeHTTPPreviewValsREADME.md5 matches

@stevekrouse•Updated 9 months ago
16 "name": "harlequinChickadee",
17 "probabilityUpgradeNeeded": true,
18 "reason": "The current code structure has several functions and program logic outside the main handler, including word selection, game state management, and SVG generation. These parts would not re-run with the new runtime, potentially affecting functionality. They need to be moved inside the handler to ensure consistent behavior across requests."
19 },
20 {
31 "name": "untitled_pinkRoundworm",
32 "probabilityUpgradeNeeded": true,
33 "reason": "The functions `addComment` and `getComments` as well as the initialization \nof the KEY variable perform actions that are intended to be run per request. These need to be moved \ninside the relevant HTTP handler to ensure the behavior remains consistent in the new runtime."
34 },
35 {
46 "name": "untitled_maroonSwallow",
47 "probabilityUpgradeNeeded": false,
48 "reason": "All the code, including the check for authentication,\n is inside the handler function. This means the behavior will stay \n the same with the new runtime."
49 },
50 {
51 "name": "wikiOG",
52 "probabilityUpgradeNeeded": true,
53 "reason": "The function `getWikipediaInfo` defined outside of the handler makes network requests and processes data for each request. In the new runtime, this function would only be executed once and cached. To ensure the same behavior in the new runtime, this function should be moved into the handler."
54 },
55 {
61 "name": "discordEventReceiver",
62 "probabilityUpgradeNeeded": false,
63 "reason": "All the relevant code for handling requests and logging input is inside the handler.\n No code needs to be moved for the new runtime to function correctly."
64 }
65]

pinkEgretmain.tsx1 match

@maxm•Updated 9 months ago
1// import { Request, Response } from "./node_modules/express/index.js";
2export default async function(req: Request): Promise<Response> {
3 console.log("Request received:", req);
4

getFileEmail4 file matches

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

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago