card-utility
v1.0.0
Published
This library provides utilities for creating, shuffling, sorting, and managing a deck of cards. It is designed to be used as an NPM package.
Readme
Card Utility Library
This library provides utilities for creating, shuffling, sorting, and managing a deck of cards. It is designed to be used as an NPM package.
Installation
To install the library, run:
npm install card-utilityUsage
Importing Classes
The library provides the following main classes:
Card: Represents an individual card.Deck: Represents a deck of cards with various operations.
You can import these classes as follows:
const { Card, Deck } = require('card-utility');Creating a Deck
To create a standard deck of 52 cards:
const deck = new Deck();To create a deck with jokers:
const deckWithJokers = new Deck(true);Shuffling the Deck
To shuffle the deck:
deck.shuffle();Sorting the Deck
To sort the deck by suit (default):
deck.sort();To sort the deck by symbol:
deck.sort('symbol');Drawing Cards
To draw a specified number of cards:
const drawnCards = deck.draw(5); // Draws 5 cardsDiscarding Cards
To discard cards:
deck.discardCards(drawnCards);Resetting the Deck
To reset the deck to its original state:
deck.reset();Working with Individual Cards
You can create individual cards using the Card class:
const card = new Card('Hearts', 'A');
console.log(card.toString()); // "Ace of Hearts"
console.log(card.toEmojis()); // "❤️ A"