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=1448&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 18957 results for "function"(1300ms)

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 6 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 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();

fetchValInfomain.tsx1 match

@pomdtr•Updated 6 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 6 months ago
1# getMyValId
2
3Helper function for a val to get its own ID.
4
5## Usage

protectiveCrimsonGalliformmain.tsx1 match

@stevekrouse•Updated 6 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);

getMyValIdmain.tsx1 match

@stevekrouse•Updated 6 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);

getMyValIdREADME.md1 match

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

exaltedChocolateHamstermain.tsx1 match

@heettike•Updated 6 months ago
1import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts";
2
3export default async function scrapeBookMyShow() {
4 const url = "https://in.bookmyshow.com/explore/home/mumbai"; // Example URL, you may need to adjust this
5 const response = await fetch(url, {

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": "*",