2.0.13 • Published 2 years ago

mtg-decklist-parser2 v2.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

MTG decklist parser

Library for parsing MTG Online & Arena decklists

Installation

The library is available as a package on npm. Currently there is no static location for a production file to hotlink to.

npm install mtg-decklist-parser --save

After that import the Decklist class from the library. This is where all parsing is done. Just pass your decklist string into the constructor of the class.

import {Decklist} from 'mtg-decklist-parser2';

let parsed = new Decklist(rawString);

API documentation

Decklists to be given to the parser follow the conventional newline separated format that can be found on many popular sites such as MTGGoldfish. Supports lists exported from MTG Arena and MTGO .dek files. There are multiple example decklists in the example folder.

Decklist & MTGO

Both the Decklist and MTGO classes share the same properties. Both expect strings passed into their constructor.

PropertyTypeDescription
validBooleanIf the parsing of the decklist was successful. Note: this does not necessarily mean the input was well formed.
deckArrayAn array of CardModel for the main deck.
sideboardArrayAn array of CardModel for the sideboard.
companionCardModelIf a companion is specified in the input will be available, otherwise null.
commanderCardModelIf a commander is specified in the input will be available, otherwise null.

CardModel

Note: This is used internally and not publicly exposed.

PropertyTypeOptionalDescription
nameStringFalseThe name of the card specified within the deck.
amountNumberFalseThe amount of the card specified within the deck.
setStringTrueThe set code of the card.
collectorsNumberTrueThe collector number of the card within the specific set.
mtgoIDStringTrueThe ID of the card specific to MTG Online.

autoParse

Method for automatically parsing an MTGO or MTGA decklist.

@param  rawInput String        A decklist string to be parsed.
@return          Decklist|MTGO Either a Decklist or MTGO class object.

Dev setup

To get the project up and running with a test page and hot reloading, clone the repo and run the following:

npm install
npm start

To build the project for production code:

npm build