Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

77 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

bmi.calc

bmi.calc is a Body Mass Index (BMI) calculator project consisting of a web application and a command-line interface (CLI), both using the standard World Health Organization (WHO) BMI formula.

The project focuses on correctness, simplicity, and reusable core calculation logic shared across applications.

πŸ’š Calculate your BMI now!


Body Mass Index Formula

BMI is calculated using the global standard formula:

Β  Β  Β  $BMI = weight\ (kg)\ /\ (height\ (m))^2$

Example:
A 60 kg person with height 165 cm (1.65 m) will resulting: 22.04 BMI (healthy weight)

Note

Height values entered in centimeters are internally normalized to meters before calculation.

Body Mass Index Categories

Category BMI Range
Underweight < 18.5
Healthy 18.5 - 24.9
Overweight 25 - 29.9
Obesity β‰₯ 30

Tip

In web app, the categories are displayed as sidebar (for desktop).

In CLI app, the categories are displayed as table with colored texts and can be shown using command as below:

bmi categories

Featured Applications

Web App

A simple browser-based BMI calculator that allows users to:

  • Enter weight in kilograms (kg)
  • Enter height in centimeters (cm) or meters (m)
  • Instantly calculate BMI
  • View BMI categories based on WHO classification

For more details about the web app, visit here.

Command-Line App

A lightweight command-line tool designed for quick BMI calculations and scripting:

  • Calculate BMI directly from terminal
  • Support metric units (centimeters and meters) using -u option
  • Optional colored output
  • JSON output support for automation
  • View BMI categories based on WHO classification

For more details about the CLI app, visit here.

Need installation guide? Read here.

See examples
bmi calc 80 175
# OR:
bmi -w 80 -h 175

Output:

 BMI Result
 ──────────
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ BMI      β”‚ Category           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 26.12    β”‚ Overweight         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

 BMI Classification
 ──────────────────
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Category     β”‚ BMI Range          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Underweight  β”‚ < 18.5             β”‚
β”‚ Healthy      β”‚ 18.5 - 24.9        β”‚
β”‚ *Overweight  β”‚ 25 - 29.9          β”‚
β”‚ Obesity      β”‚ β‰₯ 30               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Result in JSON format:

bmi calc 80 175 --json

Output:

{
  "bmi": "26.12",
  "category": "Overweight"
}

Project Architecture

                                     β”Œβ”€ CLI-based App
                                     β”‚
              β”Œβ”€ Logic Core          β”‚
              β”‚                  <apps/cli>
              β”‚          β”Œβ”€β”€β”€β”€  @bmi-calc/cli
       @bmi-calc/core  ───
       <packages/core>   └────  @bmi-calc/web
                                 <apps/web>
                                     β”‚
                                     β”‚
                      Web-based App β”€β”˜
  • @bmi-calc/core 👒 Not an app, but core library. Contains logic core for these two applications.
  • @bmi-calc/cli 👒 A simple command-line interface app to calculate BMI.
  • @bmi-calc/web 👒 A web application provides BMI calculation with ease and fast UI response.

Development

Installation

bun install

Build Apps

Build CLI App

bun @cli build

Build Web App

Build for Development:

bun @web build

Build for Production:

BASE_URL="/bmi.calc/" bun @web build

Caution

Specify the BASE_URL only if deploying the web app to a subpath (e.g., GitHub Pages).

Build All at Once

bun @all build

Packing Applications

Important

The packaging process only applies to @bmi-calc/cli. The web application (@bmi-calc/web) is built and bundled separately using Vue and Vite.

Caution

The script file is still experimental.

The packaging process is not equivalent to a standard bun pm pack execution due to the project’s architecture and custom bundling requirements. Use the provided script instead:

bun run pack cli --verbose

Or:

bash ./scripts/pack.sh cli --verbose

Tip

Recommended to always run the script with --verbose flag to see what the script is doing.

If you want to know what commands are executed inside the script, you can set XTRACE=1 before the command.
For instance:

XTRACE=1 bun run pack cli --verbose

Why not using bun pm pack or npm pack directly?

In this project architecture, the CLI depends on a locally bundled core package instead of pulling it from a registry. Because of this, the normal packing mechanisms (bun pm pack or npm pack) are not suitable since they are designed for publishing workflows, not for selective in-repo packaging.

The goal of this step is to replicate the behavior of the files field in package.json, but in reverse: instead of defining what to include during publish time, we remove everything except the required runtime assets. This ensures the bundled core remains minimal while still being fully functional.

This approach is necessary because:

  • The core package is consumed as a local dependency during build time
  • We only need compiled assets (such as dist/, type definitions, and essential metadata)
  • Development files (tests, configs, sources, temporary build artifacts) would unnecessarily increase bundle size
  • bun pm pack / npm pack would require creating an intermediate tarball, which does not fit this workflow
  • The project uses a custom packaging pipeline rather than a registry-based distribution model

The cleanup logic will restores the core package to its original state. Any stashed changes will be applied back after the tarball is created.


Testing

bun @all test

Lint with ESLint

bun @all lint

Format using Prettier

bun format

License

Licensed under MIT license.

About

A minimal and accurate BMI calculator based on WHO standards.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages