Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Byte Unit Converter Laravel Package

open-southeners/byte-unit-converter

PHP 8.1+ utility to convert byte sizes between multiple units with no dependencies. Inspired by macOS ByteCountFormatter, it helps format and convert storage values consistently for apps and libraries.

View on GitHub
Deep Wiki
Context7
3.0.0

Added

  • Introducing operations with add, sub and subtract (object bytes still immutable, so new instance of the object will be returned on each operation)

Changed

  • Breakchange: Refactor asRound method now accepts integer and boolean (default now is round up to 2 decimal positions if possible).
2.2.0

Added

  • ByteUnitConverter::numberFormat() static method to be reused within library (although can be used externally)

Changed

  • ByteUnitConverter::new() method now accepts strings or integers as input argument
  • ByteUnitConverter::from() method now accepts strings, floats or integers as first input argument

Fixed

  • ByteUnitConverter::asRound() method now returns zero (0) results with decimals only if results are 0
2.1.0

Added

  • ByteUnitConverter::nearestUnit() method to convert to nearest byte unit (and metric system):
(string) ByteUnitConverter::new("1024")->nearestUnit(MetricSystem::Binary); // 1 KiB
(string) ByteUnitConverter::new("500")->nearestUnit(stoppingAt: ByteUnit::KB); // 0.50 KB
2.0.1

Fixed

  • Conversion to bytes doesn't give decimals
2.0.0

Added

  • OpenSoutheners\ByteUnitConverter\MetricSystem enum for decimal or binary metric systems
  • OpenSoutheners\ByteUnitConverter\DataUnit enum for bytes or bits data units
  • In order to support long numbers most-precisive operations now this library requires BCMath PHP extension
  • ByteUnitConverter::toArray method to serialise to array
  • ByteUnitConverter::__toString method to serialise to string with the closest unit appended
  • ByteUnitConverter::__serialize & ByteUnitConverter::__deserialize methods to object serialization and deserialization
  • ByteUnit::lowerThan method to check current unit lower than specified (opposite than already available greaterThan)
  • ByteUnitConverter::new convenience method to create an instance of ByteUnitConverter class
  • ByteUnitConverter::usingBits & ByteUnitConverter::usingBytes to switch data units (using bytes by default)
  • ByteUnitConverter::asRound while precision method only operates during decimal conversions, this method will return a round number with no decimals (defaulted to false). E.g:
(string) ByteUnitConverter::new('1924')->toKiB(); // "1.87 KiB"
(string) ByteUnitConverter::new('1924')->asRound()->toKiB(); // "2 KiB"

Fixed

  • Support to long numbers (floats or integers on PHP must be strings)
  • Working with conversions sometimes returns float numbers when integers were the only allowed
  • Correctness in all conversions and comparisons between different systems (decimal to binary, bytes to bits...)

Changed

  • OpenSoutheners\ByteUnitConverter\DecimalByteUnit & OpenSoutheners\ByteUnitConverter\BinaryByteUnit replaced by OpenSoutheners\ByteUnitConverter\ByteUnit
  • Precision argument to from and toBytesFromUnit methods
  • to* methods (toTB, toGB, toMB, etc...) now returns instance instead of number. Use the following to get it casted to a string:
(string) ByteUnitConverter::new('1024')->toKiB(); // "1.00 KiB"

Removed

  • ByteUnitConverter::conversion static method (simplified to ByteUnitConverter::new()->to...)
  • ByteUnitConverter::toBitsFromUnit static method (we only use bytes as a starter, can switch to bits while having an instance but not before)
1.0.0

Added

  • Initial release!
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle