Skip to content

Main content

Convert Mass Source Code

Browse the implementation files for Convert Mass.
@tool.io/tools/convert/mass source ↗
tool.ts typescript
import { convertMass as convertPortableMass } from '@tool.io/tools/convert/mass';
import { measureFactorOptions } from '../tool';
import { measureFactors } from './factors';

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

export const Tool: TypeTool = {
	name: 'Convert Mass',
	slug: 'convert/mass',
	tool: convertMass,
	intro:
		'Convert mass values between SI, US customary, imperial, scientific, and astronomical units.',
	i: [
		{
			example: '1',
			id: 'value',
			label: 'Value',
			placeholder: '1',
			type: 'number',
			valueType: { format: 'mass', type: 'number' }
		},
		{
			example: 'lb',
			id: 'fromUnit',
			label: 'From',
			placeholder: 'Select the source mass unit',
			options: measureFactorOptions(measureFactors, 'lb'),
			type: 'select',
			valueType: { format: 'mass-unit', type: 'string' },
			value: 'lb'
		},
		{
			example: 'kg',
			id: 'toUnit',
			label: 'To',
			placeholder: 'Select the destination mass unit',
			options: measureFactorOptions(measureFactors, 'kg'),
			type: 'select',
			valueType: { format: 'mass-unit', type: 'string' },
			value: 'kg'
		}
	],
	o: [
		{
			example: '0.45359237',
			id: 'value',
			label: 'Mass',
			placeholder: 'Converted mass',
			render: 'textarea',
			type: 'number',
			valueType: { format: 'mass', type: 'number' }
		}
	],
	swap: {
		inputs: [1, 2],
		name: 'Swap mass units',
		state: false
	},
	alternative: [
		{ title: 'Convert length', url: '/convert/length' }
	],
	cite: [
		{
			title: 'SI base units — BIPM',
			url: 'https://www.bipm.org/en/measurement-units/si-base-units'
		}
	]
};

export default Tool;

Description

Browse the implementation files for Convert Mass.

References

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

Similar or alternative tools