cards-52-encoder v0.1.0
cards-52-encoder 
Encodes and decodes playing cards of a 52 card deck
const sixbit = require('6bit-encoder')
const { cardsEncoder } = require('../')
const cards = [ '2d', '5c', 'Js', '8h', 'Ad' ]
const encoder = cardsEncoder(5)
const encodedBits = encoder.encode(cards)
const encoded = sixbit.encode5(encodedBits)
const decodedChars = sixbit.decode5(encoded)
const decoded = encoder.decode(decodedChars)
console.log({ encoded, decoded })
// => { encoded: '2OFbo', decoded: [ '2d', '5c', 'Js', '8h', 'Ad' ] }Installation
npm install cards-52-encoderAPI
cardEncoder
Creates a encoder that encodes/decodes one card.
Parameters
- idxNumber? index in the bits at which the encoded card is located (optional, default- 0)
Returns CardEncoder a card encoder with encode(String card) and decode(Number bits) methods
cardsEncoder
Creates a encoder that encodes/decodes a specific number of cards.
Parameters
- nNumber the number of cards to encode/decode
- idxNumber? index in the bits at which the encoded cards are located (optional, default- 0)
Returns CardsEncoder a card encoder with encode(String cards) and decode(Number bits) methods
CARD_NOT_PRESENT
A 2 char string indicating a non present card as '??'.
Type: String
CardEncoder.encode
Encodes a card.
The idx is taken into account so that an | operation allows including
the encoded information into existing bits.
Parameters
- cardString the card to encode
Returns Number the bits representing that card
CardEncoder.decode
Decodes a card.
The idx is taken into account so that the card can be decoded from within anywhere inside the given bits.
Parameters
- allBitsNumber the bits in which a card is encoded
Returns String the decoded card
CardsEncoder.encode
Encodes a number of cards.
The idx is taken into account so that an | operation allows including
the encoded information into existing bits.
Parameters
Returns Number the bits representing the cards
CardsEncoder.decode
Encodes a number of cards.
The idx is taken into account so that an | operation allows including
the encoded information into existing bits.
Parameters
- allBitsNumber the bits in which the cards are encoded
Returns Array<String> the decoded cards
License
MIT
8 years ago