npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@jgphilpott/polyconvert

v1.0.7

Published

A library of functions for converting between different units of measurement.

Readme

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 formatting gist to help you turn your converted values into legible strings.

Contents

Install

Node

Package on npm: https://www.npmjs.com/package/@jgphilpott/polyconvert

Install with:

npm i @jgphilpott/polyconvert

Then require it:

const polyconvert = require('@jgphilpott/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: {...},
    terabyte: {...},
    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 / (8 * 1024),
    megabyte: f(x) = x / (8 * 1024 ** 2),
    gigabyte: f(x) = x / (8 * 1024 ** 3),
    terabyte: f(x) = x / (8 * 1024 ** 4),
    petabyte: f(x) = x / (8 * 1024 ** 5),
    exabyte: f(x) = x / (8 * 1024 ** 6),
    zettabyte: f(x) = x / (8 * 1024 ** 7),
    yottabyte: f(x) = x / (8 * 1024 ** 8)

}

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

polyconvert.data.kilobyte.byte(1) // Returns 1024 meaning that 1 kibibyte equals 1024 bytes

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

polyconvert.data.byte.kilobyte(1024) // Returns 1 meaning that 1024 bytes equals 1 kibibyte

Testing

The Polyconvert library includes comprehensive testing to ensure accuracy and reliability. The test suite validates conversions using two complementary approaches:

Internal Consistency Tests

These tests verify that forward and reverse conversions return to the original value. For example:

  • Convert 1 meter → feet → back to meters should equal 1 meter
  • Convert 1 kilogram → pounds → back to kilograms should equal 1 kilogram

This ensures that conversion formulas are mathematically consistent and properly inverted.

External Validation Tests

These tests validate conversions against well-known values from reputable sources including:

  • NIST (National Institute of Standards and Technology)
  • International standards bodies (SI units, ISO standards)
  • Widely accepted scientific references

Example validations:

  • 1 meter = 3.28084 feet
  • 0°C = 32°F (freezing point of water)
  • 100°C = 212°F (boiling point of water)
  • 1 kilogram = 2.20462 pounds
  • 1 inch = 2.54 centimeters (exact)
  • 1 atmosphere = 101325 pascals (exact)

The external validation tests cover all major categories including length, mass, temperature, volume, pressure, energy, data, time, speed, angle, area, and frequency conversions.

Running Tests

All tests can be run with the command:

npm test

This will execute both the internal consistency tests and external validation tests, providing comprehensive verification of all conversion formulas.

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.

The library includes comprehensive testing to ensure accuracy:

  1. Internal Consistency Tests: Validate that forward and reverse conversions return to the original value (e.g., meter → foot → meter should equal the original meter value).

  2. External Validation Tests: Validate conversions against well-known values from reputable sources like NIST (National Institute of Standards and Technology) and international standards bodies. These tests verify that conversions match widely accepted reference values (e.g., 1 meter = 3.28084 feet, 0°C = 32°F, 1 kg = 2.20462 pounds).

All tests can be run with the command npm test.

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: {...},
    terabyte: {...},
    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 11 different units for conversion, see the object map below:

polyconvert.energy = {

    joule: {...},
    kilojoule: {...},
    wattHour: {...},
    kilowattHour: {...},
    electronvolt: {...},
    calorie: {...},
    kilocalorie: {...},
    btu: {...},
    footPound: {...},

    // Power (time-dependent) units:
    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: {...},
    decagray: {...},
    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: {...}

}

Polyconvert is developed and maintained by @jgphilpott.