npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

magic-card-parser

v0.3.0

Published

A utility for parsing magic cards into a JSON structure for further processing.

Readme

Magic Card Parser

This is a project to implement a parser that will support parsing most Magic the Gathering card texts. The current goal is to parse 80% of cards successfully. To use simply run npm i magic-card-parser then you can include it in your project with import { parseCard } from 'magic-card-parser'. parseCard takes a single argument, card, that must include the properties name and oracle_text. It will automatically replace the cards name with ~ in the oracle text and convert to lowercase before parsing. The return value is an object like the following:

{
  "error": null,
  "oracleText": "{t}: create a 1/1 white human creature token.\nfateful hour — as long as you have 5 or less life, other creatures you control get +2/+2.",
  "result": [
    [
      {
        "costs": "tap",
        "activatedAbility": {
          "create": {
            "amount": 1,
            "type": { "and": ["human", "creature"] },
            "size": { "power": 1, "toughness": 1 },
            "color": "w"
          }
        }
      },
      {
        "asLongAs": {
          "actor": "you",
          "does": {
            "comparison": { "lte": 5 },
            "value": "life"
          }
        },
        "effect": {
          "what": {
            "type": "creature",
            "prefixes": ["other"],
            "suffix": {
              "actor": "you",
              "does": "control"
            }
          },
          "does": {
            "powerToughnessMod": {
              "powerMod": 2,
              "toughnessMod": 2
            }
          }
        }
      }
    ]
  ],
  "card": {
    "name": "Thraben Doomsayer",
    "oracle_text": "{T}: create a 1/1 white Human creature token.\nFateful hour — as long as you have 5 or less life, other creatures you control get +2/+2."
  }
}

Most notably result is an array of possible parses. If there is more than one possible parse, meaning it parses to a different json value, than it will report an error of "Ambiguous parse". If the parse is incomplete, meaning it expected more input than it got, then it will return a null result with the error "Incomplete parse". Finally, if the input was invalid, meaning there is no possible parse tree for it, you will get a null result and an Error object describing where the parser failed.

We do not guarantee that all the parses are correct, it is just too much work to manually review all of them at this time. We do check many of the parses and fix any errors we discover from those, so we have high confidence that the vast majority of the parses are correct.

Contributor Guide

We greatly appreciate any contributions. You can check the issue tracker for active bugs and TODO items. You can also run npm run assess to get a list of cards that are failing to parse and try getting those to parse, before running this you need to update submodules, setup the CubeCobra .env file according to their README and run npm i && npm setup in the extern/CubeCobra folder. It is also appreciated if you improve the JSON output to make it more machine-readable, so our users can better utilize it. When making commits that change the number of cards "successfully," correctly or ambiguously, parsed please include Parses <amount>/<cardCount>. in your commit message. If you change how the example would parse please update the README with the new version as well.