UNPKG

@vim-crouwel/cfpc

Version:

TypeScript library for calculating CO2 emissions from food, energy, and transportation

49 lines (48 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.co2PerKwh = co2PerKwh; exports.acUsage = acUsage; exports.acCo2Emissions = acCo2Emissions; exports.dataSource = dataSource; const utils_1 = require("../utils"); const energyData = (0, utils_1.getEnergy)(); /** * Calculate CO2 emissions for energy consumption * @param kwh - Energy consumption in kilowatt hours * @returns CO2 emissions in kg */ function co2PerKwh(kwh) { if (kwh < 0) throw new Error('Energy consumption cannot be negative'); return energyData.co2_per_kwh.value * kwh; } /** * Calculate AC usage for given area and hours * @param m2 - Area in square meters * @param hours - Usage hours * @returns Energy consumption in kWh */ function acUsage(m2, hours) { if (m2 < 0) throw new Error('Area cannot be negative'); if (hours < 0) throw new Error('Hours cannot be negative'); return energyData.ac_usage_per_m2_per_hour_kwh * m2 * hours; } /** * Calculate CO2 emissions for AC usage * @param m2 - Area in square meters * @param hours - Usage hours * @returns CO2 emissions in kg */ function acCo2Emissions(m2, hours) { const kwh = acUsage(m2, hours); return co2PerKwh(kwh); } /** * Get data source for energy emissions * @returns Data source reference */ function dataSource() { return energyData.co2_per_kwh.source; }