mainwaring.dev
Search…
⌃K

Card Dealer

A robust card-dealing JavaScript Class written in TypeScript

Features

  • Use any card deck with the Dealer class
  • Shuffle deck into a random order
  • Draw cards for use
  • Discard cards without revealing them
  • Cut the deck
  • Included Decks
    • Standard 52 Playing Cards
    • Uno

Installation

npm

$ npm install card-dealer --save

yarn

$ yarn add card-dealer

Usage

TypeScript

import { Dealer, standardDeck } from "card-dealer";
​
const dealer = new Dealer(standardDeck);

JavaScript

const Dealer = require("card-dealer/dealer");
const standardDeck = require("card-dealer/decks/standard");
​
const dealer = new cardDealer.Dealer(standardDeck);

API

const dealer = new Dealer(cardArray)

Dealer() takes a deck of cards to use for a game & places it on the draw pile.

dealer.shuffle()

Randomizes the dealer's draw pile order using the Fisher-Yates shuffle algorithm.

dealer.cut(index)

Cuts the deck at the specified position in the deck, moving the bottom half to the top of the draw pile.

dealer.draw(count)

Returns the number of cards requested from the draw pile for use in the game.

dealer.discard(count)

Moves the number of cards specified from the draw pile to the discard pile without revealing the value to the game.

dealer.reset()

Resets the draw & discard piles to the default deck position.

dealer.remainingCards()

Returns a count for the remaining cards in the draw pile.