Harry Stevens

Stories and graphics at The Washington Post. Arlington, VA.

Last updated on 12 July, 2017 | Originally published on Medium

Introducing “party-time”: An npm package for converting Indian political party names

One thing I’ve had to do more than once in my work at the Hindustan Times is convert party acronyms to full party names, or vice versa. Imagine you have a page showing the results of the Goa state assembly elections. On mobile devices, you want to only show the party acronyms (in this case, “INC” and “BJP”), but on wider screens you want to show the full party names (“Indian National Congress” and “Bharatiya Janata Party”). To do this, you need a function that will output either the acronym or the full name, after detecting the screen size.

Show the parties on a wide screen…
…or on a narrower mobile device.

This problem is easy to solve, but I’ve had to write the code to do it more than once, which is time consuming. I also keep creating different libraries of party acronyms and their associated full names, and I always end up looking for them over and over again.

To solve these problems, I created an npm package called party-time.

It’s party-time!

party-time has just three functions: getType(), getInfo(), and convert(). The convert() function uses the first two, but those can also be called by themselves.

Right now, the library of parties is almost certainly not comprehensive. But as I (and, perhaps, you) use the library, the gaps will be filled in. To give it a test, you can install it with npm:

npm i party-time -S

Or you can use it in the browser by including the CDN:

<script src="https://unpkg.com/party-time/lib/party-time.min.js"></script>

It’s pretty simple to use, but if you want to take a look at the documentation, head over to the GitHub repo. If you find a party I’m missing, open up an issue.

Last note: I think npm is really great. It makes creating and sharing reusable JavaScript code easy. If you have some code you think you (or someone else) might want to reuse, and you want to turn it into a package, I recommend this useful tutorial by Joanne Daudier. I’ve been on a package-creating binge lately.