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

uconvert

v0.1.5

Published

Lightweight utility for converting common measurement units.

Downloads

590

Readme

uconvert

Lightweight utility for converting common measurement units.

Table of contents

Installation

npm install uconvert

Usage

convert(value, options)

Converts a numeric value from one unit to another.

Parameters:

  • value (number) — The value in the source unit.
  • options (object):
    • fromUnits — Source unit (use MetricUnits or ImperialUnits).
    • toUnits — Target unit. Must be the same dimension as fromUnits (e.g. length ↔ length), or an error is thrown.
    • roundTo (optional) — Number of decimal places to round the result. Omit to return the unrounded value.

Returns: The value in the target unit (optionally rounded).

Example:

import { convert, MetricUnits, ImperialUnits } from "uconvert";

// 5 feet to meters, rounded to 2 decimals
convert(5, {
  fromUnits: ImperialUnits.FT,
  toUnits: MetricUnits.M,
  roundTo: 2,
});
// => 1.52

// Same unit: returns value unchanged
convert(100, { fromUnits: MetricUnits.CM, toUnits: MetricUnits.CM });
// => 100

round(value, decimalPlaces?)

Rounds a number to a given number of decimal places.

Parameters:

  • value (number) — The number to round.
  • decimalPlaces (optional) — Number of digits after the decimal point. Omit to return the value unchanged.

Returns: The rounded number (or the original number if decimalPlaces is omitted).

Example:

import { round } from "uconvert";

round(1.2345, 2); // => 1.23
round(1.2345); // => 1.2345

Exported types and enums

Use these with convert for type-safe unit arguments:

| Export | Description | | ---------------- | ------------------------------------------------------------------------------------ | | ConvertOptions | Options object for convert: { fromUnits, toUnits, roundTo? }. | | Units | Union type: MetricUnits \| ImperialUnits. | | MetricUnits | Enum: MM, CM, M, KM, G, KG, TONNE, CELSIUS, KELVIN, M_S, KM_H. | | ImperialUnits | Enum: IN, FT, YD, MI, OZ, LB, ST, FAHRENHEIT, FT_S, MPH. | | UnitSystem | Enum: METRIC, IMPERIAL. | | Dimension | Enum: LENGTH, WEIGHT, SPEED, TEMPERATURE. |

fromUnits and toUnits must use the same dimension (e.g. both length, or both weight); otherwise convert throws.


Supported units

Units are grouped by dimension. Use the Code value with convert().

Length

| Unit | Code | System | | ---- | ------------------ | -------- | | mm | MetricUnits.MM | Metric | | cm | MetricUnits.CM | Metric | | m | MetricUnits.M | Metric | | km | MetricUnits.KM | Metric | | in | ImperialUnits.IN | Imperial | | ft | ImperialUnits.FT | Imperial | | yd | ImperialUnits.YD | Imperial | | mi | ImperialUnits.MI | Imperial |

Weight

| Unit | Code | System | | ---- | ------------------- | -------- | | g | MetricUnits.G | Metric | | kg | MetricUnits.KG | Metric | | t | MetricUnits.TONNE | Metric | | oz | ImperialUnits.OZ | Imperial | | lb | ImperialUnits.LB | Imperial | | st | ImperialUnits.ST | Imperial |

Speed

| Unit | Code | System | | ---- | -------------------- | -------- | | m/s | MetricUnits.M_S | Metric | | km/h | MetricUnits.KM_H | Metric | | ft/s | ImperialUnits.FT_S | Imperial | | mph | ImperialUnits.MPH | Imperial |

Temperature

| Unit | Code | System | | ------ | -------------------------- | -------- | | °C (C) | MetricUnits.CELSIUS | Metric | | K | MetricUnits.KELVIN | Metric | | °F (F) | ImperialUnits.FAHRENHEIT | Imperial |


Height utility

The height object provides helpers for converting between centimeters and feet–inches and for parsing feet–inches strings.

Import:

import { height } from "uconvert";

height.toFeetInches(valueInCm, roundTo?)

Converts a height in centimeters to feet and inches.

Parameters:

  • valueInCm (number) — Height in centimeters.
  • roundTo (optional) — Number of decimal places for the inches part. Omit for unrounded.

Returns: A FeetInches tuple [feet, inches].

Example:

height.toFeetInches(170); // => [5, 6.93...]
height.toFeetInches(170, 1); // => [5, 6.9]

height.toCentimeters(feetInches)

Converts a feet–inches tuple to centimeters.

Parameters:

  • feetInches — A FeetInches tuple [feet, inches] (e.g. from toFeetInches or parseFeetInches).

Returns: Height in centimeters (number).

Example:

height.toCentimeters([5, 10]); // => 177.8

height.parseFeetInches(input)

Parses a string into a [feet, inches] tuple. Accepts formats like "5 ft 10 in", "5'10\"", "5 10", and variations with "feet"/"foot"/"inches"/"inch".

Parameters:

  • input (string) — String to parse.

Returns: A FeetInches tuple [feet, inches]. Returns [0, 0] if parsing fails or input is not a string.

Example:

height.parseFeetInches("5 ft 10 in"); // => [5, 10]
height.parseFeetInches("5'10\""); // => [5, 10]
height.parseFeetInches("6 2"); // => [6, 2]

FeetInches type

Tuple type [number, number]: first element is feet, second is inches. Use it when passing or receiving values from toFeetInches, toCentimeters, and parseFeetInches.

import { height, type FeetInches } from "uconvert";

const fi: FeetInches = height.toFeetInches(170);
height.toCentimeters(fi);