-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
35 lines (29 loc) · 801 Bytes
/
index.ts
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
import {
decode as base64Decode,
encode as base64Encode,
} from "universal-base64";
type OriginDeck = {
Cards: OriginCardInfo[];
};
type OriginCardInfo = {
CardDefId: string;
};
type DeckList = string[]; // CardDefId[]
interface DeckDefinition {
cards: DeckList;
}
const encode = (deck: DeckDefinition) => {
return base64Encode(
JSON.stringify({
Cards: deck.cards.map((cardDefId) => ({ CardDefId: cardDefId })),
})
);
};
const decode = (base64String: string): DeckDefinition => {
const originDeck = JSON.parse(base64Decode(base64String)) as OriginDeck;
return {
cards: originDeck.Cards.map((cardInfo) => cardInfo.CardDefId),
};
};
export { encode, decode };
export type { DeckDefinition };