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

odds

v0.1.4

Published

Fixed betting odds parser and formatter

Downloads

4

Readme

odds.js

Fixed betting odds parser and formatter. Supports decimal, fractional and moneyline/american style odds.

Build Status

Installation

npm install odds --save

Usage

var odds = require('odds');

odds(5, 2).format('decimal'); // "3.50"
odds(100).format('moneyline'); // "+10,000"

Parsing

Odds default to "0/1" and may be passed in as strings or numbers.

As parameters:

odds(num, [den]);

As an array:

odds([num, den]);

As an object:

odds({num: num, den: den});

As a string:

odds('2/3');
odds('+10,000');
odds('2.50');

Formating

Defaults to decimal if a format type is not specified.

Types:

  • american (alias)
  • decimal
  • fractional
  • moneyline

Methods

config({opts}) - Get or set configuration options.

frac({num, den}) - Get or set the fractional odds.

num(num) - Get or set the odds numerator.

den(num) - Get or set the odds denominator.

parse(val) - Parse options or string to set the odds.

format() - Format the odds as a string.

Global Settings

You may configure options globally. If your data always represents odds as an object with numerator/denumerator properties then configure the library to use those properties by default. e.x:

var Odds = require('odds');

var odds = odds
  .global()
  .config({num: 'numerator'})
  .config({den: 'denominator'});

var data1 = {numerator: 2, denominator: 3};
var data2 = {numerator: 4, denominator: 1};
odds(data1).format('fractional'); // "2/3"
odds(data2).format('fractional'); // "4/1"