code-distortion/laravel-helpers

Various helpers and tools for Laravel

0.1.4 2023-07-03 08:44 UTC

This package is auto-updated.

Last update: 2024-12-03 11:53:22 UTC


README

Latest Version on Packagist PHP Version Laravel GitHub Workflow Status

Warning

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.

Installation

Install the package via composer:

composer require code-distortion/laravel-helpers

The package will automatically register itself.

String Macros

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.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Contributions are not being sought for this package.

Security

If you discover any security related issues, please email tim@code-distortion.net instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.