1.0.3 • Published 5 months ago

cl-cricket-utils v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

cl-cricket-utils

A cricket utility package to calculate target runs, required run rate, and projected scores dynamically.

šŸš€ Features

  • āœ… Calculate target runs and balls left in a match
  • āœ… Compute required run rate
  • āœ… Estimate projected scores
  • āœ… More cricket-related utilities coming soon!

šŸ“¦ Installation

Install via NPM:

npm install cl-cricket-utils

šŸ”„ Usage

const { calculateTargetRunsAndBallsLeft, calculateRequiredRunRate, calculateProjectedScore } = require('cl-cricket-utils');

const match = {
  status: { id: 2 },
  currentInning: {
    targetRuns: 200,
    totalRuns: 150,
    ballsLeft: 30,
    overs: 5,
  }
};

// Calculate Target Runs and Balls Left
const { targetRuns, ballsLeft, ballText } = calculateTargetRunsAndBallsLeft(match);
console.log(`Target Runs: ${targetRuns}, Balls Left: ${ballsLeft}, Display: ${ballText}`);

// Required Run Rate
const rrr = calculateRequiredRunRate(targetRuns, ballsLeft);
console.log(`Required Run Rate: ${rrr}`);

// Projected Score
const projected = calculateProjectedScore(150, 15, 20);
console.log(`Projected Score: ${projected}`);

šŸ›  Functions

1ļøāƒ£ calculateTargetRunsAndBallsLeft(match)

šŸ“Œ Description: Determines how many runs are needed to win and how many balls are left.

šŸ“Œ Parameters:

  • match (Object) – Match data including status, target runs, total runs, balls left.

šŸ“Œ Returns:

{
  targetRuns: 50,
  ballsLeft: 30,
  ballText: "Overs" // or "Balls"
}

šŸ“Œ Example:

const { calculateTargetRunsAndBallsLeft } = require('cl-cricket-utils');
const result = calculateTargetRunsAndBallsLeft(match);
console.log(result);

2ļøāƒ£ calculateRequiredRunRate(targetRuns, ballsLeft)

šŸ“Œ Description: Computes the required run rate to chase the target.

šŸ“Œ Parameters:

  • targetRuns (Number) – Runs required to win.
  • ballsLeft (Number) – Balls remaining.

šŸ“Œ Returns: Number (Required Run Rate)

šŸ“Œ Example:

const rrr = calculateRequiredRunRate(50, 30);
console.log(`Required Run Rate: ${rrr}`);

3ļøāƒ£ calculateProjectedScore(currentRuns, currentOvers, totalOvers)

šŸ“Œ Description: Predicts the final score based on the current run rate.

šŸ“Œ Parameters:

  • currentRuns (Number) – Runs scored so far.
  • currentOvers (Number) – Overs played.
  • totalOvers (Number) – Total overs in the match.

šŸ“Œ Returns: Number (Projected Score)

šŸ“Œ Example:

const projected = calculateProjectedScore(150, 15, 20);
console.log(`Projected Score: ${projected}`);

šŸ“œ License

This package is open-source under the MIT License.

šŸ¤ Contributing

Feel free to open issues or pull requests on GitHub.


Final Notes:

āœ… Users can now see everything on NPM and GitHub
āœ… Functions are well documented
āœ… Easy-to-follow examples

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago