- Is spe/filesize-extension-bundle a Laravel package?
- No. Despite being installable via Composer, it is a Symfony bundle that provides a Twig extension for formatting file sizes. The -bundle suffix and twig/twig dependency are the signals. It will not auto-register a Laravel service provider or expose a Blade directive.
- Can I install spe/filesize-extension-bundle in a Laravel app?
- Composer may resolve it, but it is not a Laravel package and will not integrate natively. The practical options are adding Twig to Laravel, which is not recommended, or using the package as reference source and porting its logic into a Blade directive or a Number/Str macro. For most Laravel apps, Laravel's built-in Number::fileSize() is the better dependency-free choice.
- How do I use the filesize Twig filter in Symfony?
- Install it with Composer and register the bundle, or rely on Symfony Flex auto-registration. Then apply the package's filesize filter to a byte value in a Twig template, for example a variable holding an upload size. Check the README for the exact filter name, argument order, and any precision options.
- Does this package provide a Blade directive for Laravel?
- No. It is a Twig extension for Symfony and does not ship a Blade directive, facade, config file, or Laravel service provider. Using it in Blade would require a custom adapter or porting the formatting logic. Laravel 10.x+ already provides Number::fileSize() for this use case.
- What Laravel version includes Number::fileSize()?
- Laravel 10.x and later include Number::fileSize() as part of the Number helper. It formats a byte count into a human-readable file size string. For older Laravel versions, use a small custom helper or macro instead of adding a Symfony bundle.
- What is the best way to format file sizes in Laravel?
- On Laravel 10.x+, call Number::fileSize($bytes) in your controller, model accessor, or Blade view. If you need a specific unit convention, rounding, or localization, wrap it in your own helper so the behavior is explicit and tested. Avoid pulling in a Symfony-only Twig bundle just for this formatting concern.
- Does the filter use 1024 or 1000 when converting bytes to KB?
- The provided metadata does not specify the unit convention, so verify it in the source before relying on it. Human-readable formatting has real choices: base-2 (1024, KiB-style) versus base-10 (1000, kB-style), plus rounding and precision at boundaries. If your UI or reporting requires a specific convention, test the filter or implement the logic yourself.
- Is spe/filesize-extension-bundle actively maintained?
- The available signal is weak: roughly 11 stars and 0 dependents, with no downstream constituency to notice breakage. Check the repository for last commit date, open issues, tagged releases, and CI status before adopting. Because the logic is small, budget for forking or vendoring the file if constraints drift.
- What are alternatives to this Twig filesize extension?
- In Laravel, use Number::fileSize() on Laravel 10.x+ or a small custom helper. In Symfony/Twig, use Symfony format_file_size-style helpers or a custom Twig extension. In any stack, a ten-line helper function is often enough and gives you full control over units, rounding, and localization.
- Does the filter handle zero bytes, exactly 1024, and negative values?
- Test coverage is unknown from the metadata, so those edge cases are not guaranteed. A filter without tests leaves zero, sub-unit, boundary, very large, and negative inputs undefined. Before adopting, run your own checks or inspect the source for explicit handling of those cases.