UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

25 lines 1.52 kB
/** * Format a numeric value paired with a {@link UnitMatrix} into a compact human-readable string * such as `1.3 km/s`, `2.5 N`, or `7 m`. * * The SI prefix (k, M, m, µ, ...) that brings the magnitude of `value` closest to `[1, 1000)` is * selected, then prepended to the unit string. Trailing zeros in the numeric portion are removed. * * Edge cases: * - dimensionless matrices output just the numeric portion plus a prefix (`1.5k`) * - `0` and non-finite values are reported as-is, with no prefix * - the unit and the value are separated by a single space when a unit symbol is present * * Optional named-unit recognition: when `named_units` is provided, the unit portion is rendered * via {@link unit_matrix_to_string} using that registry — so e.g. `1300 V` can be produced * directly instead of `1.3 kkg·m^2/s^3·A`. * * @param {number} value Numeric magnitude in the unit's base form (e.g. 1300 for 1300 m/s). * @param {UnitMatrix} unit_matrix * @param {number} [precision=3] Maximum number of digits after the decimal point. * @param {NamedUnit[]} [named_units] Optional registry of compound-unit symbols. * @param {NamedUnit[]} [dimension_units] Optional override for the per-dimension {@link NamedUnit} mapping; defaults to {@link UNIT_DIMENSION_MAPPING}. * @returns {string} */ export function format_quantity(value: number, unit_matrix: UnitMatrix, precision?: number, named_units?: NamedUnit[], dimension_units?: NamedUnit[]): string; //# sourceMappingURL=format_quantity.d.ts.map