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/$%7Bsuccess?q=function&page=1688&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 20195 results for "function"(2727ms)

1// This val responds with a styled "Hello, world!" in HTML with funky CSS gradients
2export default async function main(req: Request): Promise<Response> {
3 const htmlContent = `
4 <html>
1// This val responds with an HTML page styled with funky CSS gradients
2export default async function main(req: Request): Promise<Response> {
3 const html = `
4 <html>
1// This val responds with "Hello, world!"
2export default async function main(req: Request): Promise<Response> {
3 return new Response("Hello, world!");
4}
32};
33
34function renderComments(comments): string {
35 return comments
36 .map(
45}
46
47export default async function (req: Request): Promise<Response> {
48 const url = new URL(req.url);
49 const pathname = url.pathname;
65}
66
67function renderStoryPage(storyId: string): string {
68 const story = stories[storyId] || {
69 title: "Story Not Found",
107}
108
109function renderMainPage(): string {
110 return `
111<!DOCTYPE html>
41};
42
43function renderComments(comments: Comment[]): string {
44 return comments.map(comment => `
45 <div class="comment">
50}
51
52function renderStoryPage(storyId: string): string {
53 const story = stories[storyId] || { title: "Story Not Found", content: "The story you are looking for does not exist.", comments: [] };
54
88}
89
90function renderMainPage(): string {
91 const storyHtml = Object.entries(stories).map(([id, story]) => `
92 <div class="story">
126}
127
128export default async function(req: Request): Promise<Response> {
129 const url = new URL(req.url);
130 const pathname = url.pathname;
40};
41
42export default async function(req: Request): Promise<Response> {
43 const url = new URL(req.url);
44 const pathname = url.pathname;
60}
61
62function renderStoryPage(storyId: string): string {
63 const story = stories[storyId] || { title: "Story Not Found", content: "The story you are looking for does not exist.", comments: [] };
64 const commentsHtml = story.comments.map(comment => `
104}
105
106function renderHomePage(): string {
107 const storiesHtml = Object.entries(stories).map(([id, story]) => `
108 <div class="story">
3// we can make it interactive with additional scripts.
4
5export default async function(req: Request): Promise<Response> {
6 const url = new URL(req.url);
7 const pathname = url.pathname;
57}
58
59function renderStoryPage(storyId: string): string {
60 const stories = {
61 "1": {

tomatoSawfishmain.tsx1 match

@tempguy•Updated 10 months ago
2import { render } from "npm:preact-render-to-string";
3
4export default async function(req: Request) {
5 return new Response(
6 render(

valPreviewmain.tsx9 matches

@iamseeley•Updated 10 months ago
1export async function fetchVal(valId: string) {
2 try {
3 const response = await fetch(`https://api.val.town/v1/vals/${valId}`);
13}
14
15export async function evalCode(code: string) {
16 try {
17 const response = await fetch(`https://api.val.town/v1/eval`, {
46}
47
48function handleEvalCode(elementId: string) {
49 const element = document.getElementById(`code-${elementId}`);
50 if (element) {
73}
74
75export async function previewVal(valName: string, resultElementId: string) {
76 try {
77 const resultElement = document.getElementById(resultElementId);
94}
95
96function escapeHtml(unsafe: string) {
97 return unsafe
98 .replace(/&/g, "&amp;")
103}
104
105export function injectValContent(valId: string, elementId: string) {
106 return fetchVal(valId).then(data => {
107 if (data) {
225}
226
227export function initializeValComponents() {
228 document.querySelectorAll('[data-val-id]').forEach(element => {
229 const valId = element.getAttribute('data-val-id');
237}
238
239function handlePreviewVal(elementId: string, valName: string) {
240 const previewElementId = `preview-${elementId}`;
241 previewVal(valName, previewElementId).catch(error => {
248}
249
250// Ensure the handler functions are accessible globally
251(window as any).handlePreviewVal = handlePreviewVal;
252(window as any).handleEvalCode = handleEvalCode;
1// This val responds to HTTP requests with "Hello world"
2export default async function main(req: Request): Promise<Response> {
3 return new Response("Hello world");
4}

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 3 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.