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/image-url.jpg?q=function&page=2500&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 29307 results for "function"(5904ms)

debatePollAppmain.tsx3 matches

@laur3n•Updated 8 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 8 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 8 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 8 months ago
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true })
3}

sqlitemain.tsx7 matches

@boubou007•Updated 8 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 8 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 8 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 8 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 {

getJsonAndRenderAsImageREADME.md2 matches

@ashryanio•Updated 8 months ago
23
24 - The client-side React component makes a fetch request to "/image".
25 - This request is handled by our server function.
26
27
282. Server-side handling:
29
30 - The server function calls `blob.getJSON("image-test")`.
31 - This `blob.getJSON()` method makes an HTTP request to the Val Town API.
32 - The API returns a Response object containing the JSON data.

hackerNewsDigestmain.tsx4 matches

@workingpleasewait•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);
tuna

tuna9 file matches

@jxnblk•Updated 1 day ago
Simple functional CSS library for Val Town

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
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.