* Helper function to normalize a unit for conversion and formatting * @param {Unit} unit The unit to be normalized * @return {Object} Object with normalized unit and value * @private
(unit, options = {})
| 1193 | * @private |
| 1194 | */ |
| 1195 | function formatBest (unit, options = {}) { |
| 1196 | // Simplfy the unit list, unless it is valueless or was created directly in the |
| 1197 | // constructor or as the result of to or toSI |
| 1198 | const simp = unit.skipAutomaticSimplification || unit.value === null |
| 1199 | ? unit.clone() |
| 1200 | : unit.simplify() |
| 1201 | |
| 1202 | // Apply some custom logic for handling VA and VAR. The goal is to express the value of the unit as a real value, if possible. Otherwise, use a real-valued unit instead of a complex-valued one. |
| 1203 | handleVAandVARUnits(simp) |
| 1204 | // Now apply the best prefix |
| 1205 | // Units must have only one unit and not have the fixPrefix flag set |
| 1206 | applyBestPrefixIfNeeded(simp, options.offset) |
| 1207 | |
| 1208 | const value = simp._denormalize(simp.value) |
| 1209 | const valueStr = (simp.value !== null) ? format(value, options || {}) : '' |
| 1210 | const unitStr = simp.formatUnits() |
| 1211 | return { |
| 1212 | simp, |
| 1213 | valueStr, |
| 1214 | unitStr |
| 1215 | } |
| 1216 | } |
| 1217 | |
| 1218 | /** |
| 1219 | * Helper to handle VA and VAR units |
no test coverage detected
searching dependent graphs…