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=1466&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 19140 results for "function"(1316ms)

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 {

switchbot_partymain.tsx8 matches

@stevekrouse•Updated 7 months ago
37];
38
39function getPartyStatus() {
40 const now = Temporal.Now.zonedDateTimeISO(NYC_TIMEZONE);
41 for (const party of parties) {
53}
54
55function formatTimeDifference(target, now) {
56 const diff = target.since(now);
57 const hours = diff.hours;
65}
66
67async function switchbotRequest(path, args) {
68 const token = Deno.env.get("SWITCHBOT_TOKEN");
69 const secret = Deno.env.get("SWITCHBOT_KEY");
89}
90
91function botPress(device) {
92 return switchbotRequest(`v1.1/devices/${device}/commands`, {
93 method: "POST",
102const { htmlUrl } = extractValInfo(import.meta.url);
103
104function Layout({ children, title }) {
105 return (
106 <html>
122}
123
124function Button({ children }) {
125 return (
126 <button class="bg-green-500 hover:bg-green-600 text-white font-bold py-3 px-6 rounded-full shadow-lg transform transition duration-200 hover:scale-105 focus:outline-none focus:ring-2 focus:ring-green-400 focus:ring-opacity-50">
130}
131
132function MainPage({ partyName }) {
133 return (
134 <Layout title={partyName}>
147}
148
149function ErrorPage({ title, message, backLink = true }) {
150 return (
151 <Layout title={title}>

selfDestructmain.tsx1 match

@peterqliu•Updated 7 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();

fetchValInfomain.tsx1 match

@pomdtr•Updated 7 months ago
2import ValTown from "npm:@valtown/sdk";
3
4export function fetchValInfo(importMetaURL: string) {
5 const vt = new ValTown();
6 const { author, name } = extractValInfo(importMetaURL);

protectiveCrimsonGalliformREADME.md1 match

@stevekrouse•Updated 7 months ago
1# getMyValId
2
3Helper function for a val to get its own ID.
4
5## Usage

protectiveCrimsonGalliformmain.tsx1 match

@stevekrouse•Updated 7 months ago
2import ValTown from "npm:@valtown/sdk";
3
4async function getMyValId(importMetaURL: string) {
5 const vt = new ValTown();
6 const { author, name } = extractValInfo(importMetaURL);

getFileEmail4 file matches

@shouser•Updated 2 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
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": "*",