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/$%7Bart_info.art.src%7D?q=function&page=1560&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 20293 results for "function"(3224ms)

val_Qj8c8xTIqvmain.tsx2 matches

@dhvanil•Updated 6 months ago
1
2 export default async function handler(req) {
3 try {
4 const result = await (async () => {
5 function findLowestThreeDigitFibonacci() {
6 let a = 0, b = 1;
7 let lowestThreeDigit = null;

val_S1NNtqMDtfmain.tsx3 matches

@dhvanil•Updated 6 months ago
1
2 export default async function handler(req) {
3 try {
4 const result = await (async () => {
5 function isPrime(num) {
6 if (num <= 1) return false;
7 for (let i = 2; i <= Math.sqrt(num); i++) {
11}
12
13function findLowestThreeDigitPrime() {
14 for (let num = 100; num < 1000; num++) {
15 if (isPrime(num)) {

val_9Vk5LnFz7tmain.tsx2 matches

@dhvanil•Updated 6 months ago
1
2 export default async function handler(req) {
3 try {
4 const result = await (async () => {
5 function fibonacci() {
6 let a = 0, b = 1;
7 while (b < 1000) {

openaiDefinermain.tsx7 matches

@willthereader•Updated 6 months ago
3const openai = new OpenAI();
4
5export default async function(req: Request): Promise<Response> {
6 log.info("Request received:", req.method, req.url);
7
35}
36
37export async function parseRequest(req: Request): Promise<{ selection: string; followUp: string; context: string[] }> {
38 const body = await req.text();
39 log.debug("Request body:", body);
51}
52
53export function prepareMessages(selection: string, followUp: string, context: string[]): Array<Object> {
54 const contextString = context.length > 0 ? `Consider the following context: ${context.join(", ")}. ` : "";
55 const messages = [
82}
83
84export function streamResponse(stream: ReadableStream): Response {
85 const encoder = new TextEncoder();
86
108}
109
110export function handleError(error: Error): Response {
111 log.error("Error occurred:", error);
112
123}
124
125export function handleCorsPreflightRequest(): Response {
126 return new Response(null, {
127 headers: {
142const currentLogLevel = logLevels.INFO; // Adjust this to change logging level
143
144function formatMessage(level: string, message: string, ...args: any[]): string {
145 const timestamp = new Date().toISOString();
146 return `${timestamp} [${level}] ${message} ${args.join(" ")}`;

multilingualchatroommain.tsx9 matches

@daisuke•Updated 6 months ago
109};
110
111function Banner({ message, isVisible, language }) {
112 if (!isVisible) return null;
113 return <div className="banner">{message[language] || message.en}</div>;
114}
115
116function UserList({ users, t }) {
117 return (
118 <div className="user-list">
129}
130
131function Sidebar({ users, language, handleLanguageChange, roomUrl, copyToClipboard, copied, t }) {
132 return (
133 <div className="sidebar">
165}
166
167function TypingIndicator({ typingUsers, t }) {
168 if (typingUsers.length === 0) return null;
169
180}
181
182function App() {
183 const [messages, setMessages] = useState([]);
184 const [inputMessage, setInputMessage] = useState("");
506}
507
508function client() {
509 createRoot(document.getElementById("root")).render(<App />);
510}
511if (typeof document !== "undefined") { client(); }
512
513export default async function server(request: Request): Promise<Response> {
514 const url = new URL(request.url);
515 const { blob } = await import("https://esm.town/v/std/blob");
524 const TIME_WINDOW = 60 * 1000; // 1 minute
525
526 async function checkRateLimit() {
527 const now = Date.now();
528 const rateLimit = await blob.getJSON(RATE_LIMIT_KEY) || { count: 0, timestamp: now };
539 }
540
541 async function translateText(text: string, targetLanguage: string, sourceLanguage: string): Promise<string> {
542 const cacheKey = `${KEY}_translation_${sourceLanguage}_${targetLanguage}_${text}`;
543 const cachedTranslation = await blob.getJSON(cacheKey);

weatherDashboardmain.tsx6 matches

@oioioi•Updated 6 months ago
14};
15
16function getWeatherIcon(code) {
17 if (code === 0) return weatherIcons.clear;
18 if (code >= 1 && code <= 3) return weatherIcons.cloudy;
23}
24
25function WeatherDashboard() {
26 const [weatherData, setWeatherData] = useState(null);
27 const [location, setLocation] = useState("New York");
32 }, [location]);
33
34 async function fetchWeatherData(city) {
35 try {
36 const response = await fetch(`${API_BASE_URL}?latitude=40.71&longitude=-74.01&daily=weathercode,temperature_2m_max,temperature_2m_min,precipitation_probability_max&current_weather=true&timezone=auto&forecast_days=7`);
42 }
43
44 function handleSearch(e) {
45 e.preventDefault();
46 setLocation(searchInput);
93}
94
95function client() {
96 createRoot(document.getElementById("root")).render(<WeatherDashboard />);
97}
101}
102
103export default async function server(request: Request): Promise<Response> {
104 return new Response(
105 `

generateframeImagemain.tsx5 matches

@stevekrouse•Updated 6 months ago
3import { renderToString } from "https://esm.sh/react-dom/server";
4
5async function getWeather(latitude: number, longitude: number) {
6 const url =
7 `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current_weather=true&temperature_unit=fahrenheit`;
20}
21
22function getWeatherCondition(code: number): string {
23 const conditions: { [key: number]: string } = {
24 0: "Clear sky",
42}
43
44function WeatherDisplay({ weather }: { weather: any }) {
45 const currentDate = new Date().toLocaleDateString("en-US", {
46 timeZone: "America/Los_Angeles",
142}
143
144async function generateImage(html: string): Promise<Response> {
145 const apiKey = Deno.env.get("API_FLASH_KEY");
146 const encodedHtml = encodeURIComponent(html);
160}
161
162export default async function(req: Request) {
163 const url = new URL(req.url);
164 const isImageRequest = url.searchParams.get("generate") === "image";

sqlitemain.tsx7 matches

@oioioi•Updated 6 months ago
31
32// ------------
33// Functions
34// ------------
35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
49}
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
64}
65
66function createResError(body: string) {
67 try {
68 const e = zLibsqlError.parse(JSON.parse(body));
85}
86
87function normalizeStatement(statement: InStatement, args?: InArgs) {
88 if (Array.isArray(statement)) {
89 // for the case of an array of arrays
107}
108
109function upgradeResultSet(results: ImpoverishedResultSet): ResultSet {
110 return {
111 ...results,
116// adapted from
117// https://github.com/tursodatabase/libsql-client-ts/blob/17dd996b840c950dd22b871adfe4ba0eb4a5ead3/packages/libsql-client/src/sqlite3.ts#L314C1-L337C2
118function rowFromSql(
119 sqlRow: Array<unknown>,
120 columns: Array<string>,

neighborhoodOrderAppmain.tsx3 matches

@zlpkhr•Updated 6 months ago
4import Cookies from "https://esm.sh/js-cookie";
5
6function App() {
7 const [proposals, setProposals] = useState([]);
8 const [newProposal, setNewProposal] = useState({ title: '', proposer: '', targetCount: 10 });
250}
251
252function client() {
253 createRoot(document.getElementById("root")).render(<App />);
254}
255if (typeof document !== "undefined") { client(); }
256
257export default async function server(request: Request): Promise<Response> {
258 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
259 const SCHEMA_VERSION = 2

simpleWikipediaInstantSearchmain.tsx2 matches

@maxm•Updated 6 months ago
166 });
167
168 async function fetchResults(query) {
169 try {
170 const response = await fetch(\`/search?q=\${encodeURIComponent(query)}\`);
176 }
177
178 function displayResults(results) {
179 searchResults.innerHTML = '';
180 if (results.length > 0) {

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.