permafrost-dev/laravel-str-extras

Extra helper methods for the Laravel Str helper class.

1.0.1 2023-05-09 16:21 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Extra helper methods for the Laravel Str helper class.

Additional Methods

  • insert() - inserts a string at the specified position in the given string.
  • insertAfterMatch() - inserts a string after the specified pattern match.
  • insertAfter() - inserts a string after the specified substring.

Examples

$new = Str::insert('HelloWorld', '--', 5); //returns 'Hello--World'
$new = Str::insertAfterMatch('HelloWorld', '/(Hello)/', ' '); // returns 'Hello World'
$new = Str::insertAfter('HelloWorld', 'H', '_'); // returns 'H_elloWorld'

As far as making building web applications easier - consider the following use case:

// the identifier in the database is UA-1001, but we want to
// allow the user to provide the identifier without a dash for ease of entry:

$providedIdentifier = 'UA1001';
$actualIdentifier = Str::insertAfter($providedIdentifier, 'UA', '-'); 
$userExists = User::where('identifier', $actualIdentifier)->exists();

Installation

You can install the package via composer:

composer require permafrost-dev/laravel-str-extras

Usage

$new = Str::insert('HelloWorld', '--', 5); //returns 'Hello--World'

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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