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 🙏

© 2025 – Pkg Stats / Ryan Hefner

card-wizard

v1.0.1

Published

A TypeScript library for card shuffling and dealing with standard playing cards

Readme

Card Wizard 🃏⚡️

Version License

A TypeScript library for card shuffling and dealing with standard playing cards. Card Wizard provides a robust and type-safe implementation of a standard 52-card deck with common operations used in card games.

Features

  • 🃏 Standard 52-card deck with optional Jokers
  • 🔀 Multiple card shuffling techniques
  • 🎮 Methods for dealing cards to players
  • 🌈 Complete TypeScript type definitions
  • 🧪 Fully tested API

Installation

npm install card-wizard

or with yarn:

yarn add card-wizard

Usage

import { Deck, PlayingCard, Joker, createCard } from 'card-wizard';

// Create a standard 52-card deck
const deck = new Deck();

// Shuffle the deck
deck.shuffle();

// Deal a card
const card = deck.dealCard();   

// Deal multiple cards
const cards = deck.dealCards(5);

// Deal to players
const players = deck.dealToPlayers(2, 5);   

// Create a custom card
const customCard = createCard('hearts', 'king');

// Create a joker
const joker = new Joker();  

API

Deck Class

Constructor

new Deck(options?: DeckOptions);

Options:

  • includeJokers?: boolean - Whether to include jokers (default: false)
  • numJokers?: number - Number of jokers to include (default: 2)

Methods

Shuffling and Manipulation:

  • shuffle(): this - Shuffle the deck using the Fisher-Yates algorithm
  • cut(index?: number): this - Cut the deck at specified index or randomly
  • sort(): this - Sort the deck by suit and rank
  • reset(options?: DeckOptions): this - Reset to a fresh deck

Dealing:

  • dealCard(): Card | undefined - Deal one card from the top of the deck
  • dealCards(count: number): Card[] - Deal multiple cards
  • dealToPlayers(numPlayers: number, cardsPerPlayer: number): Card[][] - Deal cards to multiple players

Properties:

  • remaining: number - Get the number of remaining cards
  • allCards: Card[] - Get a copy of all cards in the deck

Card Types

PlayingCard Class

Constructor

new PlayingCard(suit: Suit, rank: Rank);

Parameters:

  • suit: Suit - The suit of the card
  • rank: Rank - The rank of the card

Methods:

  • toString(): string - Get string representation (e.g., "hearts king")
  • getValue(): number - Get card value (typically 0)

Joker Class

Constructor

new Joker(color?: 'red' | 'black');

Parameters:

  • color?: 'red' | 'black' - The color of the joker (default: 'red')

Methods:

  • toString(): string - Get string representation (e.g., "red joker")
  • getValue(): number - Get card value (typically 0)

Utility Types

Suit Enum:

export enum Suit {
  Hearts = "hearts",
  Diamonds = "diamonds",
  Clubs = "clubs",
  Spades = "spades"
}

Rank Enum:

export enum Rank {
  Ace = "ace",
  Two = "2",
  Three = "3",
  Four = "4",
  Five = "5",
  Six = "6",
  Seven = "7",
  Eight = "8",
  Nine = "9",
  Ten = "10",
  Jack = "jack",
  Queen = "queen",
  King = "king"
}

Card Interface:

export interface Card {
  suit: Suit;
  rank: Rank;
}

Deck Options Interface:

export interface DeckOptions {
  includeJokers?: boolean;
  numJokers?: number;
}

Card Deck Interface:

export interface CardDeck {
  cards: Card[];
  remaining: number;
}   

Testing

The library is fully tested with Jest. To run the tests:

npm test

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

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