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/image-url.jpg%20%22Optional%20title%22?q=function&page=109&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 21193 results for "function"(1539ms)

hn-fetchindex.tsx2 matches

@matijaโ€ขUpdated 3 days ago
1async function fetchHackerNews() {
2 try {
3 const response = await fetch("https://news.ycombinator.com/");
14}
15
16export default async function(req: Request): Promise<Response> {
17 const hackerNews = await fetchHackerNews();
18 // return Response.json({ ok: true })

satori-syntax-highlighterutils.ts2 matches

@stevekrouseโ€ขUpdated 3 days ago
2
3// Get the base URL from a request URL
4export function getBaseUrl(url: string): string {
5 const parsedUrl = new URL(url);
6 return `${parsedUrl.protocol}//${parsedUrl.host}`;
8
9// Build the highlighter URL with parameters
10export function buildHighlighterUrl(
11 baseUrl: string,
12 code: string,

satori-syntax-highlightertypes.ts1 match

@stevekrouseโ€ขUpdated 3 days ago
12export const DEFAULT_CODE = `const btn = document.getElementById('btn')
13let count = 0
14function render() {
15 btn.innerText = \`Count: \${count}\`
16}

JobChatAppREADME.md1 match

@cipherโ€ขUpdated 3 days ago
19โ”‚ โ”œโ”€โ”€ database/
20โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
21โ”‚ โ”‚ โ””โ”€โ”€ queries.ts # DB query functions
22โ”‚ โ”œโ”€โ”€ routes/ # Route modules
23โ”‚ โ”‚ โ”œโ”€โ”€ jobs.ts # Job posting endpoints

NPLLMpackage-generator.ts7 matches

@wolfโ€ขUpdated 3 days ago
7 * Generates a TypeScript implementation for a package based on its name and description
8 */
9export async function generatePackageImplementation(
10 packageName: string,
11 description: string,
18The implementation should:
191. Be a single TypeScript file
202. Export a main function or class that fulfills the package description
213. Include proper JSDoc comments
224. Be simple but functional
235. Include 2-3 helper functions if appropriate
24
25Only return the TypeScript code without any explanation or markdown formatting.
34 * In a real-world scenario, you would use the TypeScript compiler API
35 */
36export function compileTypeScript(tsCode: string): string {
37 // This is a very simplified "compilation" that just removes TypeScript types
38 // In a real implementation, you would use the TypeScript compiler
48 * Creates a tar archive for an npm package
49 */
50export async function createPackageTar(
51 packageName: string,
52 version: string = "1.0.0",
90 */
91${
92 tsImplementation.replace(/export function/g, "export declare function")
93 .replace(/export class/g, "export declare class")
94 .replace(/export const/g, "export declare const")

untitled-860checkCert.tsx4 matches

@jclack2โ€ขUpdated 3 days ago
1// This function checks a domain's SSL certificate and extracts the expiration date
2// It can be set up as a scheduled (cron) val to monitor certificate expiration
3
4export default async function checkCertExpiration(domain) {
5 // Default to cdatacloud.net if no domain is provided
6 domain = domain || "www.cdatacloud.net";
22 // So we need to use the tls module in Node.js or Deno's TLS APIs
23
24 // For Val Town, we can use Deno's TLS connect function
25 const conn = await Deno.connectTls({
26 hostname: domain,
62// If you want to run this as a cron job, you could set up email notifications
63// when certificates are close to expiration
64export async function certExpirationCron() {
65 const domains = [
66 "www.cdatacloud.net",

sa_chesschess.js24 matches

@pro56โ€ขUpdated 3 days ago
32
33 // Initialize the board
34 function initializeBoard() {
35 const board = Array(8).fill().map(() => Array(8).fill(null));
36
52
53 // Render the chess board
54 function renderBoard() {
55 const chessboard = document.getElementById('chessboard');
56 chessboard.innerHTML = '';
118
119 // Get Unicode symbol for chess piece
120 function getPieceSymbol(piece) {
121 const symbols = {
122 'white': {
142
143 // Handle square click
144 function handleSquareClick(event) {
145 if (gameState.gameOver) return;
146
185
186 // Select a piece and calculate valid moves
187 function selectPiece(row, col) {
188 gameState.selectedPiece = { row, col };
189 gameState.validMoves = calculateValidMoves(row, col);
192
193 // Make a move
194 function makeMove(from, to, special) {
195 const piece = gameState.board[from.row][from.col];
196 const capturedPiece = gameState.board[to.row][to.col];
264
265 // Handle special moves like castling and en passant
266 function handleSpecialMoves(piece, from, to, special) {
267 if (!special) return;
268
297
298 // Calculate valid moves for a piece
299 function calculateValidMoves(row, col) {
300 const piece = gameState.board[row][col];
301 if (!piece) return [];
331
332 // Calculate pawn moves
333 function calculatePawnMoves(row, col, piece) {
334 const moves = [];
335 const direction = piece.color === 'white' ? -1 : 1;
367
368 // Calculate knight moves
369 function calculateKnightMoves(row, col, piece) {
370 const moves = [];
371 const offsets = [
392
393 // Calculate bishop moves
394 function calculateBishopMoves(row, col, piece) {
395 const moves = [];
396 const directions = [
424
425 // Calculate rook moves
426 function calculateRookMoves(row, col, piece) {
427 const moves = [];
428 const directions = [
456
457 // Calculate queen moves (combination of bishop and rook)
458 function calculateQueenMoves(row, col, piece) {
459 return [
460 ...calculateBishopMoves(row, col, piece),
464
465 // Calculate king moves
466 function calculateKingMoves(row, col, piece) {
467 const moves = [];
468 const directions = [
556
557 // Check if a square is within the bounds of the board
558 function isInBounds(row, col) {
559 return row >= 0 && row < 8 && col >= 0 && col < 8;
560 }
561
562 // Check if a square is attacked by the opponent
563 function isSquareAttacked(row, col, color) {
564 const opponentColor = color === 'white' ? 'black' : 'white';
565
671
672 // Check if a player is in check
673 function isInCheck(color) {
674 const kingPosition = gameState.kingPositions[color];
675 return isSquareAttacked(kingPosition.row, kingPosition.col, color);
677
678 // Check if a move would leave the king in check
679 function wouldBeInCheck(color, from, to, special) {
680 // Create a temporary copy of the board
681 const tempBoard = gameState.board.map(row => [...row]);
812
813 // Promote a pawn
814 function promotePawn(row, col) {
815 // Create a modal for promotion options
816 const modal = document.createElement('div');
853
854 // Check game status (check, checkmate, stalemate)
855 function checkGameStatus() {
856 // Check if the current player is in check
857 const isCheck = isInCheck(gameState.currentPlayer);
902
903 // Check for insufficient material (draw condition)
904 function isInsufficientMaterial() {
905 let whitePieces = [];
906 let blackPieces = [];
963
964 // Update game status display
965 function updateGameStatus() {
966 const statusElement = document.getElementById('game-status');
967
980
981 // Update captured pieces display
982 function updateCapturedPieces() {
983 const whiteCapturedElement = document.getElementById('captured-pieces-white');
984 const blackCapturedElement = document.getElementById('captured-pieces-black');
989
990 // Reset the game
991 function resetGame() {
992 gameState.board = initializeBoard();
993 gameState.currentPlayer = 'white';

sa_chessindex.ts1 match

@pro56โ€ขUpdated 3 days ago
1import { serveFile, readFile } from "https://esm.town/v/std/utils@85-main/index.ts";
2
3export default async function(req: Request) {
4 const url = new URL(req.url);
5 const path = url.pathname;

sa_chessREADME.md3 matches

@pro56โ€ขUpdated 3 days ago
1# Val Town Chess
2
3A fully functional chess game implemented in JavaScript for Val Town. This game includes all standard chess rules and features.
4
5## Features
18 - Draw conditions (insufficient material, 50-move rule)
19- Captured pieces display
20- Reset game functionality
21
22## How to Play
52Potential enhancements for the future:
53- Move history and notation
54- Undo move functionality
55- Timer/clock for timed games
56- Save/load game state

StarterPackFeedsHome.tsx4 matches

@moeโ€ขUpdated 3 days ago
10import { UserAvatarsRow } from './StarterPack.tsx'
11
12export function Home() {
13 const [context, setContext] = useState<any>()
14 useEffect(() => {
37}
38
39function CuratedPacks() {
40 const curatedPacks = [
41 'independent-journalists-glnse9',
56}
57
58function PackCard({ packId }) {
59 const { data: starterPack, isLoading } = useQuery({
60 queryKey: ['pack', packId],
94}
95
96function VisitForm({}) {
97 const navigate = useNavigate()
98 const [url, setUrl] = useState('')

getFileEmail4 file matches

@shouserโ€ขUpdated 3 weeks ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblkโ€ขUpdated 4 weeks 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.