Documentation / @interstellar-tools/types / DistanceUnitAliasType
Type Alias: DistanceUnitAliasType
ts
type DistanceUnitAliasType =
| 'meter'
| 'meters'
| 'metre'
| 'metres'
| 'kilometer'
| 'kilometers'
| 'kilometre'
| 'kilometres'
| 'AU'
| 'Au'
| 'astronomical-unit'
| 'astronomical-units'
| 'astronomical unit'
| 'astronomical units'
| 'lightyear'
| 'lightyears'
| 'light-year'
| 'light-years'
| 'kilolightyear'
| 'kilolightyears'
| 'kly'
| 'megalightyear'
| 'megalightyears'
| 'Mly'
| 'gigalightyear'
| 'gigalightyears'
| 'Gly'
| 'parsec'
| 'parsecs'
| 'kiloparsec'
| 'kiloparsecs'
| 'kpc'
| 'megaparsec'
| 'megaparsecs'
| 'Mpc'
| 'gigaparsec'
| 'gigaparsecs'
| 'Gpc';Defined in: distance.ts:96
Human-friendly distance unit aliases accepted at input time.
These strings should be parsed and normalized to canonical DistanceUnitType (e.g., "AU" → "au", "lightyears" → "ly", "kiloparsecs" → "kpc").
Scope & conventions
- Canonical vs. aliases: This type is for inputs. Convert to canonical symbols (
m,km,au,ly/kly/Mly/Gly,pc/kpc/Mpc/Gpc) before math or serialization. - Case-sensitive and exact matches: tokens are matched exactly as listed here. For example,
"AU"is valid (alias) while"au"is the canonical symbol (not part of this alias type). - IAU symbol: canonical astronomical unit is lowercase
au; we accept"AU","Au", and textual forms as aliases. - Light-year and parsec families: long names (with/without hyphens) normalize to their canonical symbols (
ly/kly/Mly/Gly,pc/kpc/Mpc/Gpc). By convention,lyuses the Julian year (consistent with your temporal units).
Typical flow
- Accept
DistanceUnitAliasType | DistanceUnitTypeat your API boundary. - Normalize to
DistanceUnitTypewithnormalizeDistanceUnitfrom@interstellar-tools/equations, or convert directly withconvertDistanceUnit. - Perform calculations using canonical units only.
Example
ts
import { normalizeDistanceUnit } from '@interstellar-tools/equations';
normalizeDistanceUnit('AU'); // 'au'
normalizeDistanceUnit('lightyears'); // 'ly'
normalizeDistanceUnit('kilolightyears'); // 'kly'
normalizeDistanceUnit('parsecs'); // 'pc'
normalizeDistanceUnit('Mpc'); // 'Mpc' (already canonical)See
- DistanceUnitType for the canonical symbol set.
- https://www.iau.org/static/resolutions/IAU2012_English.pdf (IAU 2012 B2 - astronomical unit, symbol "au")
- https://en.wikipedia.org/wiki/Light-year (Light-year; Julian-year convention)
- https://en.wikipedia.org/wiki/Parsec (Parsec definition)