My first npm package: ptcgo-parser
Tags: npm, library, learning, opensource
Published: 2019-07-09 14:32:59

---
title: My first npm package: ptcgo-parser
published: true
description: I built and published my first npm package to allow developers build tools for Pokemon TCG players
tags: npm, library, learning, open source
---

## Introduction 

Over the past couple of years I've built a couple of prototypes for myself and few players in my local and online communities to help us become better Pokemon TCG players. Based on those projects, I published my first npm package today.

Some of my prototypes are [Proxymon](http://proxymon.herokuapp.com/) which is now outdated, missing recent sets but still functional in printing proxies for playtesting and [pkmn-attack-damage](https://pkmn-attack-damage.netlify.com/) that I built one Saturday night after a discussion in a Discord community.

**Meet [ptcgo-parser](https://npmjs.com/package/ptcgo-parser)!**

I wrote [hamatti/ptcgo-parser](https://github.com/hamatti/ptcgo-parser) to learn how to build npm packages and to alleviate my pains of copy-pasting and rewriting that parsing part for all my projects. I'm a huge fan of [PokemonTCG.io API](https://pokemontcg.io) and decided to bundle in compatibility for that API.

## Quick Guide

You can install the package via npm with

```bash
npm install ptcgo-parser
```

and then use it in your own code, providing a Pokemon TCG Online decklist export as an argument to it's only exposed function `parse`:

```js
const PTCGOParser = require('ptcgo-parser')

const ptcgoExportedDecklist = `
****** Pokémon Trading Card Game Deck List ******
 
##Pokémon - 13
 
* 1 Oranguru SUM 113
* 3 Darkrai-EX BKP 74
* 4 Dratini SUM 94
* 3 Dragonair SUM 95
* 1 Dragonite ROS 51
* 1 Mew FAC 29
`
 
const decklist = PTCGOParser.parse(ptcgoExportedDecklist)
 
console.log(decklist)
 
/*
  {
    cards: [
        {
            name: 'Oranguru',
            amount: 1,
            set: 'SUM',
            code: 113,
            ptcgoio: {
                id: 'sm1-113'
            }
        },
        ...
    ]
  }
*/
```

It will return you the parsed version of the card but also includes PokemonTCG.io ID that you can use to fetch more information from the API.

## Known issues

The initial launch functions but it still has bunch of known issues, mainly that some cards (like Rainbow Rares) are not available in the PokemonTCG.io API. I will continue working on the package to bring it to a point where 1.0.0 launch will contain exceptions for missing cards so that you can get the correct card, even if the wrong rarity.

If you are a developer and Pokemon TCG player, take it a spin and let me know how I can improve it to make it perfect for your use cases.

## Publishing a package in npm

I was surprised how easy the workflow for publishing a package in npm is. All you need to do, is to [create an account to npmjs.com](https://www.npmjs.com/), [create a `package.json` file](https://docs.npmjs.com/files/package.json), write some code and run `npm publish` on your command line.

And with [Shields.io](https://shields.io), you can get this cool badges that you can put to your documentation:

![npm badge](https://img.shields.io/npm/v/ptcgo-parser.svg?style=plastic)

## Conclusion

There's still lots of work to do with the library, especially making it more stable in terms of missing or mismatching cards. But wrapping it in a npm package forced me to think about the API and what format it returns the data as well as thinking about the documentation.

If you wanna learn how to write good documentation, @jamesstone has collected great resources to his repository [jamesstoneco/docsthursday](https://github.com/jamesstoneco/docsthursday).

_The development of [ptcgo-parser](https://www.npmjs.com/package/ptcgo-parser) was supported by [Spice Program](https://spiceprogram.org/)._