Skip to content

Main content

Cloud Computing Cost Calculator Source Code

Browse the implementation files for Cloud Computing Cost Calculator.
@tool.io/tools/cost/cloud-computing source ↗
tool.ts typescript
import {
	CURRENCY_OPTIONS,
	formatCostSummary,
	formatMoney,
	parseCurrency,
	parseNonnegative,
	parsePositive
} from '../calculation';
import { calculateCloudComputingCost } from '@tool.io/tools/cost/cloud-computing';

export const cloudComputingCost = (
	currencyInput: unknown,
	instanceRateInput: unknown,
	hoursInput: unknown,
	instancesInput: unknown,
	storageInput: unknown,
	storageRateInput: unknown,
	egressInput: unknown,
	egressRateInput: unknown
): string => {
	const currency = parseCurrency(currencyInput);
	const instanceRate = parseNonnegative(instanceRateInput);
	const hours = parseNonnegative(hoursInput);
	const instances = parsePositive(instancesInput);
	const storage = parseNonnegative(storageInput);
	const storageRate = parseNonnegative(storageRateInput);
	const egress = parseNonnegative(egressInput);
	const egressRate = parseNonnegative(egressRateInput);
	if (
		!currency ||
		instanceRate === null ||
		hours === null ||
		instances === null ||
		storage === null ||
		storageRate === null ||
		egress === null ||
		egressRate === null
	)
		return '';
	const result = calculateCloudComputingCost(
		instanceRate,
		hours,
		instances,
		storage,
		storageRate,
		egress,
		egressRate,
		currency
	);
	if (!result) return '';
	return formatCostSummary([
		['Compute', formatMoney(result.computeCost, currency)],
		['Storage', formatMoney(result.storageCost, currency)],
		['Data transfer', formatMoney(result.egressCost, currency)],
		['Monthly total', formatMoney(result.monthlyTotal, currency)],
		['Yearly total', formatMoney(result.yearlyTotal, currency)]
	]);
};

export const Tool: TypeTool = {
	name: 'Cloud Computing Cost Calculator',
	slug: 'cost/cloud-computing',
	intro:
		'Estimate monthly and yearly cloud costs from compute time, storage, and outbound data transfer.',
	tool: cloudComputingCost,
	i: [
		{
			example: 'USD',
			label: 'Currency',
			options: CURRENCY_OPTIONS,
			placeholder: 'Select currency',
			type: 'select'
		},
		{
			example: '0.05',
			label: 'Instance Price per Hour',
			placeholder: 'Hourly compute price',
			type: 'number'
		},
		{
			example: '730',
			label: 'Instance Hours',
			placeholder: 'Hours per month',
			type: 'number'
		},
		{
			example: '1',
			label: 'Instances',
			placeholder: 'Instance count',
			type: 'number'
		},
		{
			example: '100',
			label: 'Storage (GB)',
			placeholder: 'Stored gigabytes',
			type: 'number'
		},
		{
			example: '0.023',
			label: 'Storage Price per GB',
			placeholder: 'Monthly storage rate',
			type: 'number'
		},
		{
			example: '50',
			label: 'Outbound Transfer (GB)',
			placeholder: 'Monthly outbound data',
			type: 'number'
		},
		{
			example: '0.09',
			label: 'Transfer Price per GB',
			placeholder: 'Outbound transfer rate',
			type: 'number'
		}
	],
	o: [
		{
			example:
				'Compute: $36.50\nStorage: $2.30\nData transfer: $4.50\nMonthly total: $43.30\nYearly total: $519.60',
			label: 'Cloud Cost',
			placeholder: 'Cloud costs will appear here...',
			render: 'textarea',
			type: 'text'
		}
	],
	alternative: [
		{
			title: 'Data Storage Cost Calculator',
			url: '/cost/data-storage'
		},
		{ title: 'API Cost Calculator', url: '/cost/api' }
	],
	cite: [
		{
			title: 'Cloud computing - Wikipedia',
			url: 'https://en.wikipedia.org/wiki/Cloud_computing'
		}
	]
};
export default Tool;

Description

Browse the implementation files for Cloud Computing Cost Calculator.

References

  1. Tool.io on GitHub
  2. Tool.io TypeScript tools library

Similar or alternative tools