victoryoalli/laravel-string-macros

A set of useful Laravel string macros

1.0.1 2023-03-20 22:34 UTC

This package is auto-updated.

Last update: 2024-05-21 01:08:26 UTC


README

GitHub release (latest by date) Packagist Downloads

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.