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=1586&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 19769 results for "function"(3564ms)

todoListUsingBlobmain.tsx3 matches

@muhammad_owais_warsi•Updated 8 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 const [todos, setTodos] = useState([]);
7 const [newTodo, setNewTodo] = useState("");
73}
74
75function client() {
76 createRoot(document.getElementById("root")).render(<App />);
77}
81}
82
83async function server(request: Request): Promise<Response> {
84 const { blob } = await import("https://esm.town/v/std/blob");
85 const url = new URL(request.url);

hackerNewsDigestmain.tsx4 matches

@roramigator•Updated 8 months ago
3import { email } from "https://esm.town/v/std/email";
4
5async function fetchStories(type: string, count: number) {
6 const response = await fetch(`https://hacker-news.firebaseio.com/v0/${type}stories.json`);
7 const storyIds = await response.json();
15}
16
17function createStoryHTML(story: any) {
18 return `
19 <li>
28}
29
30function createEmailContent(
31 topStories: any[],
32 newStories: any[],
118}
119
120export default async function server(req: Request) {
121 try {
122 const topStories = await fetchStories("top", 10);

hackerNewsDigestmain.tsx4 matches

@igel•Updated 8 months ago
3import { email } from "https://esm.town/v/std/email";
4
5async function fetchStories(type: string, count: number) {
6 const response = await fetch(`https://hacker-news.firebaseio.com/v0/${type}stories.json`);
7 const storyIds = await response.json();
15}
16
17function createStoryHTML(story: any) {
18 return `
19 <li>
28}
29
30function createEmailContent(
31 topStories: any[],
32 newStories: any[],
118}
119
120export default async function server(req: Request) {
121 try {
122 const topStories = await fetchStories("top", 10);

hackerNewsDigestmain.tsx4 matches

@aslemammad•Updated 8 months ago
3import { email } from "https://esm.town/v/std/email";
4
5async function fetchStories(type: string, count: number) {
6 const response = await fetch(`https://hacker-news.firebaseio.com/v0/${type}stories.json`);
7 const storyIds = await response.json();
15}
16
17function createStoryHTML(story: any) {
18 return `
19 <li>
28}
29
30function createEmailContent(
31 topStories: any[],
32 newStories: any[],
118}
119
120export default async function server(req: Request) {
121 try {
122 const topStories = await fetchStories("top", 10);

hackerNewsDigestmain.tsx4 matches

@stevekrouse•Updated 8 months ago
3import { email } from "https://esm.town/v/std/email";
4
5async function fetchStories(type: string, count: number) {
6 const response = await fetch(`https://hacker-news.firebaseio.com/v0/${type}stories.json`);
7 const storyIds = await response.json();
15}
16
17function createStoryHTML(story: any) {
18 return `
19 <li>
28}
29
30function createEmailContent(
31 topStories: any[],
32 newStories: any[],
118}
119
120export default async function server(req: Request) {
121 try {
122 const topStories = await fetchStories("top", 10);

valcontributionchartmain.tsx3 matches

@iamseeley•Updated 8 months ago
7import { createRoot } from "https://esm.sh/react-dom/client";
8
9function App() {
10 const [contributionData, setContributionData] = useState({});
11 const [loading, setLoading] = useState(true);
96}
97
98function client() {
99 createRoot(document.getElementById("root")).render(<App />);
100}
102if (typeof document !== "undefined") { client(); }
103
104async function server(request: Request): Promise<Response> {
105 return new Response(`
106 <html>

linkInBioTemplatemain.tsx1 match

@saludes•Updated 8 months ago
2import { renderToString } from "npm:react-dom/server";
3
4export default async function(req: Request) {
5 return new Response(
6 renderToString(

weatherGPTmain.tsx1 match

@abar04•Updated 8 months ago
31console.log(text);
32
33export async function weatherGPT() {
34 await email({ subject: "Weather Today", text });
35}

coverpatchmain.tsx29 matches

@yawnxyz•Updated 8 months ago
15 * @throws {Error} If the AI response cannot be parsed as JSON.
16 */
17export async function getPatchFromPrompt(obj, prompt) {
18 const input = `Given this JSON document:
19 <json>${JSON.stringify(obj, null, 2)}</json>
48 * @returns {Object} The modified object after applying the patch.
49 */
50export function patchObject (obj, patch) {
51 return jsonpatch.apply_patch(obj, patch);
52}
59 * @returns {Array} A new array with the patched objects.
60 */
61export function patchArray(arr, patch) {
62 return arr.map(obj => patchObject(obj, patch));
63}
71 * @throws {Error} If the patch generation fails.
72 */
73export async function patchObjectFromPrompt(obj, prompt) {
74 try {
75 const patch = await getPatchFromPrompt(obj, prompt);
90 * @throws {Error} If the patch generation fails.
91 */
92export async function patchArrayFromPrompt(arr, prompt) {
93 try {
94 // Get the patch from the prompt using the first object in the array as a sample
97 console.log('patchArrayFromPrompt/patch', patch);
98
99 // Use the patchArray function to apply the patch to all objects in the array
100 const patchedArray = patchArray(arr, patch);
101
115 * @returns {Array} The modified array after merging.
116 */
117export function patchObjectsByKey(obj, newObj, joinKey = "name") {
118 const patch = [];
119
149 * @throws {Error} If the patch generation or application fails.
150 */
151export async function patchObjects(obj, newObj, options = {}) {
152 let {
153 provider = "anthropic",
226 * @throws {Error} If the patch generation or application fails.
227 */
228export async function patchArrays(arr, newArr, options = {}) {
229 let {
230 provider = "anthropic",
267export const tests = {
268 /**
269 * Tests the getPatchFromPrompt function by providing a sample document and prompt.
270 * Validates that the generated patch modifies the document as expected.
271 *
272 * @returns {Promise<void>} A promise that resolves when the test is complete.
273 */
274 testGetPatchFromPrompt: async function() {
275 const doc = { "name": "John", "age": 30 };
276 const prompt = "Increase the age by 5 years and add a 'city' field with the value 'New York'";
290
291 /**
292 * Tests the patchObject function by applying a patch to a sample document.
293 * Validates that the patch is applied correctly.
294 *
295 * @returns {void}
296 */
297 testPatchObject: function() {
298 const mydoc = { "baz": "qux", "foo": "bar" };
299 const thepatch = [{ "op": "replace", "path": "/baz", "value": "boo" }];
310
311 /**
312 * Tests the patchObjectFromPrompt function by providing a sample document and instructions.
313 * Validates that the modified document matches the expected output.
314 *
315 * @returns {Promise<void>} A promise that resolves when the test is complete.
316 */
317 testPatchObjectFromPrompt: async function() {
318 const doc = { "name": "Alice", "age": 25, "hobbies": ["reading"] };
319 const instructions = "Add a 'job' field with the value 'Engineer' and add 'coding' to the hobbies array";
330
331 /**
332 * Tests the patchObjectsByKey function by merging two arrays of objects based on a specified key.
333 * Validates that the merged data contains the expected properties.
334 *
335 * @returns {void}
336 */
337 testPatchObjectsByKey: function() {
338 const baseData = [
339 { name: "John", age: 30, city: "New York" },
359
360 /**
361 * Tests the patchObjects function by modifying an object based on additional data and a prompt.
362 * Validates that the enriched data contains the expected properties.
363 *
364 * @returns {Promise<void>} A promise that resolves when the test is complete.
365 */
366 testPatchObjects: async function() {
367 const baseData = {
368 project: { name: "Project A", status: "In Progress" },
390
391 /**
392 * Tests the patchObjectsWithNotionAndAirtable function by combining Notion and Airtable data.
393 * Validates that the enriched data contains the expected properties.
394 *
395 * @returns {Promise<void>} A promise that resolves when the test is complete.
396 */
397 testPatchObjectsWithNotionAndAirtable: async function() {
398 const notionData = {
399 id: "page1",
435
436 /**
437 * Tests the patchObjectsWithJsonPatch function by using a predefined JSON patch.
438 * Validates that the enriched data contains the expected properties.
439 *
440 * @returns {Promise<void>} A promise that resolves when the test is complete.
441 */
442 testPatchObjectsWithJsonPatch: async function() {
443 const baseData = { name: "John", age: 30 };
444 const additionalData = { city: "New York", job: "Developer" };
464
465 /**
466 * Tests the patchArrays function by modifying an array of objects based on additional data and a prompt.
467 * Validates that the enriched data array contains the expected properties.
468 *
469 * @returns {Promise<void>} A promise that resolves when the test is complete.
470 */
471 testPatchArrays: async function() {
472 const baseArray = [
473 {
538
539 /**
540 * Tests the patchArray function by applying a patch to an array of objects.
541 * Validates that the patched array contains the expected properties.
542 *
543 * @returns {void}
544 */
545 testPatchArray: function() {
546 const arr = [
547 { name: "John", age: 30 },
566
567 /**
568 * Tests the patchArrayFromPrompt function by providing an array of objects and a prompt.
569 * Validates that the modified array matches the expected output.
570 *
571 * @returns {Promise<void>} A promise that resolves when the test is complete.
572 */
573 testPatchArrayFromPrompt: async function() {
574 const arr = [
575 { name: "John", details: { age: 30, address: { city: "New York", street: "Broadway" } } },

duckdbExamplemain.tsx1 match

@yawnxyz•Updated 8 months ago
2
3export let duckdbExample = await (async () => {
4 async function createWorker(url) {
5 // For Val Town / Deno environments
6 if (typeof Deno !== "undefined") {

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.