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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cardeck.js

v1.1.1

Published

A small (3kb) library for manipulating a deck of cards, to help developers creating card games

Readme

cardeck.js

A small (3kb) library for manipulating a deck of cards, to help developers creating card games

npm version

How to install it?

Using npm:

npm install cardeck.js

Using files:

Download the source file or the minified source file to your project's folder, and include it inside your HTML file:

<script type="text/javascript" src="path_to_cardeck/cardeck.min.js"></script>

How to use it?

The Card Class

The library provides you with a nice class (constructor function, to be exact) called Card.

####Basic usage:

var myCoolCard = new Card(); // Creates a random card

myCoolCard.getName(); // e.g. "King"

You can also create cards with specific properties:

var ace = new Card("A"); // Creates an Ace with a random suite
var seven = new Card(7); // Creates a seven with a random suite
var king = new Card(12); // Creates a king with a random suite

var diamond = new Card(false, Cardeck.DIAMOND); // Creates a random card of diamond.

var spadesQueen = new Card("Q", Cardeck.SPADE); // Creates a Spades Queen

All suited are referenced inside the Cardeck object. You can use the constants Cardeck.HEART, Cardeck.DIAMOND, Cardeck.CLUB, Cardeck.SPADE to reference a specific suite.

####All Getters:

var card = new Card("K", Cardeck.HEART);

card.getName(); // e.g. "King"
card.getCode(); // e.g. "K"
card.getSuit(); // e.g. "Heart"
card.getSuitSymbol(); // e.g. "♥"
card.getID(); // e.g. "K♥"
card.getColor(); // e.g. "Red"

var card2 = new Card("Q",Cardeck.CLUB);
var card3 = new Card("K", Cardeck.HEART);
card.isIdentical(card2); // e.g. false
card.isIdentical(card3); // e.g. true
card3.isIdentical(card); // e.g. true

The Deck Class

The Deck class is provided for manipulating a whole deck.

####Basic Usage:

var deck = new Deck();

deck.takeRandomCard().getID(); // e.g. "K♥"

####All methods:

deck = new Deck(); // Generates a new deck with all 52 cards.


deck.getCard(2); // If you know the card's position, you can get it.

deck.getRandomCard(); // Returns a random card from the deck.
deck.getRandomCard(1); // Returns a random Ace from the deck.
deck.getRandomCard(false, Cardeck.HEART); // Returns a random Heart from the deck.

deck.removeCard(new Card(1, Cardeck.DIAMOND)); // Removes the Diamond Ace from the deck, if exists.

deck.takeNextCard(); /* or */ deck.draw(); // Returns the next card from the deck, in order, and then removes it from the deck.

deck.takeRandomCard(); /* or */ deck.drawRandom(); // Returns a random from the deck, and then removes it from the deck.

deck.addCard( new Card("J", Cardeck.DIAMOND) ); // Adds a diamond Jack to the deck. Warning: be careful when adding cards to the deck as it might cause unwanted duplicates.

deck.reset(); // Resets the deck to it's original 52 cards.

Playing with the defaults:

Here's a pro tip: you can customize every little thing in this library by changing stuff in the Cardeck object.

Example:

Cardeck.suits.push({
  "name": "Asterisk",
  "color": "Orange",
  "symbol": "*"
});
Cardeck.ASTERISK = Cardeck.suits.length-1;


Cardeck.values.push({
  "name": "Joker",
  "code": "JK"
});