Skip to content

chancejs/chance-deck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chance-deck

Chance.js mixin for deck (playing cards) related functions

Install

npm install -S chance chance-deck

Usage

// initialize chance instance
const chance = require('chance').Chance();

// add this module as mixin
const chance_deck = require('chance-deck');
chance.mixin({
  deal: chance_deck.deal
});

// profit
chance.deal({ hands: 4 })
/*
{ 
  '0': [ '๐Ÿ‚บ', '๐Ÿƒˆ', '๐Ÿƒ‰', '๐Ÿ‚ญ', '๐Ÿƒ', '๐Ÿ‚ซ', '๐Ÿƒ‘', '๐Ÿƒ‡', '๐Ÿ‚ฅ', '๐Ÿ‚ธ', '๐Ÿƒ•', '๐Ÿ‚ท', '๐Ÿƒ' ],
  '1': [ '๐Ÿƒ”', '๐Ÿƒ–', '๐Ÿƒ…', '๐ŸƒŽ', '๐Ÿ‚จ', '๐Ÿ‚ก', '๐Ÿƒ—', '๐ŸƒŠ', '๐Ÿ‚ฒ', '๐Ÿ‚ค', '๐Ÿ‚ฆ', '๐Ÿƒ„', '๐Ÿ‚ฉ' ],
  '2': [ '๐Ÿƒ›', '๐Ÿƒ‹', '๐Ÿƒ’', '๐Ÿ‚พ', '๐Ÿƒ†', '๐Ÿ‚ต', '๐Ÿƒž', '๐Ÿƒƒ', '๐Ÿ‚ถ', '๐Ÿƒ˜', '๐Ÿ‚ฑ', '๐Ÿ‚ฃ', '๐Ÿ‚ด' ],
  '3': [ '๐Ÿƒ', '๐Ÿƒ™', '๐Ÿ‚น', '๐Ÿ‚ณ', '๐Ÿƒš', '๐Ÿ‚ช', '๐Ÿƒ‚', '๐Ÿ‚ฎ', '๐Ÿ‚ง', '๐Ÿ‚ฝ', '๐Ÿ‚ป', '๐Ÿ‚ข', '๐Ÿƒ“' ]
}
*/

chance.deal({ hands: 3, per_hand: 5 });
/*
{
  '0': [ '๐Ÿƒ–', '๐Ÿ‚ฝ', '๐Ÿƒˆ', '๐Ÿ‚ข', '๐Ÿ‚ก' ],
  '1': [ '๐Ÿƒ˜', '๐Ÿ‚ท', '๐Ÿ‚ถ', '๐Ÿƒƒ', '๐Ÿƒ' ],
  '2': [ '๐Ÿƒ', '๐Ÿƒ†', '๐Ÿ‚จ', '๐Ÿ‚ฃ', '๐Ÿƒ‘' ],
  stock: [ '๐Ÿƒ•', '๐Ÿ‚ช', '๐Ÿ‚ฑ', '๐Ÿƒ', ... ] // remaining cards
}
*/

// you can distribute anything with `deal()`
chance.deal({ deck: 'abcdefghijklmnopqrstuvwxyz'.split(''), hands: 2 });
/*
{
  '0': [ 'n', 'g', 'o', 'm', 'e', 'd', 'p', 'k' ],
  '1': [ 'v', 't', 'j', 'c', 'f', 'w', 'u', 'i' ],
  '2': [ 'a', 'y', 'l', 'q', 'z', 'b', 'x', 'h' ],
  stock: [ 's', 'r' ]
}
*/

// you can also use the built-in unicode decks as you wish
// we have the standard 52-card deck and a full deck with 2 jokers (at index 52 and 53)
chance.pickone(chance_deck.standard_deck); // '๐Ÿƒ™'
chance.pickset(chance_deck.full_deck, 5);  // [ '๐Ÿƒ˜', '๐Ÿ‚ฆ', '๐Ÿƒ•', '๐Ÿƒ“', '๐Ÿ‚ท' ]
chance_deck.full_deck[52] === '๐Ÿƒ';
chance_deck.full_deck[53] === '๐ŸƒŸ';

Reference

Playing cards in Unicode - Wikiwand
Standard 52-card deck - Wikiwand

About

Chance.js mixin for deck (playing cards) related functions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published