ptrkcsk/change-case

Convert strings to camelCase, CONSTANT_CASE, dot.case, Header-Case, lower case, param-case, PascalCase, path/case, Sentence case, snake_case, Title Case, UPPER CASE, and more!

v0.1.0 2018-08-13 15:19 UTC

This package is not auto-updated.

Last update: 2020-11-24 16:46:25 UTC


README

Test Coverage

Convert strings to camelCase, CONSTANT_CASE, dot.case, Header-Case, lower case, param-case, PascalCase, path/case, Sentence case, snake_case, Title Case, UPPER CASE, and more!

Change Case is a port to PHP from JavaScript of Blake Embrey’s project of the same name.

Installation

$ composer require ptrkcsk/change-case

Case styles

Style (& aliases) Example
Camel, lower camel test stringtestString
Constant, screaming snake test stringTEST_STRING
Dot test stringtest.string
Header test stringTest-String
Lower test stringtest string
Lower first TEST STRINGtEST STRING
No test stringtest string
Param, kebab, lisp test stringtest-string
Pascal, upper camel test stringTestString
Path test stringtest/string
Sentence test stringTest string
Snake, pothole test stringtest_string
Swap TeSt StRiNgtEsT sTrInG
Title, start test stringTest String
Upper, all caps test stringTEST STRING
Upper first test stringTest string

API Methods

Camel case, lower camel case: test stringtestString

use ChangeCase\ChangeCase;

ChangeCase::camel('test string');      // 'testString'
ChangeCase::lowerCamel('test string'); // 'testString'

Constant case, screaming snake case: test stringTEST_STRING

use ChangeCase\ChangeCase;

ChangeCase::constant('test string');       // 'TEST_STRING'
ChangeCase::screamingSnake('test string'); // 'TEST_STRING'

Dot case: test stringtest.string

use ChangeCase\ChangeCase;

ChangeCase::dot('test string'); // 'test.case'

Header case: test stringTest-String

use ChangeCase\ChangeCase;

ChangeCase::header('test string'); // 'Test-String'

Lower case: test stringtest string

use ChangeCase\ChangeCase;

ChangeCase::lower('test string'); // 'test string'

Lower case first: TEST STRINGtEST STRING

use ChangeCase\ChangeCase;

ChangeCase::lowerFirst('TEST STRING'); // 'tEST STRING'

No case: test stringtest string

use ChangeCase\ChangeCase;

ChangeCase::no('test string'); // 'test string'

Param case, kebab case, lisp case: test stringtest-string

use ChangeCase\ChangeCase;

ChangeCase::param('test string'); // 'test-string'
ChangeCase::kebab('test string'); // 'test-string'
ChangeCase::lisp('test string');  // 'test-string'

Pascal case, upper camel case: test stringTestString

use ChangeCase\ChangeCase;

ChangeCase::pascal('test string');     // 'TestString'
ChangeCase::upperCamel('test string'); // 'TestString'

Path case: test stringtest/string

use ChangeCase\ChangeCase;

ChangeCase::path('test string'); // 'test/string'

Sentence case: test stringTest string

use ChangeCase\ChangeCase;

ChangeCase::sentence('test string'); // 'Test string'

Snake case, pothole case: test stringtest_string

use ChangeCase\ChangeCase;

ChangeCase::snake('test string');   // 'test_string'
ChangeCase::pothole('test string'); // 'test_string'

Swap case: TeSt StRiNgtEsT sTrInG

use ChangeCase\ChangeCase;

ChangeCase::swap('TeSt StRiNg'); // 'tEsT sTrInG'

Title case, start case: test stringTest String

use ChangeCase\ChangeCase;

ChangeCase::title('test string'); // 'Test String'
ChangeCase::start('test string'); // 'Test String'

Upper case, all caps: test stringTEST STRING

use ChangeCase\ChangeCase;

ChangeCase::upper('test string');   // 'TEST STRING'
ChangeCase::allCaps('test string'); // 'TEST STRING'

Upper case first: test stringTest string

use ChangeCase\ChangeCase;

ChangeCase::upperFirst('test string');  // 'Test string'