victoryoalli / laravel-string-macros
A set of useful Laravel string macros
Fund package maintenance!
victoryoalli
victoryoalli.me/open-source/support-us
Installs: 2 654
Dependents: 1
Suggesters: 0
Security: 0
Stars: 8
Watchers: 0
Forks: 2
Open Issues: 2
Requires
- php: ^8.0
- illuminate/support: ^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0
README
This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
Installation
You can install the package via composer:
composer require victoryoalli/laravel-string-macros
Macros
Initials
Gets the initicals of the words you provide. It defaults to 2 initials.
Str::initials('Victor Yoalli Dominguez'); //default to 2 initials // VY Str::initials('Victor Yoalli Dominguez',3); // VYD
Interpolate
Replaces question mark symbol to the words that you provide.
Str::interpolate('Roses are ? Violets are ?','RED','BLUE'); // Roses are RED Violets are BLUE Str::interpolate('Roses are ? Violets are ?',['RED','BLUE']); // Roses are RED Violets are BLUE Str::interpolate('Roses are ? Violets are ?',...['RED','BLUE']); // Roses are RED Violets are BLUE
readingMinutes
Calculates how many minutes it takes to read the text provided. It accepts HTML too, it will strip tags to make an accurate calculation.
Str::readingMinutes('Roses are RED Violets are BLUE...'); // 1 Str::readingMinutes('Pellentesque purus imperdiet dis duis netus dapibus mattis adipiscing at ultricies, rutrum volutpat quam ex himenaeos consectetur fusce tempus nostra, mollis fermentum ac fringilla donec lobortis potenti eros pharetra...'); // 1
stripTags
Str::stripTags('<strong>Hello</strong> <i>World!</i>'); // Hello World!
Fluent String supported
Example
$str = Str::of('Hac non ? dolor nisi penatibus maecenas luctus purus rutrum, ? leo sed ut lacinia gravida primis aliquet eget finibus, consequat sapien platea urna vehicula adipiscing est tortor.')->interpolate(['RED','BLUE'])->initials(28)->upper(); echo $str; // HNRDNPMLPRBLSULGPAEFCSPUVAET
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email victoryoalli@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.