@mitchallen/playing-card-rank

0.1.3 • Public • Published

@mitchallen/playing-card-rank

An enum-like object for representing the ranks in a playing card deck.


Installation

You must use npm 2.7.0 or higher because of the scoped package name.

$ npm init
$ npm install @mitchallen/playing-card-rank --save

Usage

This module returns an object that has thirteen frozen and unique properties that can be used to represent playing card ranks:

  • ACE
  • TWO
  • THREE
  • FOUR
  • FIVE
  • SIX
  • SEVEN
  • EIGHT
  • NINE
  • TEN
  • JACK
  • QUEEN
  • KING

You can use them to define the rank of each card in a deck.

var SUIT = require("@mitchallen/playing-card-suit");
var RANK = require("@mitchallen/playing-card-rank");

card[0].suit = SUIT.HEART;
card[0].rank = RANK.ACE;

.isRank(value)

You can test if value is a valid rank by passing it to the isRank method:

if( RANK.isRank(card.rank) ) { ... }

.isFaceCard(value)

The JACK, QUEEN and KING are face cards. All others are not.

You can test if a value is a face card (JACK, QUEEN, KING) by passing it to the isFaceCard method:

if( RANK.isFaceCard(card.rank) ) { ... }

.isFirst(value)

For looping you can test to see if a rank is the first in the list:

while( ! RANK.isFirst(card.rank) ) { ... }

.isLast(value)

For looping you can test to see if a rank is the last in the list:

while( ! RANK.isLast(card.rank) ) { ... }

.first

For looping you can retrieve the first (lowest) value for the ranks in the list.

for( i = RANK.first; ... ) { ... }

For looping you can retrieve the last (highest) value for the ranks in the list.

for( i = RANK.first; i <= RANK.last, i++ ) { ... }

Testing

To test, go to the root folder and type (sans $):

$ npm test

Repo(s)


Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.


Version History

Version 0.1.3

  • added first, last, isFirst and isLast

Version 0.1.2

  • added isRank method
  • added isFaceCard method

Version 0.1.1

  • fixed type-o in readme

Version 0.1.0

  • initial release

Dependents (1)

Package Sidebar

Install

npm i @mitchallen/playing-card-rank

Weekly Downloads

1

Version

0.1.3

License

ISC

Last publish

Collaborators

  • mitchallen