npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dodysat/bmi

v1.0.1

Published

A BMI calculator library following WHO (World Health Organization) standards

Downloads

9

Readme

@dodysat/bmi

A comprehensive BMI (Body Mass Index) calculator library following WHO (World Health Organization) standards. This library provides accurate BMI calculations with proper categorization and health recommendations based on international guidelines.

Features

  • WHO Standard Compliance: Follows World Health Organization BMI categories and thresholds
  • TypeScript Support: Full TypeScript support with comprehensive type definitions
  • Multiple Unit Support: Metric and Imperial unit conversions
  • Health Recommendations: WHO-based health recommendations for each BMI category
  • Input Validation: Robust input validation with helpful error messages
  • Comprehensive Testing: 100% test coverage with edge case handling
  • Multi-Language Support: English and Indonesian localization with easy extensibility

Installation

npm install @dodysat/bmi

Quick Start

import { calculateBMI, BMICategory } from '@dodysat/bmi';

// Calculate BMI for a person (70kg, 1.75m)
const result = calculateBMI({ weight: 70, height: 1.75 });

console.log(`BMI: ${result.bmi}`); // 22.86
console.log(`Category: ${result.categoryName}`); // "Normal Weight"
console.log(`Recommendations:`, result.recommendations);

// With Indonesian localization
const resultId = calculateBMI({ weight: 70, height: 1.75, locale: 'id' });
console.log(`Category: ${resultId.categoryName}`); // "Berat Badan Normal"

API Reference

Main Functions

calculateBMI(input: BMIInput): BMIResult

Calculates BMI using metric units (kilograms and meters).

import { calculateBMI } from '@dodysat/bmi';

const result = calculateBMI({ weight: 70, height: 1.75 });

Parameters:

  • input.weight: Weight in kilograms (positive number)
  • input.height: Height in meters (positive number)
  • input.locale: Locale for localized output (optional, defaults to 'en')

Returns: BMIResult object with BMI value, category, and recommendations

calculateBMISimple(weight: number, height: number, locale?: Locale): BMIResult

Convenience function for calculating BMI with separate parameters.

import { calculateBMISimple } from '@dodysat/bmi';

const result = calculateBMISimple(70, 1.75);
const resultId = calculateBMISimple(70, 1.75, 'id');

calculateBMIImperial(weightInLbs: number, heightInFeet: number, heightInInches?: number, locale?: Locale): BMIResult

Calculates BMI using Imperial units (pounds and feet/inches).

import { calculateBMIImperial } from '@dodysat/bmi';

// 5 feet 9 inches, 154 pounds
const result = calculateBMIImperial(154, 5, 9);
const resultId = calculateBMIImperial(154, 5, 9, 'id');

Utility Functions

cmToMeters(heightInCm: number): number

Converts height from centimeters to meters.

import { cmToMeters } from '@dodysat/bmi';

const heightInMeters = cmToMeters(175); // 1.75

lbsToKg(weightInLbs: number, locale?: Locale): number

Converts weight from pounds to kilograms.

import { lbsToKg } from '@dodysat/bmi';

const weightInKg = lbsToKg(154.32); // 70

Localization Functions

getLocale(locale: Locale): LocaleData

Gets locale data for the specified language.

import { getLocale } from '@dodysat/bmi';

const enLocale = getLocale('en');
const idLocale = getLocale('id');

getSupportedLocales(): Locale[]

Gets all supported locale codes.

import { getSupportedLocales } from '@dodysat/bmi';

const locales = getSupportedLocales(); // ['en', 'id']

isLocaleSupported(locale: string): locale is Locale

Checks if a locale is supported.

import { isLocaleSupported } from '@dodysat/bmi';

if (isLocaleSupported('en')) {
  // English is supported
}

Types and Enums

BMICategory

enum BMICategory {
  UNDERWEIGHT = 'underweight',
  NORMAL_WEIGHT = 'normal_weight',
  OVERWEIGHT = 'overweight',
  OBESE_CLASS_I = 'obese_class_i',
  OBESE_CLASS_II = 'obese_class_ii',
  OBESE_CLASS_III = 'obese_class_iii'
}

BMIResult

interface BMIResult {
  bmi: number;                    // Calculated BMI value
  category: BMICategory;          // WHO BMI category
  categoryName: string;           // Human-readable category name
  range: string;                  // BMI range for the category
  recommendations: string[];      // Health recommendations
}

Locale and LocaleData

type Locale = 'en' | 'id';

interface LocaleData {
  categories: {
    underweight: { name: string; range: string; recommendations: string[] };
    normal_weight: { name: string; range: string; recommendations: string[] };
    overweight: { name: string; range: string; recommendations: string[] };
    obese_class_i: { name: string; range: string; recommendations: string[] };
    obese_class_ii: { name: string; range: string; recommendations: string[] };
    obese_class_iii: { name: string; range: string; recommendations: string[] };
  };
  errors: {
    weight_positive: string;
    height_positive: string;
    height_unrealistic: string;
    weight_unrealistic: string;
    cm_positive: string;
    lbs_positive: string;
  };
  units: {
    kg: string;
    m: string;
    cm: string;
    lbs: string;
    feet: string;
    inches: string;
  };
}

WHO BMI Categories

This library follows the World Health Organization (WHO) BMI classification system:

| Category | BMI Range | Description | |----------|-----------|-------------| | Underweight | < 18.5 | Below healthy weight range | | Normal Weight | 18.5 - 24.9 | Healthy weight range | | Overweight | 25.0 - 29.9 | Above healthy weight range | | Obese Class I | 30.0 - 34.9 | Moderate obesity | | Obese Class II | 35.0 - 39.9 | Severe obesity | | Obese Class III | ≥ 40.0 | Very severe obesity |

Usage Examples

Basic BMI Calculation

import { calculateBMI } from '@dodysat/bmi';

const result = calculateBMI({ weight: 70, height: 1.75 });

console.log(`Your BMI is: ${result.bmi}`);
console.log(`Category: ${result.categoryName}`);
console.log(`Range: ${result.range}`);
console.log('Recommendations:');
result.recommendations.forEach(rec => console.log(`- ${rec}`));

Using Imperial Units

import { calculateBMIImperial } from '@dodysat/bmi';

// Calculate BMI for someone who is 5'9" and 154 lbs
const result = calculateBMIImperial(154, 5, 9);

console.log(`BMI: ${result.bmi}`); // ~22.75
console.log(`Category: ${result.categoryName}`); // "Normal Weight"

Unit Conversions

import { calculateBMI, cmToMeters, lbsToKg } from '@dodysat/bmi';

// Convert from cm and lbs to metric
const heightInMeters = cmToMeters(175); // 1.75
const weightInKg = lbsToKg(154.32); // 70

const result = calculateBMI({ weight: weightInKg, height: heightInMeters });

Localization

The library supports multiple languages. Currently supported: English (en) and Indonesian (id).

import { calculateBMI, getSupportedLocales } from '@dodysat/bmi';

// Check supported locales
const locales = getSupportedLocales(); // ['en', 'id']

// Calculate BMI in English (default)
const resultEn = calculateBMI({ weight: 70, height: 1.75, locale: 'en' });
console.log(resultEn.categoryName); // "Normal Weight"

// Calculate BMI in Indonesian
const resultId = calculateBMI({ weight: 70, height: 1.75, locale: 'id' });
console.log(resultId.categoryName); // "Berat Badan Normal"

// Error messages are also localized
try {
  calculateBMI({ weight: -70, height: 1.75, locale: 'id' });
} catch (error) {
  console.log(error.message); // "Berat badan harus berupa angka positif dalam kilogram"
}

Error Handling

import { calculateBMI } from '@dodysat/bmi';

try {
  const result = calculateBMI({ weight: 70, height: 1.75 });
  console.log(`BMI: ${result.bmi}`);
} catch (error) {
  console.error('BMI calculation error:', error.message);
}

Error Messages

The library provides clear error messages for invalid inputs in multiple languages:

English

  • "Weight must be a positive number in kilograms"
  • "Height must be a positive number in meters"
  • "Height seems unusually high. Please ensure height is in meters, not centimeters"
  • "Weight seems unusually high. Please ensure weight is in kilograms"

Indonesian

  • "Berat badan harus berupa angka positif dalam kilogram"
  • "Tinggi badan harus berupa angka positif dalam meter"
  • "Tinggi badan tampak tidak realistis. Pastikan tinggi dalam meter, bukan sentimeter"
  • "Berat badan tampak tidak realistis. Pastikan berat dalam kilogram"

Development

Building the Library

npm run build

Running Tests

npm test

Running Tests in Watch Mode

npm run test:watch

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Run the test suite
  6. Submit a pull request

License

MIT License - see LICENSE file for details.

References

Support

If you encounter any issues or have questions, please open an issue on GitHub.