{"id":18946950,"url":"https://github.com/vendeka-nl/text","last_synced_at":"2025-04-15T22:31:26.379Z","repository":{"id":44720624,"uuid":"87533471","full_name":"vendeka-nl/text","owner":"vendeka-nl","description":"String helper class and functions.","archived":false,"fork":false,"pushed_at":"2025-02-28T13:30:45.000Z","size":99,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T03:51:15.996Z","etag":null,"topics":["capitalizes","character","converts","helper","helper-functions","helper-methods","helpers","language","laravel","natural-language","php","sentence","snake","standalone","string","text","words"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vendeka-nl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-07T10:14:28.000Z","updated_at":"2025-02-28T13:28:33.000Z","dependencies_parsed_at":"2024-04-03T15:58:18.665Z","dependency_job_id":"74be8459-b584-4a23-9cd6-08248b9e9bb2","html_url":"https://github.com/vendeka-nl/text","commit_stats":{"total_commits":58,"total_committers":2,"mean_commits":29.0,"dds":"0.18965517241379315","last_synced_commit":"da3c1b6ba31dad0fb996fdbd9e6bdb479ea9a7b4"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendeka-nl%2Ftext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendeka-nl%2Ftext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendeka-nl%2Ftext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vendeka-nl%2Ftext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vendeka-nl","download_url":"https://codeload.github.com/vendeka-nl/text/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249166088,"owners_count":21223382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["capitalizes","character","converts","helper","helper-functions","helper-methods","helpers","language","laravel","natural-language","php","sentence","snake","standalone","string","text","words"],"created_at":"2024-11-08T13:08:28.944Z","updated_at":"2025-04-15T22:31:26.370Z","avatar_url":"https://github.com/vendeka-nl.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Text helpers\n\n[![Packagist Version](https://img.shields.io/packagist/v/vendeka-nl/text)](https://packagist.org/packages/vendeka-nl/text)\n\nThis package adds a handful of useful string helper methods to [`Illuminate\\Support\\Str`](https://laravel.com/docs/master/helpers#strings).\n\nThe package is developed and maintained by [Vendeka](https://www.vendeka.nl/), a company from the Netherlands.\n\n\n# Installation\n\nInstall using composer:\n\n```shell\ncomposer require vendeka-nl/text\n```\n\n## With Laravel\n\nIf you are using Laravel this package automatically adds its macros to `Illuminate\\Support\\Str`.\n\n\n## Without Laravel\n\nIf 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.\n\n```php\nuse Vendeka\\Text\\Text;\n\nText::boot();\n```\n\n\n# Usage\n\nThis package adds a number of helpful methods to `Illuminate\\Support\\Str`. Check the [Laravel documentation](https://laravel.com/docs/11.x/helpers#strings-method-list) to see the available methods on `Illuminate\\Support\\Str`.\n\n```php\nuse Illuminate\\Support\\Str;\n\nStr::of('taco')-\u003eenclose('[', ']')-\u003eupper(); //=\u003e '[TACO]'\nStr::unclose('/gift/', '/'); //=\u003e 'gift'\n```\n\n\n## Available methods\n\nMost methods are chainable using the `Illuminate\\Support\\Stringable` class, either by using [`Illuminate\\Support\\Str::of()`](https://laravel.com/docs/11.x/helpers#fluent-strings) or Laravel's [`str()`](https://laravel.com/docs/11.x/helpers#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\n\n- [`enclose`](#enclose)\n- [`exclamation`](#exclamation)\n- [`glue`](#glue)*\n- [`natural`](#natural)\n- [`nullIfBlank`](#nullIfBlank)*\n- [`nullIfEmpty`](#nullIfEmpty)*\n- [`question`](#question)\n- [`sentence`](#sentence)\n- [`toParagraphs`](#toParagraphs)\n- [`toWords`](#toWords)\n- [`unclose`](#unclose)\n- [`unprefix`](#unprefix)\n- [`unsuffix`](#unsuffix)\n\n\n### enclose\n\n*Since v3.0.2*\n\nEnclose a text with a prefix and a (different) suffix. If the suffix is `null` the prefix is also used as the suffix.\n\n```php\nStr::enclose('directory', '/'); //=\u003e '/directory/'\nStr::enclose('directory/', '/'); //=\u003e '/directory/'\nStr::enclose('Paragraph', '\u003cp\u003e', '\u003c/p\u003e'); //=\u003e '\u003cp\u003eParagraph\u003c/p\u003e'\nStr::enclose('\u003cp\u003eParagraph\u003c/p\u003e', '\u003cp\u003e', '\u003c/p\u003e'); //=\u003e '\u003cp\u003eParagraph\u003c/p\u003e'\n```\n\n### exclamation\n\n*Since v3.0.0*\n\nCreate an exclamation from a string.\nThis 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.\n\n```php\nStr::exclamation('yelling'); //=\u003e 'Yelling!'\nStr::exclamation('Why are you yelling?'); //=\u003e 'Why are you yelling?!'\n``` \n\n### glue\n\n*Since v3.0.0*\n\nGlue together multiple strings, without duplicate glue between items.\n\n```php\nStr::glue('/', 'https://example.com/', '/dashboard'); //=\u003e 'https://example.com/dashboard'\nStr::glue('/', '/var', '/www/', []); //=\u003e '/var/www/'\n```\n\n\n### natural\n\n*Since v3.0.0*\n\nCreate a natural language version of a snake_case of kebab-case string.\n\n```php\nStr::natural('my-first-blog'); //=\u003e 'My first blog'\nStr::natural('i_love_kebab'); // =\u003e 'I love kebab'\n```\n\n\n### nullIfBlank\n\n*Since v3.0.0*\n\nConvert a blank string to null.\n\n```php\nStr::nullIfBlank(' '); //=\u003e null\n```\n\n\n### nullIfEmpty\n\n*Since v3.0.0*\n\nConvert an empty string to null.\n\n```php\nStr::nullIfEmpty(''); //=\u003e null\n```\n\n\n### question\n\n*Since v3.0.0*\n\nCreate 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.\n\n```php\nStr::question('Questions'); //=\u003e 'Questions?'\n```\n\n### sentence\n\n*Since v3.0.0*\n\nCreate 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.\n\n```php\nStr::sentence('this is a sentence'); //=\u003e 'This is a sentence.'\n```\n\n### toParagraphs\n\n*Since v3.0.0*\n\nSplit a text into paragraphs.\n\nPlease note that this method does not return a string, but an instance of [`Vendeka\\Text\\Paragraphs`](#paragraphs).\n\n```php\nStr::toParagraphs(\"Paragraph 1\\n\\nParagraph 2\"); // =\u003e instance of Vendeka\\Text\\Paragraphs\n```\n\n\n### toWords\n\n*Since v1.0.0*\n\nConvert a snake_case, kebab-case, camelCase or StudlyCase to a string of words. For example 'aSnake' becomes 'A snake'.\n\nPlease note that this method does not return a string, but an instance of [`Vendeka\\Text\\Words`](#words).\n\n```php\nuse Vendeka\\Text\\Words;\n\n(string) Str::toWords('a-dog'); //=\u003e 'a dog'\nStr::of('aSnake')-\u003etoWords()-\u003eof()-\u003elower(); //=\u003e 'a snake'\n(string) (new Words(['From', 'an', 'array'])); //=\u003e 'From an array'\n```\n\n\n### unclose\n\n*Since v3.1.1*\n\nUnclose (unwrap) a text with a prefix and a (different) suffix. If the suffix is `null` the prefix is also used as the suffix.\n\n```php\nStr::unclose('\u003cp\u003eGift\u003c/p\u003e', '\u003cp\u003e', '\u003c/p\u003e'); //=\u003e 'Gift'\nStr::unclose('/present/', '/') //=\u003e 'present'\n```\n\n\n### unprefix\n\n*Since v1.0.0*\n\nRemove a prefix if it is present.\n\n```php\nStr::unprefix('#yolo', '#') //=\u003e 'yolo'\n```\n\n\n### unsuffix\n\n*Since v1.0.0*\n\nRemove a suffix if it is present.\n\n```php\nStr::unsuffix('/var/www/', '/') //=\u003e '/var/www'\n```\n\n\n## Available classes\n\n### Paragraphs\n\n*Since v3.0.0*\n\nThe class `Vendeka\\Text\\Paragraphs` extends `Illuminate\\Support\\Collection`. The class can be initialized via its constructor or the `Illuminate\\Support\\Str::toParagraphs()` method.\n\n```php\n$paragraphs = new Paragraphs(\"First paragraph\\n\\nSecond paragraph...\");\n$paragraphs = new Paragraphs(['First paragraph', 'Second paragraph...']);\n$paragraphs = Str::toParagraphs(\"First paragraph\\n\\nSecond paragraph...\");\n```\n\nIt adds the following useful methods:\n\n#### br\n\n`br(string $br)` sets the `\u003cbr\u003e` HTML tag used in `toHtml()`. The default is set to `\u003cbr\u003e`.\n\n#### eol\n\n`eol(string $char)` sets the EOL character(s), used in both `toHtml()` and `toString()`.\n\n#### of\n\n`of()` returns a new instance of `Illuminate\\Support\\Stringable` to continue the method chain.\n\n#### toString\n\n`toString()` returns the paragraphs as a string\n\n#### toHtml\n\n`toHtml()` returns the paragraphs as a HTML string wrapped in `\u003cp\u003e` tags. Single new lines are replaced with `\u003cbr\u003e`.\n\n\n### Words \n\n*Since v2.0.0*\n\nThe class `Vendeka\\Text\\Words` extends `Illuminate\\Support\\Collection`. The class can be initialized via its constructor or the `Illuminate\\Support\\Str::toWords()` method.\n\n\n```php\n$words = new Words(\"First Second\");\n$words = new Words(['First', 'Second']);\n$words = Str::toWords(\"First Second\");\n```\n\nIt adds the following useful methods:\n\n\n#### of\n\n`of()` returns a new instance of `Illuminate\\Support\\Stringable` to continue the method chain.\n\n\n#### toString\n\n`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).\n\n```php\nStr::toWords('my-slug')-\u003etoString(); // =\u003e 'my slug'\nStr::toWords('my-folder')-\u003etoString('/'); // =\u003e 'my/slug'\n(string) Str::toWords(\"It's a kind of magic!\"); // =\u003e \"It's a kind of magic!\"\n```\n\n\n# Upgrading\n\n## Upgrading from v1\n\nVersion 2.0.x requires PHP 7.4 or higher. Version 3.0.x requires PHP 8.0 or higher. Version 3.3 requires PHP 8.2 or higher.\n\nNext, update the package version of `vendeka-nl/text` to `\"^3\"` in your composer.json and run `composer update vendeka-nl/text` to update the package.\n\nAfter updating the package, change your calls using the table below. \nReplace all other references to `Vendeka\\Text\\Text` with `Illuminate\\Support\\Str`.\n\n| v1 | v2+ |\n|----|----|\n| `Vendeka\\Text\\Fluid` | `Illuminate\\Support\\Str::of()`\n| `Vendeka\\Text\\Text::changeCase()` | `Illuminate\\Support\\Str::lower()`\u003cbr\u003e`Illuminate\\Support\\Str::upper()`\u003cbr\u003e`Illuminate\\Support\\Str::ucfirst()` \u003cbr\u003e`Illuminate\\Support\\Str::title()` |\n| `Vendeka\\Text\\Text::firstToUpperCase()` | `Illuminate\\Support\\Str::ucfirst()` |\n| `Vendeka\\Text\\Text::startsWith()` | `Illuminate\\Support\\Str::startsWith()` |\n| `Vendeka\\Text\\Text::toLowerCase()` | `Illuminate\\Support\\Str::lower()` |\n| `Vendeka\\Text\\Text::toTitleCase()` | `Illuminate\\Support\\Str::title()` |\n| `Vendeka\\Text\\Text::toUpperCase()` | `Illuminate\\Support\\Str::upper()` |\n\n## Upgrading from v3.0\n\n### Deprecated `wrap` method\n\nVersion 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.\n\n| v3.0 | v3.1+ |\n|----|----|\n|`Illuminate\\Support\\Str::wrap()`|`Illuminate\\Support\\Str::enclose()`|\n\n\n### Deprecated `unwrap` method\n\nVersion 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.\n\n| v3.0 | v3.1.1+ |\n|----|----|\n|`Illuminate\\Support\\Str::unwrap()`|`Illuminate\\Support\\Str::unclose()`|\n\n\n## Upgrading from v3.2\n\n### Deprecated `normalizeWhitespace` method\n\nVersion 3.1.1 deprecated the `normalizeWhitespace` method, in favor of `squish` method that comes with `illuminate/support`.\n\n| v3.2 | v3.3.1+ |\n|----|----|\n|`Illuminate\\Support\\Str::normalizeWhitespace()`|`Illuminate\\Support\\Str::squish()`|\n\n\n# Testing\n\n```\ncomposer run test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvendeka-nl%2Ftext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvendeka-nl%2Ftext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvendeka-nl%2Ftext/lists"}