PHPackages                             vendeka-nl/text - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. vendeka-nl/text

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vendeka-nl/text
===============

String helper class and functions.

4.0.0(1y ago)33651[1 issues](https://github.com/vendeka-nl/text/issues)MITPHPPHP ^8.2.0CI passing

Since Jun 26Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/vendeka-nl/text)[ Packagist](https://packagist.org/packages/vendeka-nl/text)[ RSS](/packages/vendeka-nl-text/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)DependenciesVersions (22)Used By (0)

Text helpers
============

[](#text-helpers)

[![Packagist Version](https://camo.githubusercontent.com/0d019b554c9c3a666767fd5e741026ad8f04ecb25c202934f85d670df573edd4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76656e64656b612d6e6c2f74657874)](https://packagist.org/packages/vendeka-nl/text)

This package adds a handful of useful string helper methods to [`Illuminate\Support\Str`](https://laravel.com/docs/strings).

The package is developed and maintained by [Vendeka](https://www.vendeka.nl/), a company from the Netherlands.

Installation
============

[](#installation)

Install using composer:

```
composer require vendeka-nl/text
```

With Laravel
------------

[](#with-laravel)

If you are using Laravel this package automatically adds its macros to `Illuminate\Support\Str`.

Without Laravel
---------------

[](#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.

```
use Vendeka\Text\Text;

Text::boot();
```

Usage
=====

[](#usage)

This package adds a number of helpful methods to `Illuminate\Support\Str`. Check the [Laravel documentation](https://laravel.com/docs/strings#available-methods) to see the available methods on `Illuminate\Support\Str`.

```
use Illuminate\Support\Str;

Str::of('taco')->enclose('[', ']')->upper(); //=> '[TACO]'
Str::unclose('/gift/', '/'); //=> 'gift'
```

Available methods
-----------------

[](#available-methods)

Most methods are chainable using the `Illuminate\Support\Stringable` class, either by using [`Illuminate\Support\Str::of()`](https://laravel.com/docs/strings#fluent-strings-method-list) or Laravel's [`str()`](https://laravel.com/docs/strings#method-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

- [`enclose`](#enclose)
- [`exclamation`](#exclamation)
- [`glue`](#glue)\*
- [`natural`](#natural)
- [`nullIfBlank`](#nullIfBlank)\*
- [`nullIfEmpty`](#nullIfEmpty)\*
- [`question`](#question)
- [`sentence`](#sentence)
- [`toParagraphs`](#toParagraphs)
- [`toWords`](#toWords)
- [`unclose`](#unclose)
- [`unprefix`](#unprefix)
- [`unsuffix`](#unsuffix)

### enclose

[](#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.

```
Str::enclose('directory', '/'); //=> '/directory/'
Str::enclose('directory/', '/'); //=> '/directory/'
Str::enclose('Paragraph', '', ''); //=> 'Paragraph'
Str::enclose('Paragraph', '', ''); //=> 'Paragraph'
```

### exclamation

[](#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.

```
Str::exclamation('yelling'); //=> 'Yelling!'
Str::exclamation('Why are you yelling?'); //=> 'Why are you yelling?!'
```

### glue

[](#glue)

*Since v3.0.0*

Glue together multiple strings, without duplicate glue between items.

```
Str::glue('/', 'https://example.com/', '/dashboard'); //=> 'https://example.com/dashboard'
Str::glue('/', '/var', '/www/', []); //=> '/var/www/'
```

### natural

[](#natural)

*Since v3.0.0*

Create a natural language version of a snake\_case of kebab-case string.

```
Str::natural('my-first-blog'); //=> 'My first blog'
Str::natural('i_love_kebab'); // => 'I love kebab'
```

### nullIfBlank

[](#nullifblank)

*Since v3.0.0*

Convert a blank string to null.

```
Str::nullIfBlank(' '); //=> null
```

### nullIfEmpty

[](#nullifempty)

*Since v3.0.0*

Convert an empty string to null.

```
Str::nullIfEmpty(''); //=> null
```

### question

[](#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.

```
Str::question('Questions'); //=> 'Questions?'
```

### sentence

[](#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.

```
Str::sentence('this is a sentence'); //=> 'This is a sentence.'
```

### toParagraphs

[](#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`](#paragraphs).

```
Str::toParagraphs("Paragraph 1\n\nParagraph 2"); // => instance of Vendeka\Text\Paragraphs
```

### toWords

[](#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`](#words).

```
use Vendeka\Text\Words;

(string) Str::toWords('a-dog'); //=> 'a dog'
Str::of('aSnake')->toWords()->of()->lower(); //=> 'a snake'
(string) (new Words(['From', 'an', 'array'])); //=> 'From an array'
```

### unclose

[](#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.

```
Str::unclose('Gift', '', ''); //=> 'Gift'
Str::unclose('/present/', '/') //=> 'present'
```

### unprefix

[](#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.

```
Str::unprefix('#yolo', '#') //=> 'yolo'
```

### unsuffix

[](#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.

```
Str::unsuffix('/var/www/', '/') //=> '/var/www'
```

Available classes
-----------------

[](#available-classes)

### Paragraphs

[](#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.

```
$paragraphs = new Paragraphs("First paragraph\n\nSecond paragraph...");
$paragraphs = new Paragraphs(['First paragraph', 'Second paragraph...']);
$paragraphs = Str::toParagraphs("First paragraph\n\nSecond paragraph...");
```

It adds the following useful methods:

#### br

[](#br)

`br(string $br)` sets the `` HTML tag used in `toHtml()`. The default is set to ``.

#### eol

[](#eol)

`eol(string $char)` sets the EOL character(s), used in both `toHtml()` and `toString()`.

#### of

[](#of)

`of()` returns a new instance of `Illuminate\Support\Stringable` to continue the method chain.

#### toString

[](#tostring)

`toString()` returns the paragraphs as a string

#### toHtml

[](#tohtml)

`toHtml()` returns the paragraphs as a HTML string wrapped in `` tags. Single new lines are replaced with ``.

### Words

[](#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.

```
$words = new Words("First Second");
$words = new Words(['First', 'Second']);
$words = Str::toWords("First Second");
```

It adds the following useful methods:

#### of

[](#of-1)

`of()` returns a new instance of `Illuminate\Support\Stringable` to continue the method chain.

#### toString

[](#tostring-1)

`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).

```
Str::toWords('my-slug')->toString(); // => 'my slug'
Str::toWords('my-folder')->toString('/'); // => 'my/slug'
(string) Str::toWords("It's a kind of magic!"); // => "It's a kind of magic!"
```

Upgrading
=========

[](#upgrading)

Upgrading to v4.1
-----------------

[](#upgrading-to-v41)

### Deprecated `unprefix` method

[](#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

[](#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
-----------------

[](#upgrading-to-v40)

### Dropped `wrap` method

[](#dropped-wrap-method)

Version 4.0.0 removed the `wrap` method. Use `enclose` instead.

### Dropped `unwrap` method

[](#dropped-unwrap-method)

Version 4.0.0 removed the `unwrap` method. Use `unclose` instead.

### Dropped `normalizeWhitespace` method

[](#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
-----------------

[](#upgrading-to-v33)

### PHP version bumped to 8.2

[](#php-version-bumped-to-82)

Version 3.3 requires PHP 8.2 or higher.

### Deprecated `normalizeWhitespace` method

[](#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
-----------------

[](#upgrading-to-v31)

### Deprecated `wrap` method

[](#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

[](#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
-----------------

[](#upgrading-to-v30)

### PHP version bumped to 8.0

[](#php-version-bumped-to-80)

Version 3.x requires PHP 8.0 or higher.

Upgrading to v2.x
-----------------

[](#upgrading-to-v2x)

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

[](#removed-methods)

Version 2 relies more on `illuminate/support` and dropped a few helper methods and the `Vendeka\Text\Fluid` class.

v1v2+`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()`Testing
=======

[](#testing)

```
composer run test

```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance63

Regular maintenance activity

Popularity16

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~200 days

Recently: every ~82 days

Total

15

Last Release

441d ago

Major Versions

1.1.0 → 2.0.02020-11-11

2.0.1 → 3.0.02022-03-30

3.3.2 → 4.0.02025-02-28

PHP version history (5 changes)1.0.0PHP &gt;=5.3.0

1.1.0PHP &gt;=7.1

2.0.0PHP &gt;=7.4

3.0.0PHP ^8.0.2

3.3.0PHP ^8.2.0

### Community

---

Top Contributors

[![royvanv](https://avatars.githubusercontent.com/u/18717340?v=4)](https://github.com/royvanv "royvanv (84 commits)")

---

Tags

capitalizescharacterconvertshelperhelper-functionshelper-methodshelperslanguagelaravelnatural-languagephpsentencesnakestandalonestringtextwords

### Embed Badge

![Health badge](/badges/vendeka-nl-text/health.svg)

```
[![Health](https://phpackages.com/badges/vendeka-nl-text/health.svg)](https://phpackages.com/packages/vendeka-nl-text)
```

###  Alternatives

[aoepeople/zettr

Manage and apply settings (formerly known as EnvSettingsTool)

209.8k](/packages/aoepeople-zettr)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
