Skip to main content

How values and seasons are normalised

{
  "normValue('12.0')": "12",
  "normValue(' Montréal ')": "montreal",
  "normSeason(2020)": 2020,
  "normSeason('2020-21')": "season must be a year such as 2020, got \"2020-21\"; for a split season pass its ending year (2021 for '2020-21')",
  "seasonBounds('nfl')[0]": 1920,
  "latestSeason('nfl')": 2026,
  "LEAGUES.length": 28,
  "VARIANTS.length": 32
}
import {
InputError,
LEAGUES,
VARIANTS,
latestSeason,
normSeason,
normValue,
seasonBounds,
} from "@sportsdataverse/sdvplot";

let splitSeason = "";
try {
normSeason("2020-21");
} catch (e) {
if (e instanceof InputError) splitSeason = e.message;
}

{
// Ids compare as text: an integral float loses its ".0"; case and accents fold.
"normValue('12.0')": normValue("12.0"),
"normValue(' Montréal ')": normValue(" Montréal "),
"normSeason(2020)": normSeason(2020),
"normSeason('2020-21')": splitSeason,
// The first season; the upper bound is next year, so it moves every January.
"seasonBounds('nfl')[0]": seasonBounds("nfl")?.[0],
"latestSeason('nfl')": latestSeason("nfl"),
"LEAGUES.length": LEAGUES.length,
"VARIANTS.length": VARIANTS.length,
};

Tags: normValue · normSeason · seasons. All sdvplot examples.