xxzeroxx/unit-converter
最新稳定版本:v2.0.0
Composer 安装命令:
composer require xxzeroxx/unit-converter
包简介
PHP library for converting units.
README 文档
README
UnitConverter is a simple and robust PHP library for converting units of measurement. It supports conversions between lengths, masses, volumes, temperatures and areas. Useful in scientific and educational applications, or any project that requires the manipulation of units.
🚀 Features
- Length conversion (mm, cm, m, km)
- Mass conversion (g, kg, t)
- Volume conversion (ml, l, m³)
- Temperature conversion (C, F, K)
- Area conversion (m², cm², km²)
- Simple and intuitive API
- Lightweight and dependency-free
- Fully tested with PHPUnit
- PHP 8+ support
⚠️ Breaking Changes (v2.0.0)
- Dropped support for PHP 7.x
- Minimum required PHP version is now 8.0
📦 Installation
Install via Composer:
composer require xxzeroxx/unit-converter
📖 Usage
require 'vendor/autoload.php'; use UnitConverter\UnitConverter; $converter = new UnitConverter(); // Length echo $converter->convertLength(1, 'km', 'm'); // 1000 // Mass echo $converter->convertMass(1000, 'g', 'kg'); // 1 // Volume echo $converter->convertVolume(1, 'm³', 'l'); // 1000 // Temperature echo $converter->convertTemperature(0, 'C', 'F'); // 32 // Area echo $converter->convertArea(1, 'm²', 'cm²'); // 10000
❗ Error Handling
The library throws exceptions for invalid units:
$converter->convertLength(10, 'invalid', 'm');
🧪 Running Tests
composer test
📜 Changelog
See CHANGELOG.md for version history.
🤝 Contributing
Contributions are welcome!
- Fork the project
- Create your feature branch
- Commit your changes
- Push to your branch
- Open a Pull Request
📄 License
This project is licensed under the MIT License.
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-05-15