Unit

Docs

Fast path to Unit conversion, parsing, opt-in localization, and API reference.

Unit docs

Unit is TypeScript measurement toolkit for converting, parsing, formatting, validating, and inspecting units in real app flows.

Core idea:

  • canonical units inside app
  • opt-in localization at input and output edges
  • explicit conversion traces when precision matters
  • schema helpers when forms and imports need enforcement

Start here

NeedGo to
Install packageGetting Started
Convert valuesConversion
Use Bangla namesLocalization
Check API surfaceReference

Common tasks

TaskAPI
Convert 1 km to metersconvert(1, "km", "m")
Parse Bangla measurementparseMeasurement("১২.৫০ কেজি")
Limit decimal placesparseMeasurement(input, { maxDecimalPlaces: 2 })
Format Bangla outputformatMeasurement(12, "kg", { locale: "bn-BD", localizeUnits: true })
Run perf benchbun run bench --json --repeats 9

Choose right API

SituationUse
One compatible conversionconvert
Need warnings, rounding state, traceconvertDetailed
Need many targets from one sourceconvertMany
Parse 12.5 kgparseMeasurement
Parse 5 ft 7 inparseMixedMeasurement
Normalize mixed input to one unitnormalizeMixedMeasurement
Pick readable display unitbestUnit or formatBest
Enforce form or import rulescreateMeasurementSchema
Recover from misspelled unit inputsuggestUnit
Resolve alias or localized label to canonicalresolveUnit

For most teams:

  1. Accept user input in many shapes.
  2. Parse and validate at boundary.
  3. Store canonical value + canonical unit.
  4. Convert only when view or export needs it.
  5. Add localization only where product needs localized labels or digits.

Also built in

  • clearer validation and parse error messages for users
  • regional conversion warnings for units like bigha and seer
  • bench CLI for before/after perf comparison

On this page