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=761&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 7802 results for "function"(677ms)

postmanClonemain.tsx4 matches

@maxmUpdated 8 months ago
2 * This val creates a Postman-like interface for testing HTTP requests directly in the browser.
3 * It uses React for the UI and the Fetch API to make requests.
4 * The server function serves the HTML and handles the API requests.
5 */
6
9import { createRoot } from "https://esm.sh/react-dom/client";
10
11function App() {
12 const [url, setUrl] = useState('https://jsonplaceholder.typicode.com/posts/1');
13 const [method, setMethod] = useState('GET');
94}
95
96function client() {
97 createRoot(document.getElementById("root")).render(<App />);
98}
102}
103
104async function server(request: Request): Promise<Response> {
105 const url = new URL(request.url);
106

niceTodoListmain.tsx1 match

@maxmUpdated 8 months ago
8
9// Server-side only code
10export default async function server(request: Request): Promise<Response> {
11 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
12 const SCHEMA_VERSION = 1

test_migratedmain.tsx5 matches

@jxnblkUpdated 8 months ago
2import { render } from "npm:preact-render-to-string";
3
4export function it(name, fn) {
5 const ok = "✅ [OK]: ";
6 const fail = "❌ [FAIL]: ";
15}
16
17export function describe(name, run) {
18 console.log(name);
19 return async function(req: Request): Promise<Response> {
20 await run();
21 return Response.json({ ok: true, status: 200 });
34};
35
36function Badge({ status }: BadgeProps) {
37 const color = colors[status];
38 const label = status ? status.toUpperCase() : "N/A";
68}
69
70export default async function(req: Request): Promise<Response> {
71 const params = new URL(req.url).searchParams;
72 const valURL = params.get("url");

hnmain.tsx3 matches

@maxmUpdated 8 months ago
16`);
17
18function createErrorPage(title: string, message: string): string {
19 return `
20 <html>
108};
109
110function injectNotificationIndicator(html: string): string {
111 const notificationCount = 21; // Hardcoded for now
112 const notificationIndicator = `
125}
126
127export default async function(req: Request): Promise<Response> {
128 const url = new URL(req.url);
129 let userCookie: string | undefined;

emailmain.tsx1 match

@shouserUpdated 8 months ago
12 * The email address(es) to send the email to. Only available to Val Town Pro subscribers.
13 * Can be a single string, IAddress object, or an array of strings/IAddress objects.
14 * @default the email of the logged user calling this function.
15 */
16 to?: (IAddress | string)[] | IAddress | string;

sqlitemain.tsx5 matches

@maxmUpdated 8 months ago
31
32// ------------
33// Functions
34// ------------
35
36async function execute(statement: InStatement): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
48}
49
50async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
51 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
52 method: "POST",
62}
63
64function createResError(body: string) {
65 try {
66 const e = zLibsqlError.parse(JSON.parse(body));
113 *
114 * The types are currently shown for types declared in a SQL table. For
115 * column types of function calls, for example, an empty string is
116 * returned.
117 */

phpServemain.tsx3 matches

@maxmUpdated 8 months ago
3const php = new PhpWeb();
4
5export default async function(req: Request): Promise<Response> {
6 let output = "";
7 let headers = new Headers();
55
56 // Simple router
57 function route($uri, $method) {
58 switch ($uri) {
59 case '/api':
79 <title>Greeting Form</title>
80 <script>
81 async function submitForm(event) {
82 event.preventDefault();
83 const form = event.target;

quickjsmain.tsx1 match

@maxmUpdated 8 months ago
3const QuickJS = await newQuickJSWASMModuleFromVariant(releaseVariant);
4
5async function main() {
6 const vm = QuickJS.newContext();
7

pgliteCountermain.tsx1 match

@maxmUpdated 8 months ago
18})();
19
20export default async function(req: Request): Promise<Response> {
21 await init;
22 await pg.query(`

switchbotmain.tsx2 matches

@stevekrouseUpdated 8 months ago
18const ValTownOfficeDeviceId = "CD6F3A810848";
19
20async function switchbotRequest(path, args) {
21 const token = Deno.env.get("SWITCHBOT_TOKEN");
22 const secret = Deno.env.get("SWITCHBOT_KEY");
42}
43
44function botPress(device) {
45 return switchbotRequest(`v1.1/devices/${device}/commands`, {
46 method: "POST",

getFileEmail4 file matches

@shouserUpdated 6 days ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemiUpdated 2 months ago