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=1565&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 18317 results for "function"(2653ms)

Queriesmain.tsx10 matches

@iamseeley•Updated 11 months ago
3
4// Fetch user by username
5export async function getUserByUsername(username: string) {
6 const userResult = await sqlite.execute({
7 sql: `SELECT id, name, bio, username, email, location, currently_listening, currently_reading_title,
29
30// Update user profile
31export async function updateUser(userId, name, bio, location, currentlyListening, currentlyReading, currentlyWatching, profile_theme, profile_img) {
32 if (typeof userId !== "number") {
33 throw new Error("userId must be a number.");
46}
47
48export async function insertUserLink(userId: number, label: string, url: string) {
49 await sqlite.execute({
50 sql: `INSERT INTO user_links (user_id, label, url) VALUES (?, ?, ?)`,
53}
54
55export async function getLinkById(linkId: number) {
56 const result = await sqlite.execute({
57 sql: `SELECT id, label, url, user_id FROM user_links WHERE id = ?`,
68}
69
70export async function updateUserLink(linkId: number, label: string, url: string) {
71 await sqlite.execute({
72 sql: `UPDATE user_links SET label = ?, url = ? WHERE id = ?`,
75}
76
77export async function deleteUserLink(linkId: number, userId: number) {
78 await sqlite.execute({
79 sql: `DELETE FROM user_links WHERE id = ? AND user_id = ?`,
82}
83
84export async function getUserLinks(userId) {
85 if (typeof userId !== "number") {
86 throw new Error("userId must be a number.");
101}
102
103export async function isUsernameTaken(username) {
104 const result = await sqlite.execute({
105 sql: `SELECT COUNT(*) FROM users WHERE username = ?`,
110}
111
112export async function isEmailTaken(email) {
113 const result = await sqlite.execute({
114 sql: `SELECT COUNT(*) FROM users WHERE email = ?`,
140
141
142export async function getProfileImageUrl(username) {
143 const key = `profile_img/${username}`;
144 const imageUrl = await blob.get(key);

incremementCloudLabCountAntiSpammain.tsx1 match

@todepond•Updated 11 months ago
4// Make SQLite table to store the count increments (with timestamps)
5
6export default async function(req: Request): Promise<Response> {
7 const result = await sqlite.batch([
8 "CREATE TABLE IF NOT EXISTS counter_2_baby (timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)",

getCloudLabCountmain.tsx1 match

@todepond•Updated 11 months ago
4// TODO: Convert to sqlite
5
6export default async function(req: Request): Promise<Response> {
7 const result = await sqlite.execute(
8 "SELECT COUNT(*) FROM counter_2_baby",

createValmain.tsx1 match

@stevekrouse•Updated 11 months ago
29}
30
31export function createVal({ token, ...data }: { token?: string } & CreateValArgs): Promise<ValResponse> {
32 return fetchJSON("https://api.val.town/v1/vals", {
33 bearer: token || Deno.env.get("valtown"),

hono_react_ssrmain.tsx1 match

@stevekrouse•Updated 11 months ago
40
41export const middleware = (importMetaURL: string) =>
42 async function(req: Request): Promise<Response> {
43 const { author, name } = extractValInfo(importMetaURL);
44 const valURL = `https://www.val.town/v/${author}/${name}`;

linkInBioTemplatemain.tsx1 match

@vhugoobject•Updated 11 months ago
12};
13
14export default async function(req: Request) {
15 return new Response(
16 renderToString(

valTownBadgeExamplemain.tsx1 match

@jxnblk•Updated 11 months ago
4import { render } from "npm:preact-render-to-string";
5
6function handler(req: Request): Promise<Response> {
7 const body = render(
8 <div>

codeIconReactmain.tsx1 match

@jxnblk•Updated 11 months ago
2import React from "npm:react";
3
4export default function CodeIcon(props: React.SVGProps<SVGSVGElement>) {
5 return (
6 <svg

staticChessREADME.md1 match

@bjenhamin4alfredolvchenki•Updated 11 months ago
8Plain, brutalist, no bloat chess. Every page is only html and css. Every chess move is made by clicking a link. Send a link to your friend and they'll send you one back to make your move. No silly animations or slick interactivity to trip up your gameplay. When Google indexes this site will we successfully compute all possible chess moves?
9
10Functionality is quite limited, and things might be broken. Please let me know if you find bugs!
11
12Inspired by [this HN discussion](https://news.ycombinator.com/item?id=39456467) about sites that have all possible game states of tic-tac-toe.

frontmattermain.tsx2 matches

@pomdtr•Updated 11 months ago
6import { frontmatter } from "npm:micromark-extension-frontmatter";
7
8export async function extractFrontmatter(readme: string) {
9 const tree = await fromMarkdown(readme, {
10 extensions: [frontmatter(["yaml"])],
23}
24
25export async function extractValFrontmatter(val: { author: string; name: string }) {
26 const { readme } = await api<{ readme: string }>(`/v1/alias/${val.author}/${val.name}`);
27 return extractFrontmatter(readme);

getFileEmail4 file matches

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