# osu-sr-calculator

> Star rating calculator for osu! beatmaps

Latest version **2.0.3** (published 2024-11-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install osu-sr-calculator
pnpm add osu-sr-calculator
yarn add osu-sr-calculator
bun add osu-sr-calculator
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2024-11-27 |
| First published | 2019-02-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=16.0.0 |
| Dependencies | 2 |
| Unpacked size | 152.6 KB |
| Known vulnerabilities | 0 (+36 in 2 direct dependencies) |
| Install scripts | no |
| Author | Mr. HeliX |
| Maintainers | mr_helix |
| Keywords | osu, star, rating, calculator, difficulty |

## Links

- npm: https://www.npmjs.com/package/osu-sr-calculator
- Repository: https://gitlab.com/MrHeliX/star-rating-calculator
- Homepage: https://gitlab.com/MrHeliX/star-rating-calculator#readme
- Issues: https://gitlab.com/MrHeliX/star-rating-calculator/issues
- npm.io page: https://npm.io/package/osu-sr-calculator

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) 1.7.7
- [lodash](https://npm.io/package/lodash.md) 4.17.21

## Alternatives

- [lodash.startswith](https://npm.io/package/lodash.startswith.md) — 769.7K weekly downloads
- [@tarojs/service](https://npm.io/package/@tarojs/service.md) — 33.9K weekly downloads
- [io.extendreality.tilia.indicators.spatialtargets.unity](https://npm.io/package/io.extendreality.tilia.indicators.spatialtargets.unity.md) — 131 weekly downloads
- [@rtarojs/taro](https://npm.io/package/@rtarojs/taro.md) — 90 weekly downloads
- [node-branch-io](https://npm.io/package/node-branch-io.md) — 50 weekly downloads

## Recent versions

- 2.0.3 (latest) — 2024-11-27
- 2.0.1 — 2024-11-26
- 2.0.0 — 2024-11-26
- 1.0.13 — 2021-01-06
- 1.0.12 — 2021-01-06
- 1.0.11 — 2021-01-05
- 1.0.10 — 2020-05-13
- 1.0.9 — 2020-04-05
- 1.0.8 — 2020-04-05
- 1.0.7 — 2020-04-05
- 1.0.6 — 2019-02-10
- 1.0.5 — 2019-02-09
- 1.0.4 — 2019-02-08
- 1.0.3 — 2019-02-08
- 1.0.2 — 2019-02-08
- … 2 more at https://npm.io/package/osu-sr-calculator/versions

## README

# osu-sr-calculator
Package to calculate star ratings with any mod combination on osu! beatmaps
Using the recently updated star rating algorithm (november 2024)

## Installation
```sh
npm install osu-sr-calculator --save
```
```sh
yarn add osu-sr-calculator
```

## Usage
```typescript
import { calculateStarRating } from 'osu-sr-calculator';

const starRating = await calculateStarRating(mapId, options);
```

The calculateStarRating function accepts four parameters:
* mapId: the map id of the beatmap (make sure you use the id from the /b url)
* options (optional): an object with additional options:
  * path: the path to the .osu file. If omitted (or invalid), the beatmap file will be downloaded from osu!
  * checksum: only used if the `path` parameter is included. This checksum will be compared to the checksum of the file found and if they don't match, a new version will be downloaded from osu
  * mods: an array containing the mods you want to include in the calculation. Omitting this will default to nomod.
  * allModCombinations: if you set this to true, all unique star ratings for all possible mod combinations will be calculated. The `mods` parameter will be ignored

This function returns an object containing the calculated star ratings for the requested mod combination. In case of allCombinations, the object will contain all mod combinations with their corresponding star ratings. 

## Examples

* Nomod star rating:
```typescript
const starRating = await calculateStarRating(53);
/* Response:
{
    map_id: 1616712,
    star_ratings: {
        NM: {
            star_rating: 3.01,
            aim_rating: 1.22,
            speed_rating: 1.56,
            flashlight_rating: 0
        }
    }
}
*/
```

* HDDT star rating:
```typescript
const starRating = await calculateStarRating(53, { mods: ["HD", "DT"] });
/* Response:
{
  map_id: 53,
  star_ratings: {
    DT: {
      star_rating: 2.735860220359399,
      aim_rating: 1.523548357182464,
      speed_rating: 0.9245861222096409,
      flashlight_rating: 0
    }
  }
}
*/
```

* All possible star ratings:
```typescript
const starRating = await calculateStarRating(53, { allModCombinations: true });
/* Response:
{
  map_id: 53,
  star_ratings: {
    NM: {
      star_rating: 2.16744499506542,
      aim_rating: 1.2229963002109072,
      speed_rating: 0.6674524713948623,
      flashlight_rating: 0
    },
    DT: {
      star_rating: 2.735860220359399,
      aim_rating: 1.523548357182464,
      speed_rating: 0.9245861222096409,
      flashlight_rating: 0
    },
    HT: {
      star_rating: 1.8168007574947767,
      aim_rating: 1.0292870550736428,
      speed_rating: 0.5352279304274877,
      flashlight_rating: 0
    },
    FL: {
      star_rating: 2.2551847754071184,
      aim_rating: 1.2229963002109072,
      speed_rating: 0.6674524713948623,
      flashlight_rating: 0.2250617956885513
    },
    DTFL: {
      star_rating: 2.8484620204020183,
      aim_rating: 1.523548357182464,
      speed_rating: 0.9245861222096409,
      flashlight_rating: 0.32546995821729424
    },
    HTFL: {
      star_rating: 1.8864928491799893,
      aim_rating: 1.0292870550736428,
      speed_rating: 0.5352279304274877,
      flashlight_rating: 0.16651754693919033
    },
    HR: {
      star_rating: 2.531701319459565,
      aim_rating: 1.4434931163267344,
      speed_rating: 0.7107917744933737,
      flashlight_rating: 0
    },
    HRDT: {
      star_rating: 3.174610386554348,
      aim_rating: 1.795317574069883,
      speed_rating: 0.9717464259789171,
      flashlight_rating: 0
    },
    HRHT: {
      star_rating: 2.124093716471545,
      aim_rating: 1.2137628591775727,
      speed_rating: 0.5736284204550813,
      flashlight_rating: 0
    },
    HRFL: {
      star_rating: 2.631850542616678,
      aim_rating: 1.4434931163267344,
      speed_rating: 0.7107917744933737,
      flashlight_rating: 0.28329496193372905
    },
    HRDTFL: {
      star_rating: 3.305673303792074,
      aim_rating: 1.795317574069883,
      speed_rating: 0.9717464259789171,
      flashlight_rating: 0.40990716459244575
    },
    HRHTFL: {
      star_rating: 2.203215831905636,
      aim_rating: 1.2137628591775727,
      speed_rating: 0.5736284204550813,
      flashlight_rating: 0.20963051380803988
    },
    EZ: {
      star_rating: 1.798430035637836,
      aim_rating: 0.9910282808642945,
      speed_rating: 0.6363150364246655,
      flashlight_rating: 0
    },
    EZDT: {
      star_rating: 2.304126953415762,
      aim_rating: 1.2430277766277935,
      speed_rating: 0.8867192569440014,
      flashlight_rating: 0
    },
    EZHT: {
      star_rating: 1.5039819402206744,
      aim_rating: 0.8351364515076349,
      speed_rating: 0.5094607669651633,
      flashlight_rating: 0
    },
    EZFL: {
      star_rating: 1.8664284296115408,
      aim_rating: 0.9910282808642945,
      speed_rating: 0.6363150364246655,
      flashlight_rating: 0.16276285314792546
    },
    EZDTFL: {
      star_rating: 2.3881180649606932,
      aim_rating: 1.2430277766277935,
      speed_rating: 0.8867192569440014,
      flashlight_rating: 0.235476166689555
    },
    EZHTFL: {
      star_rating: 1.5585352962584755,
      aim_rating: 0.8351364515076349,
      speed_rating: 0.5094607669651633,
      flashlight_rating: 0.12039957822311322
    }
  }
}
*/
```

## Accuracy
This package parses the beatmap and calculates the star rating in exactly the same way as in the official osu! source code.
Due to slight difference between C# and TypeScript, a fault margin of at most 0.01 should be expected.
Accuracy on "unrankable" beatmaps can be further off.

---
_Source: https://npm.io/package/osu-sr-calculator · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
