Download the PHP package victoryoalli/laravel-string-macros without Composer
On this page you can find all versions of the php package victoryoalli/laravel-string-macros. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download victoryoalli/laravel-string-macros
More information about victoryoalli/laravel-string-macros
Files in victoryoalli/laravel-string-macros
Package laravel-string-macros
Short Description A set of useful Laravel string macros
License MIT
Homepage https://github.com/victoryoalli/laravel-string-macros
Informations about the package laravel-string-macros
Laravel String Macros
A collection of useful string macros for Laravel's Str and Stringable classes.
Requirements
| Version | PHP | Laravel |
|---|---|---|
| 2.1+ | ^8.2 | 10.x, 11.x, 12.x |
| 2.0 | ^8.1 | 10.x, 11.x |
| 1.x | ^8.0 | 8.x, 9.x, 10.x |
Installation
Available Macros
All macros are available both as static methods on Str and as fluent methods on Stringable.
initials
Gets the initials of the words you provide. Defaults to 2 initials.
Note: Words are split by spaces, commas, underscores, and hyphens. For example, Jean-Pierre is treated as two words.
interpolate
Replaces ? placeholders with the values you provide.
readingMinutes
Calculates how many minutes it takes to read the text. Accepts HTML (tags are stripped for accurate calculation). Default reading speed is 200 words per minute.
linesCount
Counts the number of lines in a string (splits by \n or \r).
Fluent Chaining
All macros can be chained with other Stringable methods:
Upgrading from v1.x to v2.x
Breaking Changes
Removed Macros
The following macros have been removed because they are now available natively in Laravel 10+:
| Removed Macro | Use Instead | Available Since |
|---|---|---|
Str::human($value) |
Str::headline($value) |
Laravel 9.x |
Str::matches($pattern, $value) |
Str::isMatch($pattern, $value) |
Laravel 10.x |
Migration Examples
Before (v1.x):
After (v2.x) - Use Laravel native methods:
Note: Str::headline() capitalizes each word, while the old Str::human() did not. If you need lowercase output, chain with ->lower():
PHP and Laravel Version Requirements
| Requirement | v1.x | v2.0 | v2.1+ |
|---|---|---|---|
| PHP | ^8.0 | ^8.1 | ^8.2 |
| Laravel | 8.x, 9.x, 10.x | 10.x, 11.x | 10.x, 11.x, 12.x |
Upgrade Steps
-
Update your
composer.jsonor run: -
Search and replace removed macros in your codebase:
-
Replace with native Laravel methods:
Str::human()→Str::headline()Str::matches()→Str::isMatch()->human()→->headline()->matches()→->isMatch()
- Run your tests to ensure everything works correctly.
Testing
Changelog
Please see CHANGELOG for more information about recent changes.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Victor Yoalli
- All Contributors
License
The MIT License (MIT). Please see License File for more information.