1tomany / twig-filesize
A Twig extension to render human readable filesizes
Installs: 106
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/1tomany/twig-filesize
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. Thescalemust be between0and4, inclusive, and has a default value of0.spacer: A string that separates the filesize and unit. Thespaceris an empty string by default.
{{ 851856|filesize(1) # 831.9KB }}
{{ 851856|filesize(0, ' ') # 832 KB }}
Testing
./vendor/bin/phpunit
Credits
License
The MIT License