1.0.3 ⢠Published 8 months ago
cl-cricket-utils v1.0.3
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