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

poker-hand-utils

v1.0.8

Published

A utility library for evaluating poker hands.

Downloads

18

Readme

Poker Hand Utils

This utility library for evaluating poker hands an upgrade version of https://github.com/codeKonami/poker-hand with adding support for TypeScript.

Evaluate the score (the lower the better) of a poker hand as described in this post blog : http://suffe.cool/poker/evaluator.html. You can compare two poker hands to find out who wins or if it's a tie.

Installation

You can install the library using npm:

npm install poker-hand-utils

or with yarn:

yarn add poker-hand-utils

Usage

Importing the Library

First, import the necessary functions from the library:

import { createPokerHand, getDescription, handToString, getEvaluatedScore, getRank, updateHand, compareTo } from 'poker-hand-utils';

Functions

createPokerHand

Creates a poker hand from a string.

Parameters:

  • handString: A string representing the poker hand (e.g., "AS KS QS JS TS").

Returns:

  • An object representing the poker hand, including the hand, score, and rank.

Example:

const handString = "AS KS QS JS TS";
const pokerHand = createPokerHand(handString);

console.log(pokerHand);

getDescription

Returns a description of the poker hand.

Parameters:

  • pokerHand: A PokerHand object.

Returns:

  • An object containing the hand, score, and rank.

Example:

const description = getDescription(pokerHand);
console.log(description);

handToString

Returns the poker hand as a string.

Parameters:

  • pokerHand: A PokerHand object.

Returns:

  • A string representing the poker hand.

Example:

const handStr = handToString(pokerHand);
console.log(handStr); // Output: "AS KS QS JS TS"

getEvaluatedScore

Returns the evaluated score of the poker hand.

Parameters:

  • pokerHand: A PokerHand object.

Returns:

  • A number representing the score of the poker hand.

Example:

const score = getEvaluatedScore(pokerHand);
console.log(score); // Output: (some numeric score)

getRank

Returns the rank of the poker hand.

Parameters:

  • pokerHand: A PokerHand object.

Returns:

  • A string representing the rank of the poker hand.

Example:

const rank = getRank(pokerHand);
console.log(rank); // Output: (rank string based on score)

updateHand

Updates the poker hand with a new hand string.

Parameters:

  • pokerHand: A PokerHand object.
  • handString: A new hand string.

Returns:

  • An updated PokerHand object.

Example:

const newHandString = "2D 3D 4D 5D 6D";
const updatedPokerHand = updateHand(pokerHand, newHandString);

console.log(updatedPokerHand);

compareTo

Compares two poker hands.

Parameters:

  • hand1: A PokerHand object.
  • hand2: A PokerHand object.

Returns:

  • 1 if hand1 wins, 2 if hand2 wins, 3 if it's a draw.

Example:

const anotherHandString = "2D 3D 4D 5D 6D";
const anotherPokerHand = createPokerHand(anotherHandString);

const result = compareTo(pokerHand, anotherPokerHand);

if (result === 1) {
  console.log('Hand 1 wins');
} else if (result === 2) {
  console.log('Hand 2 wins');
} else {
  console.log('It's a draw');
}

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

License

This project is licensed under the MIT License. See the LICENSE file for details.