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/$%7Bsuccess?q=function&page=1706&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"(2214ms)

indexValsTursomain.tsx2 matches

@janpaul123โ€ขUpdated 11 months ago
6import { truncateMessage } from "npm:openai-tokens";
7
8export default async function(interval: Interval) {
9 const sqlite = createClient({
10 url: "libsql://valsembeddings-jpvaltown.turso.io",
23 );
24
25 function idForVal(val: any): string {
26 return `${val.author_username}!!${val.name}!!${val.version}`;
27 }

bloomingButtonmain.tsx7 matches

@maxmโ€ขUpdated 11 months ago
1let active = false;
2
3function getRandomEmoji() {
4 const emojis = ["๐ŸŒณ", "๐ŸŒณ", "๐ŸŒฒ", "๐ŸŒฟ", "๐ŸŒฑ", "๐ŸŒพ", "๐Ÿ", "๐Ÿ‚", "๐Ÿƒ", "๐ŸŒท", "๐Ÿชป", "๐Ÿ„"];
5 const randomIndex = Math.floor(Math.random() * emojis.length);
7}
8
9function injectCSS(css: string) {
10 const style = document.createElement("style");
11 style.type = "text/css";
33const buttonBackgroundMap = new Map();
34
35// Function to create or get the background div
36function getBackgroundDiv(button) {
37 if (!buttonBackgroundMap.has(button)) {
38 const newDiv = document.createElement("div");
49}
50
51// Function to position the background div behind the button
52function positionDivBehindButton(button) {
53 const rect = button.getBoundingClientRect();
54 const newDiv = getBackgroundDiv(button);
63 window.addEventListener("scroll", () => positionDivBehindButton(button));
64
65 button.addEventListener("click", function() {
66 if (active) return;
67 active = true;

tinygoMandelbrotExampleREADME.md1 match

@stevekrouseโ€ขUpdated 11 months ago
18const resp = await fetch("https://maxm-wasmblobhost.web.val.run/jpxqvyy5tphiwehzklmioklpkpz4gpzs.wasm");
19const handler = await wasmHandler(new Uint8Array(await resp.arrayBuffer()));
20export default async function(req: Request): Promise<Response> {
21 return handler(req);
22}

gptApiFrameworkmain.tsx9 matches

@xkontiโ€ขUpdated 11 months ago
79
80 /**
81 * An optional function that returns the policy to be used available at `/privacypolicy`.
82 */
83 policyGetter?: (() => string) | (() => Promise<string>);
89 * @returns The generated JSON schema.
90 */
91function getSchemaDesc(schema: z.Schema | null) {
92 if (!schema) return null;
93 return zodToJsonSchema(schema, {
140 * @returns The paths of the OpenAPI spec.
141 */
142function getPathsDesc(endpoints: EndpointDefinition[]): Paths {
143 const paths: Paths = {};
144 for (const endpoint of endpoints) {
186 * @returns The OpenAPI spec.
187 */
188function getOpenApiSpec(
189 url: string,
190 title: string,
258 * only a status code.
259 * @param endpointDef Definition of the endpoint.
260 * @param handler Function that handles the request.
261 */
262 jsonToNothing<TRequestSchema extends z.Schema>(
290 * returns a specific JSON response.
291 * @param endpointDef Definition of the endpoint.
292 * @param handler Function that handles the request.
293 */
294 nothingToJson<TResponseSchema extends z.Schema>(
320 * returns a specific JSON response.
321 * @param endpointDef Definition of the endpoint.
322 * @param handler Function that handles the request.
323 */
324 jsonToJson<TRequestSchema extends z.Schema, TResponseSchema extends z.Schema>(
356 * Regusters a handler for a verb + path combo.
357 * @param endpointDef Definition of the endpoint.
358 * @param handler Function that handles the request.
359 */
360 private registerHandler(
388
389 /**
390 * Returns a function that can be used to serve the API.
391 *
392 * @example ValTown usage:

bloomingButtonREADME.md1 match

@maxmโ€ขUpdated 11 months ago
11import { renderToString } from "npm:react-dom/server";
12
13export default async function(req: Request): Promise<Response> {
14 return new Response(
15 renderToString(

htmlExamplemain.tsx1 match

@todepondโ€ขUpdated 11 months ago
1// View at https://andreterron-htmlExample.web.val.run?name=Andre
2export default async function(req: Request): Promise<Response> {
3 const query = new URL(req.url).searchParams;
4

uniswapV3PositionREADME.md4 matches

@midnightlightningโ€ขUpdated 11 months ago
11This val fetches blockchain data from the following smart contracts:
12
13- **NonfungiblePositionManager(`0xc36442b4a4522e871399cd717abdd847ab11fe88`)** Manages the liquidity position tokens as an ERC721 contract. The `positions` function is used to determine what tokens and tick ranges the individual liquidity position has.
14- **UniswapV3Factory (`0x1F98431c8aD98523631AE4a59f267346ea31F984`)** Contract that manages liquidity pools, and acts as a registry to record where each pairing is deployed to. The `getPool` function is used to find where the smart contract for a specific pairing of ERC20 tokens is deployed to.
15- **ERC20 tokens** Each position has two tokens it's balancing between, and each token has its own instance of an ERC20 contract deployed to the blockchain. The `name` and `symbol` functions are used to determine how to describe each token, and the `decimals` function to determine how to scale the price value for the ratio between them.
16- **UniswapV3Pool** Contract that handles swaps between specific pairs of tokens. The `slot0` function is used to fetch the current price the two tokens are swapping at.

valTownAnalyticsmain.tsx1 match

@iamseeleyโ€ขUpdated 11 months ago
94};
95
96async function handler(req: Request): Promise<Response> {
97 const url = new URL(req.url);
98 if (req.method === "GET" && url.pathname === "/event") {

allValsmain.tsx1 match

@stevekrouseโ€ขUpdated 11 months ago
3import { sqlite } from "https://esm.town/v/std/sqlite?v=6";
4
5function truncate(str: string) {
6 if (str.length > 20) {
7 return `${str.slice(0, 20)}...`;

pinBlobmain.tsx1 match

@stevedylandevโ€ขUpdated 11 months ago
2const JWT = Deno.env.get("PINATA_JWT");
3
4async function pinFileToIPFS() {
5 try {
6 const text = "Hello World!";

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.