MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / convert

Function convert

plugins/units.js:123–137  ·  view source on GitHub ↗
(value, from, to)

Source from the content-addressed store, hash-verified

121 return celsius + 273.15; // kelvin
122}
123function 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}
138function formatNumber(n) {
139 if (Math.abs(n) < 0.0001 || Math.abs(n) >= 1e12)
140 return n.toExponential(4);

Callers 1

handlerFunction · 0.85

Calls 1

convertTemperatureFunction · 0.85

Tested by

no test coverage detected