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/image-url.jpg%20%22Optional%20title%22?q=function&page=1753&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 20424 results for "function"(2479ms)

HttpMiddlewareRequireHttpMethodmain.tsx3 matches

@emarref•Updated 11 months ago
2import { forbidden } from "https://esm.town/v/emarref/HttpResponse";
3
4export function requireHttpMethod(method: Request["method"]): HttpMiddleware {
5 return function(next) {
6 return function(request) {
7 if (request.method !== method) {
8 console.warn(`${method} method required.`);

HttpMiddlewareREADME.md1 match

@emarref•Updated 11 months ago
1Chainable middleware functions to simplify http requests.
2
3Migrated from folder: http/middleware/HttpMiddleware

HttpMiddlewareChainREADME.md2 matches

@emarref•Updated 11 months ago
1An implementation of chainable http middleware.
2
3Wrap your http handlers in middleware to add functionality and reduce code duplication.
4
5```ts
6export default function chain()
7 .then(add(requireHttpMethod("post")))
8 .then(add(requireAuthentication()))

HttpResponseREADME.md1 match

@emarref•Updated 11 months ago
1Factory functions for creating HTTP Response objects.
2
3Migrated from folder: http/HttpResponse

translatemain.tsx5 matches

@yawnxyz•Updated 11 months ago
1if (import.meta.main) Deno.serve(translate);
2
3export async function translate(req: Request) {
4 if (req.method === "POST") {
5 return await fetch("https://deepl.deno.dev/translate", {
45 };
46
47 translate = async function () {
48 this.setState({ loading: true, translation: "" });
49 const { text, source_lang, target_lang } = this.state;
52 }.bind(this);
53
54 swap = function () {
55 if (this.state.source_lang.toLowerCase() === "auto") {
56 this.setState({ source_lang: "en" });
62 }.bind(this);
63
64 handleShortcut = function (e) {
65 if (this.state.loading !== true && e.ctrlKey && e.key === "Enter") {
66 this.translate();
125 render(html\`<\${App} page="All" />\`, document.body);
126
127 async function translate({ text, source_lang, target_lang }) {
128 const Options = z.object({
129 text: z.string(),

honoAlpineHtmxDemomain.tsx1 match

@yawnxyz•Updated 11 months ago
27 output: null,
28 init() {
29 // if you don't use an arrow function (this) will refer to document, not alpine
30 document.addEventListener('htmx:afterRequest', (event) => this.updateOutput(event));
31 },

honoAlpineExamplemain.tsx1 match

@yawnxyz•Updated 11 months ago
27 output: null,
28 init() {
29 // if you don't use an arrow function (this) will refer to document, not alpine
30 document.addEventListener('htmx:afterSwap', (event) => this.updateOutput(event));
31 },

tealBadgermain.tsx1 match

@stevekrouse•Updated 11 months ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2export default async function(req: Request): Promise<Response> {
3 const openai = new OpenAI();
4 const stream = await openai.chat.completions.create({

testCodemirrorTsBrowserEmacsmain.tsx2 matches

@saolsen•Updated 11 months ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request): Promise<Response> {
5 return new Response(
6 renderToString(
11 {`let hasAnError: string = 10;
12
13function increment(num: number) {
14 return num + 1;
15}

openAIStreamingExamplemain.tsx1 match

@stevekrouse•Updated 11 months ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(req: Request): Promise<Response> {
4 const openai = new OpenAI();
5 const stream = await openai.chat.completions.create({

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.