Downloads
Stars
Version
This package was developed for use in my own projects. It might not suit your needs or be documented properly, and may change at any time.
Install the package via composer:
composer require code-distortion/laravel-helpers
The package will automatically register itself.
These macros are applied to Illuminate\Support\Str
and Illuminate\Support\Stringable
:
unspace
Trim and remove repeated-spaces from a string:
// ' a b c ' >> 'a b c'
Str::unspace($string);
Str::of($string)->unspace();
By default, all whitespace characters are searched for and replaced with spaces.
You can specify which character/s to search for:
// '_a__b__c_' >> 'a_b_c'
Str::unspace($string, '_');
Str::of($string)->unspace('_');
Searching for an empty string will search for all whitespace characters.
And you can specify a replacement:
// ' a b c ' >> 'a-b-c'
Str::unspace($string, ' ', '-');
Str::of($string)->unspace(' ', '-');
If no replacement is specified, the character being searched for will be used.
If more than one character is being searched for, a space is used as the replacement.
Please see CHANGELOG for more information what has changed recently.
$ composer test
Contributions are not being sought for this package.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.