# oddsjs

> Calculate the true odds of a single bet or parlay.

Latest version **0.0.1** (published 2020-03-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install oddsjs
pnpm add oddsjs
yarn add oddsjs
bun add oddsjs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2020-03-17 |
| First published | 2020-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | Lance Whatley |
| Maintainers | whatl3y |

## Links

- npm: https://www.npmjs.com/package/oddsjs
- Repository: https://github.com/whatl3y/oddsjs
- Homepage: https://github.com/whatl3y/oddsjs#readme
- Issues: https://github.com/whatl3y/oddsjs/issues
- npm.io page: https://npm.io/package/oddsjs

## Dependencies (7)

- [gulp](https://npm.io/package/gulp.md) ^4.0.2
- [core-js](https://npm.io/package/core-js.md) ^3.6.4
- [gulp-babel](https://npm.io/package/gulp-babel.md) ^8.0.0
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.8.4
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.0.0
- [gulp-plumber](https://npm.io/package/gulp-plumber.md) ^1.2.1
- [@babel/preset-env](https://npm.io/package/@babel/preset-env.md) ^7.8.4

## Recent versions

- 0.0.1 (latest) — 2020-03-17

## README

# oddsjs

This package provides helper methods to convert between different odds types,
calculate overall odds of single and multiple/parlay bets, etc.

NOTE: All methods in this package return instances of the main object in
[bignumber.js, or `BigNumber` in their examples](https://www.npmjs.com/package/bignumber.js).
This is to prevent losing precision when returning final odds before all of your desired transformations
are done, but you can convert to a javascript string or number using
[`toString()`](https://mikemcl.github.io/bignumber.js/#toS),
[`toFixed(n)`](https://mikemcl.github.io/bignumber.js/#toFix),
[`toNumber()`](https://mikemcl.github.io/bignumber.js/#toN), or others.

## Install

`npm install --save oddsjs`

## Usage

This package exposes a factory function `Odds(options)` that takes an optional options object.

### Options

1. `precision` (default 4): a number representing how far to show fractional odds. Another way to look at it is this is the y in `1ey` or `1 x 10^y` in terms of how precise to show fractional odds (i.e. 12345/10000)

### Methods

1. `calculateOdds(...americanOdds) => BigNumber`: Takes one or multiple american odds and returns the overall odds. For multiple odds provided it assumes a parlay of events. The total odds can be multiplied by a test wager to see how much would be returned to the bettor if she wins (this amount includes the wager, so total amount returned including the wager amount)
2. `getAmericanOddsFromOverall(overallOdds) => BigNumber`: Takes overall odds (also the output of `calculateOdds`) and returns a american odds representation of the odds.
3. `getFractionalOddsFromOverall(overallOdds) => BigNumber`: Takes overall odds (also the output of `calculateOdds`) and returns a fractional odds representation of the odds.

## Example

```js
import Odds from 'oddsjs'
// or const Odds = require('oddsjs').default

const odds = Odds() // same as  `const odds = Odds({ precision: 4 })`

// two team parlay, each with american odds of -110
const twoTeamParlayOdds = odds.calculateOdds(-110, -110)
// returns instance of BigNumber with final odds

twoTeamParlayOdds.toNumber()
// 3.644628099173554

odds.getAmericanOddsFromOverall(twoTeamParlayOdds)
// +264

odds.getFractionalOddsFromOverall(twoTeamParlayOdds)
// 320/121
```

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