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 🙏

© 2026 – Pkg Stats / Ryan Hefner

poker-bitvaljs

v1.2.0

Published

High-performance poker hand evaluator optimized for browser environments, using bitwise operations for rapid poker hand analysis and equity calculations.

Readme

BitVal

High-performance poker hand evaluator optimized for browser environments, using bitwise operations for rapid poker hand analysis and equity calculations.

🌐 Try it online - Range vs Range Evaluator

Features

  • Fast hand evaluation using bitwise operations
  • Range vs range equity calculations with canonical key caching optimization
  • Web Workers support for parallel processing across multiple CPU cores (3-7x speedup)
  • Monte Carlo simulation for preflop and postflop scenarios
  • Exhaustive enumeration for flop/turn scenarios (2 or fewer cards to come)
  • Progress callbacks with configurable update intervals
  • Browser and Node.js compatible

Installation

npm install poker-bitvaljs

Usage

Basic Hand Evaluation

const BitVal = require('poker-bitvaljs');
const bitval = new BitVal();

// Evaluate a hand (7 cards: 2 hole cards + 5 board cards)
const handMask = bitval.getBitMasked(['As', 'Ah', 'Ks', 'Qs', 'Js', 'Ts', '9s']);
const [evaluation, kickers] = bitval.evaluate(handMask);

// Returns [evaluation_score, kickers]
// Higher evaluation score = stronger hand

Range vs Range Comparison

const BitVal = require('poker-bitvaljs');
const bitval = new BitVal();

// Compare two ranges
const heroHands = ['AsAh', 'AsAd', 'AsAc', 'AhAd', 'AhAc', 'AdAc']; // All AA combinations
const villainHands = ['KsKh', 'KsKd', 'KsKc', 'KhKd', 'KhKc', 'KdKc']; // All KK combinations

const result = await bitval.compareRange(
  heroHands,
  villainHands,
  [], // board cards (empty for preflop)
  [], // dead cards
  5,  // number of board cards
  10000, // iterations
  true, // optimize (use canonical caching)
  null, // progress callback (optional)
  100, // progress interval (optional, default: 100)
  true // use workers (optional, default: true)
);

// Result: { win: 8120, tie: 30, lose: 1850 }
// Calculate equity: (win + tie/2) / (win + tie + lose) * 100

With Progress Callback

const result = await bitval.compareRange(
  heroHands,
  villainHands,
  [],
  [],
  5,
  100000,
  true,
  (current, total, message) => {
    console.log(`${Math.round((current/total)*100)}% - ${message}`);
  },
  100, // Update progress every 100 matchups
  true // Use Web Workers for parallelization
);

With Web Workers Disabled

// Disable Web Workers (useful for debugging or when workers aren't supported)
const result = await bitval.compareRange(
  heroHands,
  villainHands,
  [],
  [],
  5,
  10000,
  true,
  null,
  100,
  false // Disable Web Workers, use sequential execution
);

With Board Cards (Postflop)

// Compare ranges on a flop
const boardCards = ['As', 'Ks', 'Qs'];
const result = await bitval.compareRange(
  heroHands,
  villainHands,
  boardCards,
  [],
  5,
  10000,
  true
);

API

new BitVal()

Creates a new BitVal instance.

evaluate(handMask)

Evaluates a poker hand represented as a BigInt bitmask.

Parameters:

  • handMask (BigInt): Bitmask representing 5-7 cards

Returns:

  • [evaluation, kickers] (Array): Evaluation score and kicker bits

getBitMasked(cards)

Converts an array of card strings to a BigInt bitmask.

Parameters:

  • cards (Array): Array of card strings (e.g., ['As', 'Kh', 'Qd'])

Returns:

  • BigInt: Bitmask representing the cards

simulate(iterations, numberOfBoardCards, hero, villain, board, deadCards)

Simulates a single hand vs hand matchup.

Parameters:

  • iterations (Number): Number of simulations
  • numberOfBoardCards (Number): Total board cards (default: 5)
  • hero (Array): Hero's hole cards as bitmask
  • villain (Array): Villain's hole cards as bitmask
  • board (Array): Board cards as bitmask
  • deadCards (Array): Dead cards as bitmask

Returns:

  • { win, tie, lose }: Results object

compareRange(heroHands, villainHands, boardCards, deadCards, numberOfBoardCards, iterations, optimize, progressCallback, progressInterval, useWorkers)

Compares two ranges of hands with optional optimization and Web Workers parallelization.

Parameters:

  • heroHands (Array): Array of hero hand strings (e.g., ['AsAh', 'AsAd'])
  • villainHands (Array): Array of villain hand strings
  • boardCards (Array): Board cards as strings (default: [])
  • deadCards (Array): Dead cards as strings (default: [])
  • numberOfBoardCards (Number): Total board cards (default: 5)
  • iterations (Number): Number of simulations per matchup (default: 10000)
  • optimize (Boolean): Use canonical key caching for performance (default: true). Note: Optimizations may result in a ±0.5% margin of error compared to unoptimized calculations.
  • progressCallback (Function): Optional callback (current, total, message) => {} (default: null)
  • progressInterval (Number): Update progress callback every N matchups (default: 100)
  • useWorkers (Boolean): Use Web Workers for parallelization across CPU cores (default: true). Automatically falls back to sequential execution if workers are unavailable or workload is too small (< 4 matchups).

Returns:

  • Promise<{ win, tie, lose }>: Results object

Web Workers Notes:

  • Web Workers provide 3-7x speedup on multi-core systems by parallelizing matchup evaluations
  • Workers are automatically disabled when:
    • useWorkers is false
    • Workers are not supported by the browser
    • There are fewer than 4 matchups (overhead not worth it)
  • For local testing with file:// protocol, use a local web server (see Testing Locally)

Performance

  • Optimized for browser environments with efficient bitwise operations
  • Web Workers parallelization provides 3-7x speedup on multi-core systems
  • Canonical key caching reduces redundant evaluations (may introduce ±0.5% margin of error)
  • Exhaustive enumeration for flop/turn (2 or fewer cards to come)
  • Monte Carlo simulation for preflop and river scenarios
  • Adaptive progress reporting to minimize UI blocking

Test performance and benchmark online: https://darraghgeo.github.io/poker-bitvaljs/

Performance Tips

  • Enable Web Workers (default) for best performance on multi-core systems
  • Use canonical caching (optimize: true) for large range comparisons
  • Adjust progressInterval to balance UI responsiveness vs. performance
  • For very small workloads (< 4 matchups), workers are automatically disabled to avoid overhead

Testing Locally

When testing locally, Web Workers require a proper HTTP origin. If you open index.html directly from the file system (file:// protocol), workers will fail with a SecurityError.

Solution: Use a local web server

# Python 3
python3 -m http.server 8000

# Node.js (if you have npx)
npx http-server -p 8000

# PHP (if installed)
php -S localhost:8000

Then open http://localhost:8000 in your browser. The application will automatically fall back to sequential execution if workers are unavailable.

License

MIT

Copyright (c) 2024

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.