cards-52-encoder
Encodes and decodes playing cards of a 52 card deck
Last updated 3 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cards-52-encoder 
SYNC missed versions from official npm registry.

cards-52-encoder build status

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, 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

  • n Number the number of cards to encode/decode
  • idx Number? 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

  • 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

Current Tags

  • 0.1.0                                ...           latest (3 years ago)

1 Versions

  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (0)
None
Dev Dependencies (4)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |