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=1924&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 24514 results for "function"(1781ms)

valSessionREADME.md1 match

@maxm•Updated 6 months ago
25);
26
27function formatPEM(b64: string, type: "PRIVATE KEY" | "PUBLIC KEY"): string {
28 const lines = b64.match(/.{1,64}/g) || [];
29 return `-----BEGIN ${type}-----\n${lines.join("\n")}\n-----END ${type}-----`;

cfetchmain.tsx1 match

@temptemp•Updated 6 months ago
3const uuid = "1fd98a05-4959-42bc4-2f83-2c487c1cde6d";
4const build = `https://${uuid}.cloudflarepreviews.com/?url=`;
5export async function cfetch(input: string | URL, requestInit?: RequestInit) {
6 return fetch(`${build}${encodeURIComponent(input.toString())}`, {
7 ...requestInit,

Storyweavermain.tsx7 matches

@aioe0x417a•Updated 6 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function LoadingSpinner() {
6 return (
7 <div className="loading-spinner">
12}
13
14function cleanText(text: string) {
15 return text
16 .replace(/\*+/g, '')
19}
20
21function App() {
22 const [storyParts, setStoryParts] = useState({
23 title: null,
133}
134
135function client() {
136 createRoot(document.getElementById("root")).render(<App />);
137}
138if (typeof document !== "undefined") { client(); }
139
140// Utility function to implement timeout
141async function withTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T> {
142 let timeoutHandle: number;
143 const timeoutPromise = new Promise<never>((_, reject) => {
152}
153
154export default async function server(request: Request): Promise<Response> {
155 if (request.method === 'POST' && new URL(request.url).pathname === '/generate-story') {
156 const formData = await request.formData();

blob_adminmain.tsx8 matches

@emilo•Updated 6 months ago
13}
14
15function Tooltip({ children, content }: TooltipProps) {
16 const [isVisible, setIsVisible] = useState(false);
17 const tooltipRef = useRef<HTMLDivElement>(null);
52}
53
54function formatBytes(bytes, decimals = 2) {
55 if (bytes === 0) return "0 Bytes";
56 const k = 1024;
61}
62
63function copyToClipboard(text) {
64 navigator.clipboard.writeText(text).then(() => {
65 console.log("Text copied to clipboard");
69}
70
71function ActionMenu({ blob, onDownload, onRename, onDelete, onMoveToPublic, onMoveOutOfPublic }) {
72 const [isOpen, setIsOpen] = useState(false);
73 const menuRef = useRef(null);
76
77 useEffect(() => {
78 function handleClickOutside(event) {
79 if (menuRef.current && !menuRef.current.contains(event.target)) {
80 event.stopPropagation();
158}
159
160function BlobItem({ blob, onSelect, isSelected, onDownload, onRename, onDelete, onMoveToPublic, onMoveOutOfPublic }) {
161 const [isLoading, setIsLoading] = useState(false);
162 const decodedKey = decodeURIComponent(blob.key);
219}
220
221function App({ initialEmail, initialProfile }) {
222 const encodeKey = (key: string) => encodeURIComponent(key);
223 const decodeKey = (key: string) => decodeURIComponent(key);
645}
646
647function client() {
648 const initialEmail = document.getElementById("root").getAttribute("data-email");
649 const initialProfile = JSON.parse(document.getElementById("root").getAttribute("data-profile"));

MathFlashCard_RetroEditionmain.tsx5 matches

@qkiii•Updated 6 months ago
4import confetti from "https://esm.sh/canvas-confetti";
5
6function generateProblem(config) {
7 const operations = [];
8 if (config.addition) operations.push('+');
54}
55
56function MathFlashcards() {
57 const MAX_STREAK = 5; // Number of segments in streak bar
58 const SUPER_STREAK_THRESHOLD = 5; // Threshold for special animations
383}
384
385function App() {
386 return React.createElement("div", { className: "app" }, React.createElement(MathFlashcards, null));
387}
388
389function client() {
390 createRoot(document.getElementById("root")).render(React.createElement(App, null));
391}
392if (typeof document !== "undefined") { client(); }
393
394export default async function server(request: Request): Promise<Response> {
395 return new Response(
396 `

katakanaWordApimain.tsx1 match

@jdan•Updated 6 months ago
1import { OpenAI } from "https://esm.town/v/std/openai";
2
3export default async function(request: Request): Promise<Response> {
4 try {
5 const openai = new OpenAI();

sqlitemain.tsx7 matches

@Madlean•Updated 6 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>,

decisiveRoseFelidaemain.tsx5 matches

@techMember•Updated 6 months ago
3import { createRoot } from "https://esm.sh/react-dom/client";
4
5function WeatherDashboard() {
6 const [theme, setTheme] = useState('light');
7 const [weather, setWeather] = useState(null);
15
16 useEffect(() => {
17 async function fetchWeather() {
18 try {
19 const response = await fetch(
157}
158
159function client() {
160 createRoot(document.getElementById("root")).render(<WeatherDashboard />);
161}
163if (typeof document !== "undefined") { client(); }
164
165export default async function server(request: Request): Promise<Response> {
166 return new Response(`
167 <html>
182}
183
184function generateCSS(theme: 'light' | 'dark') {
185 return `
186:root {

Snake_gamemain.tsx4 matches

@ilianp•Updated 6 months ago
8const INITIAL_FOOD = { x: 15, y: 15 };
9
10// Helper function to check if two directions are opposite
11const isOppositeDirection = (dir1, dir2) => {
12 const oppositeMap = {
19};
20
21function SnakeGame() {
22 const [snake, setSnake] = useState(INITIAL_SNAKE);
23 const [food, setFood] = useState(INITIAL_FOOD);
211}
212
213function client() {
214 createRoot(document.getElementById("root")).render(<SnakeGame />);
215}
216if (typeof document !== "undefined") { client(); }
217
218export default async function server(request: Request): Promise<Response> {
219 return new Response(`
220 <html>

switchExtractormain.tsx2 matches

@temptemp•Updated 6 months ago
12const dataChart: { variable: string; value: number }[][] = [];
13
14function getValueOf(text: string): number {
15 const pattern = new RegExp(`,${text}=0x([a-zA-Z0-9]+)`, "g");
16 const match = pattern.exec(str);
40 }
41};
42export function solve(p: Array<any> | string) {
43 if (Array.isArray(p)) {
44 return p;

getFileEmail4 file matches

@shouser•Updated 1 month ago
A helper function to build a file's email
tuna

tuna8 file matches

@jxnblk•Updated 1 month 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.