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/?q=function&page=1447&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 18955 results for "function"(1140ms)

markdown_downloadmain.tsx10 matches

@taras•Updated 6 months ago
16 * @returns markdown in string
17 */
18export async function html2markdown(html: string): Promise<string> {
19 if (AgentMarkdownImport) {
20 // TurndownService doesn't work on cf
34 * @returns markdown in string
35 */
36export async function readability2markdown(html: string): Promise<{ title: string; markdown: string }> {
37 const doc = await (new DOMParser().parseFromString(html, "text/html"));
38
44}
45
46function response(message: string, contentType = "text/markdown"): Response {
47 const headers = new Headers();
48 headers.set("Access-Control-Allow-Origin", "*");
64}
65
66function err(msg: string): Response {
67 const errorMessage = JSON.stringify({
68 error: {
74}
75
76function fudgeURL(url: string) {
77 try {
78 return new URL(url);
83}
84
85async function processInput(req: Request) {
86 let ret = {
87 url: undefined as undefined | URL,
129}
130
131export async function youtube2markdown(url: URL): Promise<string | undefined> {
132 function getYoutubeVideoID(url: URL): string | null {
133 const regExp = /(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/i;
134 const match = url.href.match(regExp);
161 * Simple UI that takes a url
162 */
163export function generate_ui(input_description: string, link: string, link_text: string): string {
164 const html = `
165<!DOCTYPE html>
195}
196
197export default async function(req: Request): Promise<Response> {
198 const action = await processInput(req);
199 const url = action.url;
102];
103
104function App() {
105 const [selectedItem, setSelectedItem] = useState(null);
106 const [showWords, setShowWords] = useState(true);
176}
177
178function client() {
179 createRoot(document.getElementById("root")).render(<App />);
180}
184}
185
186export default async function server(request: Request): Promise<Response> {
187 const randomColor = Math.floor(Math.random() * 16777215).toString(16);
188 return new Response(
111) Interactive vocabulary grid
12
132) Real-time search functionality
14
153) Word visibility toggle

RobotBackupCallGraphmain.tsx15 matches

@lev_greshilov•Updated 6 months ago
2import { thisWebURL } from "https://esm.town/v/stevekrouse/thisWebURL?v=2";
3
4export default async function server(req: Request): Promise<Response> {
5 // Handle GET requests
6 if (req.method === "GET") {
288 layout: {
289 name: 'preset',
290 positions: function(node) {
291 return { x: 0, y: 0 }; // Initial positions, will be overwritten
292 }
297 });
298
299 // Custom layout function
300 function customLayout() {
301 const mainGraph = cy.elements().not('#isolated, #isolated > node');
302 const isolatedGraph = cy.getElementById('isolated');
349
350 // Add event listeners for highlighting
351 cy.on('mouseover', 'node', function(e) {
352 const node = e.target;
353 highlightNodeChildrenAndParents(node);
354 });
355
356 cy.on('mouseout', 'node', function(e) {
357 unhighlightAll();
358 });
359
360 cy.on('click', 'node', function(e) {
361 const node = e.target;
362 if (node.hasClass('highlighted') || node.hasClass('parent-highlighted')) {
368 });
369
370 function highlightNodeChildrenAndParents(node) {
371 const children = node.outgoers();
372 const parents = node.incomers();
376 }
377
378 function unhighlightAll() {
379 cy.elements().removeClass('highlighted');
380 cy.elements().removeClass('parent-highlighted');
529 let match;
530 while ((match = callRegex.exec(line)) !== null) {
531 const calledFunction = match[1].toLowerCase();
532 relationships.get(caller).add(calledFunction);
533 allNodes.add(calledFunction);
534 }
535 });
545
546 const edges = [];
547 relationships.forEach((calledFunctions, file) => {
548 calledFunctions.forEach(calledFunction => {
549 edges.push({
550 data: {
551 source: file,
552 target: calledFunction,
553 },
554 });

wakatime-readme-chartmain.tsx7 matches

@loading•Updated 6 months ago
12}
13
14function roundRect(
15 ctx: any,
16 x: any,
39}
40
41function roundRectTop(
42 ctx: any,
43 x: any,
64}
65
66function App() {
67 const [chartUrl, setChartUrl] = useState<string | null>(null);
68
81}
82
83function client() {
84 createRoot(document.getElementById("root")!).render(<App />);
85}
89}
90
91async function fetchWakaTimeData(): Promise<DataPoint[]> {
92 const response = await fetch("https://wakatime.com/share/@load1n9/899abefd-d814-4e99-b603-e94af0305d4a.json");
93 const data = await response.json();
98}
99
100async function generateChart(data: DataPoint[]): Promise<string> {
101 const width = 1000;
102 const height = 600;
150}
151
152export default async function server(request: Request): Promise<Response> {
153 const url = new URL(request.url);
154

translatemain.tsx5 matches

@yieldray•Updated 6 months ago
1if (import.meta.main) Deno.serve(translate);
2
3export async function translate(req: Request) {
4 if (req.method === "POST") {
5 const { code: status, data } = await fetch("https://deepl.deno.dev/translate", {
46 };
47
48 translate = async function () {
49 this.setState({ loading: true, translation: "" });
50 const { text, source_lang, target_lang } = this.state;
53 }.bind(this);
54
55 swap = function () {
56 if (this.state.source_lang.toLowerCase() === "auto") {
57 this.setState({ source_lang: "en" });
63 }.bind(this);
64
65 handleShortcut = function (e) {
66 if (this.state.loading !== true && e.ctrlKey && e.key === "Enter") {
67 this.translate();
126 render(html\`<\${App} page="All" />\`, document.body);
127
128 async function translate({ text, source_lang, target_lang }) {
129 const Options = z.object({
130 text: z.string(),

cronmain.tsx8 matches

@with_heart•Updated 6 months ago
6const EMAIL_INTERVAL_DAYS = 14 // Send email every 2 weeks
7
8async function ensureTableExists() {
9 await sqlite.execute(`
10 CREATE TABLE IF NOT EXISTS ${KEY}_xstate_downloads_${SCHEMA_VERSION} (
24}
25
26async function fetchAndProcessData() {
27 const response = await fetch(
28 'https://api.npmjs.org/versions/xstate/last-week',
60}
61
62async function isTableEmpty() {
63 const result = await sqlite.execute(`
64 SELECT COUNT(*) as count FROM ${KEY}_xstate_downloads_${SCHEMA_VERSION}
67}
68
69async function getStats() {
70 const results = await sqlite.execute(`
71 SELECT
90}
91
92async function checkAndSendEmail() {
93 const lastSentResult = await sqlite.execute(`
94 SELECT last_sent_date FROM ${KEY}_email_log_${SCHEMA_VERSION}
141}
142
143export default async function server(req: Request,): Promise<Response> {
144 await ensureTableExists()
145
155}
156
157export default async function cron(interval: Interval,): Promise<void> {
158 await ensureTableExists()
159 await fetchAndProcessData()
160}
161
162// Schedule the function to run once per day starting from tomorrow
163const tomorrow = new Date()
164tomorrow.setDate(tomorrow.getDate() + 1,)

selfDestructmain.tsx1 match

@codemore•Updated 6 months ago
2import { fetchValInfo } from "https://esm.town/v/pomdtr/fetchValInfo?v=2";
3
4export async function selfDestruct(importMetaUrl: string) {
5 const { id } = await fetchValInfo(importMetaUrl);
6 const { vals } = new ValTown();

lastloginmain.tsx3 matches

@olifrah•Updated 6 months ago
5import { LoginWithGoogleButton } from "https://esm.town/v/stevekrouse/LoginWithGoogleButton";
6
7function App({ initialEmail }) {
8 const [email, setEmail] = useState(initialEmail);
9
40}
41
42function client() {
43 const initialEmail = document.getElementById('root').dataset.email;
44 createRoot(document.getElementById("root")).render(<App initialEmail={initialEmail} />);
49}
50
51async function handler(request: Request): Promise<Response> {
52 const url = new URL(request.url);
53 const email = request.headers.get("X-LastLogin-Email");

telegramWebhookEchoMessageOLDmain.tsx17 matches

@dcm31•Updated 6 months ago
47};
48
49async function handleMessage(message) {
50 const userMessage = message.text;
51 const chatId = message.chat.id;
62}
63
64async function processUserInputWithAI(userMessage: string, tasks: Task[], state: UserState): Promise<{ response: string, updatedTasks: Task[], updatedState: UserState, suggestedActions: string[] }> {
65 const taskListString = JSON.stringify(tasks);
66 const stateString = JSON.stringify(state);
78 Based on the user's message and the conversation context, determine the appropriate action to take and execute it.
79 Be proactive in guiding the user through their tasks, focusing on prioritization and breaking down tasks into microsteps.
80 You can use the following functions:
81 - addTask(tasks: Task[], title: string): Adds a new task
82 - markTaskAsDone(tasks: Task[], taskId: string): Marks a task as done
138}
139
140function addTask(tasks: Task[], title: string) {
141 const newTask: Task = {
142 id: Date.now().toString(),
150}
151
152function markTaskAsDone(tasks: Task[], taskId: string) {
153 const task = findTask(tasks, taskId);
154 if (task) {
157}
158
159function breakDownTask(tasks: Task[], taskId: string, subtasks: string[]) {
160 const task = findTask(tasks, taskId);
161 if (task) {
175}
176
177function findTask(tasks: Task[], taskId: string): Task | null {
178 return tasks.find(task => task.id === taskId) || null;
179}
180
181function compareTaskPriorities(tasks: Task[], taskId1: string, taskId2: string) {
182 const task1 = findTask(tasks, taskId1);
183 const task2 = findTask(tasks, taskId2);
191}
192
193function suggestMicrosteps(taskTitle: string): string[] {
194 // This function would ideally use AI to generate suggestions, but for simplicity, we'll return static suggestions
195 return ["Get materials", "Prepare workspace", "Start first step"];
196}
197
198function navigateTaskHierarchy(tasks: Task[], currentTaskId: string | null, direction: 'up' | 'down' | 'next' | 'prev'): string | null {
199 if (!currentTaskId) return null;
200 const currentTask = findTask(tasks, currentTaskId);
217}
218
219function generateTaskList(tasks: Task[], showCompleted: boolean, parentId: string | null = null, indent = ''): string {
220 let list = '';
221 const currentLevelTasks = tasks.filter(task => task.parent_id === parentId && (showCompleted || !task.done));
231}
232
233async function sendResponse(chatId: number, message: string, suggestedActions: string[]) {
234 const keyboard = [
235 ...suggestedActions.map(action => [{ text: action }]),
254}
255
256async function getTasks(chatId: number): Promise<Task[]> {
257 const key = `tasks_${chatId}`;
258 try {
265}
266
267async function updateTasks(chatId: number, tasks: Task[]) {
268 const key = `tasks_${chatId}`;
269 try {
274}
275
276async function getUserState(chatId: number): Promise<UserState> {
277 const key = `state_${chatId}`;
278 try {
285}
286
287async function updateUserState(chatId: number, state: UserState) {
288 const key = `state_${chatId}`;
289 try {

getFileEmail4 file matches

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

tuna8 file matches

@jxnblk•Updated 2 weeks ago
Simple functional CSS library for Val Town
webup
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
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": "*",