Required and found values as text
64-bitA limit or a measured value in words, such as ≤ 196.85 mm or 863.6–965.2 mm.
text = round(x × 100) ÷ 100, then the unit
The default formatter rounds to 2 decimals in the value's own unit, so a value such as 0.004 m is written as 0 m. The CSV writer in the same file calls this function with the default formatter for the Required and Found columns, so the exported file has the rounded text. A caller can pass its own formatter.
/** A requirement or a found value in words: "≤ 196.85 mm", "863.6–965.2 mm". fmt(value, unit) writes one number. */
export function valueText(v, fmt = (x, u) => String(Math.round(x * 100) / 100) + (u && u !== 'pct' ? ' ' + u : u === 'pct' ? ' %' : '')) {
if (!v) return '';
if (v.op) {
if (v.op === 'between') return fmt(v.value[0], v.unit).replace(/\s*\S+$/, '') + '–' + fmt(v.value[1], v.unit);
return v.op.replace('<=', '≤').replace('>=', '≥') + ' ' + fmt(v.value, v.unit);
}
return v.value === null ? '–' : fmt(v.value, v.unit);
}