From 580ae4137abe59298c369a2b1a6a259be7a2b33c Mon Sep 17 00:00:00 2001 From: Roy van Veldhuizen <18717340+royvanv@users.noreply.github.com> Date: Fri, 16 Feb 2024 14:04:54 +0100 Subject: [PATCH] Improved documentation for v3.1.1. --- README.md | 41 ++++++++++++++++++++++++++++++----------- src/Text.php | 15 ++++++++++----- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d6ca676..14f1f7c 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,8 @@ Replace all other references to `Vendeka\Text\Text` with `Illuminate\Support\Str ### Upgrading from v3.0 +#### Deprecated `wrap` method + Version 3.0.2 deprecated the `wrap` method because a method with the same name was added in `illuminate/support` v9.31 and overrides this packages' version. | v3.0 | v3.1+ | @@ -60,6 +62,15 @@ Version 3.0.2 deprecated the `wrap` method because a method with the same name w |`Illuminate\Support\Str::wrap()`|`Illuminate\Support\Str::enclose()`| +#### Deprecated `unwrap` method + +Version 3.1.1 deprecated the `unwrap` method because a method with the same name was added in `illuminate/support` v10.43 and overrides this packages' version. + +| v3.0 | v3.1.1+ | +|----|----| +|`Illuminate\Support\Str::unwrap()`|`Illuminate\Support\Str::unclose()`| + + # Usage This package adds a number of helpfull methods to `Illuminate\Support\Str`. Check the [Laravel documentation](https://laravel.com/docs/9.x/helpers#strings-method-list) to see the available methods on `Illuminate\Support\Str`. @@ -79,9 +90,10 @@ Most methods are chainable using [`Illuminate\Support\Str::of()`](https://larave - [`sentence`](#sentence) - [`toParagraphs`](#toParagraphs) - [`toWords`](#toWords) +- [`unclose`](#unclose) - [`unprefix`](#unprefix) - [`unsuffix`](#unsuffix) -- [`unwrap`](#unwrap) +- ~~[`unwrap`](#unwrap)~~ - ~~[`wrap`](#wrap)~~ @@ -102,7 +114,7 @@ Most methods return an instance of the class. To convert to a string, either typ *Since v3.0.2* -Enclose a text with a prefix and a (different) suffix. If the suffix is empty the prefix is also used as the suffix. +Enclose a text with a prefix and a (different) suffix. If the suffix is `null` the prefix is also used as the suffix. ```php Str::enclose('directory', '/'); //=> '/directory/' @@ -230,6 +242,18 @@ Str::of('aSnake')->toWords()->of()->lower(); //=> 'a snake' ``` +## unclose + +*Since v3.1.1* + +Unclose (unwrap) a text with a prefix and a (different) suffix. If the suffix is `null` the prefix is also used as the suffix. + +```php +Str::unclose('
Gift
', '', '
'); //=> 'Gift' +Str::unclose('/present/', '/') //=> 'present' +``` + + ### unprefix *Since v1.0.0* @@ -252,23 +276,18 @@ Str::unsuffix('/var/www/', '/') //=> '/var/www' ``` -### unwrap +### ~~unwrap~~ *Since v1.0.0* - -Unwrap a text with a prefix and a (different) suffix. If the suffix is empty the prefix is also used as the suffix. - -```php -Str::unwrap('Gift
', '', '
'); //=> 'Gift' -Str::unwrap('/present/', '/') //=> 'present' -``` +\ +**Deprecated since v3.1.1**: No longer to be used in Laravel v10.42 or above, because `Illuminate\Support\Str::unwrap()` overrides this method. Use the `unclose()` method instead. ### ~~wrap~~ *Since v1.0.0* \ -**Deprecated since v3.0.2**: No longer to be used in Laravel v9.31 or above, because `Str::wrap()` overrides this method. Use `Str::enclose()` instead. +**Deprecated since v3.0.2**: No longer to be used in Laravel v9.31 or above, because `Illuminate\Support\Str::wrap()` overrides this method. Use the `enclose()` method instead. ## Available classes diff --git a/src/Text.php b/src/Text.php index 563e3e8..87d81e9 100644 --- a/src/Text.php +++ b/src/Text.php @@ -37,7 +37,8 @@ public static function boot(): void } /** - * Enclose a text with a prefix and a (different) suffix. If the suffix is empty the prefix is also used as the suffix. + * Enclose a text with a prefix and a (different) suffix. + * If the suffix is `null` the prefix is also used as the suffix. * * @param string $text * @param string|iterable $before @@ -219,7 +220,8 @@ public static function toWords(mixed $text): Words } /** - * Unclose (unwrap) a text with a prefix and a (different) suffix. If the suffix is `null` the prefix is also used as the suffix. + * Unclose (unwrap) a text with a prefix and a (different) suffix. + * If the suffix is `null` the prefix is also used as the suffix. * * @param string $text * @param string|iterable $before @@ -272,7 +274,8 @@ public static function unsuffix(string $text, string|iterable $cap): string } /** - * Unwrap a text with a prefix and a (different) suffix. If the suffix is `null` the prefix is also used as the suffix. + * Unwrap a text with a prefix and a (different) suffix. + * If the suffix is `null` the prefix is also used as the suffix. * * @deprecated 3.1.1 No longer to be used in Laravel v10.42 or above, because `Illuminate\Support\Str::unwrap()` overrides this method. Use the `unclose()` method instead. * @see Vendeka\Text\Text::unclose() @@ -290,7 +293,8 @@ public static function unwrap(string $text, string|iterable $before, string|iter } /** - * Wrap a text with a prefix and a (different) suffix. If the suffix is empty the prefix is also used as the suffix. + * Wrap a text with a prefix and a (different) suffix. + * If the suffix is `null` the prefix is also used as the suffix. * * @deprecated 3.0.2 No longer to be used in Laravel v9.31 or above, because `Illuminate\Support\Str::wrap()` overrides this method. Use the `enclose()` method instead. * @see Vendeka\Text\Text::enclose() @@ -340,7 +344,8 @@ private static function bootStrMacros(): void * * @codeCoverageIgnore */ - private static function bootStringableMacros(): void + +. private static function bootStringableMacros(): void { Stringable::macro('enclose', fn ($before, $after = null): Stringable => new Stringable(Text::enclose($this->value, $before, $after))); Stringable::macro('exclamation', fn (): Stringable => new Stringable(Text::exclamation($this->value)));