@1hko/mtg 中文文档教程
mtg
parseDeck - 将套牌列表解析为[{ board, count, name, set, collector_number }]
。 当输入行无效时抛出 Error { board, lineno, line }
。
const decklist = `
1 Ulamog, the Infinite Gyre (mm2) 6
4 Urza's Mine (atq) 83c
4 Urza's Power Plant (atq) 84a
4 Urza's Tower (atq) 85a
4 Wall of Tanglecord (som) 222
SIDEBOARD:
1 Channel the Suns (5dn) 84
4 Cloudpost (mrd) 280
`
parseDeck(decklist)
[
{ board: "main", "count": 1, "set": "mm2", "collector_number": "6" },
{ board: "main", "count": 4, "set": "atq", "collector_number": "83c" },
{ board: "main", "count": 4, "set": "atq", "collector_number": "84a" },
{ board: "main", "count": 4, "set": "atq", "collector_number": "85a" },
{ board: "main", "count": 4, "set": "som", "collector_number": "222" },
{ board: "side", "count": 1, "set": "5dn", "collector_number": "84" },
{ board: "side", "count": 4, "set": "mrd", "collector_number": "280" }
]
mtg
parseDeck - parse a decklist to [{ board, count, name, set, collector_number }]
. Throws Error { board, lineno, line }
when an input line is invalid.
const decklist = `
1 Ulamog, the Infinite Gyre (mm2) 6
4 Urza's Mine (atq) 83c
4 Urza's Power Plant (atq) 84a
4 Urza's Tower (atq) 85a
4 Wall of Tanglecord (som) 222
SIDEBOARD:
1 Channel the Suns (5dn) 84
4 Cloudpost (mrd) 280
`
parseDeck(decklist)
[
{ board: "main", "count": 1, "set": "mm2", "collector_number": "6" },
{ board: "main", "count": 4, "set": "atq", "collector_number": "83c" },
{ board: "main", "count": 4, "set": "atq", "collector_number": "84a" },
{ board: "main", "count": 4, "set": "atq", "collector_number": "85a" },
{ board: "main", "count": 4, "set": "som", "collector_number": "222" },
{ board: "side", "count": 1, "set": "5dn", "collector_number": "84" },
{ board: "side", "count": 4, "set": "mrd", "collector_number": "280" }
]