Bookmark this: tool.io/convert/density/source-code
Convert Density Source Code
Browse the implementation files for Convert Density.tool.ts typescript
import { convertDensity as convertPortableDensity } from '@tool.io/tools/convert/density';
import { measureFactorOptions } from '../tool';
import { measureFactors } from './factors';
export const convertDensity = (
value: number,
from: string,
to: string
) => convertPortableDensity(value, from, to) ?? '';
export const Tool: TypeTool = {
name: 'Convert Density',
slug: 'convert/density',
tool: convertDensity,
intro:
'Convert mass density between metric, US customary, and imperial mass-per-volume units.',
i: [
{
example: '1',
label: 'Value',
placeholder: '1',
type: 'number'
},
{
example: 'g/cm3',
label: 'From',
placeholder: 'Select the source density unit',
options: measureFactorOptions(measureFactors, 'g/cm3'),
type: 'select',
value: 'g/cm3'
},
{
example: 'lb/ft3',
label: 'To',
placeholder: 'Select the destination density unit',
options: measureFactorOptions(measureFactors, 'lb/ft3'),
type: 'select',
value: 'lb/ft3'
}
],
o: [
{
example: '62.4279605761',
label: 'Density',
placeholder: 'Converted density',
render: 'textarea',
type: 'number'
}
],
swap: {
inputs: [1, 2],
name: 'Swap density units',
state: false
},
alternative: [
{ title: 'Convert mass', url: '/convert/mass' },
{ title: 'Convert volume', url: '/convert/volume' }
],
cite: [
{
title: 'Density — Wikipedia',
url: 'https://en.wikipedia.org/wiki/Density'
},
{
title: 'NIST Guide to SI conversion factors',
url: 'https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors'
}
]
};
export default Tool;
Description
Browse the implementation files for Convert Density.