Bookmark this: tool.io/cost/heating/source-code
Heating Cost Calculator Source Code
Browse the implementation files for Heating Cost Calculator.tool.ts typescript
import {
CURRENCY_OPTIONS,
formatCostSummary,
formatMoney,
parseCurrency,
parseNonnegative,
parsePositive
} from '../calculation';
import { calculateHeatingCost } from '@tool.io/tools/cost/heating';
export const heatingCost = (
currencyInput: unknown,
monthlyEnergyInput: unknown,
rateInput: unknown,
fixedChargeInput: unknown,
monthsInput: unknown
): string => {
const currency = parseCurrency(currencyInput);
const energy = parseNonnegative(monthlyEnergyInput);
const rate = parseNonnegative(rateInput);
const fixed = parseNonnegative(fixedChargeInput);
const months = parsePositive(monthsInput);
if (
!currency ||
energy === null ||
rate === null ||
fixed === null ||
months === null ||
!Number.isInteger(months)
)
return '';
const result = calculateHeatingCost(
energy,
rate,
fixed,
months,
currency
);
if (!result) return '';
return formatCostSummary([
['Energy', `${result.energyKwh.toFixed(2)} kWh`],
['Usage cost', formatMoney(result.usageCost, currency)],
['Fixed charges', formatMoney(result.fixedCharges, currency)],
['Total cost', formatMoney(result.totalCost, currency)]
]);
};
export const Tool: TypeTool = {
name: 'Heating Cost Calculator',
slug: 'cost/heating',
intro:
'Estimate heating energy charges and fixed service fees over one or more months.',
tool: heatingCost,
i: [
{
example: 'USD',
label: 'Currency',
options: CURRENCY_OPTIONS,
placeholder: 'Select currency',
type: 'select'
},
{
example: '800',
label: 'Energy per Month (kWh)',
placeholder: 'Monthly heating energy',
type: 'number'
},
{
example: '0.12',
label: 'Price per kWh',
placeholder: 'Energy rate',
type: 'number'
},
{
example: '15',
label: 'Fixed Monthly Charge',
placeholder: 'Monthly service charge',
type: 'number'
},
{
example: '6',
label: 'Months',
placeholder: 'Billing months',
type: 'number'
}
],
o: [
{
example:
'Energy: 4800.00 kWh\nUsage cost: $576.00\nFixed charges: $90.00\nTotal cost: $666.00',
label: 'Heating Cost',
placeholder: 'Heating costs will appear here...',
render: 'textarea',
type: 'text'
}
],
alternative: [
{
title: 'Electricity Cost Calculator',
url: '/cost/electricity'
}
],
cite: [
{
title: 'Energy cost - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Cost_of_electricity_by_source'
}
]
};
export default Tool;
Description
Browse the implementation files for Heating Cost Calculator.