nutrition
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -1,2 +0,2 @@ | ||
"use strict"; | ||
'use strict'; | ||
@@ -11,21 +11,30 @@ Object.defineProperty(exports, "__esModule", { | ||
* @param {boolean} [eng = false] | ||
* @returns {int} | ||
* @returns {float} | ||
*/ | ||
/* | ||
* English BMI Formula: | ||
* BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703 | ||
* Metric BMI Formula: | ||
* BMI = ( Weight in Kilograms / ( Height in meters x Height in meters ) ) | ||
*/ | ||
var bmi = exports.bmi = function bmi() { | ||
var weigth = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; | ||
var height = arguments.length <= 1 || arguments[1] === undefined ? 1 : arguments[1]; | ||
var eng = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; | ||
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
/* | ||
English BMI Formula | ||
BMI = ( Weight in Pounds / ( Height in inches x Height in inches ) ) x 703 | ||
Metric BMI Formula | ||
BMI = ( Weight in Kilograms / ( Height in Centimeters x Height in Centimeters ) ) | ||
*/ | ||
var result = weigth / (height * height); | ||
var _ref$weight = _ref.weight; | ||
var weight = _ref$weight === undefined ? 0 : _ref$weight; | ||
var _ref$height = _ref.height; | ||
var height = _ref$height === undefined ? 1 : _ref$height; | ||
var _ref$eng = _ref.eng; | ||
var eng = _ref$eng === undefined ? false : _ref$eng; | ||
if (typeof weight !== 'number' || typeof height !== 'number' || typeof eng !== 'boolean') { | ||
return 0; | ||
} | ||
var result = weight / (height * height); | ||
if (eng) { | ||
result = result * 703; | ||
} | ||
result = +result.toFixed(2); | ||
result = result > 0 ? +result.toFixed(2) : 0; | ||
@@ -32,0 +41,0 @@ return result; |
@@ -25,2 +25,4 @@ 'use strict'; | ||
return _constants.MORBID_OBESE; | ||
} else { | ||
return _constants.UNDERWEIGHT; | ||
} | ||
@@ -34,13 +36,13 @@ }; /** | ||
/* | ||
Weight classification based on BMI | ||
- Underweight: < 18.5 | ||
- Normal weight: 18.5 - 24.9 | ||
- Overweight: 25 - 29.9 | ||
- Obese Class 1: 30 - 34.99 | ||
- Obese Class 2: 35 - 39.99 | ||
- Morbid Obese: >= 40 | ||
* | ||
* Weight classification based on BMI | ||
* | ||
* - Underweight: < 18.5 | ||
* - Normal weight: 18.5 - 24.9 | ||
* - Overweight: 25 - 29.9 | ||
* - Obese Class 1: 30 - 34.99 | ||
* - Obese Class 2: 35 - 39.99 | ||
* - Morbid Obese: >= 40 | ||
* | ||
*/ | ||
//# sourceMappingURL=bmiClass.js.map |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.bmiClass = exports.bmi = undefined; | ||
exports.definitions = exports.dailyCalories = exports.bmr = exports.bmiClass = exports.bmi = undefined; | ||
@@ -13,7 +13,13 @@ var _bmi = require('./core/bmi'); | ||
/* | ||
Export for ES5 | ||
*/ | ||
var _bmr = require('./core/bmr'); | ||
var _dailyCalories = require('./core/dailyCalories'); | ||
var _definitions = require('./core/definitions'); | ||
exports.bmi = _bmi.bmi; | ||
exports.bmiClass = _bmiClass.bmiClass; | ||
exports.bmr = _bmr.bmr; | ||
exports.dailyCalories = _dailyCalories.dailyCalories; | ||
exports.definitions = _definitions.definitions; | ||
@@ -23,4 +29,7 @@ | ||
bmi: _bmi.bmi, | ||
bmiClass: _bmiClass.bmiClass | ||
bmiClass: _bmiClass.bmiClass, | ||
bmr: _bmr.bmr, | ||
dailyCalories: _dailyCalories.dailyCalories, | ||
definitions: _definitions.definitions | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,3 @@ 'use strict'; | ||
}); | ||
// BMI Classes | ||
var UNDERWEIGHT = 'Underweight'; | ||
@@ -13,2 +14,8 @@ var NORMAL = 'Normal'; | ||
var MORBID_OBESE = 'Morbid Obesity'; | ||
// Exercise frequency | ||
var NO_EXERCISE = 'No'; | ||
var LIGHT_EXERCISE = 'Light'; | ||
var MODERATE_EXERCISE = 'Moderate'; | ||
var HEAVY_EXERCISE = 'Heavy'; | ||
var EXTRA_HEAVY_EXERCISE = 'Full'; | ||
@@ -21,2 +28,7 @@ exports.UNDERWEIGHT = UNDERWEIGHT; | ||
exports.MORBID_OBESE = MORBID_OBESE; | ||
exports.NO_EXERCISE = NO_EXERCISE; | ||
exports.LIGHT_EXERCISE = LIGHT_EXERCISE; | ||
exports.MODERATE_EXERCISE = MODERATE_EXERCISE; | ||
exports.HEAVY_EXERCISE = HEAVY_EXERCISE; | ||
exports.EXTRA_HEAVY_EXERCISE = EXTRA_HEAVY_EXERCISE; | ||
//# sourceMappingURL=constants.js.map |
{ | ||
"name": "nutrition", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Simple nutrition facts wrapper", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -30,17 +30,57 @@ | ||
#### `bmi(weight, height, eng)` | ||
#### `bmi(opts)` | ||
If eng (for English BMI style) is true then: | ||
BMI (Body Mass Index) is a measurement of body fat based on height and weight that applies to both men and women. It can be used to indicate if you are overweight, obese, underweight or normal. | ||
- **weight** is used in pounds, otherwise in kilograms. | ||
- **height** is used in inches, otherwise in meters. | ||
`opts` is an object with properties containing formula values | ||
The following arguments are expected: | ||
- **weight** : Subject weight (default is kilograms) | ||
- **height** : Subject height (default is meters) | ||
- **eng** : | ||
- If true then **weight** is used in pounds, otherwise in kilograms. | ||
- If true then **height** is used in inches, otherwise in meters. | ||
#### `bmiClass(bmi)` | ||
Returns the class for the bmi value. Possible results are: | ||
Returns the class from Body Mass Index value. Possible results are: | ||
- Underweight, Normal, Overweight, Obese 1 Class, Obese 2 Class, Morbid Obesity | ||
- Underweight, Normal, Overweight, Obese Class 1, Obese Class 2, Morbid Obesity | ||
#### `bmr(opts)` | ||
BMR (Basal Metabolic Rate) is the amount of energy expended while at rest in a neutrally temperate environment. | ||
`opts` is an object with properties containing formula values | ||
The following arguments are expected: | ||
- **weight** : Weight in kilograms | ||
- **height** : Height in meters | ||
- **age** : Age in years | ||
- **woman** : True if subject is a woman, False if men. (Default is true) | ||
#### `dailyCalories(opts)` | ||
This method also know as the Harris–Benedict equation is a method used to estimate individual's daily kilocalorie requirements based on a basal metabolic rate (BMR). | ||
`opts` is an object with properties containing formula values | ||
The following arguments are expected: | ||
- **bmr** : Float obtained from bmr method | ||
- **exerciseType** : Exercise frequency. Use one of the following options: | ||
- 'No' if little to no exercise | ||
- 'Light' if light exercise (1-3 days per week) | ||
- 'Moderate' if medium exercise (3-5 days per week) | ||
- 'Heavy' if heavy exercise (6-7 days per week) | ||
- 'Full' if extra heavy exercise (twice per day) | ||
## Next steps | ||
@@ -47,0 +87,0 @@ |
@@ -6,5 +6,7 @@ import * as nutrition from '../lib/' | ||
it('should calculate BMI using common formula convention', function (done) { | ||
console.log('nutr') | ||
console.log(nutrition) | ||
expect(nutrition.bmi(65, 1.75)).to.equal(21.22) | ||
const opts = { | ||
weight: 65, | ||
height: 1.75 | ||
} | ||
expect(nutrition.bmi(opts)).to.equal(21.22) | ||
done() | ||
@@ -14,5 +16,21 @@ }) | ||
it('should calculate BMI using English formula convention', function (done) { | ||
expect(nutrition.bmi(143, 69, true)).to.equal(21.12) | ||
const opts = { | ||
weight: 143, | ||
height: 69, | ||
eng: true | ||
} | ||
expect(nutrition.bmi(opts)).to.equal(21.12) | ||
done() | ||
}) | ||
it('should work with undefined values', function (done) { | ||
expect(nutrition.bmi(undefined)).to.equal(0) | ||
done() | ||
}) | ||
it('should work with different types', function (done) { | ||
expect(nutrition.bmi('')).to.equal(0) | ||
expect(nutrition.bmi({})).to.equal(0) | ||
done() | ||
}) | ||
}) |
@@ -48,2 +48,11 @@ import * as nutrition from '../lib/' | ||
}) | ||
it('should work with null and special values', function (done) { | ||
expect(nutrition.bmiClass(null)).to.equal(UNDERWEIGHT) | ||
expect(nutrition.bmiClass(undefined)).to.equal(UNDERWEIGHT) | ||
expect(nutrition.bmiClass()).to.equal(UNDERWEIGHT) | ||
expect(nutrition.bmiClass(4)).to.equal(UNDERWEIGHT) | ||
expect(nutrition.bmiClass({})).to.equal(UNDERWEIGHT) | ||
done() | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
27645
28
385
99
1