npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lovebowls/leaguejs

v0.2.28

Published

A framework-agnostic JavaScript library for managing leagues, teams, and matches

Readme

LeagueJS

A pure JavaScript library for managing leagues, teams, and matches.

Note: This library is currently in alpha status. The API may change without notice.

Overview

LeagueJS is a framework-agnostic JavaScript library that provides a clean, efficient way to manage leagues, teams, and matches. It follows a class-based approach, allowing you to create and manipulate league data directly. The library supports both CommonJS and ES Modules, making it compatible with various environments including Node.js, browsers, and Wix. With full TypeScript support including declaration files, it offers excellent IDE integration and type safety for all operations.

Features

  • League Management

    • Create customizable leagues with configurable point systems
    • Direct operations on league instances
    • JSON import/export for data portability
  • Team Management

    • Create and manage teams within leagues
    • Track team details and statistics
    • Handle team additions and removals
  • Match Management

    • Create and record match results between teams
    • Support for match scheduling
    • Comprehensive match history tracking
    • Unique match identifiers using UUID v4
  • League Table Calculations

    • Automated position table generation
    • Configurable scoring systems (points for wins, draws, losses)
    • Sort by points, shot difference, and shots scored
  • TypeScript Support

    • Full TypeScript declaration files (.d.ts) for all classes and functions
    • Enhanced IDE autocompletion support for Wix and other environments
    • Comprehensive type definitions for all classes and methods
    • Seamless integration with TypeScript projects
    • Type safety for all classes and methods
    • Comprehensive interface definitions

Dependencies

  • uuid: Used for generating unique match identifiers
    • Version: ^11.1.0
    • Purpose: Ensures each match has a globally unique identifier
    • Implementation: Uses UUID v4 for maximum uniqueness

Installation

npm install @lovebowls/leaguejs

Usage

ES Modules (Recommended)

import { League, Team, Match } from '@lovebowls/leaguejs';

// Create a new league
const league = new League({
  name: 'Premier League',
  settings: {
    pointsForWin: 3,
    pointsForDraw: 1,
    pointsForLoss: 0
  }
});

// Add teams
const team1 = new Team({ _id: 'arsenal', name: 'Arsenal' });
const team2 = new Team({ _id: 'chelsea', name: 'Chelsea' });
league.addTeam(team1);
league.addTeam(team2);

// Add a match with the result
const match = new Match({
  homeTeam: team1,
  awayTeam: team2,
  date: new Date(),
  result: { homeScore: 2, awayScore: 1 }
});
league.addMatch(match);

// Get team stats
const teamStats = league.getTeamStats(team1._id);

// Get league table
const leagueTable = league.getLeagueTable();

CommonJS

const { League, Team, Match } = require('@lovebowls/leaguejs');

// Usage is identical to ES Modules example above

Wix Backend Usage

For Wix backend code, use Direct import:

// Method 1: Direct import (recommended)
import { League, Team, Match } from '@lovebowls/leaguejs';

### Data Persistence
To save and load league data:

```javascript
// Convert to JSON for storage
const leagueJSON = league.toJSON();

// Later, load from JSON
const loadedLeague = League.fromJSON(leagueJSON);

API Reference

League

Represents a league with teams and matches.

Methods

  • addTeam(team) - Add a team to the league
  • removeTeam(teamId) - Remove a team from the league
  • addMatch(match) - Add a match to the league
  • getTeam(teamId) - Get a team by ID
  • getMatch(matchId) - Get a match by ID
  • getTeamMatches(teamId) - Get all matches for a team
  • getTeamStats(teamId) - Get statistics for a team
  • getLeagueTable() - Get the current league table
  • toJSON() - Convert league to JSON
  • static fromJSON(jsonData) - Create a League instance from JSON data

Team

Represents a team in a league.

Properties

  • _id - Unique identifier for the team
  • name - Name of the team (defaults to _id if not provided)

Methods

  • update(updates) - Update team details
  • toJSON() - Convert team to JSON

Match

Represents a match between two teams.

Methods

  • getWinner() - Determines the winner (team name or 'draw') or null if no result.
  • isDraw() - Returns true if the match is a draw, false otherwise, or null if no result.
  • setRinkScores(rinkScores) - Set rink scores for an existing match result
  • getRinkResults() - Get rink win/draw counts
  • toJSON() - Convert match to JSON
  • _id - The unique identifier for the match

Project Structure

leaguejs/
├── src/
│   ├── models/
│   │   ├── League.js
│   │   ├── Team.js
│   │   └── Match.js
│   ├── utils/
│   │   ├── calculators.js
│   │   └── validators.js
│   └── index.js
├── dist/
│   ├── index.js        # ES Module build
│   ├── index.js.map    # Source map for ES Module
│   ├── index.cjs       # CommonJS build
│   └── index.cjs.map   # Source map for CommonJS
├── tests/
├── package.json
├── rollup.config.js
└── README.md

Development

Source Control

This project uses Git for version control. To clone the repository:

git clone https://helixteamhub.cloud/lovebowlscouk/projects/leaguejs/repositories/leagueJS/tree/main.git
cd leaguejs
npm install

Building

The library is built using rollup to generate both CommonJS and ES Module formats:

# Development build with watch mode
npm run dev

# Production build
npm run build

Testing

The library includes comprehensive tests using Jest:

npm test

License

MIT

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please ensure your code follows the existing style and includes appropriate tests.