You must use npm 2.7.0 or higher because of the scoped package name.
$ npm init
$ npm install @mitchallen/playing-card --save
A playing card contains a suit and a rank property. Use these two modules to create objects containing the suits and ranks for a standard 52 playing card deck:
var SUIT = require("@mitchallen/playing-card-suit");
var RANK = require("@mitchallen/playing-card-rank");
The module itself returns a factory that you can use to create playing cards.
var cardFactory = require("@mitchallen/playing-card");
const suit = SUIT.DIAMOND;
const rank = RANK.JACK;
var card = cardFactory({suit: suit, rank: rank});
should.exist(card);
card.suit.should.eql(suit);
card.rank.should.eql(rank);
You can find more info on the suit and rank modules here:
- https://www.npmjs.com/package/@mitchallen/playing-card-suit
- https://www.npmjs.com/package/@mitchallen/playing-card-rank
- If the card factory is passed invalid values for suit or rank a null object will be returned.
To test, go to the root folder and type (sans $):
$ npm test
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.
- refreshed for latest version of suit and rank module dependencies
- added missing checkins and refreshed readme
- factory now uses spec object to create card
- checked in lint issue
- added validation checks for suit and rank
- initial release