Bookmark this: tool.io/ideal-body-weight/source-code
Ideal body weight Source Code
Browse the implementation files for Ideal body weight.tool.ts typescript
import { calculateIdealBodyWeight } from '@tool.io/tools/ideal-body-weight';
export const idealBodyWeight = (
height: number,
female: boolean,
formula: string
): string => {
if (
!Number.isFinite(height) ||
typeof female !== 'boolean' ||
(formula !== 'devine' && formula !== 'hamwi')
)
return '';
const result = calculateIdealBodyWeight(
height,
female ? 'female' : 'male',
formula
);
return result === null ? '' : result.toPrecision(4);
};
// The tool definition.
export const Tool: TypeTool = {
name: 'Ideal body weight',
slug: 'ideal-body-weight',
intro:
'Calculate your the ideal body weight (IBW) with the Devine formula.',
tool: idealBodyWeight,
i: [
{
example: '180',
label: 'Height',
placeholder: 'Height in cm',
type: 'number'
},
{
//default: 'false',
label: 'Female?',
placeholder: 'Gender',
type: 'switch'
},
{
example: 'Devine',
label: 'Formula',
placeholder: 'Ideal body weight formula',
type: 'select',
options: [
{
value: 'devine',
text: 'Devine formula',
selected: true
},
{
value: 'hamwi',
text: 'Hamwi method'
}
]
}
],
o: [
{
example: '70.8',
label: 'IBW',
placeholder: 'Ideal body weight',
render: 'textarea',
type: 'number'
}
],
// Has 4 different formulas,
// depending on the method.
// equation:
// '$$ idealBodyWeight(\\text{height}, \\text{gender}) \\rightarrow ...$$',
equation: [
{
name: 'Male ideal body weight (Devine)',
eq: '$$ idealBodyWeight(\\text{height}, \\text{gender}) \\rightarrow 50 kg + 0.9 kg * (height (cm) - 152) $$'
},
{
name: 'Female ideal body weight (Devine)',
eq: '$$ idealBodyWeight(\\text{height}, \\text{gender}) \\rightarrow 45.5 kg + 0.9 kg * (height (cm) - 152) $$'
},
{
name: 'Male ideal body weight (Hamwi)',
eq: '$$ idealBodyWeight(\\text{height}, \\text{gender}) \\rightarrow 48 kg + 1.1 kg * (height (cm) - 152) $$'
},
{
name: 'Female ideal body weight (Hamwi)',
eq: '$$ idealBodyWeight(\\text{height}, \\text{gender}) \\rightarrow 45.5 kg + 0.9 kg * (height (cm) - 152) $$'
}
],
alternative: [
{
title: 'Waist to hip calculator',
url: '/waist-to-hip'
},
{
title: 'Body mass index calculator',
url: '/body-mass-index'
}
],
cite: [
{
title: 'Ideal body weight - Wikipedia',
url: 'https://en.wikipedia.org/wiki/Human_body_weight'
}
]
};
export default Tool;
Description
Browse the implementation files for Ideal body weight.