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/$%7Bart_info.art.src%7D?q=function&page=1587&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 19678 results for "function"(3951ms)

googleCalendarWeekEndpointmain.tsx1 match

@ejfox•Updated 8 months ago
10const SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"];
11
12export default async function server(request: Request): Promise<Response> {
13 const url = new URL(request.url);
14 const path = url.pathname;

valleBlogV0main.tsx4 matches

@heaversm•Updated 8 months ago
8import _ from "npm:lodash@4";
9
10async function main(req: Request): Promise<Response> {
11 const { readable, writable } = new TransformStream();
12 const writer = writable.getWriter();
20 <script>
21 // Scroll to the bottom of the page when the page changes.
22 (new MutationObserver(function (mutationsList, observer) {
23 window.scrollTo({ left: 0, top: document.body.scrollHeight, behavior: "instant" });
24 })).observe(document, { childList: true, characterData: true, subtree: true });
47 Your response should start with \`\`\`ts and end with \`\`\`, so full code fences.
48 There should be no comments like "more content here", it should be complete and directly runnable.
49 The val should have an "export default async function main". The val should return a valid HTML website.
50 Prefer using Tailwind. Put frontend functions in a <script> tag, using dangerouslySetInnerHTML. Don't use Hono. Don't use Response.redirect.
51 `.replace("\n", " "),
52 },

ReactStreamREADME.md4 matches

@lisardo•Updated 8 months ago
7import { render, React } from "https://esm.town/v/jxnblk/ReactStream";
8
9function App() {
10 const [count, setCount] = React.useState(0);
11 return (
62```tsx
63// example middleware
64async function api (req: Request, res: Response, next): Promise<Response> {
65 if (req.pathname !== "/api") return next();
66 if (req.method === "POST") {
78```tsx
79// example middleware
80async function getInitialProps (req: Request, res: Response, next) {
81 // fetch data or do async work to pass as props to the component
82 req.data = {
95import { render } from "https://esm.town/v/jxnblk/ReactStream";
96
97function App () {
98 return (
99 <html>

ReactStreammain.tsx3 matches

@lisardo•Updated 8 months ago
22}
23
24export function render<T>(
25 /** Root-level React component that renders an entire <html> element
26 * including the head and body tags.
41 }
42
43 return async function handler(request: Request): Promise<Response> {
44 const main = reactStream(Component, module);
45 const middleware: Middleware[] = [
76 module: string | false,
77): Middleware =>
78 async function(req: DataRequest, res: Response): Promise<Response> {
79 const { renderToReadableStream } = await import("https://esm.sh/react-dom@18.3.1/server");
80

supremeRedCranemain.tsx1 match

@mvmattgray•Updated 8 months ago
2
3export default async (request) => {
4 // Function to create a standard response with CORS headers
5 const createResponse = (body, status = 200) => {
6 return new Response(body, {

ExampleGetParamsmain.tsx1 match

@stevekrouse•Updated 8 months ago
1export default async function(req: Request): Promise<Response> {
2 const url = new URL(req.url);
3 const search = url.searchParams;

endpointCalculatormain.tsx8 matches

@ejfox•Updated 8 months ago
6 */
7
8export default async function server(request: Request): Promise<Response> {
9 const url = new URL(request.url);
10 const operation = url.pathname.split('/').pop();
58}
59
60function add(numbers: number[]): number {
61 return numbers.reduce((a, b) => a + b, 0);
62}
63
64function subtract(numbers: number[]): number {
65 return numbers.reduce((a, b) => a - b);
66}
67
68function multiply(numbers: number[]): number {
69 return numbers.reduce((a, b) => a * b, 1);
70}
71
72function divide(numbers: number[]): number {
73 if (numbers.includes(0)) {
74 throw new Error("Cannot divide by zero");
77}
78
79function pow(numbers: number[]): number {
80 return numbers.reduce((a, b) => Math.pow(a, b));
81}
82
83function sqrt(number: number): number {
84 if (number < 0) {
85 throw new Error("Cannot calculate square root of a negative number");
88}
89
90function log(number: number): number {
91 if (number <= 0) {
92 throw new Error("Cannot calculate logarithm of a non-positive number");

untitled_azureWhippetmain.tsx1 match

@jordonezrodri2•Updated 8 months ago
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",

weeklyTanPonymain.tsx1 match

@stevekrouse•Updated 8 months ago
1// This val demonstrates how to handle form data and display it back to the user
2
3export default async function server(req: Request): Promise<Response> {
4 if (req.method === 'POST') {
5 const formData = await req.formData();

hungryWhiteLeoponmain.tsx3 matches

@gr8gatsby•Updated 8 months ago
12import { createRoot } from "https://esm.sh/react-dom/client";
13
14function App() {
15 const [coffeeShops, setCoffeeShops] = useState([]);
16 const [reviews, setReviews] = useState([]);
163}
164
165function client() {
166 createRoot(document.getElementById("root")).render(<App />);
167}
168if (typeof document !== "undefined") { client(); }
169
170async function server(request: Request): Promise<Response> {
171 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
172 const url = new URL(request.url);

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 3 weeks 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.