Skip to content

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, ly uses the Julian year (consistent with your temporal units).

Typical flow ​

  1. Accept DistanceUnitAliasType | DistanceUnitType at your API boundary.
  2. Normalize to DistanceUnitType with normalizeDistanceUnit from @interstellar-tools/equations, or convert directly with convertDistanceUnit.
  3. 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 ​