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=1596&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 18856 results for "function"(2190ms)

EnvironmentConfigmain.tsx1 match

@emarref•Updated 10 months ago
2import { z } from "npm:zod";
3
4export function config<T extends z.ZodRawShape>(schema: T) {
5 return z.object(schema).parse(process.env);
6}

HttpMiddlewareChainmain.tsx7 matches

@emarref•Updated 10 months ago
8};
9
10export function chain(): Promise<Chain> {
11 const stack = new Set<HttpMiddleware>();
12
13 async function getChain(): Promise<Chain> {
14 return { add, send };
15 }
27 let happy = true;
28
29 async function loop() {
30 middleware = queue.shift();
31
60}
61
62export function add(middleware: HttpMiddleware) {
63 return function({ add }: Chain) {
64 return add(middleware);
65 };
66}
67
68export function send(response?: Response) {
69 return function({ send }: Chain) {
70 return send(response ?? success());
71 };

HttpMiddlewareRequireValidHmacSignaturemain.tsx5 matches

@emarref•Updated 10 months ago
6type HmacFactory = typeof createHmac;
7type Hmac = ReturnType<HmacFactory>;
8type DigestFunction = Hmac["digest"];
9
10type Algorithm = Parameters<HmacFactory>[0];
11type Encoding = Parameters<DigestFunction>[0];
12
13type Options = {
18};
19
20export function requireValidHmacSignature({
21 algorithm = "sha256",
22 encoding = "base64",
24 signingKey,
25}: Options): HttpMiddleware {
26 return function(next) {
27 return async function(request) {
28 const providedSignature = request.headers.get(signatureHeaderName) ?? "";
29 const body = await request.text();

HttpMiddlewareRequireHttpMethodmain.tsx3 matches

@emarref•Updated 10 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 10 months ago
1Chainable middleware functions to simplify http requests.
2
3Migrated from folder: http/middleware/HttpMiddleware

HttpMiddlewareChainREADME.md2 matches

@emarref•Updated 10 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 10 months ago
1Factory functions for creating HTTP Response objects.
2
3Migrated from folder: http/HttpResponse

translatemain.tsx5 matches

@yawnxyz•Updated 10 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 10 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 10 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 },

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 2 weeks ago
Simple functional CSS library for Val Town
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
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": "*",