Skip to content

Main content

Convert Energy Source Code

Browse the implementation files for Convert Energy.
@tool.io/tools/convert/energy source ↗
tool.ts typescript
import { convertEnergy as convertPortableEnergy } from '@tool.io/tools/convert/energy';
import { measureFactorOptions } from '../tool';
import { measureFactors } from './factors';

export const convertEnergy = (
	value: number,
	from: string,
	to: string
) => convertPortableEnergy(value, from, to) ?? '';

export const Tool: TypeTool = {
	name: 'Convert Energy',
	slug: 'convert/energy',
	tool: convertEnergy,
	intro:
		'Convert energy and work between joules, watt-hours, calories, BTUs, electronvolts, foot-pounds, therms, and large energy equivalents.',
	i: [
		{
			example: '1',
			label: 'Value',
			placeholder: '1',
			type: 'number'
		},
		{
			example: 'kWh',
			label: 'From',
			placeholder: 'Select the source energy unit',
			options: measureFactorOptions(measureFactors, 'kWh'),
			type: 'select',
			value: 'kWh'
		},
		{
			example: 'Btu-IT',
			label: 'To',
			placeholder: 'Select the destination energy unit',
			options: measureFactorOptions(measureFactors, 'Btu-IT'),
			type: 'select',
			value: 'Btu-IT'
		}
	],
	o: [
		{
			example: '3412.141633127942',
			label: 'Energy',
			placeholder: 'Converted energy',
			render: 'textarea',
			type: 'number'
		}
	],
	swap: {
		inputs: [1, 2],
		name: 'Swap energy units',
		state: false
	},
	alternative: [
		{ title: 'Convert mass', url: '/convert/mass' },
		{
			title: 'Convert temperature',
			url: '/convert/temperature'
		},
		{ title: 'Convert time', url: '/convert/time' }
	],
	cite: [
		{
			title: 'NIST Guide to SI conversion factors',
			url: 'https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors'
		},
		{
			title: 'Electron volt-joule relationship — NIST',
			url: 'https://physics.nist.gov/cgi-bin/cuu/Value?evj'
		},
		{
			title: 'Energy — Wikipedia',
			url: 'https://en.wikipedia.org/wiki/Energy'
		}
	]
};

export default Tool;

Description

Browse the implementation files for Convert Energy.

References

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

Similar or alternative tools