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=539&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 20222 results for "function"(2177ms)

clickbaitbotgetContent1 match

@minimasoft•Updated 4 weeks ago
190 </style>
191 <script>
192 function handleSubmit(event) {
193 event.preventDefault();
194 const urlInput = document.getElementById('url-input');

perplexityAPIREADME.md3 matches

@nbbaier•Updated 4 weeks ago
1# Perplexity API Wrapper
2
3This val exports a function `pplx` that provides an interface to the Perplexity AI chat completions API.
4
5
6You'll need a Perplexity AI API key, see [their documentation](https://docs.perplexity.ai/) for how to get started with getting a key. By default, the function will use `PERPLEXITY_API_KEY` in your val town env variables unless overridden by setting `apiKey` in the function.
7
8## pplx
19You can also specify an `apiKey` to override the default `Deno.env.get("PERPLEXITY_API_KEY")`.
20
21The function returns an object of types `PplxResponse`, see below.
22
23## Types

remark-frontmatter-starterlayout.ts3 matches

@arfan•Updated 4 weeks ago
1export function buildSidebarToggle(): string {
2 return `<button class="sidebar-toggle" id="sidebar-toggle" aria-controls="sidebar toc-sidebar" aria-expanded="false">☰ Menu</button>`;
3}
4
5export function buildSidebarContainer(sidebarHtml: string): string {
6 return `<div class="sidebar" id="sidebar" aria-hidden="true">${sidebarHtml}</div>`;
7}
8
9export function buildLayoutWrapper(innerHtml: string): string {
10 return `<div class="layout-wrapper">${innerHtml}</div>`;
11}

remark-frontmatter-starterscripts.ts13 matches

@arfan•Updated 4 weeks ago
8 * @returns {string} The JavaScript code as a string
9 */
10export function buildScripts(): string {
11 return `
12 <script>
13 document.addEventListener('DOMContentLoaded', function() {
14 // Setup code blocks with copy buttons
15 setupCodeBlocks();
16
17 // Setup sidebar toggle functionality
18 setupSidebar();
19
20 // Setup accordion functionality
21 setupAccordions();
22
23 // Setup tabs functionality
24 setupTabs();
25 });
26
27 // Add copy buttons to code blocks and enable syntax highlighting
28 function setupCodeBlocks() {
29 document.querySelectorAll('pre code').forEach((codeBlock) => {
30 const pre = codeBlock.parentElement;
41 copyBtn.setAttribute('aria-label', 'Copy code block');
42
43 // Add copy functionality
44 copyBtn.addEventListener('click', () => {
45 navigator.clipboard.writeText(codeBlock.textContent || '').then(() => {
61 }
62
63 // Setup sidebar toggle functionality
64 function setupSidebar() {
65 const sidebarToggle = document.getElementById('sidebar-toggle');
66 const sidebar = document.getElementById('sidebar');
103 }
104
105 // Setup accordion functionality
106 function setupAccordions() {
107 document.querySelectorAll('.accordion-header').forEach((header) => {
108 header.addEventListener('click', () => {
140 }
141
142 // Setup tabs functionality
143 function setupTabs() {
144 // Setup tab button click handlers
145 document.querySelectorAll('.tab-button').forEach((button) => {

remark-frontmatter-starterhandlers.ts3 matches

@arfan•Updated 4 weeks ago
13 * @returns Object containing HTML content and metadata
14 */
15export async function renderDoc(docPath: string): Promise<{ html: string, meta: Record<string, any> }> {
16 let html = "";
17 let meta: Record<string, any> = {};
41
42/**
43 * Main handler function to process requests and generate HTML response
44 * @param req Request object
45 * @returns Response object with HTML content
46 */
47export async function appHandler(req: Request): Promise<Response> {
48 const url = new URL(req.url);
49 const defaultDoc = docs[0]?.path || "README.md";

remark-frontmatter-starternavigation.ts2 matches

@arfan•Updated 4 weeks ago
7 * @returns HTML string for navigation links
8 */
9export function buildNav(nodes: DocTreeNode[], current: string): string {
10 if (!nodes?.length) return '';
11
27 * @returns HTML string for sidebar
28 */
29export function buildSidebar(groups: NestedGroupedDocs, current: string): string {
30 let html = '';
31

gptToolsdraftReadme6 matches

@nbbaier•Updated 4 weeks ago
9}
10
11function createPrompt(code: string, userPrompt?: string) {
12 return `
13 You are an AI assistant that writes documentation for code. You output readmes
23}
24
25async function getVal(username: string, valName: string) {
26 try {
27 const res = await fetch(`https://api.val.town/v1/alias/${username}/${valName}`, {
40}
41
42async function performOpenAICall(prompt: string, model: string, openaiOptions: ClientOptions) {
43 const openai = new OpenAI(openaiOptions);
44
65}
66
67async function updateReadme(id: string, readme: string) {
68 try {
69 const res = await fetch(`https://api.val.town/v1/vals/${id}`, {
82}
83
84async function draftReadme(options: WriterOptions) {
85 const { username, valName, model = "gpt-3.5-turbo", userPrompt, ...openaiOptions } = options;
86 const { id, code } = await getVal(username, valName);
90}
91
92async function writeReadme(options: WriterOptions) {
93 const { username, valName, model = "gpt-3.5-turbo", userPrompt, ...openaiOptions } = options;
94 const { id, code } = await getVal(username, valName);

openaiPricingusageDB1 match

@nbbaier•Updated 4 weeks ago
3const usage = await blob.getJSON("usageDB");
4
5export default async function(req: Request): Promise<Response> {
6 const path = new URL(req.url).pathname;
7 if (path === "/usage") {

openaiPricingopenAiPricing2 matches

@nbbaier•Updated 4 weeks ago
1// This approach standardizes all prices to be in terms of 1_000_000 tokens
2// We'll use Decimal.js for precise calculations and adjust the createPricing function
3
4import Decimal from "npm:decimal.js";
5
6// Helper function to create pricing object, now standardized to 1_000_000 tokens
7const createPricing = (inPrice: number, outPrice: number = inPrice) => ({
8 in: new Decimal(inPrice).div(1_000_000),

openaiPricingdeftAmberSwallow2 matches

@nbbaier•Updated 4 weeks ago
23 mode: "chat" | "embedding" | "completion" | "image_generation" | "audio_transcription" | "audio_speech";
24
25 supports_function_calling: boolean;
26 supports_parallel_function_calling: boolean;
27 supports_vision: boolean;
28 supports_audio_input: boolean;

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.