Skip to content

Commit

Permalink
Merge pull request #13 from vendeka-nl/improved-docs-3-1-1
Browse files Browse the repository at this point in the history
Improved documentation for v3.1.1.
  • Loading branch information
royvanv authored Feb 16, 2024
2 parents 614d63b + 83e0d2d commit ab53020
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,24 @@ 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+ |
|----|----|
|`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`.
Expand All @@ -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)~~


Expand All @@ -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/'
Expand Down Expand Up @@ -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('<p>Gift</p>', '<p>', '</p>'); //=> 'Gift'
Str::unclose('/present/', '/') //=> 'present'
```


### unprefix

*Since v1.0.0*
Expand All @@ -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('<p>Gift</p>', '<p>', '</p>'); //=> '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
Expand Down
12 changes: 8 additions & 4 deletions src/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit ab53020

Please sign in to comment.