cards-52-encoder
v0.1.0
Published
Encodes and decodes playing cards of a 52 card deck
Downloads
2
Readme
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-encoder
API
cardEncoder
Creates a encoder that encodes/decodes one card.
Parameters
idx
Number? index in the bits at which the encoded card is located (optional, default0
)
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
n
Number the number of cards to encode/decodeidx
Number? index in the bits at which the encoded cards are located (optional, default0
)
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
card
String 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
allBits
Number 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
allBits
Number the bits in which the cards are encoded
Returns Array<String> the decoded cards
License
MIT