fitzroy 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jack McPherson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # fitzroy
2
+
3
+ TypeScript library and CLI for AFL data — match results, player stats, fixtures, ladders, lineups, squads, and teams.
4
+
5
+ A port of the [fitzRoy R package](https://github.com/jimmyday12/fitzRoy).
6
+
7
+ ## Data Sources
8
+
9
+ - **AFL API** — official AFL/AFLW match results, player stats, fixtures, lineups, ladders, and teams
10
+ - **FootyWire** — scraped match results
11
+ - **AFL Tables** — historical season results (1897-present)
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install fitzroy
17
+ ```
18
+
19
+ ## Library Usage
20
+
21
+ ```typescript
22
+ import { fetchMatchResults, fetchPlayerStats, fetchLadder } from "fitzroy";
23
+
24
+ // Match results for a season
25
+ const matches = await fetchMatchResults({ source: "afl-api", season: 2025, competition: "AFLM" });
26
+
27
+ // Player stats for a specific round
28
+ const stats = await fetchPlayerStats({ source: "afl-api", season: 2025, round: 1 });
29
+
30
+ // Ladder standings
31
+ const ladder = await fetchLadder({ source: "afl-api", season: 2025 });
32
+ ```
33
+
34
+ All functions return `Result<T, Error>` — check `result.success` before accessing `result.data`.
35
+
36
+ ## CLI
37
+
38
+ ```bash
39
+ # Install globally
40
+ npm install -g fitzroy
41
+
42
+ # Match results
43
+ fitzroy matches --season 2025 --round 1
44
+
45
+ # Player stats
46
+ fitzroy stats --season 2025 --round 1
47
+
48
+ # Ladder
49
+ fitzroy ladder --season 2025
50
+
51
+ # Fixture
52
+ fitzroy fixture --season 2025
53
+
54
+ # Output formats
55
+ fitzroy matches --season 2025 --json # JSON (default when piped)
56
+ fitzroy matches --season 2025 --csv # CSV with headers
57
+ fitzroy matches --season 2025 --full # All columns in table view
58
+ ```
59
+
60
+ Run `fitzroy --help` for all commands and options.
61
+
62
+ ## Contributing
63
+
64
+ 1. Clone the repo
65
+ 2. Install dependencies: `bun install`
66
+ 3. Run quality checks: `npm run typecheck && npm run check && npm run test`
67
+
68
+ ## License
69
+
70
+ MIT
package/dist/cli.js ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ __require
4
+ } from "./shared/chunk-xv8z2kms.js";
5
+
6
+ // src/cli.ts
7
+ import { defineCommand, runMain } from "citty";
8
+ import pc from "picocolors";
9
+
10
+ // src/lib/errors.ts
11
+ class AflApiError extends Error {
12
+ statusCode;
13
+ name = "AflApiError";
14
+ constructor(message, statusCode) {
15
+ super(message);
16
+ this.statusCode = statusCode;
17
+ }
18
+ }
19
+
20
+ class ScrapeError extends Error {
21
+ source;
22
+ name = "ScrapeError";
23
+ constructor(message, source) {
24
+ super(message);
25
+ this.source = source;
26
+ }
27
+ }
28
+
29
+ class UnsupportedSourceError extends Error {
30
+ source;
31
+ name = "UnsupportedSourceError";
32
+ constructor(message, source) {
33
+ super(message);
34
+ this.source = source;
35
+ }
36
+ }
37
+
38
+ class ValidationError extends Error {
39
+ issues;
40
+ name = "ValidationError";
41
+ constructor(message, issues) {
42
+ super(message);
43
+ this.issues = issues;
44
+ }
45
+ }
46
+
47
+ // src/cli.ts
48
+ var main = defineCommand({
49
+ meta: {
50
+ name: "fitzroy",
51
+ version: "1.0.0",
52
+ description: "CLI for fetching AFL data — match results, player stats, fixtures, ladders, and more"
53
+ },
54
+ subCommands: {
55
+ matches: () => import("./shared/chunk-kr78ch1j.js").then((m) => m.matchesCommand),
56
+ stats: () => import("./shared/chunk-ngvkaczn.js").then((m) => m.statsCommand),
57
+ fixture: () => import("./shared/chunk-99nkfy8s.js").then((m) => m.fixtureCommand),
58
+ ladder: () => import("./shared/chunk-d6fkap72.js").then((m) => m.ladderCommand),
59
+ lineup: () => import("./shared/chunk-9zcjfgwe.js").then((m) => m.lineupCommand),
60
+ squad: () => import("./shared/chunk-c7vawngt.js").then((m) => m.squadCommand),
61
+ teams: () => import("./shared/chunk-b380x0p6.js").then((m) => m.teamsCommand)
62
+ }
63
+ });
64
+ function formatError(error) {
65
+ if (error instanceof ValidationError && error.issues) {
66
+ const issueLines = error.issues.map((i) => ` ${pc.yellow(i.path)}: ${i.message}`);
67
+ return `${pc.red("Validation error:")}
68
+ ${issueLines.join(`
69
+ `)}`;
70
+ }
71
+ if (error instanceof AflApiError) {
72
+ const status = error.statusCode ? ` (HTTP ${error.statusCode})` : "";
73
+ return `${pc.red("AFL API error:")} ${error.message}${status}`;
74
+ }
75
+ if (error instanceof ScrapeError) {
76
+ const source = error.source ? ` [${error.source}]` : "";
77
+ return `${pc.red("Scrape error:")} ${error.message}${source}`;
78
+ }
79
+ if (error instanceof UnsupportedSourceError) {
80
+ return `${pc.red("Unsupported source:")} ${error.message}`;
81
+ }
82
+ if (error instanceof Error) {
83
+ return `${pc.red("Error:")} ${error.message}`;
84
+ }
85
+ return `${pc.red("Error:")} ${String(error)}`;
86
+ }
87
+ runMain(main).catch((error) => {
88
+ console.error(formatError(error));
89
+ process.exit(1);
90
+ });