1.0.1 • Published 3 years ago

simpleconvert v1.0.1

Weekly downloads
4
License
MIT
Repository
-
Last release
3 years ago

SimpleConvert

A simple node package for unit conversion.

This is a simple library designed to make it easy to start converting units. The package doesn't come pre-installed with a set of units.


How to use

First install the package through NPM, npm install simpleconvert. We will now need to import the package into our NPM project. We can do this by adding const unit = require("simpleconvert"). This by itself does not allow you to use the functionality of Convert. Instead, we must call the "unit" method to supply Convert with the list of conversion rates. You can do so by const unit = require("simpleconvert").unit(<LIST>).

Defining Conversion Rates

The list is formatted very simply. You supply Convert with a list of JavaScript objects, and it looks like this: [{original: "kg", new: "lb", rate: "* 2.205"}].

All objects have three properties. "original", which is your original unit. If you were converting kg > lb, kg would be your original unit. "new", which is the unit you are converting to. And finally, you have your rate. This is the rate of conversion.

Converting units

Simply convert units by calling the "get" method. unit.get(original, value, new). Value is the number of 'original' you want to convert into 'new', It will return the value, so then you can do whatever you want with it.