1tomany / twig-filesize
A Twig extension to render human readable filesizes
v0.0.1
2025-05-15 22:28 UTC
Requires
- php: >=8.1
- ext-bcmath: *
- twig/twig: ^3.0|^4.0
Requires (Dev)
- php: >=8.4
- friendsofphp/php-cs-fixer: ^3.75
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
README
This Twig extension allows you to easily convert an integer, in bytes, to a human readable string with the correct unit.
Installation
Install the library with Composer:
composer require 1tomany/twig-filesize
Tag the OneToMany\Twig\FilesizeExtension
as a Twig extension in your services configuration:
services: OneToMany\Twig\MailtoExtension: tags: [twig.extension]
Usage
This extension exposes a single filter named filesize
with the following arguments:
scale
: The number of decimals to display. Thescale
must be between0
and4
, inclusive, and has a default value of0
.spacer
: A string that separates the filesize and unit. Thespacer
is an empty string by default.
{{ 851856|filesize(1) # 831.9KB }} {{ 851856|filesize(0, ' ') # 832 KB }}
Testing
./vendor/bin/phpunit
Credits
License
The MIT License