size

Simple PHP helper to convert bytes to different sizes

MIT License

Downloads
642
Stars
46
Committers
2

Size

🧮 A super simple helper package for converting between different byte units.

composer require aschmelyun/size

Requirements

  • PHP 7.4 or higher

Usage

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

Tests

Size comes with a small suite of tests powered by Pest. To run them, clone this repository and then use:

./vendor/bin/pest

Contact Info

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.

License

The MIT License (MIT). See LICENSE.md for more details.