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 🙏

© 2024 – Pkg Stats / Ryan Hefner

football-scoreboard

v1.0.2

Published

A live football World Cup scoreboard library.

Downloads

57

Readme

Live Football World Cup Scoreboard

Welcome to the Live Football World Cup Scoreboard library! This library allows you to track ongoing football matches, update scores, finish matches, and get a summary of all matches in progress, ordered according to specific criteria.

Table of Contents

Features

  • Start a New Match: Begin tracking a new football match with specified home and away teams.
  • Update Scores: Update the scores of an ongoing match with absolute values.
  • Finish Matches: Conclude an ongoing match, removing it from the scoreboard.
  • Get Summary: Retrieve a summary of all matches in progress, ordered by total score and recency.

Installation

You can install the package from npm:

npm install football-scoreboard

Ensure you have Node.js installed on your system.

Clone the repository and install the dependencies:

git clone https://github.com/yourusername/scoreboard.git
cd scoreboard
npm install

Usage

This library is designed to be simple and straightforward to use in any Node.js project.

Starting a Match

To start tracking a new match:

import { Scoreboard } from './src/scoreboard';

const scoreboard = new Scoreboard();
scoreboard.startMatch('Mexico', 'Canada');

Updating a Score

To update the score of an ongoing match:

scoreboard.updateScore('Mexico', 'Canada', 0, 5);

The scores are absolute and correspond to the home and away teams, respectively.

Finishing a Match

To finish a match and remove it from the scoreboard:

scoreboard.finishMatch('Mexico', 'Canada');

Getting the Summary

To get a summary of all matches in progress:

const summary = scoreboard.getSummary();
console.log(summary);

The summary will list matches ordered by their total score (descending). Matches with the same total score are ordered by the most recently started match.

Example Output:

1. Uruguay 6 - Italy 6
2. Spain 10 - Brazil 2
3. Mexico 0 - Canada 5
4. Argentina 3 - Australia 1
5. Germany 2 - France 2

Running Tests

The project uses Vitest for testing. To run the test suite:

npm run test

Ensure all tests pass before using the library in production.

Assumptions

  • Unique Team Names: Each team is uniquely identified by its name. Duplicate team names are not allowed.
  • Case Insensitivity: Team names are case-insensitive and trimmed of leading/trailing whitespace.
  • Team Participation: A team cannot participate in more than one match simultaneously.
  • Valid Scores: Scores are non-negative integers.
  • Team Order: When updating scores or finishing matches, team names must be provided in the same order as when the match was started (home team first, away team second).

Design Decisions

  • In-Memory Data Structures: Used Map, Array, and Set to store matches, sorted matches, and active teams for efficient data management.
  • Normalization of Team Names: Team names are normalized (trimmed and converted to lowercase) to ensure consistency in comparisons.
  • Order-Independent Match Key: The match key is generated based on normalized team names to prevent duplicate matches and ensure consistency.
  • Binary Search for Insertion: A binary search algorithm (findInsertionIndex) is used to efficiently insert matches into the sorted array based on total score and start time.
  • Error Handling: Clear and descriptive error messages are provided for invalid operations, enhancing usability and debugging.

Project Structure

├── src
│   ├── constants.ts       // Error messages and constants
│   ├── match.ts           // Match class definition
│   ├── scoreboard.ts      // Scoreboard class definition
├── tests
│   ├── match.test.ts      // Tests for Match class
│   ├── scoreboard.test.ts // Tests for Scoreboard class
├── package.json           // Project configuration and scripts
├── tsconfig.json          // TypeScript configuration
└── README.md              // Project documentation

Dependencies

  • Node.js: Runtime environment for executing JavaScript code.
  • TypeScript: For static type checking and improved code quality.
  • Vitest: A fast unit test framework for running tests.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch with a descriptive name.
  3. Make your changes, ensuring code quality and passing tests.
  4. Submit a pull request with a detailed description of your changes.

License

This project is licensed under the ISC License.


Note: This library is a simplified implementation intended for educational purposes and may not cover all real-world scenarios.