Chance.js mixin for deck (playing cards) related functions
npm install -S chance chance-deck
// 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] === '๐';
Playing cards in Unicode - Wikiwand
Standard 52-card deck - Wikiwand