(value, from, to)
| 121 | return celsius + 273.15; // kelvin |
| 122 | } |
| 123 | function convert(value, from, to) { |
| 124 | from = from.toLowerCase(); |
| 125 | to = to.toLowerCase(); |
| 126 | const cat = UNIT_TO_CATEGORY[from]; |
| 127 | if (!cat || UNIT_TO_CATEGORY[to] !== cat) |
| 128 | return null; |
| 129 | if (cat === 'temperature') { |
| 130 | return { result: convertTemperature(value, from, to), category: cat }; |
| 131 | } |
| 132 | const fromUnit = UNITS[cat][from]; |
| 133 | const toUnit = UNITS[cat][to]; |
| 134 | const base = value * fromUnit.factor; |
| 135 | const result = base / toUnit.factor; |
| 136 | return { result, category: cat }; |
| 137 | } |
| 138 | function formatNumber(n) { |
| 139 | if (Math.abs(n) < 0.0001 || Math.abs(n) >= 1e12) |
| 140 | return n.toExponential(4); |
no test coverage detected