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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mtg-json

v1.0.1

Published

A module for interacting with the MtG JSON website, a site providing a series of JSON files that act as a database for Magic the Gathering Cards

Downloads

6

Readme

MtG JSON

Introduction

This module is designed for interacting with the MtG JSON website, a site providing a series of JSON files that act as a database for Magic the Gathering Cards.

You might be interested in this module if you're making any kind of node app involved with Magic the Gathering, for example a database, simulator, etc.

The scope of this module can include anything to do with the website, and currently is able to download and read all 8 files stored in the website.

Compatibility

This module uses some features from ES6, so requires node version 4.0 and greater.

Usage

Quickstart

  • First install the module: npm install mtg-json --save

  • Then require the module and call it:

        //Require the module
        const getMtgJson = require('mtg-json');
    
        //Request AllCards.json and store it in the current directory
        getMtgJson('cards', __dirname)
    
        //Use the json data
          .then(json => {
              let stormCrow = json['stormCrow'];
              console.log(stormCrow.types) // Logs ['Creature']
          });

API

The module consists of one function with the following signature: getMtgJson(type, directory, opts)

  • type (string): Required. Either 'cards' or 'sets', to determine if you want a file organized by card or by set. See the MtG JSON website for details.

  • directory (string): Required. The directory in which to place or look for the JSON file. This may often be __dirname, the current directory constant, but you must set this yourself, __dirname is not the default.

  • opts (object): Options. An object with three optional keys:

    • extras (boolean): True if you want the file to include extras (rulings, printings, foreign language names etc.). Again, see the MtG JSON website for details.
    • zip (boolean): True if you want the file to be downloaded as a zip file. If this is true, the promise return value will be a filepath, and not JSON.
    • returnFile (boolean): True if you want the promise to resolve with the json filename, rather than the JSON data itself. True by default if zip is true.

Tests

The module is quite comprehensively tested. Simply run npm test or mocha test.js twith Mocha globally installed to run the tests. Note that these can take a while (about a minute) because they actually involve downloading the large JSON files from the website a number of times.