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=4&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 30159 results for "function"(1540ms)

townie-126requests.ts1 match

@dinavinter•Updated 1 hour ago
29}
30
31export function renderRequests(data: RequestRow[], pagination: PaginationData, baseUrl: string, filtered = false): string {
32 // Calculate totals
33 const totalRequests = pagination.totalItems;

townie-126requests.ts4 matches

@dinavinter•Updated 1 hour ago
6 * Get paginated usage requests
7 */
8export async function getRequests(url: URL) {
9 const { page, pageSize } = getPaginationParams(url);
10 const userId = url.searchParams.get("user_id");
41 * Get a single request by ID
42 */
43export async function getRequestById(id: string) {
44 const result = await sqlite.execute(`
45 SELECT * FROM ${USAGE_TABLE}
57 * Get inference calls for a specific usage request
58 */
59export async function getInferenceCallsForRequest(usageId: string) {
60 const result = await sqlite.execute(`
61 SELECT
81 * Calculate totals from inference calls for a request
82 */
83export async function getInferenceTotalsForRequest(usageId: string) {
84 const calls = await getInferenceCallsForRequest(usageId);
85

townie-126queries.tsx8 matches

@dinavinter•Updated 1 hour ago
9// but in the meantime, we can cache user info in memory
10const userIdCache: { [key: string]: any } = {};
11export async function getUser(bearerToken: string) {
12 if (userIdCache[bearerToken]) return userIdCache[bearerToken];
13
19
20// Get user's current credit balance
21export async function getCreditBalance(userId: string, tablePrefix: string = ""): Promise<number> {
22 const result = await sqlite.execute(
23 `
35
36// Check if user has insufficient credits for estimated cost
37export async function hasInsufficientCredits({
38 bearerToken,
39 estimatedCost = 0.01,
51
52// Add credits to user account
53export async function addCredits(
54 userId: string,
55 amount: number,
75}
76
77export async function insertInferenceCall({
78 usage_id,
79 input_tokens,
135}
136
137export async function startTrackingUsage({
138 bearerToken,
139 val_id,
179}
180
181export async function calculatePartialUsageFromInferenceCalls(usageId: number, tablePrefix: string = "") {
182 const result = await sqlite.execute(`
183 SELECT
203}
204
205export async function finishTrackingUsage({
206 rowid,
207 input_tokens,

townie-126queries_test.tsx1 match

@dinavinter•Updated 1 hour ago
4import { CREDIT_ADDITIONS_TABLE, INFERENCE_CALLS_TABLE, USAGE_TABLE } from "./schema.tsx";
5
6async function runTests() {
7 await deleteTables("test_");
8 await migrateTables("test_");

townie-126PurchaseCreditsRoute.tsx1 match

@dinavinter•Updated 1 hour ago
3import { isProdBranch } from "../../shared/is-prod-branch.ts";
4
5export default function PurchaseCreditsRoute() {
6 const [amount, setAmount] = useState<number>(10);
7 const [balance, setBalance] = useState<number | null>(null);

townie-126ProjectsRoute.tsx3 matches

@dinavinter•Updated 1 hour ago
5import { Footer } from "./Footer.tsx";
6
7export function ProjectsRoute() {
8 const projects = useProjects();
9
38}
39
40function ProjectCard({
41 user,
42 project,
76}
77
78function Privacy({ privacy }: { privacy: "public" | "unlisted" | "private" }) {
79 switch (privacy) {
80 case "public":

townie-126PreviewFrame.tsx4 matches

@dinavinter•Updated 1 hour ago
9}
10
11export function PreviewFrame(props: PreviewProps) {
12 const previewKey = useRef<string>("new-chat");
13 const [count, setCount] = useState<number>(0);
73const TSRE = /\/$/;
74
75function URLInput({ url, pathname, setPathname }) {
76 const prefix = url.replace(TSRE, "");
77 return (
90}
91
92function PreviewSelect({ index, setIndex, files }) {
93 return (
94 <div>
116}
117
118function usePreviewURL({ files }) {
119 const [index, setIndex] = useState<number>(0);
120 const htmlVals = files?.filter(file => file.links?.endpoint !== undefined);

townie-126pagination.ts5 matches

@dinavinter•Updated 1 hour ago
21 * Parse pagination parameters from URL
22 */
23export function getPaginationParams(url: URL): { page: number; pageSize: number } {
24 const page = parseInt(url.searchParams.get("page") || "1", 10);
25 const pageSize = parseInt(url.searchParams.get("pageSize") || "50", 10);
35 * Calculate pagination metadata
36 */
37export function calculatePagination(params: PaginationParams): PaginationResult {
38 const totalPages = Math.ceil(params.totalItems / params.pageSize);
39
51 * Generate SQL LIMIT and OFFSET clauses for pagination
52 */
53export function getPaginationSQL(page: number, pageSize: number): string {
54 const offset = (page - 1) * pageSize;
55 return `LIMIT ${pageSize} OFFSET ${offset}`;
59 * Generate HTML for pagination controls
60 */
61export function renderPaginationControls(pagination: PaginationResult, baseUrl: string): string {
62 const url = new URL(baseUrl);
63
64 // Function to generate page URL
65 const getPageUrl = (page: number) => {
66 url.searchParams.set("page", page.toString());

townie-126NotFoundRoute.tsx1 match

@dinavinter•Updated 1 hour ago
1/** @jsxImportSource https://esm.sh/react@18.2.0?dev */
2
3export function NotFoundRoute () {
4 return (
5 <div className="container">Page not found</div>

townie-126NewProjectRoute.tsx2 matches

@dinavinter•Updated 1 hour ago
4import { useCreateProject } from "../hooks/useCreateProject.tsx";
5
6export function NewProjectRoute () {
7 const [name, setName] = useState("");
8 const [privacy, setPrivacy] = useState("public");
65]
66
67function PrivacyRadios ({
68 value,
69 onChange,
tuna

tuna9 file matches

@jxnblk•Updated 5 days ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
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.