UNPKG

heatingpro-efficiency

Version:

Utility functions for MonitoringPro efficiency calculations with flexible unit support (GJ, kWh, MWh)

32 lines (27 loc) 783 B
const toFloatWithDot = (value) => { if (typeof value === "string") { value = value.replace(",", "."); } return parseFloat(value); }; const hasPropertiesAndNotDash = (a, b, key) => a.hasOwnProperty(key) && b.hasOwnProperty(key) && a[key] !== "-" && b[key] !== "-"; const convertHeatToKwh = (value, fromUnit) => { const unit = fromUnit.toLowerCase(); switch (unit) { case "gj": return value * 277.778; // 1 GJ = 277.778 kWh case "kwh": return value; // Already in kWh case "mwh": return value * 1000; // 1 MWh = 1000 kWh default: throw new Error( `Unsupported heat unit: ${fromUnit}. Supported units: GJ, kWh, MWh` ); } }; module.exports = { toFloatWithDot, hasPropertiesAndNotDash, convertHeatToKwh };