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=1532&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 17310 results for "function"(3009ms)

basicAuthV2main.tsx3 matches

@pomdtr•Updated 1 year ago
5};
6
7export function basicAuth(next: (Request) => Response | Promise<Response>, options: BasicAuthOptions) {
8 return async (req: Request) => {
9 if (req.headers.get("referer") == "https://www.val.town/") {
33}
34
35function extractCredentials(authorization): { username: string; password: string } {
36 const parts = authorization.split(" ");
37 if (parts[0] != "Basic") {
47}
48
49async function isRequestAuthenticated(req, userTable: string) {
50 if (!req.headers.has("authorization")) {
51 return false;

lucia_sqlitemain.tsx4 matches

@pomdtr•Updated 1 year ago
4import {Scrypt, generateId} from "npm:lucia"
5
6export async function createTables(userTable: string, sessionTable: string) {
7 return sqlite.batch([
8 `CREATE TABLE ${userTable} (
20}
21
22export async function createUser(table: string, username: string, password: string) {
23 if (
24 username.length < 3
43}
44
45export async function getUser(
46 table: string,
47 username: string,
56}
57
58export async function verifyPassword(hashed_password: string, password: string): Promise<boolean> {
59 return new Scrypt().verify(hashed_password, password);
60}

lucia_adapter_basemain.tsx3 matches

@pomdtr•Updated 1 year ago
127}
128
129function transformIntoDatabaseSession(raw: SessionSchema): DatabaseSession {
130 const { id, user_id: userId, expires_at: expiresAtUnix, ...attributes } = raw;
131 return {
137}
138
139function transformIntoDatabaseUser(raw: UserSchema): DatabaseUser {
140 const { id, ...attributes } = raw;
141 return {
145}
146
147function escapeName(val: string): string {
148 return "`" + val + "`";
149}

listSqliteTablesmain.tsx1 match

@nbbaier•Updated 1 year ago
1import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
2
3export async function listSqliteTables() {
4 return (await sqlite.execute(
5 `select name from sqlite_schema where type='table' and name != 'libsql_wasm_func_table' and name != 'sqlite_sequence'`,

test_explorer_uimain.tsx5 matches

@pomdtr•Updated 1 year ago
57};
58
59function TestItem({ test, run }: { test: Test; run: () => void }) {
60 return (
61 <div>
75}
76
77function groupBySlug(tests: Test[]): Record<string, Test[]> {
78 const groups = {};
79 for (const test of Object.values(tests)) {
89}
90
91function useTests(initialTests: Test[]) {
92 const id = (test: Test) => `${test.val.name}/${test.name}`;
93 const [tests, setTests] = useState(Object.fromEntries(initialTests.map((test) => {
118}
119
120function TestExplorerView({ tests }: Props) {
121 const { groups, runTest } = useTests(tests);
122 return (
187}
188
189export default function(props: { tests: Test[] }) {
190 return (
191 <>

valshotmain.tsx2 matches

@pomdtr•Updated 1 year ago
24export default router.fetch;
25
26export async function createScreenshot(code: string, theme: string = "dark-plus"): Promise<URL> {
27 const apiUrl = "https://sourcecodeshots.com/api/image/permalink";
28 const { url } = await ky.post(apiUrl, {
35}
36
37async function fetchValCode(alias: string): Promise<string> {
38 const prefixUrl = "https://api.val.town/v1/alias";
39 const { code } = await ky.get(alias, { prefixUrl }).json();

authDescribeScopesmain.tsx1 match

@postpostscript•Updated 1 year ago
3import { pathMatches } from "https://esm.town/v/postpostscript/pathAsScope";
4
5export async function authDescribeScopes(scopes: string[]) {
6 return Promise.all(scopes.map(async (scope) => {
7 const [author, name, ..._scopeName] = scope.slice(1).split("/");

filterValsREADME.md1 match

@nbbaier•Updated 1 year ago
1# filterVals
2
3This val exports a utility function that returns a list of all a user's val, filtered by a callback function.
4
5## Example

jwksmain.tsx2 matches

@postpostscript•Updated 1 year ago
20};
21
22export function publicKeys() {
23 try {
24 return JSON.parse(Deno.env.get("JWKS_PUBLIC"));
38});
39
40export default async function(req: Request) {
41 return Response.json(publicKeys());
42}

hono_countermain.tsx1 match

@pomdtr•Updated 1 year ago
3import { useState } from "https://esm.sh/hono/jsx/dom";
4
5export default function Counter(props: { initialCount?: number }) {
6 const [count, setCount] = useState(props.initialCount || 0);
7 return (

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 1 week 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": "*",