Skip to content

Main content

Feet and Inches Formatter Source Code

Browse the implementation files for Feet and Inches Formatter.
@tool.io/tools/format/feet-and-inches source ↗
tool.ts typescript
import { formatFeetAndInches as formatPortableFeetAndInches } from '@tool.io/tools/format/feet-and-inches';

export const formatFeetAndInches = (input: unknown): string => {
	const total =
		typeof input === 'number'
			? input
			: typeof input === 'string' && input.trim()
				? Number(input)
				: Number.NaN;
	if (!Number.isFinite(total)) return '';

	return formatPortableFeetAndInches(total);
};

export const Tool: TypeTool = {
	name: 'Feet and Inches Formatter',
	slug: 'format/feet-and-inches',
	intro: `Format total inches as human-readable feet and inches such as 5'10".`,
	tool: formatFeetAndInches,
	i: [
		{
			example: '70',
			id: 'inches',
			label: 'Total inches',
			placeholder: '70',
			type: 'number',
			valueType: { format: 'length', type: 'number', unit: 'in' }
		}
	],
	o: [
		{
			example: `5'10"`,
			id: 'value',
			label: 'Feet and inches',
			placeholder: 'Formatted feet and inches',
			render: 'textarea',
			type: 'text',
			valueType: { format: 'feet-and-inches', type: 'string' }
		}
	],
	alternative: [
		{ title: 'Parse Feet and Inches', url: '/parse/feet-and-inches' },
		{ title: 'Convert Length', url: '/convert/length' }
	]
};

export default Tool;

Description

Browse the implementation files for Feet and Inches Formatter.

References

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

Similar or alternative tools