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/$%7Burl%7D?q=function&page=1&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 18147 results for "function"(1462ms)

TownieHome.tsx1 match

@valdottown•Updated 32 mins ago
4import { EyeIcon, FileCode2Icon, SparklesIcon, SquarePenIcon } from "./icons.tsx";
5
6export function Home() {
7 return (
8 <div className="container">

TownieLoginRoute.tsx1 match

@valdottown•Updated 33 mins ago
4import { useAuth } from "../hooks/useAuth.tsx";
5
6export function LoginRoute() {
7 const navigate = useNavigate();
8 const { isAuthenticated, authenticate, error } = useAuth();

testPondiverseaddCreation1 match

@argmn•Updated 53 mins ago
4import { TABLE_NAME } from "./updateTable";
5
6export default async function(req: Request): Promise<Response> {
7 // body contains:
8 // - title (string)

testPondiverseupdateTable1 match

@argmn•Updated 1 hour ago
2
3export const TABLE_NAME = "pondiverse_creations_v4";
4export default async function(req: Request): Promise<Response> {
5 let body;
6 try {

telegramBotStarterindex.ts14 matches

@asdfg•Updated 1 hour ago
1// ============================================================
2// CORE FUNCTIONALITY
3// ============================================================
4import sendTelegramMessage from "https://esm.town/v/asdfg/telegramBotStarter/sendTelegramMessage.tsx";
7 * Expose this as an HTTP endpoint in Val.town
8 */
9export default async function handleTelegramWebhook(req) {
10 try {
11 // Ensure the request is a POST request
74 * Process commands from the owner
75 */
76async function processOwnerCommand(message) {
77 const text = message.text || "";
78
199 * Get information about a user
200 */
201async function getUserInfo(userId) {
202 return await DB.get(`userInfo:${userId}`);
203}
206 * Get list of all active users who have messaged the bot
207 */
208async function getActiveUsers() {
209 const keys = await DB.list({ prefix: "userInfo:" });
210 const users = [];
222 * Get list of blocked user IDs
223 */
224async function getBlockedUsers() {
225 return await DB.get("blockedUsers") || [];
226}
229 * Block a user
230 */
231async function blockUser(userId) {
232 const blockedUsers = await getBlockedUsers();
233 userId = userId.toString();
244 * Unblock a user
245 */
246async function unblockUser(userId) {
247 const blockedUsers = await getBlockedUsers();
248 userId = userId.toString();
264 * Store a message in the database
265 */
266async function storeMessage(userId, userName, text, direction) {
267 const messages = await getMessages(userId) || [];
268
291 * Get message history for a specific user
292 */
293async function getMessages(userId) {
294 return await DB.get(`messages:${userId}`) || [];
295}
298 * Notify the owner about new incoming messages
299 */
300async function notifyOwner(userId, userName, messageText) {
301 const ownerChatId = process.env.OWNER_CHAT_ID;
302
311 * Reply to a specific user
312 */
313async function replyToUser(userId, text) {
314 // Send the message to the user
315 const success = await sendTelegramMessage(userId, text);
343
344// ============================================================
345// SETUP FUNCTIONS
346// ============================================================
347
350 * Use this once during initial setup
351 */
352export async function setupWebhook(webhookUrl) {
353 try {
354 const botToken = process.env.TELEGRAM_BOT_TOKEN;

telegramBotStartertestBot.tsx2 matches

@asdfg•Updated 1 hour ago
5import { sendTelegramMessage } from "https://esm.town/v/asdfg/telegramBotStarter/sendTelegramMessage.tsx";
6
7async function testBot() {
8 const ownerChatId = process.env.OWNER_CHAT_ID;
9
26}
27
28// console log testBot function
29console.log(await testBot);

telegramBotStartersendTelegramMessage.tsx1 match

@asdfg•Updated 1 hour ago
3 * Requires a Telegram Bot token as an environment variable
4 */
5export async function sendTelegramMessage(chatId: string, message: string) {
6 const botToken = Deno.env.get('TELEGRAM_BOT_TOKEN');
7

Townieusage-dashboard.ts4 matches

@valdottown•Updated 1 hour ago
4
5// Basic Auth middleware
6async function basicAuthMiddleware(req: Request): Promise<Response | null> {
7 const realm = "Usage Dashboard";
8 const unauthorizedResponse = new Response("Unauthorized", {
50}
51
52export default async function(req: Request) {
53 // Check authentication first
54 const authResponse = await basicAuthMiddleware(req);
286
287 <script>
288 document.addEventListener('DOMContentLoaded', function() {
289 // Add click event listeners to all tabs
290 document.querySelectorAll('.tab').forEach(tab => {
291 tab.addEventListener('click', function() {
292 const tabId = this.getAttribute('data-tab');
293

Townieschema.tsx2 matches

@valdottown•Updated 1 hour ago
20}
21
22async function createTables() {
23 await sqlite.execute(`
24 CREATE TABLE IF NOT EXISTS ${USAGE_TABLE} (
42}
43
44async function deleteTables() {
45 await sqlite.execute(`DROP TABLE IF EXISTS ${USAGE_TABLE}`);
46}

Towniequeries.tsx4 matches

@valdottown•Updated 1 hour ago
7// but in the meantime, we can cache user info in memory
8const userIdCache: { [key: string]: any } = {};
9export async function getUser(bearerToken: string) {
10 if (userIdCache[bearerToken]) return userIdCache[bearerToken];
11
16}
17
18async function last24Hours(userId: string) {
19 const usage = await sqlite.execute(
20 `SELECT
37const DAILY_PRO_LIMIT = 5; // $5 per day
38
39export async function overLimit(bearerToken: string) {
40 const user = await getUser(bearerToken);
41 const last24HourUsage = await last24Hours(user.id);
44}
45
46export async function trackUsage({
47 bearerToken,
48 val_id,

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": "*",