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=2352&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 27494 results for "function"(1888ms)

selectHtmlmain.tsx7 matches

@yawnxyzβ€’Updated 9 months ago
6import { JSDOM } from 'npm:jsdom';
7
8// Function to fetch HTML from a URL and remove <style> and <script> tags
9export async function fetchHtml(url, removeSelectors = "style, script, link, noscript, frame, iframe, comment") {
10 try {
11 const response = await fetch(url);
22}
23
24// Function to use Cheerio to select text from the html, and attempts to clean it a bit
25export function selectHtml(html, selector = "h1", removeSelectors = "style, script, link, noscript, frame, iframe, comment") {
26 const $ = cheerio.load(html); // Load the cleaned HTML into Cheerio
27 $(removeSelectors).remove(); // Remove unwanted tags
37}
38
39// Function to convert HTML to Pug using html2pug
40export function convertHtmlToPug(html, options = { tabs: true }) {
41 const pug = html2pug(html, options);
42 return pug;
59}
60
61export function convertHtmlToMarkdown(htmlStr: string, options?: ConversionOptions): string {
62 const dom = new JSDOM(htmlStr);
63 const markdown = semanticMarkdown(htmlStr, { ...options, overrideDOMParser: new dom.window.DOMParser() });

dailyDadJokemain.tsx1 match

@rahulgβ€’Updated 9 months ago
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3
4export async function dailyDadJoke() {
5 let { setup, punchline } = await fetchJSON("https://official-joke-api.appspot.com/random_joke");
6 return email({

aqimain.tsx1 match

@unicornβ€’Updated 9 months ago
2import { easyAQI } from "https://esm.town/v/stevekrouse/easyAQI?v=5";
3
4export async function aqi(interval: Interval) {
5 const location = "ZΓΌrich, Schweiz"; // <-- change to place, city, or zip code
6 const data = await easyAQI({ location });

virtualPetSimmain.tsx5 matches

@muhammad_owais_warsiβ€’Updated 9 months ago
16const FOODS = ["🍎", "🍌", "πŸ₯•", "πŸ–", "🍣"];
17
18function App() {
19 const [pet, setPet] = useState(null);
20 const [loading, setLoading] = useState(true);
77}
78
79function client() {
80 createRoot(document.getElementById("root")).render(<App />);
81}
85}
86
87async function server(request: Request): Promise<Response> {
88 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
89 const SCHEMA_VERSION = 1;
138}
139
140async function getPet() {
141 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
142 const SCHEMA_VERSION = 1;
164}
165
166async function updatePet(action) {
167 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
168 const SCHEMA_VERSION = 1;

migrationsmain.tsx1 match

@saolsenβ€’Updated 9 months ago
1import { sqlite as valtown_sqlite } from "https://esm.town/v/std/sqlite";
2
3export async function migrate(
4 sqlite: typeof valtown_sqlite,
5 key: string,

KidsCodingDameDinoAdventuremain.tsx3 matches

@jbwintersβ€’Updated 9 months ago
69};
70
71function App() {
72 const [grid, setGrid] = useState(initialGrid);
73 const [moves, setMoves] = useState([]);
354}
355
356function client() {
357 createRoot(document.getElementById("root")).render(<App />);
358}
359if (typeof document !== "undefined") { client(); }
360
361async function server(request: Request): Promise<Response> {
362 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
363 const SCHEMA_VERSION = 1

getWeathermain.tsx1 match

@escalonaβ€’Updated 9 months ago
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2
3export async function getWeather(location: string): Promise<WeatherResponse> {
4 return fetchJSON(`https://wttr.in/${location}?format=j1`);
5}

getWeatherREADME.md1 match

@escalonaβ€’Updated 9 months ago
1## Get Weather
2
3Simple function to get weather data from the free [wttr.in](https://wttr.in/:help) service.
4
5```ts

sunsetNYCalendarmain.tsx3 matches

@ejfoxβ€’Updated 9 months ago
2// and creates a simple form to generate a calendar of events occurring before sunset.
3
4async function server(request: Request): Promise<Response> {
5 try {
6 const url = new URL(request.url);
79}
80
81async function generateSunsetEvents(action: string, minutesBefore: number, endDate: Date) {
82 const events = [];
83 let currentDate = new Date();
105}
106
107async function getSunsetTime(date: Date): Promise<Date> {
108 const formattedDate = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}`;
109 const response = await fetch(`https://api.sunrise-sunset.org/json?lat=40.7128&lng=-74.0060&date=${formattedDate}&formatted=0`);

TopHackerNewsDailyEmailmain.tsx3 matches

@browserbaseβ€’Updated 9 months ago
27// we create a OpenAI Tool that takes our schema as argument
28const extractContentTool: any = {
29 type: "function",
30 function: {
31 name: "extract_content",
32 description: "Extracts the content from the given webpage(s)",
56
57// we retrieve the serialized arguments generated by OpenAI
58const result = completion.choices[0].message.tool_calls![0].function.arguments;
59// the serialized arguments are parsed into a valid JavaScript array of objects
60const parsed = schema.parse(JSON.parse(result));

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.