Contributing to convert.js

Have you ever needed to convert a cup into ounces for a project? Or milliliters into tablespoons?

No?

Apparently not a lot of people have as there aren’t many open source JavaScript libraries that do these kinds of conversions. They aren’t built into Vanilla JS by default and it’s such an uncommon problem (not all websites are about recipes and cooking) so it hasn’t gotten much attention.

One of the wonderful (and frustrating) things about being a developer is to be able contribute to solving problems when I don’t see anyone else has already addressed it.

After a bit of searching a few projects looked like they came close to being what I needed, were well written, and uglified to be a very small package. convert.js is the project that I think has the best approach to solving unit conversion. It is well coded and easy to extend, so the amount of time I spent on this was actually less than I spent searching for alternatives. Though the available conversions were not what I needed (weight, length, and temperature) it was extensible enough that I could easily add fluid volume to the library. At least that was the idea going into the update.

Aside from adding the volumetric measurements I also extended the library’s existing conversions and adding in conversions for data storage units (bytes, kilobytes, terabytes, petabytes, etc.). In the end I believe I more than tripled conversion capabilities, even going so far as to add conversions from weight to volume. All of these additions were not something I will use in my current project but since I’m working on this I may as well make it robust.

All of this work was fine and good, but instead of locking this in my own private project repository I took these updates and applied them to the public repository. What’s even cooler is that the developer is super responsive and accepted my pull request within a day. So my updates are now online and I’m a contributor on yet another Github project.

All these updates do add weight to the final uglified JS file but not substantially. In the future I may come back to this and see what I can do to bring down the final file size, but for now this library does more than what I need for a current project.

Not bad for an afternoon’s work.

Leave a Comment