New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

unitfyi

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unitfyi

Pure TypeScript unit conversion engine — 200 units across 20 categories, temperature formulas, smart rounding. Zero dependencies.

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

unitfyi

npm version TypeScript License: MIT Zero Dependencies

Pure TypeScript unit conversion engine for developers. Convert between 200 units across 20 measurement categories including length, weight, temperature, volume, area, speed, time, data storage, pressure, energy, frequency, force, power, angle, fuel economy, data transfer, density, torque, cooking, and typography -- all with zero dependencies.

Try the interactive tools at unitfyi.com -- unit converter, conversion tables, and category explorer.

unitfyi demo — unit conversion with precision

Table of Contents

Install

npm install unitfyi

Works in Node.js, Deno, Bun, and browsers (ESM).

Quick Start

import { convert, conversionTable, getCategoryUnits, getOrderedCategories } from "unitfyi";

// Convert between any compatible units
const temp = convert(100, "celsius", "fahrenheit");
console.log(temp.result);        // 212
console.log(temp.formulaText);   // "°F = (°C × 9/5) + 32"

const length = convert(1, "mile", "kilometer");
console.log(length.result);      // 1.6093
console.log(length.fromSymbol);  // "mi"
console.log(length.toSymbol);    // "km"

// Generate a conversion table
const table = conversionTable("kilogram", "pound");
// [[1, 2.2046], [5, 11.0231], [10, 22.0462], ...]

// Browse categories and units
const categories = getOrderedCategories();
console.log(categories.length);  // 20

const lengthUnits = getCategoryUnits("length");
console.log(lengthUnits.length); // 20 (meter, km, cm, mm, ...)

What You Can Do

Precision in Unit Conversion

JavaScript uses IEEE 754 double-precision floats. For most unit conversions this is sufficient, but temperature and very large/small values use smart rounding to avoid floating-point artifacts like 99.99999999996.

The engine applies magnitude-aware rounding:

MagnitudePrecisionExample
>= 1,0002 decimal places5,280.00
>= 14 decimal places1.6093
>= 0.016 decimal places0.453592
< 0.0110 decimal places0.0000000001

Temperature conversions use function-based formulas (not linear factors) to maintain exact results: °F = (°C * 9/5) + 32, K = °C + 273.15, etc.

The engine covers 20 measurement categories with a total of 200 units:

CategoryUnitsExamples
Length20meter, kilometer, mile, foot, inch, yard, nautical mile, ...
Weight15kilogram, pound, ounce, gram, stone, metric ton, ...
Temperature4Celsius, Fahrenheit, Kelvin, Rankine
Volume15liter, gallon (US/UK), cup, tablespoon, fluid ounce, ...
Area10square meter, acre, hectare, square foot, ...
Speed8km/h, mph, m/s, knot, Mach, speed of light, ...
Data Storage16byte, KB, MB, GB, TB, PB, KiB, MiB, GiB, ...
Pressure8pascal, bar, atm, psi, mmHg, torr, ...
Energy10joule, calorie, kWh, BTU, eV, ...
Cooking8cup, tablespoon, teaspoon, fluid ounce, ...

Learn more: Unit Converter · SI Base Units · Category Explorer

Temperature Conversion

import { convert } from "unitfyi";

// All temperature conversions use exact formulas (not linear approximation)
const c2f = convert(0, "celsius", "fahrenheit");
console.log(c2f.result);        // 32
console.log(c2f.formulaText);   // "°F = (°C × 9/5) + 32"

const f2c = convert(72, "fahrenheit", "celsius");
console.log(f2c.result);        // 22.2222

const c2k = convert(-40, "celsius", "kelvin");
console.log(c2k.result);        // 233.15

// Rankine scale also supported
const f2r = convert(100, "fahrenheit", "rankine");
console.log(f2r.result);        // 559.67

Learn more: Temperature Converter · Absolute Zero

Conversion Tables

import { conversionTable } from "unitfyi";

// Default values: [1, 5, 10, 25, 50, 100, 250, 500, 1000]
const table = conversionTable("meter", "foot");
for (const [meters, feet] of table) {
  console.log(`${meters} m = ${feet} ft`);
}

// Custom values
const custom = conversionTable("celsius", "fahrenheit", [0, 20, 37, 100]);
// [[0, 32], [20, 68], [37, 98.6], [100, 212]]

Learn more: Conversion Tables · REST API Docs

Unit Lookup

import { getUnit, getCategoryUnits, getOrderedCategories } from "unitfyi";

// Look up a single unit
const meter = getUnit("meter");
console.log(meter?.name);         // "Meter"
console.log(meter?.symbol);       // "m"
console.log(meter?.category);     // "length"
console.log(meter?.aliases);      // ["metre", "meters", "metres"]

// List all units in a category
const tempUnits = getCategoryUnits("temperature");
// [{ slug: "celsius", name: "Celsius", symbol: "°C", ... }, ...]

// Get all 20 categories sorted by display order
const cats = getOrderedCategories();
for (const cat of cats) {
  console.log(`${cat.icon} ${cat.name}: ${cat.description}`);
}

Learn more: All Units · OpenAPI Spec

API Reference

Conversion

FunctionDescription
convert(value, fromSlug, toSlug) -> ConversionResultConvert a value between two compatible units
conversionTable(fromSlug, toSlug, values?) -> [number, number][]Generate a conversion table for a unit pair

Unit Lookup

FunctionDescription
getUnit(slug) -> UnitInfo | nullLook up a unit by slug
getCategoryUnits(categorySlug) -> UnitInfo[]Get all units in a category
getOrderedCategories() -> CategoryDef[]Get all 20 categories sorted by display order

Error Classes

ClassDescription
UnknownUnitErrorThrown when a unit slug is not found
IncompatibleUnitsErrorThrown when converting between different categories

Data Exports

ExportDescription
UNITSRecord of all 200 unit definitions
CATEGORIESRecord of all 20 category definitions
FORMULASNon-linear conversion formulas (temperature)

TypeScript Types

import type {
  UnitDef,
  CategoryDef,
  ConversionResult,
  UnitInfo,
  TemperatureFormula,
} from "unitfyi";

Features

  • 200 units: Across 20 measurement categories
  • 20 categories: Length, weight, temperature, volume, area, speed, time, data storage, pressure, energy, frequency, force, power, angle, fuel economy, data transfer, density, torque, cooking, typography
  • Temperature formulas: Exact function-based conversion (Celsius, Fahrenheit, Kelvin, Rankine)
  • Smart rounding: Magnitude-aware precision to avoid floating-point artifacts
  • Conversion tables: Generate value tables for any unit pair
  • Human-readable formulas: Each conversion includes a formula string (e.g., "1 mi = 1.6093 km")
  • Unit aliases: Search-friendly aliases (e.g., "metre", "meters", "metres" all find Meter)
  • Zero dependencies: Pure TypeScript, no runtime deps
  • Type-safe: Full TypeScript with strict mode
  • Tree-shakeable: ESM with named exports
  • Fast: All computations under 1ms

Learn More About Units

Also Available for Python

pip install unitfyi

See the Python package on PyPI.

Utility FYI Family

Part of the FYIPedia open-source developer tools ecosystem — everyday developer reference and conversion tools.

PackagePyPInpmDescription
unitfyiPyPInpmUnit conversion, 220 units -- unitfyi.com
timefyiPyPInpmTimezone ops & business hours -- timefyi.com
holidayfyiPyPInpmHoliday dates & Easter calculation -- holidayfyi.com
namefyiPyPInpmKorean romanization & Five Elements -- namefyi.com
distancefyiPyPInpmHaversine distance & travel times -- distancefyi.com

Embed Widget

Embed UnitFYI widgets on any website with unitfyi-embed:

<script src="https://cdn.jsdelivr.net/npm/unitfyi-embed@1/dist/embed.min.js"></script>
<div data-unitfyi="entity" data-slug="example"></div>

Zero dependencies · Shadow DOM · 4 themes (light/dark/sepia/auto) · Widget docs

License

MIT

Keywords

unit

FAQs

Package last updated on 30 Mar 2026

Did you know?

Socket

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.

Install

Related posts