Skip to the content

Toranpuトランプ

Use a deck, play eleven games with computers, solve a solitaire, or display cards in your own design.

Toranpu is Japanese for playing cards. About the name

Contents

Reference

Deck tools

import { … } from "@johnmorrisdotca/toranpu/deck";

1.5 kB minified and gzipped, with everything it imports (measured with esbuild)

The deck on its own: fifty-two cards as objects ({ suit, rank }), a seeded shuffle, dealing, one-character and two-character codes, and the names a card is written and spoken by. For a solitaire or any game of your own.

Exports

NameKindWhat it is
CardtypeA card as an object: its suit and its rank.
CARD_ALPHABETconstantThe fifty-two characters a card is written as, in deck order: spades A–K are A–M, hearts N–Z, diamonds a–m, clubs n–z.
cardAtfunctionThe card at a place in a fresh deck, 0 to 51.
cardCodefunctionOne character for a card (CARD_ALPHABET).
CardCodetypeA card as ONE character, A–Z then a–z (cardCode): a whole deck is a fifty-two-character string, so a deal travels in a saved game, an address and a move list without any separator to parse.
cardFromCodefunctionThe card a character names, or null for one that names none — a kept string is read, never trusted.
cardFromIdfunctionThe card a two-character id names, or null.
cardIdfunction"QS", "TH", "AC": the two-character id card players write, rank then suit, with T for the ten.
cardIndexfunctionThe card's place in a fresh deck, 0 to 51.
cardNamefunction"queen of hearts": the name a screen reader says.
cardShortNamefunction"Q♥": the short name a corner shows.
colourOffunctionA card's colour: red for hearts and diamonds, black for spades and clubs.
dealAllfunctionDeal the whole deck round the table: the first hands get one more where it does not divide evenly.
dealRoundfunctionDeal one card at a time round the table, as a dealer does: hands hands of each cards, dealt from the top (the start of the array), and what is left.
DECK_SIZEconstantHow many cards a deck holds: fifty-two.
freshDeckfunctionA fresh deck in the order a new pack is sorted: spades ace to king, then hearts, diamonds, clubs.
isRedfunctionWhether a card is a heart or a diamond.
isWholeDeckfunctionWhether a string is a whole deck: fifty-two cards, each exactly once.
RandomtypeA number in [0, 1), like Math.random, from a stream a seed fixes.
RanktypeAce is 1 and King 13.
RANK_DISPLAYconstantHow each rank is written: short (A, 10, K) and as a word (ace, ten, king).
RankDisplaytypeHow a rank is written: A, 2…10, J, Q, K, and in a sentence.
RANKSconstantThe ranks in order, ace low: 1 (the ace) to 13 (the king).
readCardsfunctionA string of card characters read back, or null if any character names no card.
sameCardfunctionWhether two card objects are the same card.
seededRandomfunctionA stream of numbers in [0, 1) fixed by a seed.
shuffledfunctionA copy of the list in a random order (Fisher–Yates); the list given is left alone.
shuffledDeckfunctionA deck shuffled from a seed: the same seed, the same order, in every browser and every test.
sortedHandfunctionA hand sorted by suit (the fresh-deck order) and then by rank: how a player arranges one.
SuittypeOne of the four suits, by name.
SUIT_DISPLAYconstantHow each suit is written and drawn: its symbol, its name and its colour.
SuitColourtypeA suit's colour, which Klondike's alternating runs and Crazy Eights' matches both read.
SuitDisplaytypeHow a suit is written and drawn.
SUITSconstantThe suits in the order a fresh deck is sorted and a foundation row is laid out: spades, hearts, diamonds, clubs — black, red, red, black, so no two neighbours on a row of four look alike.
takefunctionTake count from the top: what was taken, and what is left.
writeCardsfunctionA run of cards as a string, one character each.

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/toranpu 2.15.0.