Skip to content

Commit 2411dea

Browse files
committed
- Update to slug to title to handle studly case as well
1 parent 37505bd commit 2411dea

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/helpers.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,12 @@ function remove_suffix($needle, $haystack): string
226226
*/
227227
function slug_to_title($slug, string $separator = '_'): string
228228
{
229-
return Str::title(str_replace($separator, ' ', $slug));
229+
return Str::of($slug)
230+
->camel()
231+
->snake($separator)
232+
->replace($separator, ' ')
233+
->title()
234+
->toString();;
230235
}
231236
}
232237

tests/Unit/HelpersTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public function it_correctly_runs_slug_to_title()
160160
$this->assertEquals('Apple', slug_to_title('apple'));
161161
$this->assertEquals('Apple Magic', slug_to_title('apple_magic'));
162162
$this->assertEquals('Apple Magic', slug_to_title('apple Magic', ' '));
163+
$this->assertEquals('Apple Magic', slug_to_title('AppleMagic'));
163164
}
164165

165166
#[Test]

0 commit comments

Comments
 (0)