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=1431&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 18633 results for "function"(5329ms)

weatherGPTmain.tsx1 match

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

dobbymain.tsx2 matches

@yawnxyz•Updated 7 months ago
414}
415
416// New standalone function to drop any database
417export async function dropDatabase(dbName: string): Promise<void> {
418 try {
419 await sqlite.execute(`DROP TABLE IF EXISTS ${dbName}`);

debatePollAppmain.tsx3 matches

@laur3n•Updated 7 months ago
4import Chart from "https://esm.sh/chart.js/auto";
5
6function App() {
7 const [polls, setPolls] = useState([]);
8 const [newPollQuestion, setNewPollQuestion] = useState("");
142}
143
144function client() {
145 createRoot(document.getElementById("root")).render(<App />);
146}
147if (typeof document !== "undefined") { client(); }
148
149export default async function server(request: Request): Promise<Response> {
150 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
151 const SCHEMA_VERSION = 1

SimpleAdditionmain.tsx3 matches

@efoley•Updated 7 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function App() {
6 const [num1, setNum1] = useState(0);
7 const [num2, setNum2] = useState(0);
93}
94
95function client() {
96 createRoot(document.getElementById("root")).render(<App />);
97}
101}
102
103export default async function server(request: Request): Promise<Response> {
104 return new Response(
105 `

btcPriceAlertmain.tsx1 match

@workingpleasewait•Updated 7 months ago
4import { currency } from "https://esm.town/v/stevekrouse/currency";
5
6export async function btcPriceAlert() {
7 const lastBtcPrice: number = await blob.getJSON("lastBtcPrice");
8 let btcPrice = await currency("usd", "btc");

drivingTealKitemain.tsx1 match

@stevekrouse•Updated 7 months ago
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true })
3}

sqlitemain.tsx7 matches

@boubou007•Updated 7 months ago
31
32// ------------
33// Functions
34// ------------
35
36async function execute(statement: InStatement, args?: InArgs): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
49}
50
51async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
52 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
53 method: "POST",
64}
65
66function createResError(body: string) {
67 try {
68 const e = zLibsqlError.parse(JSON.parse(body));
85}
86
87function normalizeStatement(statement: InStatement, args?: InArgs) {
88 if (Array.isArray(statement)) {
89 // for the case of an array of arrays
107}
108
109function upgradeResultSet(results: ImpoverishedResultSet): ResultSet {
110 return {
111 ...results,
116// adapted from
117// https://github.com/tursodatabase/libsql-client-ts/blob/17dd996b840c950dd22b871adfe4ba0eb4a5ead3/packages/libsql-client/src/sqlite3.ts#L314C1-L337C2
118function rowFromSql(
119 sqlRow: Array<unknown>,
120 columns: Array<string>,

getJsonAndRenderAsImagemain.tsx4 matches

@ashryanio•Updated 7 months ago
4import { blob } from "https://esm.town/v/std/blob";
5
6function App() {
7 const [imageData, setImageData] = useState<string | null>(null);
8 const [error, setError] = useState<string | null>(null);
9
10 useEffect(() => {
11 async function fetchImage() {
12 try {
13 const response = await fetch("/image");
47}
48
49function client() {
50 createRoot(document.getElementById("root")!).render(<App />);
51}
55}
56
57export default async function server(request: Request): Promise<Response> {
58 if (request.url.endsWith("/image")) {
59 try {

cardSortDragDropAppmain.tsx4 matches

@trob•Updated 7 months ago
27}
28
29function App() {
30 console.log("Rendering App component");
31 const [categories, setCategories] = useState([]);
229}
230
231function client() {
232 try {
233 console.log("Starting client-side rendering");
251if (typeof document !== "undefined") { setTimeout(client, 0); }
252
253export default async function server(request: Request): Promise<Response> {
254 const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
255 const SCHEMA_VERSION = 1
284 <body>
285 <div id="root"></div>
286 <script>window.onerror = function(message, source, lineno, colno, error) { console.error("Global error:", message, source, lineno, colno, error); };</script>
287 <script src="https://esm.town/v/std/catch"></script>
288 <script type="module" src="${import.meta.url}"></script>

getBlobAndRenderAsImagemain.tsx4 matches

@ashryanio•Updated 7 months ago
4import { blob } from "https://esm.town/v/std/blob";
5
6function App() {
7 const [imageData, setImageData] = useState<string | null>(null);
8 const [error, setError] = useState<string | null>(null);
9
10 useEffect(() => {
11 async function fetchImage() {
12 try {
13 const response = await fetch("/image");
49}
50
51function client() {
52 createRoot(document.getElementById("root")!).render(<App />);
53}
57}
58
59export default async function server(request: Request): Promise<Response> {
60 if (request.url.endsWith("/image")) {
61 try {

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