joachim-n / case-converter
Case converter library
Installs: 312 236
Dependents: 2
Suggesters: 0
Security: 0
Stars: 8
Watchers: 2
Forks: 1
Open Issues: 1
Requires (Dev)
- phpunit/phpunit: ^6.2
- symfony/var-dumper: ^3.2
README
Case Converter is a small library for converting strings from one case to another. It handles, as both input and output:
- camelCase
- PascalCase
- snake_case
- kebab-case
- Title Case
Installation:
With Composer:
$ composer require joachim-n/case-converter
Usage:
$output = \CaseConverter\CaseString::INPUTFORMAT('MyString')->OUTPUTFORMAT();
For example:
$output = \CaseConverter\CaseString::camel('MyString')->pascal();
$output = \CaseConverter\CaseString::camel('MyString')->snake();
$output = \CaseConverter\CaseString::camel('MyString')->kebab();
$output = \CaseConverter\CaseString::snake('my_string')->camel();
$output = \CaseConverter\CaseString::snake('my_string')->pascal();
$output = \CaseConverter\CaseString::snake('my_string')->kebab();
If your input string is in a format that requires custom splitting, you can pass the pieces to StringAssembler for output. For example:
$output = (new \CaseConverter\StringAssembler(['my', 'string']))->camel();