Skip to main content

Function: parseEndpoint()

parseEndpoint(kind, key, raw, section?): ParsedResult

Defined in: src/parsers/browser.ts:84

Unified parse helper: turn a raw payload into tidy rows given how the endpoint was dispatched.

  • kind: "espn" — key is the endpoint short name (e.g. "scoreboard", "summary"); the summary dispatcher (and the CDN game pages, which run it) honours section (omit it to get the dict of all 21 sub-frames).
  • kind: "flat" — key is the registered parser name (a native wrapper's parser, e.g. "parse_mlb_schedule"); a multi-table parser (MULTI_TABLE_SECTIONS) honours section exactly as the wrapper's { parsed: true, section } does.

Returns null when no parser is registered, so callers fall back to raw.

Parameters​

kind​

"espn" | "flat"

"espn" (look key up in ESPN_ENDPOINT_PARSERS via parserForEndpoint) or "flat" (look it up in the flat PARSERS registry via parserFor).

key​

string

The ESPN endpoint short name, or the flat parser's registered name.

raw​

unknown

The raw payload exactly as the endpoint returned it (decoded JSON, or the text body for CSV / HTML parsers).

section?​

string

A sub-frame name. Forwarded only to a sectioned ESPN endpoint (SECTIONED_ENDPOINTS) or a flat parser listed in MULTI_TABLE_SECTIONS; otherwise ignored. Omitted = the parser's default (a dict of every sub-frame for the ESPN summary dispatcher and the dict-default flat parsers).

Returns​

ParsedResult

Rows, a dict of row arrays, or null when key has no parser of that kind.

Remarks​

This function throws nothing itself, but a multi-table flat parser rejects an unknown section with an Error listing the valid names (sectionError in _frames.ts). The flat branch dispatches exactly as the wrapper's { parsed: true, section } does (callFlat, src/leagues/_make_flat.ts). Browser-safe: no network, no node-only parser — a "flat" key registered only on node (parse_kenpom_page) returns null here.

Example​

const rows = parseEndpoint("espn", "scoreboard", raw);
const players = parseEndpoint("flat", "parse_mls_match", match, "players");