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%22Image%20title%22?q=function&page=2538&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 28713 results for "function"(3700ms)

26const STORIES_KEY = "hn_clone_stories";
27
28async function getStories(): Promise<Story[]> {
29 return (await blob.getJSON(STORIES_KEY)) ?? DEFAULT_STORIES;
30}
31
32async function saveStories(stories: Story[]): Promise<void> {
33 await blob.setJSON(STORIES_KEY, stories);
34}
1import { blob } from "https://esm.town/v/std/blob";
2
3// Function to initialize the stories in blob storage
4const initializeStories = async () => {
5 const initialStories = Array.from({ length: 30 }, (_, i) => ({
13};
14
15// Function to get all stories
16const getAllStories = async () => {
17 return await blob.getJSON("stories");
18};
19
20// Function to submit a new story
21const submitNewStory = async (newStory) => {
22 const stories = await getAllStories();
30};
31
32// Function to upvote a story
33const upvoteStory = async (storyId) => {
34 const stories = await getAllStories();
48initializeStories();
49
50export default async function main(req: Request): Promise<Response> {
51 const url = new URL(req.url);
52
5await blob.setJSON("stories", []);
6
7// Function to get all stories
8const getAllStories = async () => {
9 const stories = await blob.getJSON("stories");
11};
12
13// Function to add a new story
14const addStory = async (title, author) => {
15 const newStory = {
27};
28
29// Function to upvote a story
30const upvoteStory = async (id) => {
31 const stories = await getAllStories();
42};
43
44// Export the functions for use in the HTTP server
45
46export default async function main(req: Request): Promise<Response> {
47 const url = new URL(req.url);
48 const path = url.pathname;
3
4// Fetch all stories or initialize an empty array if no data exists yet
5export default async function main(req: Request): Promise<Response> {
6 let stories = await blob.getJSON("hackerNewsStories") || [];
7
9];
10
11// Main function to handle HTTP requests
12export default async function(req: Request): Promise<Response> {
13 if (req.method === "GET") {
14 return getStories(req);
22}
23
24// Function to get the list of stories
25async function getStories(req: Request): Promise<Response> {
26 let existingStories = await blob.getJSON("hacker-news-stories");
27 return new Response(JSON.stringify(existingStories), { headers: { "Content-Type": "application/json" } });
28}
29
30// Function to submit a new story
31async function submitStory(req: Request): Promise<Response> {
32 const data = await req.json();
33 const newStory = { id: stories.length + 1, title: data.title, votes: 0 };
37}
38
39// Function to upvote a story
40async function upvoteStory(req: Request): Promise<Response> {
41 const data = await req.json();
42 const storyId = data.id;
8];
9
10// Main function to handle HTTP requests
11export default async function main(req: Request): Promise<Response> {
12 if (req.method === "GET") {
13 // Get the list of stories
38`;
39
40export default async function main(req: Request): Promise<Response> {
41 // Fetch existing comments
42 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
32`;
33
34export default async function main(req: Request): Promise<Response> {
35 // Fetch existing comments
36 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
32`;
33
34export default async function main(req: Request): Promise<Response> {
35 // Fetch existing comments
36 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];
36`;
37
38export default async function main(req: Request): Promise<Response> {
39 // Fetch existing comments
40 let comments: string[] = await blob.getJSON(COMMENTS_KEY) || [];

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.