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

@sim38/cardsjs

v0.0.3

Published

A Package for Poker Card Utilities

Downloads

397

Readme

CardsJS

CardsJS is a simple Typescript Library providing utilities for playing Cards, Decks and poker hand evaluation

Features

  • Card and Deck Classes
  • Standard 52-card Deck
  • Insert and draw Cards
  • Peek at Cards
  • Shuffle Cards
  • Poker hand evaluation
  • Typescript support

Installation

npm i @sim38/cardsjs

Usage

Card

import { Card, Rank, Suit } from "@sim38/cardsjs";

const aceOfSpades = new Card(Rank.Ace, Suit.Spades);

console.log(aceOfSpades.name); // Ace of Spades
console.log(aceOfSpades.rank); // A
console.log(aceOfSpades.rankDisplay); // Ace
console.log(aceOfSpades.rankValue); // 14

Deck

Default Deck

import { Deck } from "@sim38/cardsjs";

const deck = new Deck();

console.log(deck.length); // 52

Custom Deck

import { Deck, Card, Rank, Suit } from "@sim38/cardsjs";

const deck = new Deck([
  new Card(Rank.Ace, Suit.Spades),
  new Card(Rank.Ace, Suit.Diamonds),
]);

console.log(deck.length); // 2
console.log(deck.cards);
//  [
//      Card { rank: 'A', suit: 'Spades' },
//      Card { rank: 'A', suit: 'Diamonds' }
//  ]

Draw Card

draw() draws and removes cards from the top of the deck. Draw one card by default. It returns an array containing the drawn card, or undefined if the deck is empty.

import { Deck } from "@sim38/cardsjs";

const deck = new Deck();
const drawnCards = deck.draw();

if (drawnCards != undefined) {
  console.log(drawnCards[0].name); // King of Hearts
}

Draw Multiple Cards

Pass the number of cards you want to draw and remove from the deck to draw(). If the deck does not contain enough cards, draw() returns undefined

import { Deck } from "@sim38/cardsjs";

const deck = new Deck();
const drawnCards = deck.draw(2);

if (drawnCards) {
  console.log(drawnCards.length); // 2
  console.log(drawnCards);
  // [
  //    Card { rank: 'K', suit: 'Clubs' },
  //    Card { rank: 'K', suit: 'Hearts' }
  // ]
}

Draw Bottom

drawBottom() works the same way as draw(), but draws and removes cards from the bottom of the deck. If the deck does not contain enough cards, returns undefined

import { Deck } from "@sim38/cardsjs";

const deck = new Deck();
const drawnCards = deck.drawBottom(2);

if (drawnCards) {
  console.log(drawnCards.length); // 2
  console.log(drawnCards);
  // [
  //    Card { rank: 'A', suit: 'Spades' },
  //    Card { rank: 'A', suit: 'Diamonds' }
  // ]
}

Peek

peek() returns the card at the top card of the deck without removing it.

import { Deck } from "@sim38/cardsjs";

const deck = new Deck();
const peekedCard = deck.peek();

console.log(peekedCard?.name); // King of Hearts

Peek Bottom

peekBottom() returns the card at the bottom card of the deck without removing it.

import { Deck } from "@sim38/cardsjs";

const deck = new Deck();
const peekedCard = deck.peekBottom();

console.log(peekedCard?.name); // Ace of Spades

Insert Top

insertTop() inserts a card or an array of cards into the top of the deck.

import { Deck, Card, Rank, Suit } from "@sim38/cardsjs";

const deck = new Deck();

const card = new Card(Rank.Nine, Suit.Diamonds);
deck.insertTop(card);

console.log(deck.peek()); // Card { rank: '9', suit: 'Diamonds' }

const cardArray = [
  new Card(Rank.Six, Suit.Diamonds),
  new Card(Rank.Seven, Suit.Diamonds),
];
deck.insertTop(cardArray);

console.log(deck.peek()); // Card { rank: '6', suit: 'Diamonds' }

Insert Bottom

insertBottom() inserts a card or an array of cards into the bottom of the deck.

import { Deck, Card, Rank, Suit } from "@sim38/cardsjs";

const deck = new Deck();

const card = new Card(Rank.Nine, Suit.Diamonds);
deck.insertBottom(card);

console.log(deck.peekBottom()); // Card { rank: '9', suit: 'Diamonds' }

const cardArray = [
  new Card(Rank.Six, Suit.Diamonds),
  new Card(Rank.Seven, Suit.Diamonds),
];
deck.insertBottom(cardArray);

console.log(deck.peekBottom()); // Card { rank: '7', suit: 'Diamonds' }

Shuffle

shuffle() shuffles the deck of cards.

import { Deck } from "@sim38/cardsjs";

const deck = new Deck();

console.log(deck.peek()); // Card { rank: 'K', suit: 'Hearts' }

deck.shuffle();

console.log(deck.peek()); // New Random Card

Poker Hand Evaluation

CardsJS can evaluate a standard five-card poker hand.

import { Card, Rank, Suit, evaluateHand } from "@sim38/cardsjs";

const hand = [
  new Card(Rank.Ace, Suit.Spades),
  new Card(Rank.King, Suit.Spades),
  new Card(Rank.Queen, Suit.Spades),
  new Card(Rank.Jack, Suit.Spades),
  new Card(Rank.Ten, Suit.Spades),
];

const result = evaluateHand(hand);

console.log(result);

Example result:

{
  name: 'Royal Flush',
  value: 10,
  scoringCards: [
    Card { rank: '10', suit: 'Spades' },
    Card { rank: 'J', suit: 'Spades' },
    Card { rank: 'Q', suit: 'Spades' },
    Card { rank: 'K', suit: 'Spades' },
    Card { rank: 'A', suit: 'Spades' }
  ]
}

Supported Hands

| Hand | Value | | --------------- | ----- | | High Card | 1 | | 1 Pair | 2 | | 2 Pair | 3 | | Three of a Kind | 4 | | Straight | 5 | | Flush | 6 | | Full House | 7 | | Four of a Kind | 8 | | Straight Flush | 9 | | Royal Flush | 10 |

TODO

  • [ ] Hand Comparison
  • [ ] Change Hands to enum