chance-deck

0.1.0 • Public • Published

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 card - Wikiwand
Standard 52-card deck - Wikiwand

Package Sidebar

Install

npm i chance-deck

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • leesei