Download the PHP package ramazancetinkaya/byte-formatter without Composer
On this page you can find all versions of the php package ramazancetinkaya/byte-formatter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ramazancetinkaya/byte-formatter
More information about ramazancetinkaya/byte-formatter
Files in ramazancetinkaya/byte-formatter
Package byte-formatter
Short Description A modern PHP library for formatting and parsing byte values with precision and flexibility.
License MIT
Homepage https://github.com/ramazancetinkaya/byte-formatter
Informations about the package byte-formatter
Byte Formatter Library
Byte Formatter is your go-to PHP library for converting bytes into human-readable strings and vice versa. Built with modern PHP 8 features, it’s fast, reliable, and developer-friendly—making your life just that little bit easier when handling data sizes.
Report a Bug · New Pull Request
⭐ Show Your Support
If you like this project, give it a ⭐ and share it with your network!
🚀 Features
- 🧠 Smart Formatting: Converts bytes to formats like
10 KiB
or10 KB
. - 🔄 Two-Way Conversion: Parse size strings like
1.5 MB
into bytes. - 🎛️ Customizable Precision: Fine-tune decimal places in formatted outputs.
- ⚙️ Binary & Decimal Prefixes: Switch between 1024 (binary) and 1000 (decimal) systems.
- 💪 Error Resilient: Robust validation and descriptive error handling.
- 📦 Lightweight & Dependency-Free: No external dependencies—just clean, reliable PHP.
📦 Installation
You can install the ByteFormatter
library using Composer. Run the following command in your terminal:
Alternatively, download the source code and include it in your project manually.
Requirements
- PHP 8.0 or higher.
- No additional dependencies.
📖 Usage Examples
1. Basic Formatting
2. Parse Human-Readable Strings
3. Convert Byte Sizes Between Prefix Systems
⚙ Configuration
Option | Description | Default |
---|---|---|
useBinaryPrefix |
Use binary prefixes (1024-based) or decimal (1000) | true |
precision |
Number of decimal places for formatted output | 2 |
📖 Documentation
Public Methods
Method | Description |
---|---|
formatBytes() |
Formats a byte size into a human-readable string. |
parseSize() |
Parses a human-readable size string into bytes. |
convert() |
Converts a size between binary and decimal prefix systems or to a specific unit. |
📂 Project Structure
🛡 Security
This library is designed with security in mind. Input validation and error handling are implemented to prevent misuse. For vulnerabilities, please open an issue.
🤝 Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
📄 License
This project is licensed under the MIT License. See the LICENSE file for more details.