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=779&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 7849 results for "function"(640ms)

timedmain.tsx1 match

@stevekrouse•Updated 1 year ago
1// Times how long an execution takes
2// usage: @stevekrouse.panphoraDistanceTimed
3export async function timed(f) {
4 const start = Date.now();
5 const res = await f();

discordMessagesmain.tsx1 match

@stevekrouse•Updated 1 year ago
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export function discordMessages({ botToken, channelId }) {
4 return fetchJSON(
5 `https://discord.com/api/channels/${channelId}/messages`,

projmain.tsx1 match

@tmcw•Updated 1 year ago
1export function proj(ll: Pos2): Pos2 {
2 // Arbitrary.
3 const D2R = Math.PI / 180;

untitled_mutate_test_statemain.tsx1 match

@stevekrouse•Updated 1 year ago
1let { untitled_test_state } = await import("https://esm.town/v/stevekrouse/untitled_test_state");
2
3export function untitled_mutate_test_state(newState) {
4 return (untitled_test_state = newState);
5}

preactTestmain.tsx1 match

@tmcw•Updated 1 year ago
4 );
5 const html = htm.bind(h);
6 function Component() {
7 const [count, setCount] = useState(0);
8 return html`<div class="foo">${count}</div>`;

hmain.tsx3 matches

@tmcw•Updated 1 year ago
1import { h as h2 } from "https://esm.town/v/tmcw/h";
2
3export function h(tagName: string, attrsPlus?: any, ...children: any[]) {
4 if (!attrsPlus) attrsPlus = {};
5 if (attrsPlus.isEl || typeof attrsPlus === "string")
28 .join("");
29 const attrsToEmit = Object.entries(attrsPlus).reduce((acc: any, [k, v]) => {
30 if (k.startsWith("on") && typeof v === "function") return acc; // Skip events
31 if (v === null || v === undefined) return acc; // Skip null/undefined
32 if (typeof v === "function") v = v(); // Allow dynamic stuff (continue to rest of function)
33 if (k === "innerHTML") innerHtml = String(v);
34 else if (k === "innerText") innerHtml = text2Html(String(v));

jsJamHTMLmain.tsx1 match

@stevekrouse•Updated 1 year ago
1import { jsJamMessages } from "https://esm.town/v/stevekrouse/jsJamMessages";
2
3export function jsJamHTML(req, res) {
4 res.send(`<h1>${JSON.stringify(jsJamMessages)}</h1>`);
5}

questionmain.tsx1 match

@tmcw•Updated 1 year ago
1export function question() {
2 return "hello";
3}

measureValTownE2emain.tsx1 match

@tmcw•Updated 1 year ago
28
29 console.log(
30 `average e2e user function time: ${(
31 userFuncTimes.reduce((a, b) => a + b, 0) / count
32 ).toFixed(0)}ms (fastest was ${userFuncTimes

doublemain.tsx1 match

@stevekrouse•Updated 1 year ago
1export function double(x: number) {
2 return 2 * x;
3}

getFileEmail4 file matches

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

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago