fabyo0 / weight-conversion
A simple and flexible weight conversion package for PHP
Fund package maintenance!
v1.1.0
2025-12-23 18:10 UTC
Requires
- php: ^8.2
Requires (Dev)
- pestphp/pest: ^3.0
- spatie/ray: ^1.28
This package is auto-updated.
Last update: 2026-03-30 01:35:44 UTC
README
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.