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.5.2

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 four 13-bit suit lanes and plain 32-bit integers (no BigInt in the hot path) — ~28–70× faster than the previous BigInt engine
  • Exact range vs range equity on the flop and turn via evaluate-once with counting (byte-identical to brute force, no approximation)
  • Exact, instant preflop via an optional precomputed equity table (loadPreflopTable) — replaces Monte Carlo entirely for preflop
  • Monte Carlo with confidence-interval early-stop for the remaining sampled case (preflop with dead cards)
  • Web Workers for the Monte Carlo path
  • 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, mcTargetPct)

Compares two ranges of hands.

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): Monte Carlo samples per matchup (default: 10000). Ignored on the flop/turn (exhaustive) and preflop-table paths, which are exact.
  • optimize (Boolean): Use the optimized path (default: true). On the flop/turn this is exact (byte-identical to optimize: false), just much faster.
  • 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 the Monte Carlo path (default: true). The exact flop/turn path runs on the main thread.
  • mcTargetPct (Number): Monte Carlo early-stop target — stop sampling a matchup once its 95% confidence-interval half-width is within this many equity percentage points (default: 0.3). Pass 0 to force the full iterations. Only affects the Monte Carlo (preflop) path.

Returns:

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

loadPreflopTable(buffer)

Loads the precomputed exact preflop equity table and enables the preflop fast path in compareRange (empty board, no dead cards). Accepts an ArrayBuffer (browser) or Node Buffer. Generate the table with npm run gen:preflop.

// Browser
const buf = await (await fetch('./bench/preflop-table.bin')).arrayBuffer();
bitval.loadPreflopTable(buf);

// Node
const fs = require('fs');
bitval.loadPreflopTable(fs.readFileSync('bench/preflop-table.bin'));

Without a table loaded, preflop falls back to Monte Carlo — nothing else changes.

Performance

  • No BigInt in the hot path — cards are four 13-bit suit lanes evaluated with plain 32-bit integer ops. ~28–70× faster than the previous BigInt engine.
  • Flop/turn: exact and fast. Each unique concrete hand is evaluated once per runout; wide range-vs-range is resolved by counting. No ±0.5% approximation.
  • Preflop: exact table lookup (with loadPreflopTable) instead of Monte Carlo — effectively instant.
  • Monte Carlo (only preflop with dead cards) uses confidence-interval early-stop and Web Workers.

Reproduce the benchmarks with node bench/pre-vs-post.js and npm run bench; correctness with npm test (and npm run test:full for the exhaustive proofs).

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

Performance Tips

  • Call loadPreflopTable once at startup for exact, instant preflop equity.
  • Keep optimize: true (default) — on the flop/turn it is exact and much faster.
  • Lower mcTargetPct (or set 0) for higher-precision Monte Carlo; raise it for faster, looser preflop-with-dead-cards estimates.
  • Adjust progressInterval to balance UI responsiveness vs. performance.

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.