1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export let espntcFindGroups = async (options?: {
search?: string,
access?: "all" | "private" | "public",
type?: "all" | "celebrity" | "fans",
locked?: "all" | "unlocked" | "locked",
dropWorst?: boolean,
start?: number,
num?: number,
gender?: "m" | "f",
}) => {
const params = {
search: options?.search || "",
type_access: ["all", "private", "public"].indexOf(options?.access ?? "all"),
type_group: ["all", "celebrity", "fans"].indexOf(options?.type ?? "all"),
type_lock: ["all", "unlocked", "locked"].indexOf(options?.locked ?? "all"),
type_dropWorst: options?.dropWorst ? 1 : 0,
start: options?.start || 0,
num: options?.num || 30,
gender: options?.gender || "m",
};
const baseURL =
"https://fantasy.espncdn.com/tournament-challenge-bracket" +
(params.gender == "f" ? "-women" : "") +
"/2023/en/api/findGroups";
console.log(`${baseURL}?${new URLSearchParams(params)}`);
const res = await fetchJSON(
`${baseURL}?${new URLSearchParams(params)}`
);
interface Group {
id: number;
name: string;
motto: string;
size: number;
private: boolean;
locked: boolean;
type: "user" | "celebrity" | "fans";
raw: any;
}
console.log(res);
const groups: Group[] = res.g.map((g): Group => ({
id: g.id,
name: g.n,
motto: g.m,
size: g.s,
private: g.p,
locked: g.l,
type: g.t == "u" ? "user" : g.t == "c" ? "celebrity" : "fans",
raw: g,
}));
return groups;
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.