gh-o-st/bytesize
Composer 安装命令:
composer require gh-o-st/bytesize
包简介
A simple conversion library for dealing with digital size units.
README 文档
README
A simple conversion library for dealing with digital size units.
Features
- Comprehensive Unit Support: Supports both IEC and SI units, from bits and bytes up to ronabits and ronabytes.
- Simple API: Offers a straightforward static method to perform conversions without the need to instantiate classes.
Requirements
- PHP ≥ 8.3: Leverages modern PHP features, including enums and strict typing.
- BCMath Extension: Ensure that the
ext-bcmathextension is enabled in your PHP installation.
Installation
Install Bytesize via Composer:
composer require gh-o-st/bytesize
Make sure Composer's autoloader is included in your project:
require 'vendor/autoload.php';
Error Handling
The convert method will throw an InvalidArgumentException in the following cases:
- If the value provided is not numeric.
- If the source or target units are invalid or not supported.
use InvalidArgumentException; try { $result = SizeConverter::convert('abc', SI::BYTE->value, SI::KILOBYTE->value); } catch (InvalidArgumentException $e) { echo $e->getMessage(); }
Supported Units
SI Units
- Bits
band BytesB - Kilobit
Kband KilobyteKB - Megabit
Mband MegabyteMB - Gigabit
Gband GigabyteGB - Terabit
Tband TerabyteTB - Petabit
Pband PetabytePB - Exabit
Eband ExabyteEB - Zetabit
Zband ZetabyteZB - Yotabit
Yband YotabyteYB - Ronabit
Rband RonabyteRB
IEC Units
- Bits
band BytesB - Kibibit
Kiband KibibyteKiB - Mebibit
Miband MebibyteMiB - Gibibit
Giband GibibyteGiB - Tebibit
Tiband TebibyteTiB - Pebibit
Piband PebibytePiB - Exbibit
Eiband ExbibyteEiB - Zebibit
Ziband ZebibyteZiB - Yobibit
Yiband YobibyteYiB - Ronbibit
Riband RonbibyteRiB
Running Tests
To run the included test suite, you'll need to have PHPUnit installed:
composer install --dev vendor/bin/phpunit
License
This project is licensed under the MIT License
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-15