定制 xxzeroxx/unit-converter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

PHP Version Packagist Version GitHub Release GitHub License Tests

🚀 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, '', 'l'); // 1000

// Temperature
echo $converter->convertTemperature(0, 'C', 'F'); // 32

// Area
echo $converter->convertArea(1, '', '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!

  1. Fork the project
  2. Create your feature branch
  3. Commit your changes
  4. Push to your branch
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-15