
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
A lightweight TypeScript utility to convert measurements between unit systems like metric and imperial.
Lightweight utility for converting common measurement units.
npm install uconvert
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
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.
Units are grouped by dimension. Use the Code value with convert().
| 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 |
| 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 |
| 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 |
| Unit | Code | System |
|---|---|---|
| °C (C) | MetricUnits.CELSIUS | Metric |
| K | MetricUnits.KELVIN | Metric |
| °F (F) | ImperialUnits.FAHRENHEIT | Imperial |
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 typeTuple 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);
FAQs
A lightweight TypeScript utility to convert measurements between unit systems like metric and imperial.
We found that uconvert demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.