4.0.2 • Published 9 months ago

polyconvert v4.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Intro

Polyconvert is a library of functions for converting between different units of measurement. It currently consists of 17 top level categories, each with several different units of measurement. The project currently supports JavaScript only but it would be nice to add more languages in the future!

If you find this tool useful you may also like this abbreviations gist and this formating gist to help you turn your converted values into legible strings.

Contents

Install

Node

If your using Node you can install the package with this command:

npm i polyconvert

It can then be included with this line:

const polyconvert = require('polyconvert')

Link

The other option you have is to link to the polyconvert.min.js file from an HTML document for use in the browser, like this:

<script src="polyconvert.min.js"></script>

You can either link to the polyconvert.min.js file in this repo or download it and use your own copy.

Usage

The library features the polyconvert object that contains all of the formulas. The top level keys represent all the different categories available, see the object map below:

polyconvert = {

    angle: {...},
    area: {...},
    data: {...},
    density: {...},
    dimension: {...},
    energy: {...},
    frequency: {...},
    illumination: {...},
    length: {...},
    magnetomotive: {...},
    mass: {...},
    pressure: {...},
    radiation: {...},
    speed: {...},
    temperature: {...},
    time: {...},
    volume: {...}

}

The second level keys represent all the different units of measurement available within that category. See the object map below using the data category as an example:

polyconvert.data = {

    bit: {...},
    byte: {...},
    kilobyte: {...},
    megabyte: {...},
    gigabyte: {...},
    terrabyte: {...},
    petabyte: {...},
    exabyte: {...},
    zettabyte: {...},
    yottabyte: {...}

}

The third level keys represent all the different units of measurement that you can convert the original unit into and the values are formulas in the format of a function. See the object map below using the bit unit as an example:

polyconvert.data.bit = {

    bit: f(x) = x,
    byte: f(x) = x/8,
    kilobyte: f(x) = x/8e+3,
    megabyte: f(x) = x/8e+6,
    gigabyte: f(x) = x/8e+9,
    terrabyte: f(x) = x/8e+12,
    petabyte: f(x) = x/8e+15,
    exabyte: f(x) = x/8e+18,
    zettabyte: f(x) = x/8e+21,
    yottabyte: f(x) = x/8e+24

}

So, to use these functions, reference them through the polyconvert object and pass in the value you want to convert, like this:

polyconvert.data.bit.byte(100) // Returns 12.5 meaning that 100 bits equals 12.5 bytes

To reverse the conversion simply switch the order of the unit keys, like this:

polyconvert.data.byte.bit(12.5) // Returns 100 meaning that 12.5 bytes equals 100 bits

Contribute

There are two main ways you can contribute to the Polyconvert library.

1) Adding a new language, category or unit for conversion. 2) Report an inaccurate formula or typo.

See below for more information on each of the options, also feel free to simply ask any question you like.

Adding Features

Currently this library supports JavaScript only but it would be nice to add more languages in the future! It would also be nice to add new categories and units for conversion since the current list is not universal, yet. If you need an idea for a new category to work on I suggest browsing the UnitConverters.net website, this site can also be useful for testing the accuracy of existing formulas.

If you would like to contribute in this way please start by opening a feature request. Once your work is done and ready for review you can proceed to opening a pull request.

Reporting Errors

I have done my best to ensure the accuracy of all the formulas but I am only human and I can easily make mistakes! If you find an inaccurate formula or typo please don't hesitate to open a bug report.

I have also written some simple tests that can be run against the polyconvert object with the command npm test. If you want you could also contribute by helping to write a more detailed and comprehensive test suite.

If you have any other issues with the Polyconvert library then please open a general issue. Your efforts will improve the functionality and usability of this tool for everyone, thanks in advance!

Categories

Each category below is available as a top level key in the polyconvert object. An object map of each category is available below.

Angle

The Angle category provides 6 different units for conversion, see the object map below:

polyconvert.angle = {

    degree: {...},
    gradian: {...},
    milliradian: {...},
    radian: {...},
    arcSecond: {...},
    arcMinute: {...}

}

Area

The Area category provides 15 different units for conversion, see the object map below:

polyconvert.area = {

    nanometerSq: {...},
    micrometerSq: {...},
    millimeterSq: {...},
    centimeterSq: {...},
    decimeterSq: {...},
    meterSq: {...},
    decameterSq: {...},
    hectometerSq: {...},
    kilometerSq: {...},

    inchSq: {...},
    footSq: {...},
    yardSq: {...},
    mileSq: {...},

    acre: {...},
    hectare: {...}

}

Data

The Data category provides 10 different units for conversion, see the object map below:

polyconvert.data = {

    bit: {...},
    byte: {...},
    kilobyte: {...},
    megabyte: {...},
    gigabyte: {...},
    terrabyte: {...},
    petabyte: {...},
    exabyte: {...},
    zettabyte: {...},
    yottabyte: {...}

}

Density

The Density category provides 8 different units for conversion, see the object map below:

polyconvert.density = {

    gramCentimeterCu: {...},
    gramMeterCu: {...},
    kilogramCentimeterCu: {...},
    kilogramMeterCu: {...},

    ounceInchCu: {...},
    ounceFootCu: {...},
    poundInchCu: {...},
    poundFootCu: {...}

}

Dimension

The Dimension category provides 2 different units for conversion, see the object map below:

polyconvert.dimension = {

    d2: {...},
    d3: {...}

}

Energy

The Energy category provides 4 different units for conversion, see the object map below:

polyconvert.energy = {

    joule: {...},
    kilojoule: {...},
    watt: {...},
    kilowatt: {...}

}

Frequency

The Frequency category provides 4 different units for conversion, see the object map below:

polyconvert.frequency = {

    hertz: {...},
    kilohertz: {...},
    megahertz: {...},
    gigahertz: {...}

}

Illumination

The Illumination category provides 4 different units for conversion, see the object map below:

polyconvert.illumination = {

    phot: {...},
    lux: {...},
    nox: {...},
    flame: {...}

}

Length

The Length category provides 13 different units for conversion, see the object map below:

polyconvert.length = {

    nanometer: {...},
    micrometer: {...},
    millimeter: {...},
    centimeter: {...},
    decimeter: {...},
    meter: {...},
    decameter: {...},
    hectometer: {...},
    kilometer: {...},

    inch: {...},
    foot: {...},
    yard: {...},
    mile: {...}

}

Magnetomotive

The Magnetomotive category provides 5 different units for conversion, see the object map below:

polyconvert.magnetomotive = {

    milliampere: {...},
    ampere: {...},
    abampere: {...},
    kiloampere: {...},

    gilbert: {...}

}

Mass

The Mass category provides 13 different units for conversion, see the object map below:

polyconvert.mass = {

    nanogram: {...},
    microgram: {...},
    milligram: {...},
    centigram: {...},
    decigram: {...},
    gram: {...},
    decagram: {...},
    hectogram: {...},
    kilogram: {...},

    ounce: {...},
    pound: {...},
    stone: {...},
    ton: {...}

}

Pressure

The Pressure category provides 5 different units for conversion, see the object map below:

polyconvert.pressure = {

    bar: {...},
    pascal: {...},
    atmospheric: {...},
    psi: {...},
    torr: {...}

}

Radiation

The Radiation category provides 14 different units for conversion, see the object map below:

polyconvert.radiation = {

    nanogray: {...},
    microgray: {...},
    milligray: {...},
    centigray: {...},
    decigray: {...},
    gray: {...},
    dekagray: {...},
    hectogray: {...},
    kilogray: {...},
    megagray: {...},
    gigagray: {...},
    teragray: {...},
    petagray: {...},
    exagray: {...}

}

Speed

The Speed category provides 25 different units for conversion, see the object map below:

polyconvert.speed = {

    millimeterSecond: {...},
    millimeterMinute: {...},
    millimeterHour: {...},
    centimeterSecond: {...},
    centimeterMinute: {...},
    centimeterHour: {...},
    meterSecond: {...},
    meterMinute: {...},
    meterHour: {...},
    kilometerSecond: {...},
    kilometerMinute: {...},
    kilometerHour: {...},

    inchSecond: {...},
    inchMinute: {...},
    inchHour: {...},
    footSecond: {...},
    footMinute: {...},
    footHour: {...},
    yardSecond: {...},
    yardMinute: {...},
    yardHour: {...},
    mileSecond: {...},
    mileMinute: {...},
    mileHour: {...},

    knots: {...}

}

Temperature

The Temperature category provides 3 different units for conversion, see the object map below:

polyconvert.temperature = {

    celsius: {...},
    fahrenheit: {...},
    kelvin: {...}

}

Time

The Time category provides 13 different units for conversion, see the object map below:

polyconvert.time = {

    nanosecond: {...},
    microsecond: {...},
    millisecond: {...},
    second: {...},
    minute: {...},
    hour: {...},
    day: {...},
    week: {...},
    month: {...},
    year: {...},
    decade: {...},
    century: {...},
    millennium: {...}

}

Volume

The Volume category provides 21 different units for conversion, see the object map below:

polyconvert.volume = {

    nanometerCu: {...},
    micrometerCu: {...},
    millimeterCu: {...},
    centimeterCu: {...},
    decimeterCu: {...},
    meterCu: {...},
    decameterCu: {...},
    hectometerCu: {...},
    kilometerCu: {...},

    inchCu: {...},
    footCu: {...},
    yardCu: {...},
    mileCu: {...},

    milliliter: {...},
    liter: {...},

    teaspoon: {...},
    tablespoon: {...},
    cup: {...},
    pint: {...},
    quart: {...},
    gallon: {...}

}