Unit Converter
Convert between units of length, weight, temperature, data, time, area, volume, and speed.
The Unit Converter covers eight categories — Length, Weight / Mass, Temperature, Data, Time, Area, Volume, and Speed — with bidirectional conversion: type into From and To updates live; type into To and From back-fills. A Precision slider (0–10 decimals, default 6) controls rounding, trailing zeros are trimmed for clean display, and a round swap button flips both units and values in one click. The footer always shows "Category: {label} | {fromUnit} → {toUnit}" so you never lose track of direction.
Every conversion factor lives in-repo (inch = 0.0254 m, lb = 0.453592 kg, binary data steps of 1024, and so on) — there is no external conversion API. Category switches reset the From/To pair to that category's first two units. You can copy the result, download a plain-text conversion note as conversion-{category}-{timestamp}.txt, or Clear both fields. The card notes "Runs locally — nothing is uploaded."
How it works
lib/unitConverter.ts defines 8 CATEGORIES; each unit carries toBase and fromBase functions around a base unit — meter, kilogram, celsius, byte, second, squareMeter, liter, and meterPerSecond. convertUnit routes value → base → target, so °F and K convert correctly through Celsius as the shared base. Data units use binary steps: toBase multiplies by 1024 per level (KB=1024 B, MB=1024²…).
The page rounds with toFixed(precision) then strips trailing zeros (replace(/\.?0+$/, '')), so precision 0 shows integers and "1.000000" renders as "1". Editing either textarea recomputes the other (handleFromChange / handleToChange), and a setTimeout-0 effect clears both values when the category changes. Everything runs in the browser with no network.
How to use
- Pick a Category: Length, Weight / Mass, Temperature, Data, Time, Area, Volume, or Speed.
- Units auto-reset to the first two of that category — adjust the From/To "Select unit" dropdowns as needed.
- Set Precision with the slider (0–10 decimals, displayed "{n} decimals"); changing it re-converts immediately.
- Type a value in the From textarea (placeholder "Enter value...") — the result appears in To ("Result will appear here...") right away.
- Or type into To to convert backwards into From — conversion is fully bidirectional.
- Click the round swap button (aria-label "Swap units") to flip direction; the arrow icon rotates 180° as units and values swap.
- Click "Copy" next to the To value; the footer shows "Category: {label} | {fromUnit} → {toUnit}".
- Click "Download" to save conversion-{category}-{timestamp}.txt (containing the equation, category, and precision), or "Clear" to empty both fields.
Tips
- Data units use binary steps (KB=1024 B, MB=1024²…) — the toBase multiplies by 1024 per step, matching how disks are advertised.
- Temperature is special-cased through Celsius as the base unit, so °F↔K round-trips correctly instead of double-converting.
- Precision 0 rounds to integers; trailing zeros are always trimmed, so '1.000000' displays as '1'.
- Changing category resets From/To values via a setTimeout-0 effect — copy or download anything you still need first.
Unit Converter FAQ
Does it need the internet?
No — the card says "Convert between units of measurement. Runs locally — nothing is uploaded," and all factors live in lib/unitConverter.ts.
How many categories are there?
Eight: Length, Weight / Mass, Temperature, Data, Time, Area, Volume, and Speed (the UnitCategory union).
Can I convert both directions?
Yes — editing either textarea recomputes the other through handleFromChange and handleToChange.
What precision is used?
User-controlled 0–10 decimals (default 6), applied via toFixed(precision) with a trailing-zero strip for clean output.
Credits
- Conversion tables (in-repo) — All unit factors live in lib/unitConverter.ts (e.g. inch=0.0254m, lb=0.453592kg); no external conversion API