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

handranker-latest

v3.0.2

Published

poker hand ranking program

Downloads

2

Readme

Ranker

Ranker is a poker hand ranking program written in javascript and available through npm.
It can be used to evaluate a hand or rank a series of hands. It supports the following game types:

  • Texas Holdem
  • Omaha Hi
  • Omaha Hi/Lo
  • Stud
  • Stud Hi/Lo
  • Razz
  • Kansas City Lowball
  • California Lowball
  • Deuce to Seven
  • Deuce to Six
  • Ace to Six

Installation

Ranker is available through npm:

  $ npm install handranker-latest

Usage

Evaluate a single hand:

  var Ranker = require('handranker-latest');
  var cards = ['3s', '3c', 'Ac', 'Ah', '3d'];
  var result = Ranker.getHand(cards);

Produces the following result:

    ranking: 'full house',
    cards: [ 
      { rank: '3', suit: 's' },
      { rank: '3', suit: 'c' },
      { rank: 'A', suit: 'c' },
      { rank: 'A', suit: 'h' },
      { rank: '3', suit: 'd' } 
    ],
    board: [],
    playingCards: [ 
        { rank: '3', suit: 'd' },
        { rank: '3', suit: 'c' },
        { rank: '3', suit: 's' },
        { rank: 'A', suit: 'h' },
        { rank: 'A', suit: 'c' } 
    ],
    description: 'full house threes full of aces' 
  }

Multiple hands can be ranked and board cards can be specified:


  var hand1 = {id: 1, cards: ['Ac', '5c']}; // tie
  var hand2 = {id: 2, cards: ['Ad', '8d']}; // tie
  var hand3 = {id: 3, cards: ['Kh', 'Jc']}; // win
  var board = ['Th', '9h', 'Tc', '6c', 'Jh'];
  var hands = [hand1, hand2, hand3];
  var results = Ranker.orderHands(hands, board);

The hands are ranked with higher ranked hands first keeping their original id. Tieing hands are grouped together:


[
  [
    { id: 3,
      ranking: 'two pair',
      cards: [ ... ],
      board: [ ... ],
      playingCards: [ ... ],
      description: 'two pair jacks and tens' }
  ],
  [ 
    { id: 1,
      ranking: 'pair',
      cards: [ ... ],
      board: [ ... ],
      playingCards: [ ... ],
      description: 'a pair of tens' },
    { id: 2,
      ranking: 'pair',
      cards: [ ... ],
      board: [ ... ],
      playingCards: [ ... ],
      description: 'a pair of tens' } 
  ]
]

Hands can be ranked with a game type, Ranker.TEXAS_HOLDEM is the default. Below Omaha Hi is shown:

  var board = ['Ts', '9s', '8s', '3h', '2h'];
  var hand1 = {id: 1, cards: ['As', 'Ks', 'Qs', 'Js']};
  var hand2 = {id: 2, cards: ['2s', '2c', '9c', '8c']};
  var hand3 = {id: 3, cards: ['4c', '4s', '5h', '5c']};
  var hand4 = {id: 4, cards: ['7s', '6s', '3c', '2c']};
  var hands = [hand1, hand2, hand3, hand4];
  var results = Ranker.orderHands(hands, board, Ranker.OMAHA_HI);

Hi/Lo is also supported. High and low hands are grouped and low can be qualified by eight or better. Below is a complex Stud Hi/Lo hand:

var hand1 = {id: 1, cards: ['Js', '7d', '4c', '3c', 'Qc', '3s', 'Td']};
var hand2 = {id: 2, cards: ['7h', '6h', 'Th', '9s', 'Ks', 'Kc', '4d']};
var hand3 = {id: 3, cards: ['2s', 'Ah', '2d', '2c', '6s', 'Ts', 'Qd']};
var hand4 = {id: 4, cards: ['5c', '4s', 'Ac', '3d', '8d', 'Jd', 'Jc']};
var hand5 = {id: 5, cards: ['8h', 'Ad', '5h', '4h', '3h', '8c', '8s']};
var hand6 = {id: 6, cards: ['As', 'Qs', 'Tc', 'Kh', 'Jh', '2h', '5s']};
var hands = [hand1, hand2, hand3, hand4, hand5, hand6];
var results = Ranker.orderHands(hands, Ranker.STUD_HI_LO)
{ "low" : 
[ [ { id: 4,
      ranking: 'high card',
      cards: [Object],
      board: [],
      playingCards: [Object],
      description: 'eight high' },
    { id: 5,
      ranking: 'high card',
      cards: [Object],
      board: [],
      playingCards: [Object],
      description: 'eight high' } ] ]
  "high" :      
[
  [ { id: 6,
      ranking: 'straight',
      cards: [Object],
      board: [],
      playingCards: [Object],
      description: 'straight ace high' } ],
  [ { id: 5,
      ranking: 'three of a kind',
      cards: [Object],
      board: [],
      playingCards: [Object],
      description: 'three of a kind eights' } ],
  [ { id: 3,
      ranking: 'three of a kind',
      cards: [Object],
      board: [],
      playingCards: [Object],
      description: 'three of a kind twos' } ],
  [ { id: 2,
      ranking: 'pair',
      cards: [Object],
      board: [],
      playingCards: [Object],
      description: 'a pair of kings' } ],
  [ { id: 4,
      ranking: 'pair',
      cards: [Object],
      board: [],
      playingCards: [Object],
      description: 'a pair of jacks' } ],
  [ { id: 1,
      ranking: 'pair',
      cards: [Object],
      board: [],
      playingCards: [Object],
      description: 'a pair of threes' } ]
 ]
}

Ranker has a convenience method for a deck, also Ranker can except cards in multiple formats.


var _ = require('underscore');
var Ranker = require('handranker-latest');

var cards = _.shuffle( Ranker.deck() );


Ranker.getHand(['As', 'Ks', 'Qs', 'Js', 'Ts']);

Ranker.getHand([
  {rank: "A", suit: "s"},
  {rank: "K", suit: "s"},
  {rank: "Q", suit: "s"},
  {rank: "J", suit: "s"},
  {rank: "T", suit: "s"},
]);

Ranker.getHand([
  ["A","s"],
  ["K","s"],
  ["Q","s"],
  ["J","s"],
  ["T","s"]
]);

Ranks and Suits allowed by ranker:


var RANKS = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'];
var SUITS = ['s', 'h', 'd', 'c'];