@hammerhead/deckmanager
v1.1.0
Published
A ready-to-use card deck manager with pile support using Deck of Cards API
Maintainers
Readme
Deck Manager
A ready-to-use card deck manager with pile support using the Deck of Cards API. Perfect for building card games like Poker, Blackjack, or custom card-based apps.
Features
- Automatically initializes a new deck on creation
- Draw cards from the main deck
- Shuffle the main deck
- Support for piles (add, draw, shuffle, and list cards in piles)
- Works with Jokers
- Ready-to-use in Node.js (Node 18+ or with
node-fetchfor older versions)
Installation
# If using Node 18+ (fetch is built-in)
npm install deck-manager
# For Node <18
npm install deck-manager node-fetchUsage
Initialize Deck
import Deck from "deck-manager";
const deck = new Deck(); // auto-initializes a deckDraw From Main Deck
const { cards, remaining } = await deck.draw(3);
console.log("Drawn cards:", cards);
console.log("Remaining in deck:", remaining);Shuffle Deck
await deck.shuffle(); // shuffle the main deckWorking With Piles
// Add cards to a pile
await deck.addToPile("player1", cards);
// Draw from a pile
const pileCards = await deck.drawFromPile("player1", 1);
console.log("Card from pile:", pileCards.cards);
// List all cards in a pile
const remainingPile = await deck.listPile("player1");
console.log("Remaining in pile:", remainingPile);
// Shuffle a pile
await deck.shufflePile("player1");Example: Deal Hands to Multiple Players
const players = ["Alice", "Bob"];
for (let player of players) {
const { cards } = await deck.draw(5); // Draw 5 cards for the player
await deck.addToPile(player, cards); // Add to player pile
}
// Show each player's hand
for (let player of players) {
const hand = await deck.listPile(player);
console.log(`${player}'s hand:`, hand);
}API
Constructor
new Deck(count = 1, jokers = false, shuffle = true)