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=1638&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 18979 results for "function"(1999ms)

chatREADME.md1 match

@onixoni•Updated 12 months ago
1# OpenAI ChatGPT helper function
2
3This val uses your OpenAI token if you have one, and the @std/openai if not, so it provides limited OpenAI usage for free.

chatmain.tsx3 matches

@onixoni•Updated 12 months ago
1import type { ChatCompletion, ChatCompletionCreateParamsNonStreaming, Message } from "npm:@types/openai";
2
3async function getOpenAI() {
4 // if you don't have a key, use our std library version
5 if (Deno.env.get("OPENAI_API_KEY") === undefined) {
14/**
15 * Initiates a chat conversation with OpenAI's GPT model and retrieves the content of the first response.
16 * This function can handle both single string inputs and arrays of message objects.
17 * It supports various GPT models, allowing for flexibility in choosing the model based on the application's needs.
18 *
21 * @returns {Promise<string>} A promise that resolves to the content of the first response from the completion.
22 */
23export async function chat(
24 input: string | Message[],
25 options?: Omit<ChatCompletionCreateParamsNonStreaming, "messages">,

whiteMongoosemain.tsx1 match

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

markdown_downloadmain.tsx9 matches

@curtcox•Updated 12 months ago
15 * @returns markdown in string
16 */
17export async function html2markdown(html: string): Promise<string> {
18 if (AgentMarkdownImport) {
19 // TurndownService doesn't work on cf
32 * @returns markdown in string
33 */
34export async function readability2markdown(html: string): Promise<{ title: string; markdown: string }> {
35 const doc = await (new DOMParser().parseFromString(html, "text/html"));
36
42}
43
44function getYoutubeVideoID(url: URL): string | null {
45 const regExp = /(?:youtube\.com\/(?:[^/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?/\s]{11})/i;
46 const match = url.href.match(regExp);
48}
49
50function response(message: string, contentType = "text/markdown"): Response {
51 const headers = new Headers();
52 headers.set("Access-Control-Allow-Origin", "*");
61}
62
63function err(msg: string): Response {
64 const errorMessage = JSON.stringify({
65 error: {
71}
72
73function fudgeURL(url: string) {
74 try {
75 return new URL(url);
80}
81
82function processInput(req: Request) {
83 let ret = {
84 url: undefined as undefined | URL,
107}
108
109export default async function(req: Request): Promise<Response> {
110 const action = processInput(req);
111 const url = action.url;
181 * Simple UI that takes a url
182 */
183export function generate_ui(input_description: string, link: string, link_text: string): string {
184 const html = `
185<!DOCTYPE html>

MarkdownCommandmain.tsx1 match

@curtcox•Updated 12 months ago
5import { def_from_simple } from "https://raw.githubusercontent.com/curtcox/CommandInterpreter/main/command/ToolsForCommandWriters.ts";
6
7async function markdown(url: string) {
8 const encoded = encodeURIComponent(url);
9 const response = await fetch(`https://markdown.download/?url=${encoded}`);

valTownLogotypeReactmain.tsx1 match

@jxnblk•Updated 12 months ago
2import React from "npm:react";
3
4export default function ValTownLogo(props: React.SVGProps<SVGSVGElement>) {
5 return (
6 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 442 79" {...props}>

valTownSearchmain.tsx1 match

@pomdtr•Updated 12 months ago
5const githubQuery = (query: string) => encodeURIComponent(`${query} repo:pomdtr/val-town-mirror path:vals/`);
6
7async function handler(req: Request) {
8 const url = new URL(req.url);
9

ilyBdaymain.tsx1 match

@emilycoe•Updated 12 months ago
2import { render } from "npm:preact-render-to-string";
3
4export default async function(req: Request) {
5 return new Response(
6 render(

renderFormAndSaveDataREADME.md1 match

@sjerred•Updated 12 months ago
1# Render form and save data
2
3This val provides a web-based interface for collecting email addresses. It features a dual-functionality approach: when accessed via a web browser using a GET request, it serves an HTML form where users can submit their email address. If the script receives a POST request, it implies that the form has been submitted, and it proceeds to handle the incoming data.
4
5Fork this val to customize it and use it on your account.

weatherGPTmain.tsx1 match

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

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