-
Notifications
You must be signed in to change notification settings - Fork 7
/
cards.js
108 lines (102 loc) · 1.43 KB
/
cards.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { Card } from 'tx-holdem'
const {
CLUBS,
DIAMONDS,
HEARTS,
SPADES,
ACE,
KING,
QUEEN,
JACK,
TEN,
NINE,
EIGHT,
SEVEN,
SIX,
FIVE,
FOUR,
THREE,
TWO
} = Card;
export const SUITS = [CLUBS, DIAMONDS, HEARTS, SPADES];
export const RANKS = [
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
ACE
];
export const ALIASES = {
"2": TWO,
"3": THREE,
"4": FOUR,
"5": FIVE,
"6": SIX,
"7": SEVEN,
"8": EIGHT,
"9": NINE,
"10": TEN,
hearts: HEARTS,
spades: SPADES,
diamonds: DIAMONDS,
clubs: CLUBS,
h: HEARTS,
s: SPADES,
d: DIAMONDS,
c: CLUBS,
ace: ACE,
queen: QUEEN,
jack: JACK,
king: KING,
ten: TEN,
t: TEN,
T: TEN,
a: ACE,
k: KING,
q: QUEEN,
j: JACK,
A: ACE,
K: KING,
Q: QUEEN,
J: JACK
};
export const SYMBOLS = {
[TWO]: "2",
[THREE]: "3",
[FOUR]: "4",
[FIVE]: "5",
[SIX]: "6",
[SEVEN]: "7",
[EIGHT]: "8",
[NINE]: "9",
[TEN]: "T",
[JACK]: "J",
[QUEEN]: "Q",
[KING]: "K",
[ACE]: "A",
[HEARTS]: "h",
[DIAMONDS]: "d",
[CLUBS]: "c",
[SPADES]: "s"
};
export const cardToString = ({ suit, rank }) =>
`${SYMBOLS[String(rank)]}${SYMBOLS[String(suit)]}`;
export const stringToCard = string => {
const chars = String(string)
.trim()
.split("");
const suitSign = chars.pop();
const rankSign = chars.join();
return {
suit: ALIASES[suitSign],
rank: ALIASES[rankSign]
};
};