npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simply-blackjack

v1.0.3

Published

A simple blackjack package to generate and play games.

Downloads

124

Readme

simply-blackjack

A simple blackjack module to play and manage games.

Demo gif

Usage

You will need to require the package and create a game just like this:

const Blackjack = require('simply-blackjack');

const Game = new Blackjack({
  decks: 3,
  payouts: {
    blackjack: 1.5,
    default: 1
  }
});

Options

| Option | Description | Type | Default | |-------------------|----------------------------------------------------|--------|---------| | decks | The number of decks to use when dealing cards. | Number | 3 | | payouts | | Object | {} | | payouts.blackjack | The multiplier for winning blackjack. | Number | 1.5 | | payouts.default | The default multiplier for winning (No blackjack). | Number | 1 |

Variables

| Variable | Description | Type | Default | |------------|-----------------------------------------------------------------------------------------------------------|--------|--------------------------------| | deckAmount | The number of decks being used. | Number | 3 | | payouts | The object defining blackjack and default payouts. | Object | { blackjack: 1.5, default: 1 } | | state | The current state of the game (waiting, player_blackjack, player_win, draw, dealer_blackjack, dealer_win) | String | 'waiting' | | dealer | The dealers cards. | Array | [] | | player | The players cards. | Array | [] | | table | The current table, showing player and dealer cards (Minus hidden card) and their totals. | Object | {} | | betAmount | The amount the player is betting. | Number | |

Events

These are examples of the following events:

// This will fire when the game has reached the end
Game.on('end', (results) => {
  console.log(results);
  // Example output:
  // {
  //    state: 'dealer_win',
  //    bet: 20,
  //    winnings: 0,
  //    losses: 20,
  //    player: { total: 23, cards: [ [Object], [Object], [Object] ] },
  //    dealer: { total: 11, cards: [ [Object], [Object] ] }
  // }
});

Methods

Bet

This will update the players bet on the game. | Param | Type | Required | |--------|--------|----------| | Amount | Number | Yes |

// Updates your bet on the current game
Game.bet(20);

Start

This method will start the game and draw 2 cards for the player, and the dealer (One dealer card is hidden).

let cards = Game.start();

console.log(cards);
// Example output:
//{
//  "player": {
//    "total": 7,
//    "cards": [ 
//      {
//        "name": "5 of Clubs",
//        "suit": "Clubs",
//        "value": 5
//      },
//      {
//        "name": "2 of Diamonds",
//        "suit": "Diamonds",
//        "value": 2
//      }
//    ]
//  },
//  "dealer": {
//    "total": 10,
//    "cards": [
//      {
//        "name": "J of Hearts",
//        "suit": "Hearts",
//        "value": 10
//      }
//    ]
//  }
// }

Hit

This will give the player another card.

let cards = Game.hit();

console.log(cards);
// Example output:
// {
//   "name": "J of Clubs",
//   "suit": "Clubs",
//   "value": 10
// }

Stand

This will trigger the dealer to get dealt cards and trigger the end event.

// Tells the game you no longer want cards
Game.stand();