Download the PHP package vendeka-nl/text without Composer
On this page you can find all versions of the php package vendeka-nl/text. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package text
Text helpers
This package adds a handful of useful string helper methods to Illuminate\Support\Str.
The package is developed and maintained by Vendeka, a company from the Netherlands.
Installation
Install using composer:
With Laravel
If you are using Laravel this package automatically adds its macros to Illuminate\Support\Str.
Without Laravel
If you are not using Laravel, you need to boot the package manually. This is only required to be executed once, so put it somewhere at the start of your app.
Usage
This package adds a number of helpful methods to Illuminate\Support\Str. Check the Laravel documentation to see the available methods on Illuminate\Support\Str.
Available methods
Most methods are chainable using the Illuminate\Support\Stringable class, either by using Illuminate\Support\Str::of() or Laravel's str() helper function. To convert to a string, either typecast to a string (echo will do this automatically) or call the toString() method. Methods marked with an asterisk (*) are not chainable
encloseexclamationglue*naturalnullIfBlank*nullIfEmpty*questionsentencetoParagraphstoWordsuncloseunprefixunsuffix
enclose
Since v3.0.2
Enclose a text with a prefix and a (different) suffix. If the suffix is null the prefix is also used as the suffix.
exclamation
Since v3.0.0
Create an exclamation from a string. This method automatically uppercases the first letter and adds a question mark if none if there is no period or exclamation mark at the end of it.
glue
Since v3.0.0
Glue together multiple strings, without duplicate glue between items.
natural
Since v3.0.0
Create a natural language version of a snake_case of kebab-case string.
nullIfBlank
Since v3.0.0
Convert a blank string to null.
nullIfEmpty
Since v3.0.0
Convert an empty string to null.
question
Since v3.0.0
Create a question from a string. This method automatically uppercases the first letter and adds a question mark if none if there is no period, exclamation mark or question mark at the end of it.
sentence
Since v3.0.0
Create a question from a string. This method automatically uppercases the first letter and adds a question mark if none if there is no period, exclamation mark or question mark at the end of it.
toParagraphs
Since v3.0.0
Split a text into paragraphs.
Please note that this method does not return a string, but an instance of Vendeka\Text\Paragraphs.
toWords
Since v1.0.0
Convert a snake_case, kebab-case, camelCase or StudlyCase to a string of words. For example 'aSnake' becomes 'A snake'.
Please note that this method does not return a string, but an instance of Vendeka\Text\Words.
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.
unprefix
Since v1.0.0 \
Deprecated since v4.1.0: Use \Illuminate\Support\Str::chopStart instead. Please note that chopStart returns after the first matched needle (lead).
Remove a prefix if it is present.
unsuffix
Since v1.0.0 \
Deprecated since v4.1.0: Use \Illuminate\Support\Str::chopEnd instead. Please note that chopEnd returns after the first matched needle (cap).
Remove a suffix if it is present.
Available classes
Paragraphs
Since v3.0.0
The class Vendeka\Text\Paragraphs extends Illuminate\Support\Collection. The class can be initialized via its constructor or the Illuminate\Support\Str::toParagraphs() method.
It adds the following useful methods:
br
br(string $br) sets the <br> HTML tag used in toHtml(). The default is set to <br>.
eol
eol(string $char) sets the EOL character(s), used in both toHtml() and toString().
of
of() returns a new instance of Illuminate\Support\Stringable to continue the method chain.
toString
toString() returns the paragraphs as a string
toHtml
toHtml() returns the paragraphs as a HTML string wrapped in <p> tags. Single new lines are replaced with <br>.
Words
Since v2.0.0
The class Vendeka\Text\Words extends Illuminate\Support\Collection. The class can be initialized via its constructor or the Illuminate\Support\Str::toWords() method.
It adds the following useful methods:
of
of() returns a new instance of Illuminate\Support\Stringable to continue the method chain.
toString
toString() returns the words as a string glued together with a single space (or custom string) between words (casting to a string is also supported).
Upgrading
Upgrading to v4.1
Deprecated unprefix method
Version 4.1.0 deprecates the unprefix method, in favor of the chopStart method that comes with illuminate/support. Please note that chopStart returns after the first matched needle (cap).
Deprecated unsuffix method
Version 4.1.0 deprecates the unsuffix method, in favor of the chopEnd method that comes with illuminate/support. Please note that chopEnd returns after the first matched needle (lead).
Upgrading to v4.0
Dropped wrap method
Version 4.0.0 removed the wrap method. Use enclose instead.
Dropped unwrap method
Version 4.0.0 removed the unwrap method. Use unclose instead.
Dropped normalizeWhitespace method
Version 4.0.0 removed the normalizeWhitespace method, in favor of the squish method that comes with illuminate/support.
Upgrading to v3.3
PHP version bumped to 8.2
Version 3.3 requires PHP 8.2 or higher.
Deprecated normalizeWhitespace method
Version 3.1.1 deprecated the normalizeWhitespace method, in favor of the squish method that comes with illuminate/support.
Upgrading to v3.1
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. Use enclose instead.
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.Use unclose instead.
Upgrading to v3.0
PHP version bumped to 8.0
Version 3.x requires PHP 8.0 or higher.
Upgrading to v2.x
Version 2.x requires PHP 7.4 or higher.
After updating the package, change your calls using the table below.
Replace all other references to Vendeka\Text\Text with Illuminate\Support\Str.
Removed methods
Version 2 relies more on illuminate/support and dropped a few helper methods and the Vendeka\Text\Fluid class.
| v1 | v2+ |
|---|---|
Vendeka\Text\Fluid |
Illuminate\Support\Str::of() |
Vendeka\Text\Text::changeCase() |
Illuminate\Support\Str::lower()Illuminate\Support\Str::upper()Illuminate\Support\Str::ucfirst() Illuminate\Support\Str::title() |
Vendeka\Text\Text::firstToUpperCase() |
Illuminate\Support\Str::ucfirst() |
Vendeka\Text\Text::startsWith() |
Illuminate\Support\Str::startsWith() |
Vendeka\Text\Text::toLowerCase() |
Illuminate\Support\Str::lower() |
Vendeka\Text\Text::toTitleCase() |
Illuminate\Support\Str::title() |
Vendeka\Text\Text::toUpperCase() |
Illuminate\Support\Str::upper() |