🧮 A super simple helper package for converting between different byte units.
composer require aschmelyun/size
- PHP 7.4 or higher
Instantiate the class with the data unit you're bringing in. By default, it'll return back the value in bytes. You can then tack on either a method or a property to convert that unit into a different one.
use Aschmelyun\Size\Size;
$bytesInTwoMegabytes = Size::MB(2); // 2097152
$gigabytesInTwoMegabytes = Size::MB(2)->toGB(); // 0.001953125
$kilobytesInTwoMegabytes = Size::MB(2)->KB; // 2048
That's it!
The available properties are: B, KB, MB, GB, TB, PB, EB, ZB, YB
Size comes with a small suite of tests powered by Pest. To run them, clone this repository and then use:
./vendor/bin/pest
Have an issue? Submit it here! Want to get in touch or recommend a feature? Feel free to reach out to me on Twitter for any other questions or comments.
The MIT License (MIT). See LICENSE.md for more details.