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=2329&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 28557 results for "function"(8255ms)

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;

scraper_templateREADME.md1 match

@dkinzer222•Updated 6 months ago
133. Adjust the if statement to detect changes and update your blob
14
154. Craft a message to be sent with `sendNotification()` function

sqlitemain.tsx5 matches

@dkinzer222•Updated 6 months ago
31
32// ------------
33// Functions
34// ------------
35
36async function execute(statement: InStatement): Promise<ResultSet> {
37 const res = await fetch(`${API_URL}/v1/sqlite/execute`, {
38 method: "POST",
48}
49
50async function batch(statements: InStatement[], mode?: TransactionMode): Promise<ResultSet[]> {
51 const res = await fetch(`${API_URL}/v1/sqlite/batch`, {
52 method: "POST",
62}
63
64function createResError(body: string) {
65 try {
66 const e = zLibsqlError.parse(JSON.parse(body));
113 *
114 * The types are currently shown for types declared in a SQL table. For
115 * column types of function calls, for example, an empty string is
116 * returned.
117 */

jsonpubmain.tsx31 matches

@yawnxyz•Updated 6 months ago
336 const room = db.joinRoom('editor', 'main');
337
338 // Add jq processing functions
339 async function jqFilter(input, filter) {
340 try {
341 const jsonString = typeof input === 'string' ? input : JSON.stringify(input);
349
350 // Add jq filter input with enter key handler
351 $('#jq-filter').on('keypress', async function(e) {
352 if (e.which === 13) { // Enter key
353 e.preventDefault();
400 document.body.appendChild(cursorContainer);
401
402 function updateCursor(e) {
403 const cursor = {
404 x: e.clientX,
411 }
412
413 function createCursorElement(peerId, cursor) {
414 let el = document.getElementById('cursor-' + peerId);
415 if (!el) {
428 }
429
430 function removeCursor(peerId) {
431 const el = document.getElementById('cursor-' + peerId);
432 if (el) el.remove();
433 }
434
435 $(function() {
436 // Track cursor movement
437 document.addEventListener('mousemove', throttle(updateCursor, 50));
484 });
485
486 function saveJsonDoc(content, isNew = false) {
487 if (!content) return;
488
520 }, 500);
521
522 $('#json-input').bind('input', function() {
523 const inputData = $(this).val();
524 debouncedSave(inputData, !currentDocId);
525 });
526
527 function updateDocsList(docs) {
528 const $list = $('#docs-list');
529 $list.empty();
573 });
574
575 // Resizer functionality
576 const $resizer = $("#resizer");
577 const $jsonInput = $("#json-input");
588 let isResizing = false;
589
590 $resizer.on("mousedown", function() {
591 isResizing = true;
592 $("body").css("cursor", "ew-resize");
593 });
594
595 $(document).on("mousemove", function(e) {
596 if (!isResizing) return;
597 const totalWidth = $("body").width();
604 });
605
606 $(document).on("mouseup", function() {
607 if (isResizing) {
608 isResizing = false;
644
645 // Add click handler for Apply jq button
646 $('#apply-jq').on('click', async function() {
647 const filter = $('#jq-filter').val().trim();
648 const rawInput = $('#json-input').val().trim();
665 });
666
667 // Add XML to JSON conversion function
668 function parseXmlToJson(xml) {
669 // If this is the document node, get the root element
670 if (xml.nodeType === 9) { // DOCUMENT_NODE
721 }
722
723 // Add these helper functions before detectInputFormat
724
725
726 // Modify detectInputFormat function
727 function detectInputFormat(input) {
728
729 // Rest of your existing format detection code...
791
792 // Update createJsonView to show filter info
793 function createJsonView(json, parent, depth = 0, meta = {}) {
794 if (depth === 0) {
795 if (meta.compressed) {
848 parent.append(element);
849
850 toggle.on("click", function() {
851 $(this).parent().toggleClass("collapsed");
852 });
882 }
883
884 // Add this function near other utility functions
885 async function applyJqFilter(rawInput, filter) {
886 if (!rawInput) {
887 $("#json-view").empty();
914
915 // Modify updateJsonView to use the jq filter if present
916 async function updateJsonView() {
917 const rawInput = $("#json-input").val()?.trim() || '';
918 const filter = $("#jq-filter").val()?.trim();
958
959 // Modify the document ready section to include jq filter changes
960 $(document).ready(function() {
961 const jsonInput = $("#json-input");
962 const jqFilter = $("#jq-filter");
977 });
978
979 // Utility function to throttle cursor updates
980 function throttle(func, limit) {
981 let inThrottle;
982 return function(...args) {
983 if (!inThrottle) {
984 func.apply(this, args);
990
991 // Add debounce utility
992 function debounce(func, wait) {
993 let timeout;
994 return function executedFunction(...args) {
995 const later = () => {
996 clearTimeout(timeout);

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.