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=2391&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"(7658ms)

bsky_rss_pollmain.tsx1 match

@stevekrouse•Updated 7 months ago
3import { fetch } from "https://esm.town/v/std/fetch";
4
5export async function bsky_rss_poll() {
6 const { parseFeed } = await import("https://deno.land/x/rss/mod.ts");
7 const res = await fetch("https://v8.dev/blog.atom")

bsky_rss_pollREADME.md2 matches

@stevekrouse•Updated 7 months ago
4It's split into three parts:
51. [`bsky_rss_poll`](https://val.town/@jordan.bsky_rss_poll)
6 - This function runs every hour and polls the provided RSS feed, turns it into XML and runs the check. If there *is* a new post, it tell `rss_to_bsky`to post a link (and the title) to Bluesky
72. [`latest_rss`](https://val.town/@jordan.latest_rss)
8 - This is a stored object that keeps the latest object for the poll to test against
93. [`rss_to_bsky`](https://val.town/@jordan.rss_to_bsky)
10 - This function turns the text post into a rich text post and posts it to Bluesky
11
12Migrated from folder: Archive/bsky_rss_poll

extractValInfomain.tsx1 match

@devcriollo•Updated 7 months ago
1export function extractValInfo(url: string | URL) {
2 const { pathname, search } = new URL(url);
3 const [author, filename] = pathname.split("/").slice(-2);

specialBlackMosquitomain.tsx3 matches

@lost1991•Updated 7 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 return (
7 <div>
11}
12
13function client() {
14 createRoot(document.getElementById("root")).render(<App />);
15}
16if (typeof document !== "undefined") { client(); }
17
18export default async function server(request: Request): Promise<Response> {
19 return new Response(`
20 <html>

slackScoutmain.tsx10 matches

@charlypoly•Updated 7 months ago
15}
16
17export default async function(interval: Interval): Promise<void> {
18 try {
19 await createTable();
38
39// Create an SQLite table
40async function createTable(): Promise<void> {
41 await sqlite.execute(`
42 CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
50
51// Fetch Hacker news, Twitter, and Reddit results
52async function fetchHackerNewsResults(topic: string): Promise<Website[]> {
53 return hackerNewsSearch({
54 query: topic,
58}
59
60async function fetchTwitterResults(topic: string): Promise<Website[]> {
61 return twitterSearch({
62 query: topic,
67}
68
69async function fetchRedditResults(topic: string): Promise<Website[]> {
70 return redditSearch({ query: topic });
71}
72
73function formatSlackMessage(website: Website): string {
74 const displayTitle = website.title || website.url;
75 return `*<${website.url}|${displayTitle}>*
78}
79
80async function sendSlackMessage(message: string): Promise<Response> {
81 const slackWebhookUrl = Deno.env.get("SLACK_WEBHOOK_URL");
82 if (!slackWebhookUrl) {
104}
105
106async function isURLInTable(url: string): Promise<boolean> {
107 const result = await sqlite.execute({
108 sql: `SELECT 1 FROM ${TABLE_NAME} WHERE url = :url LIMIT 1`,
112}
113
114async function addWebsiteToTable(website: Website): Promise<void> {
115 await sqlite.execute({
116 sql: `INSERT INTO ${TABLE_NAME} (source, url, title, date_published)
120}
121
122async function processResults(results: Website[]): Promise<void> {
123 for (const website of results) {
124 if (!(await isURLInTable(website.url))) {

openaimain.tsx1 match

@std•Updated 7 months ago
12 * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
13 * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
14 * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
15 * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
16 * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.

reqEvaltownmain.tsx4 matches

@vawogbemi•Updated 7 months ago
1import net, { AddressInfo } from "node:net";
2
3export default async function(req: Request): Promise<Response> {
4 return serveRequest(
5 req,
6 `data:text/tsx,${
7 encodeURIComponent(`
8export default async function(req: Request): Promise<Response> {
9 return Response.json("I am within a worker!")
10}
14}
15
16export async function serveRequest(req: Request, importUrl: string): Promise<Response> {
17 let port = await getFreePort();
18 const worker = new Worker(`https://esm.town/v/maxm/evaltownWorker?cachebust=${crypto.randomUUID()}`, {
56 });
57
58export async function isPortListening(port: number): Promise<boolean> {
59 let isListening = false;
60 const maxWaitTime = 2000; // ms

valtowntownmain.tsx5 matches

@vawogbemi•Updated 7 months ago
48await contentStore.init();
49
50function Town() {
51 return (
52 <div
69}
70
71function HomePage() {
72 return (
73 <html>
82 <form method="POST" action="/submit">
83 <textarea name="handler" rows={10} cols={50} autoFocus>
84 {`export default async function(req: Request) {
85 return Response.json("Hello, world!");
86}`}
95}
96
97function ContentPage({ handler, id }: { handler: string; id: string }) {
98 return (
99 <html>
122 let originalContent = textarea.value;
123
124 textarea.addEventListener('input', function() {
125 if (textarea.value !== originalContent) {
126 submitButton.style.display = 'inline-block';

graphqlAPIEndpointmain.tsx5 matches

@flesch•Updated 7 months ago
15});
16
17// Function to handle GraphQL requests
18async function handleGraphQLRequest(request: Request): Promise<Response> {
19 const { query, variables } = await request.json();
20
30}
31
32// HTTP handler function
33export default altairClient(async function(req: Request): Promise<Response> {
34 return handleGraphQLRequest(req);
35});
36
37// Without the Altair GraphQL client:
38// export default async function(req: Request): Promise<Response> {
39// if (req.method === "POST") {
40// return handleGraphQLRequest(req);

altairClientmain.tsx2 matches

@flesch•Updated 7 months ago
3import { getDistDirectory, renderAltair, RenderOptions } from "npm:altair-static";
4
5export function altairClient(next: (request: Request) => Response | Promise<Response>, options?: RenderOptions) {
6 return async (request: Request) => {
7 const { pathname } = new URL(request.url);
26}
27
28export default altairClient(async function(request: Request): Promise<Response> {
29 return new Response("Not found", { status: 404 });
30});

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.