( value: number, fromUnit: string, toUnit: string )
| 377 | 'Gy', |
| 378 | 'kat', |
| 379 | ].map((unit) => [UNIT_TABLE[unit].dimension.join(','), unit]) |
| 380 | ); |
| 381 | |
| 382 | /** |
| 383 | * Search for a named derived SI unit that matches the given dimension vector |
| 384 | * and has scale=1. |
| 385 | * |
| 386 | * Returns the unit symbol (e.g., 'N', 'J', 'W') or `null` if no match. |
| 387 | */ |
| 388 | export function findNamedUnit(dim: DimensionVector): string | null { |
| 389 | return NAMED_UNIT_BY_DIMENSION.get(dim.join(',')) ?? null; |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * Convert a numeric `value` from `fromUnit` to `toUnit`. |
| 394 | * |
| 395 | * Returns the converted value, or `null` when the units are unknown or |
| 396 | * dimensionally incompatible. |
| 397 | * |
| 398 | * Handles both linear conversions (most units) and affine conversions |
| 399 | * (degC, degF) via the optional `offset` field. |
| 400 | */ |
| 401 | export function convertUnit( |
no test coverage detected