Card is expressed in integer binary (2^0 <= n <= 2^51). 0b1
is ace of spade. 0b10
is deuce of spade. 0b1000000000000000000000000000000000000000000000000000n
is king of club.
Normally you can create Cards by using CardUtils.create()
and/or CardUtils.parse()
.
An utility function set for Cards.
Creates a Card from a given pair of Rank and Suit.
const aceOfSpade = CardUtils.create("A", "s");
const deuceOfSpade = CardUtils.create("2", "s");
const kingOfClub = CardUtils.create("K", "c");
Parses a string into a Card.
CardUtils.parse("As") === CardUtils.create("A", "s");
CardUtils.parse("2s") === CardUtils.create("2", "s");
CardUtils.parse("Kc") === CardUtils.create("K", "c");
Returns a CardString of a Card.
CardUtils.format(CardUtils.create("A", "s")) ===
("As" as CardString);
CardUtils.format(CardUtils.create("2", "s")) ===
("2s" as CardString);
CardUtils.format(CardUtils.create("K", "c")) ===
("Kc" as CardString);
Extract the Rank from a Card.
CardUtils.rankOf(CardUtils.parse("As")) === "A";
CardUtils.rankOf(CardUtils.parse("3h")) === "3";
CardUtils.rankOf(CardUtils.parse("Td")) === "T";
CardUtils.rankOf(CardUtils.parse("6c")) === "6";
Extract the Rank from a Card.
CardUtils.suitOf(CardUtils.parse("As")) === "s";
CardUtils.suitOf(CardUtils.parse("3h")) === "h";
CardUtils.suitOf(CardUtils.parse("Td")) === "d";
CardUtils.suitOf(CardUtils.parse("6c")) === "c";
A utility function set for Ranks.
Parses a char (= 1-charactor-length string) into a Rank.
RankUtils.parse("A") === "A";
RankUtils.parse("T") === "T";
RankUtils.parse("5") === "5";
Only "A"
, "K"
, "Q"
, "J"
, "T"
, "9"
, "8"
, "7"
, "6"
, "5"
, "4"
, "3"
or "2"
is acceptable.
RankUtils.parse("a"); // => Error: "a" is not a valid string value for RankUtils.parse().
For consistency reason, it needs to be a string even for number-based ranks (e.g. "4"
).
RankUtils.parse("4") === "4";
RankUtils.parse(4); // Error: 4 is not a valid string value for RankUtils.parse().
Stringifies a Rank.
RankUtils.format("A") === "A";
RankUtils.format("T") === "T";
RankUtils.format("5") === "5";
You can utilize this function to build a CardString.
const aceChar = RankUtils.format("A");
const spadeChar = RankUtils.format("s");
const aceOfSpade: CardString = `${aceChar}${spadeChar}`;