deckform

1.0.0 • Public • Published
This program parse deck (of customizable card games such as Magic: the
Gathering) from my own "deckform" format.

This module exports a function that takes a string containing the contents
of the file (you can use fs.readFileSync to achieve it). The output is an
object which can be converted to JSON; you will get an object containing
the same data if JSON.parse is used, except for the prototypes of card
list objects.

An optional second argument to the function is an object containing any of
the following options:

.caseFoldCards = Normally false; if true, quoted card names are converted
to uppercase. Unquoted card names are always converted to uppercase.

The object it returns has properties whose names are all uppercase.
Directives become properties whose values are primitives (string, number,
true, false, or null), while outer blocks become properties whose values
are arrays. Each element of the array represents one outer block (there
may be multiple elements if there are multiple outer blocks with the same
name as each other).

An outer block object has properties named by directives and inner blocks.
Directives from the top of the file are also copied into each outer block
object unless they are overridden by directives inside the outer block.
Inner blocks are card list objects, which have no prototype. A card list
object has properties named by the cards in that list; the value of the
property is a number indicating how many copies of that card.

The function also exports some properties which are also functions:

.convert(obj) = Converts a object from the "mtg-parser" package's output
to deckform source format (as a string, not as an object).

.export(obj) = Convert output from this module's main export function into
deckform source format. It doesn't care whether or not the card list
objects have a prototype.

.total(cardlist) = Return a number which is the total number of cards in
the card list.

Readme

Keywords

Package Sidebar

Install

npm i deckform

Weekly Downloads

0

Version

1.0.0

License

Unlicense

Last publish

Collaborators

  • zzo38