@lp-labs/tournament-standings 0.0.0-stage → 0.1.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 Libin Prasanth
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 CHANGED
@@ -1,3 +1,68 @@
1
- # Temporary Holding Version
1
+ # @lp-labs/tournament-standings
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Deterministic points-table aggregation from scored matches.
4
+
5
+ Original, standalone MIT TypeScript implementation with **zero runtime or peer dependencies**. ESM/CommonJS exports and separate declarations; Node18+ and compatible ES2022 browsers. No service, filesystem, network, clock or browser globals accessed on import. Compiler/formatter dependencies are development-only.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @lp-labs/tournament-standings
11
+ ```
12
+
13
+ ## Working example
14
+
15
+ ```js
16
+ import { standings } from '@lp-labs/tournament-standings';
17
+ if (standings(['A', 'B'], [{ home: 'A', away: 'B', homeGoals: 2, awayGoals: 1 }])[0].points !== 3)
18
+ throw new Error('Standings');
19
+ ```
20
+
21
+ CommonJS: `const api = require('@lp-labs/tournament-standings')`.
22
+
23
+ ## Behavior, customization and limits
24
+
25
+ standings(teams,matches) uses fixed3 points win,1 draw,0 loss; sorts points, goal difference, goals for, then ordinal team ID. Team IDs nonempty <=100 chars, unique, <=1000; matches<=10000 with distinct known home/away and integer goals0..1000. Repeated fixtures allowed (each is a result); returns played/won/drawn/lost/for/against/points. No head-to-head or league-specific tie rules. O(teams log teams + matches), no mutation or prototype-key hazards.
26
+
27
+ Use the explicit function arguments and public types below to customize the documented behavior. There are no hidden environment settings or sibling-library requirements. Array inputs must be dense; sparse entries are invalid. Inputs are validated before a successful result is returned. Outputs do not mutate caller-owned inputs. Hostile proxies/getters and concurrent mutation are outside the contract.
28
+
29
+ ## Errors and integration
30
+
31
+ Invalid data never produces an empty success-shaped substitute. TypeError reports incompatible runtime types/nonfinite numbers; RangeError reports unsupported ranges, invalid syntax, inconsistent states and exceeded budgets. Functions that explicitly return null, false or empty arrays describe those legitimate outcomes above. Errors propagate to callers; UI applications should catch at their boundary and visibly notify users. Numerical calculations use JavaScript IEEE754 unless the API explicitly uses bigint; compare approximate numerical results with application-appropriate tolerances.
32
+
33
+ ## Complete public API
34
+
35
+ ```ts
36
+ export interface ScoredMatch {
37
+ home: string;
38
+ away: string;
39
+ homeGoals: number;
40
+ awayGoals: number;
41
+ }
42
+ export interface Standing {
43
+ team: string;
44
+ played: number;
45
+ won: number;
46
+ drawn: number;
47
+ lost: number;
48
+ goalsFor: number;
49
+ goalsAgainst: number;
50
+ points: number;
51
+ }
52
+ export declare function standings(
53
+ teams: readonly string[],
54
+ matches: readonly ScoredMatch[],
55
+ ): Standing[];
56
+ ```
57
+
58
+ ## Performance and portability
59
+
60
+ Complexity and resource ceilings are specified above. Buffered synchronous algorithms do not create workers or timers; callers can move expensive work to their own worker. Limits are enforced, not silently truncated. No runtime imports from any other library. No compatibility or completeness claims beyond the stated scope.
61
+
62
+ ## Support
63
+
64
+ If this library is useful to you, consider supporting its maintenance with a [donation via PayPal](https://www.paypal.me/LibinPrasanth).
65
+
66
+ ## Author
67
+
68
+ Created by [Libin Prasanth](https://www.linkedin.com/in/libinprasanth/). Connect on LinkedIn for updates and discussion.
@@ -0,0 +1,17 @@
1
+ export interface ScoredMatch {
2
+ home: string;
3
+ away: string;
4
+ homeGoals: number;
5
+ awayGoals: number;
6
+ }
7
+ export interface Standing {
8
+ team: string;
9
+ played: number;
10
+ won: number;
11
+ drawn: number;
12
+ lost: number;
13
+ goalsFor: number;
14
+ goalsAgainst: number;
15
+ points: number;
16
+ }
17
+ export declare function standings(teams: readonly string[], matches: readonly ScoredMatch[]): Standing[];
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.standings = standings;
4
+ function finite(value, min = -Number.MAX_VALUE, max = Number.MAX_VALUE) {
5
+ if (typeof value !== 'number' || !Number.isFinite(value))
6
+ throw new TypeError('Expected finite number');
7
+ if (value < min || value > max)
8
+ throw new RangeError('Number outside supported bounds');
9
+ return value;
10
+ }
11
+ function integer(value, min = 0, max = 1000000) {
12
+ if (!Number.isSafeInteger(value))
13
+ throw new RangeError('Expected safe integer');
14
+ return finite(value, min, max);
15
+ }
16
+ function strictText(value, max = 16384) {
17
+ if (typeof value !== 'string')
18
+ throw new TypeError('Expected string');
19
+ if (value.length > max)
20
+ throw new RangeError('Text length budget exceeded');
21
+ }
22
+ function standings(teams, matches) {
23
+ if (!Array.isArray(teams) ||
24
+ !teams.length ||
25
+ teams.length > 1000 ||
26
+ !Array.isArray(matches) ||
27
+ matches.length > 10000)
28
+ throw new RangeError('Input budget');
29
+ const rows = new Map();
30
+ for (const team of teams) {
31
+ strictText(team, 100);
32
+ if (!team || rows.has(team))
33
+ throw new RangeError('Unique nonempty teams required');
34
+ rows.set(team, {
35
+ team,
36
+ played: 0,
37
+ won: 0,
38
+ drawn: 0,
39
+ lost: 0,
40
+ goalsFor: 0,
41
+ goalsAgainst: 0,
42
+ points: 0,
43
+ });
44
+ }
45
+ for (const match of matches) {
46
+ if (!match)
47
+ throw new TypeError('Expected match');
48
+ const a = rows.get(match.home), b = rows.get(match.away);
49
+ if (!a || !b || a === b)
50
+ throw new RangeError('Distinct known opponents required');
51
+ integer(match.homeGoals, 0, 1000);
52
+ integer(match.awayGoals, 0, 1000);
53
+ a.played++;
54
+ b.played++;
55
+ a.goalsFor += match.homeGoals;
56
+ a.goalsAgainst += match.awayGoals;
57
+ b.goalsFor += match.awayGoals;
58
+ b.goalsAgainst += match.homeGoals;
59
+ if (match.homeGoals === match.awayGoals) {
60
+ a.drawn++;
61
+ b.drawn++;
62
+ a.points++;
63
+ b.points++;
64
+ }
65
+ else {
66
+ const w = match.homeGoals > match.awayGoals ? a : b, l = w === a ? b : a;
67
+ w.won++;
68
+ w.points += 3;
69
+ l.lost++;
70
+ }
71
+ }
72
+ return [...rows.values()].sort((a, b) => b.points - a.points ||
73
+ b.goalsFor - b.goalsAgainst - (a.goalsFor - a.goalsAgainst) ||
74
+ b.goalsFor - a.goalsFor ||
75
+ (a.team < b.team ? -1 : a.team > b.team ? 1 : 0));
76
+ }
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,17 @@
1
+ export interface ScoredMatch {
2
+ home: string;
3
+ away: string;
4
+ homeGoals: number;
5
+ awayGoals: number;
6
+ }
7
+ export interface Standing {
8
+ team: string;
9
+ played: number;
10
+ won: number;
11
+ drawn: number;
12
+ lost: number;
13
+ goalsFor: number;
14
+ goalsAgainst: number;
15
+ points: number;
16
+ }
17
+ export declare function standings(teams: readonly string[], matches: readonly ScoredMatch[]): Standing[];
@@ -0,0 +1,73 @@
1
+ function finite(value, min = -Number.MAX_VALUE, max = Number.MAX_VALUE) {
2
+ if (typeof value !== 'number' || !Number.isFinite(value))
3
+ throw new TypeError('Expected finite number');
4
+ if (value < min || value > max)
5
+ throw new RangeError('Number outside supported bounds');
6
+ return value;
7
+ }
8
+ function integer(value, min = 0, max = 1000000) {
9
+ if (!Number.isSafeInteger(value))
10
+ throw new RangeError('Expected safe integer');
11
+ return finite(value, min, max);
12
+ }
13
+ function strictText(value, max = 16384) {
14
+ if (typeof value !== 'string')
15
+ throw new TypeError('Expected string');
16
+ if (value.length > max)
17
+ throw new RangeError('Text length budget exceeded');
18
+ }
19
+ export function standings(teams, matches) {
20
+ if (!Array.isArray(teams) ||
21
+ !teams.length ||
22
+ teams.length > 1000 ||
23
+ !Array.isArray(matches) ||
24
+ matches.length > 10000)
25
+ throw new RangeError('Input budget');
26
+ const rows = new Map();
27
+ for (const team of teams) {
28
+ strictText(team, 100);
29
+ if (!team || rows.has(team))
30
+ throw new RangeError('Unique nonempty teams required');
31
+ rows.set(team, {
32
+ team,
33
+ played: 0,
34
+ won: 0,
35
+ drawn: 0,
36
+ lost: 0,
37
+ goalsFor: 0,
38
+ goalsAgainst: 0,
39
+ points: 0,
40
+ });
41
+ }
42
+ for (const match of matches) {
43
+ if (!match)
44
+ throw new TypeError('Expected match');
45
+ const a = rows.get(match.home), b = rows.get(match.away);
46
+ if (!a || !b || a === b)
47
+ throw new RangeError('Distinct known opponents required');
48
+ integer(match.homeGoals, 0, 1000);
49
+ integer(match.awayGoals, 0, 1000);
50
+ a.played++;
51
+ b.played++;
52
+ a.goalsFor += match.homeGoals;
53
+ a.goalsAgainst += match.awayGoals;
54
+ b.goalsFor += match.awayGoals;
55
+ b.goalsAgainst += match.homeGoals;
56
+ if (match.homeGoals === match.awayGoals) {
57
+ a.drawn++;
58
+ b.drawn++;
59
+ a.points++;
60
+ b.points++;
61
+ }
62
+ else {
63
+ const w = match.homeGoals > match.awayGoals ? a : b, l = w === a ? b : a;
64
+ w.won++;
65
+ w.points += 3;
66
+ l.lost++;
67
+ }
68
+ }
69
+ return [...rows.values()].sort((a, b) => b.points - a.points ||
70
+ b.goalsFor - b.goalsAgainst - (a.goalsFor - a.goalsAgainst) ||
71
+ b.goalsFor - a.goalsFor ||
72
+ (a.team < b.team ? -1 : a.team > b.team ? 1 : 0));
73
+ }
package/package.json CHANGED
@@ -1,6 +1,63 @@
1
1
  {
2
2
  "name": "@lp-labs/tournament-standings",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Deterministic points-table aggregation from scored matches.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/cjs/index.js",
8
+ "module": "./dist/esm/index.js",
9
+ "types": "./dist/esm/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "import": {
13
+ "types": "./dist/esm/index.d.ts",
14
+ "default": "./dist/esm/index.js"
15
+ },
16
+ "require": {
17
+ "types": "./dist/cjs/index.d.ts",
18
+ "default": "./dist/cjs/index.js"
19
+ }
20
+ },
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "README.md",
26
+ "LICENSE"
27
+ ],
28
+ "sideEffects": false,
29
+ "engines": {
30
+ "node": ">=18"
31
+ },
32
+ "scripts": {
33
+ "build": "node scripts/build.mjs",
34
+ "typecheck": "npm run build && node scripts/check-types.mjs",
35
+ "test": "npm run build && node --test tests/*.test.mjs",
36
+ "format": "prettier --write src scripts tests *.json README.md",
37
+ "format:check": "prettier --check src scripts tests *.json README.md",
38
+ "prepack": "npm run build"
39
+ },
40
+ "devDependencies": {
41
+ "typescript": "^5.9.3",
42
+ "prettier": "^3.6.2"
43
+ },
44
+ "prettier": {
45
+ "singleQuote": true,
46
+ "semi": true,
47
+ "trailingComma": "all",
48
+ "printWidth": 100,
49
+ "endOfLine": "lf"
50
+ },
51
+ "publishConfig": {
52
+ "access": "public",
53
+ "registry": "https://registry.npmjs.org/"
54
+ },
55
+ "author": {
56
+ "name": "Libin Prasanth",
57
+ "url": "https://www.linkedin.com/in/libinprasanth/"
58
+ },
59
+ "funding": {
60
+ "type": "paypal",
61
+ "url": "https://www.paypal.me/LibinPrasanth"
62
+ }
63
+ }