fabyo0/weight-conversion

A simple and flexible weight conversion package for PHP

Maintainers

Package info

github.com/fabyo0/weight-conversion

pkg:composer/fabyo0/weight-conversion

Fund package maintenance!

Fabyo

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 3

v1.1.0 2025-12-23 18:10 UTC

README

Latest Version on Packagist Tests Total Downloads

A simple and flexible weight conversion package for PHP. Convert between kilograms, grams, pounds, ounces and more with ease.

Note: This package was developed as a learning project, following the Spatie Laravel Package Training course as a reference.

Installation

You can install the package via composer:

composer require fabyo0/weight-conversion

Usage

use Fabyo0\WeightConversion\WeightConversion;

// Static factory methods
$weight = WeightConversion::fromKilograms(100);
$weight = WeightConversion::fromPounds(220);

// Method chaining
$total = WeightConversion::fromKilograms(50)
    ->add(25, 'kg')
    ->subtract(10, 'lb')
    ->toKilograms();

// Comparison methods
$weight1 = WeightConversion::fromKilograms(100);
$weight2 = WeightConversion::fromPounds(220);

$weight1->isGreaterThan($weight2); // true/false

// Formatting output
$weight = new WeightConversion(75.5, 'kg');
echo $weight->format(2); // "75.50 kg"

// Get supported units
WeightConversion::getSupportedUnits(); // ['kg', 'g', 'mg', 'lb', 'oz', 't']

Supported Units

Unit Symbol
Kilogram kg
Gram g
Milligram mg
Pound lb
Ounce oz
Ton (Metric) t

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Security Vulnerabilities

If you discover a security vulnerability, please send an email to emredikmen002@gmail.com.

Credits

License

The MIT License (MIT). Please see License File for more information.