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/$2?q=function&page=14&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 24751 results for "function"(3448ms)

taskswapauth.ts3 matches

@vishuu6969696969•Updated 9 hours ago
17
18// Simple password hashing (in production, use bcrypt or similar)
19async function hashPassword(password: string): Promise<string> {
20 const encoder = new TextEncoder();
21 const data = encoder.encode(password + 'taskswap_salt');
25}
26
27async function verifyPassword(password: string, hash: string): Promise<boolean> {
28 const hashedInput = await hashPassword(password);
29 return hashedInput === hash;
245
246// Middleware to check authentication
247export async function requireAuth(c: any, next: any) {
248 const sessionId = getCookie(c, 'session');
249

taskswapqueries.ts23 matches

@vishuu6969696969•Updated 9 hours ago
1// Database query functions for TaskSwap
2
3import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
5
6// User queries
7export async function createUser(userData: CreateUserRequest & { password_hash: string }): Promise<User> {
8 const result = await sqlite.execute(`
9 INSERT INTO users (username, email, password_hash, full_name, bio, skills)
21}
22
23export async function getUserById(id: number): Promise<User> {
24 const result = await sqlite.execute('SELECT * FROM users WHERE id = ?', [id]);
25 if (result.length === 0) throw new Error('User not found');
33}
34
35export async function getUserByEmail(email: string): Promise<User | null> {
36 const result = await sqlite.execute('SELECT * FROM users WHERE email = ?', [email]);
37 if (result.length === 0) return null;
45}
46
47export async function getUserByUsername(username: string): Promise<User | null> {
48 const result = await sqlite.execute('SELECT * FROM users WHERE username = ?', [username]);
49 if (result.length === 0) return null;
57}
58
59export async function updateUserTokens(userId: number, tokenChange: number): Promise<void> {
60 await sqlite.execute(`
61 UPDATE users
65}
66
67export async function updateUserRating(userId: number, newRating: number): Promise<void> {
68 await sqlite.execute(`
69 UPDATE users
74
75// Task queries
76export async function createTask(taskData: CreateTaskRequest, creatorId: number): Promise<Task> {
77 const tokenCost = calculateTokenCost(taskData.difficulty, taskData.estimated_hours);
78
95}
96
97export async function getTaskById(id: number): Promise<Task> {
98 const result = await sqlite.execute(`
99 SELECT t.*,
127}
128
129export async function getTasks(filters: {
130 category?: string;
131 difficulty?: string;
212}
213
214export async function updateTaskStatus(taskId: number, status: string, assigneeId?: number): Promise<void> {
215 if (assigneeId) {
216 await sqlite.execute(`
229
230// Message queries
231export async function createMessage(senderId: number, receiverId: number, taskId: number, content: string): Promise<Message> {
232 const result = await sqlite.execute(`
233 INSERT INTO messages (sender_id, receiver_id, task_id, content)
238}
239
240export async function getMessageById(id: number): Promise<Message> {
241 const result = await sqlite.execute(`
242 SELECT m.*,
269}
270
271export async function getTaskMessages(taskId: number): Promise<Message[]> {
272 const result = await sqlite.execute(`
273 SELECT m.*,
299
300// Exchange queries
301export async function createExchange(taskId: number, creatorId: number, assigneeId: number): Promise<Exchange> {
302 const result = await sqlite.execute(`
303 INSERT INTO exchanges (task_id, creator_id, assignee_id, status)
308}
309
310export async function getExchangeById(id: number): Promise<Exchange> {
311 const result = await sqlite.execute('SELECT * FROM exchanges WHERE id = ?', [id]);
312 if (result.length === 0) throw new Error('Exchange not found');
314}
315
316export async function updateExchangeStatus(exchangeId: number, status: string): Promise<void> {
317 const completedAt = status === 'completed' ? new Date().toISOString() : null;
318
324}
325
326export async function addExchangeRating(exchangeId: number, isCreator: boolean, rating: number, feedback?: string): Promise<void> {
327 if (isCreator) {
328 await sqlite.execute(`
341
342// Session management
343export async function createSession(userId: number): Promise<string> {
344 const sessionId = crypto.randomUUID();
345 const expiresAt = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000); // 7 days
353}
354
355export async function getSessionUser(sessionId: string): Promise<User | null> {
356 const result = await sqlite.execute(`
357 SELECT u.* FROM users u
370}
371
372export async function deleteSession(sessionId: string): Promise<void> {
373 await sqlite.execute('DELETE FROM sessions WHERE id = ?', [sessionId]);
374}
375
376// Utility functions
377function calculateTokenCost(difficulty: string, estimatedHours: number): number {
378 const baseRates = {
379 easy: 2,

taskswapmigrations.ts2 matches

@vishuu6969696969•Updated 9 hours ago
3import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
4
5export async function runMigrations() {
6 console.log('Running database migrations...');
7
109
110// Seed data for development
111export async function seedDatabase() {
112 console.log('Seeding database with sample data...');
113

taskswaputils.ts11 matches

@vishuu6969696969•Updated 9 hours ago
1// Shared utility functions for TaskSwap
2
3import type { TaskDifficulty, TaskCategory } from './types.ts';
47};
48
49export function calculateTokenCost(difficulty: TaskDifficulty, estimatedHours: number): number {
50 const baseRates = {
51 easy: 2,
57}
58
59export function formatTimeAgo(dateString: string): string {
60 const date = new Date(dateString);
61 const now = new Date();
70}
71
72export function formatDate(dateString: string): string {
73 return new Date(dateString).toLocaleDateString('en-US', {
74 year: 'numeric',
78}
79
80export function validateEmail(email: string): boolean {
81 const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
82 return emailRegex.test(email);
83}
84
85export function validateUsername(username: string): boolean {
86 const usernameRegex = /^[a-zA-Z0-9_]{3,20}$/;
87 return usernameRegex.test(username);
88}
89
90export function generateAvatarUrl(username: string): string {
91 // Generate a consistent avatar URL based on username
92 const colors = ['red', 'blue', 'green', 'purple', 'orange', 'pink', 'indigo', 'teal'];
97}
98
99export function truncateText(text: string, maxLength: number): string {
100 if (text.length <= maxLength) return text;
101 return text.substring(0, maxLength) + '...';
102}
103
104export function getSkillColor(skill: string): string {
105 const colors = [
106 'bg-blue-100 text-blue-800',
118}
119
120export function debounce<T extends (...args: any[]) => any>(
121 func: T,
122 wait: number
130}
131
132export function classNames(...classes: (string | undefined | null | false)[]): string {
133 return classes.filter(Boolean).join(' ');
134}

taskswapREADME.md1 match

@vishuu6969696969•Updated 9 hours ago
37└── shared/
38 ├── types.ts # Shared TypeScript types
39 └── utils.ts # Shared utility functions
40```
41

RoadMapsREADME.md1 match

@aakash1402•Updated 11 hours ago
8- Interactive drag-and-drop interface
9- roadmap.sh-inspired styling
10- Export functionality
11- Responsive design
12

RoadMapsRoadmapCanvas.tsx1 match

@aakash1402•Updated 11 hours ago
15}
16
17export default function RoadmapCanvas({
18 nodes,
19 connections,

RoadMapsNodeEditor.tsx1 match

@aakash1402•Updated 11 hours ago
10}
11
12export default function NodeEditor({ node, onSave, onCancel, onDelete }: NodeEditorProps) {
13 const [title, setTitle] = useState(node.title);
14 const [description, setDescription] = useState(node.description || '');

RoadMapsToolbar.tsx1 match

@aakash1402•Updated 11 hours ago
12}
13
14export default function Toolbar({
15 onAddNode,
16 onExport,

RoadMapsApp.tsx1 match

@aakash1402•Updated 11 hours ago
6import type { RoadmapNode, RoadmapConnection, DragState } from "../../shared/types.ts";
7
8export default function App() {
9 const [nodes, setNodes] = useState<RoadmapNode[]>([
10 {

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 1 month ago
Simple functional CSS library for Val Town
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.