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=8&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 7147 results for "function"(378ms)

valtownInstagramindex.ts2 matches

@dcm31•Updated 1 day ago
31});
32
33// Utility function to serve files from the project
34async function serveFile(path: string, baseUrl: string): Promise<Response> {
35 try {
36 const content = await readFile(path, baseUrl);
vtProjectSearch

vtProjectSearchdb.ts23 matches

@dcm31•Updated 1 day ago
12
13// Load all usernames and val paths into memory for fast typeahead
14export async function loadTypeaheadDataIntoMemory(): Promise<void> {
15 console.log("Loading typeahead data into memory...");
16
46 * Search typeahead data by prefix
47 */
48export function searchTypeahead(query: string, limit: number = 10): string[] {
49 const lowerQuery = query.toLowerCase();
50 const results: string[] = [];
63 * Get activity data for the last 6 months
64 */
65export async function getActivityHeatmap(): Promise<{
66 date: string;
67 count: number;
96 * Get top contributors based on recency
97 */
98export async function getTopContributors(limit: number = 10): Promise<{
99 username: string;
100 valCount: number;
134 * Get most active vals based on recency and file count
135 */
136export async function getMostActiveVals(limit: number = 10): Promise<{
137 name: string;
138 username: string;
174 * Get database statistics for the homepage
175 */
176export async function getSearchStats(): Promise<{
177 totalVals: number;
178 totalFiles: number;
363};
364
365// Helper functions for val and file management
366
367/**
368 * Get a user by ID
369 */
370export async function getUser(userId: string): Promise<User | null> {
371 const result = await sqlite.execute(
372 `SELECT * FROM ${tablePrefix}_users WHERE id = ?`,
387 * Insert or update a user if it's newer than existing data
388 */
389export async function upsertUser(user: User): Promise<boolean> {
390 // Check if user exists and compare timestamps
391 const existingUser = await getUser(user.id);
430 * Get a val by ID
431 */
432async function getVal(valId: string): Promise<Val | null> {
433 const result = await sqlite.execute(
434 `SELECT * FROM ${tablePrefix}_vals WHERE id = ?`,
449 * Insert or update a val if it's newer than existing data
450 */
451export async function upsertVal(val: Val): Promise<boolean> {
452 // Convert Date object to string if needed
453 const updatedAt = val.updated_at;
501 * Get a file by ID
502 */
503async function getFile(fileId: string): Promise<File | null> {
504 const result = await sqlite.execute(
505 `SELECT * FROM ${tablePrefix}_files WHERE id = ?`,
520 * Insert or update a file if it's newer than existing data
521 */
522export async function upsertFile(file: File): Promise<boolean> {
523 // Convert Date object to string if needed
524
569 * Extract matched lines with context around matches
570 */
571function extractMatchedLines(
572 content: string,
573 searchText: string,
629 * Search for files containing specific text
630 */
631export async function searchFileContent(
632 searchText: string,
633): Promise<FileSearchResult[]> {
677 * Count total file search results
678 */
679export async function countFileSearchResults(searchText: string): Promise<number> {
680 const searchPattern = `%${searchText}%`;
681
695 * Count total val search results
696 */
697export async function countValSearchResults(searchText: string): Promise<number> {
698 const searchPattern = `%${searchText}%`;
699
712 * Count total user search results
713 */
714export async function countUserSearchResults(searchText: string): Promise<number> {
715 const searchPattern = `%${searchText}%`;
716
729 * Count total vals for a specific username
730 */
731export async function countUserVals(username: string): Promise<number> {
732 const result = await sqlite.execute(
733 `SELECT COUNT(*) as total
743 * Get vals by username with pagination
744 */
745export async function getValsByUsername(
746 username: string,
747 page: number = 1,
775 * Search for vals matching the query
776 */
777export async function searchVals(
778 searchText: string,
779 page: number = 1,
810 * Search for users matching the query
811 */
812export async function searchUsers(
813 searchText: string,
814 page: number = 1,
851 * Enhanced search that returns matched content with context and pagination
852 */
853export async function searchFileContentWithContext(
854 searchText: string,
855 contextLines: number = 2,
vtProjectSearch

vtProjectSearchapi.tsx3 matches

@dcm31•Updated 1 day ago
14
15// Handle typeahead API requests
16export function handleTypeahead(req: Request): Response {
17 const url = new URL(req.url);
18 const searchTerm = url.searchParams.get("q") || "";
46
47// Handle user vals API requests
48export async function handleUserVals(req: Request): Response {
49 const url = new URL(req.url);
50 const username = url.searchParams.get("user") || "";
142
143// Main request handler
144export async function handler(req: Request): Promise<Response> {
145 const url = new URL(req.url);
146
vtProjectSearch

vtProjectSearchcomponents.tsx14 matches

@dcm31•Updated 1 day ago
17
18// Define the Activity Heatmap component
19export function ActivityHeatmap({ activityData }: { activityData: { date: string; count: number }[] }) {
20 // Convert activity data to a map for easier lookup
21 const activityMap = new Map(activityData.map(item => [item.date, item.count]));
157
158// Helper to highlight the search terms in the code
159export function highlightText(text: string, searchTerm: string): JSX.Element {
160 if (!searchTerm) return <>{text}</>;
161
178
179// CodeBlock component for displaying code with line numbers
180export function CodeBlock(
181 { matchedLines, searchTerm, totalMatches: _totalMatches }: {
182 matchedLines: EnhancedSearchResult["matchedLines"];
204
205// File search result component
206export function FileSearchResultComponent(
207 { result, searchTerm }: { result: EnhancedSearchResult; searchTerm: string },
208) {
282
283// Val search result component
284export function ValSearchResultComponent(
285 { result, searchTerm }: { result: ValSearchResult; searchTerm: string },
286) {
356
357// User search result component
358export function UserSearchResultComponent(
359 { result, searchTerm }: { result: UserSearchResult; searchTerm: string },
360) {
415
416// Sub-section result for docs
417export function SubDocResultComponent(
418 { result, _searchTerm }: { result: SubDocResult; _searchTerm: string },
419) {
436
437// Doc search result component
438export function DocSearchResultComponent(
439 { result, searchTerm }: { result: DocSearchResult; searchTerm: string },
440) {
491
492// Result count tabs component
493export function ResultTypeTabs({
494 totalFileResults,
495 totalValResults,
539
540// Pagination component
541export function Pagination({
542 currentPage,
543 totalPages,
644
645// Sample results component for preview of other result types
646export function SampleResultsSection({
647 title,
648 linkText,
681
682// Main search page component
683export function SearchPage({
684 fileResults,
685 valResults,
1244 <a href="?q=database" className="example-link">database</a>
1245 <a href="?q=image" className="example-link">image</a>
1246 <a href="?q=function" className="example-link">function</a>
1247 <a href="?q=discord" className="example-link">discord</a>
1248 <a href="?q=openai" className="example-link">openai</a>
1399 <a href="?q=database" className="example-link">database</a>
1400 <a href="?q=image" className="example-link">image</a>
1401 <a href="?q=function" className="example-link">function</a>
1402 <a href="?q=discord" className="example-link">discord</a>
1403 <a href="?q=openai" className="example-link">openai</a>
vtProjectSearch

vtProjectSearchclient.tsx12 matches

@dcm31•Updated 1 day ago
1// Client-side script for typeahead and keyboard navigation
2export const clientScript = `
3 document.addEventListener('DOMContentLoaded', function() {
4 const searchInput = document.getElementById('search-input');
5 const resultsContainer = document.getElementById('typeahead-results');
11 let selectedIndex = -1;
12
13 // Function to fetch typeahead results
14 async function fetchTypeahead(query) {
15 if (query.length < 1) {
16 hideResults();
61 }
62
63 // Function to display results
64 function displayResults(results, query) {
65 // Clear previous results
66 resultsContainer.innerHTML = '';
102 }
103
104 // Function to hide results
105 function hideResults() {
106 resultsContainer.classList.remove('active');
107 selectedIndex = -1;
109
110 // Input event to trigger typeahead
111 searchInput.addEventListener('input', function() {
112 const query = this.value.trim();
113
135
136 // Handle keyboard navigation
137 searchInput.addEventListener('keydown', function(e) {
138 const items = resultsContainer.querySelectorAll('.typeahead-item');
139
167
168 // Update selection highlight
169 function updateSelection(items) {
170 items.forEach((item, i) => {
171 if (i === selectedIndex) {
178
179 // Close results when clicking outside
180 document.addEventListener('click', function(e) {
181 if (!searchInput.contains(e.target) && !resultsContainer.contains(e.target)) {
182 hideResults();
185
186 // Handle mouse movement to keep the search term item highlighted
187 resultsContainer.addEventListener('mouseover', function(e) {
188 // Find the search term item (last child)
189 const searchItem = resultsContainer.querySelector('.search-term');

Autoblocks_Webhook_Evaluatormain.tsx1 match

@dcm31•Updated 1 day ago
1import { Evaluation } from "npm:@autoblocks/client/testing";
2
3export default async function httpHandler(request: Request): Promise<Response> {
4 if (request.method !== "POST") {
5 return Response.json({ message: "Invalid method." }, {
vtProjectSearch

vtProjectSearchutils.tsx2 matches

@dcm31•Updated 1 day ago
1// Format date to relative time
2export function formatRelativeTime(dateString: string): string {
3 const date = new Date(dateString);
4 const now = new Date();
37
38// Format date for tooltip (full date)
39export function formatFullDate(dateString: string): string {
40 const date = new Date(dateString);
41 return date.toLocaleDateString("en-US", {
vtProjectSearch

vtProjectSearchdocsearch.ts2 matches

@dcm31•Updated 1 day ago
62 * @param query Search query
63 */
64export async function searchDocsCount(
65 query: string
66): Promise<number> {
85 * @param fetchData Whether to fetch the full data for each result
86 */
87export async function searchDocs(
88 query: string,
89 page: number = 1,
vtProjectSearch

vtProjectSearchdeno.lock4 matches

@dcm31•Updated 1 day ago
131 "dependencies": [
132 "es-errors",
133 "function-bind"
134 ]
135 },
216 ]
217 },
218 "function-bind@1.1.2": {
219 "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
220 },
226 "es-errors",
227 "es-object-atoms",
228 "function-bind",
229 "get-proto",
230 "gopd",
256 "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==",
257 "dependencies": [
258 "function-bind"
259 ]
260 },

valsmain.tsx1 match

@stevekrouse•Updated 1 day ago
8 "https://img.clerk.com/eyJ0eXBlIjoiZGVmYXVsdCIsImlpZCI6Imluc18yTm10cGhQUklwU0tqZHNiOHNnNGd2ZjJURFUiLCJyaWQiOiJ1c2VyXzJnZ3hadk1yUE5VUk5KY01VZnZtSWV2b3pkaiJ9";
9
10export default async function(req: Request): Promise<Response> {
11 const url = new URL(req.url);
12 if (url.pathname === "/") return serveFile("./index.html", import.meta.url);

getFileEmail4 file matches

@shouser•Updated 4 days ago
A helper function to build a file's email

TwilioHelperFunctions

@vawogbemi•Updated 2 months ago