Skip to content

Commit aceccf6

Browse files
committed
update filters
1 parent f4f6616 commit aceccf6

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{
2+
"php.suggest.basic": false
3+
}

src/Parsem/Filters.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,29 @@ public static function last(string $string): string
5252

5353
public static function camelCase(string $string): string
5454
{
55+
$firstCharIsLowerCase = ctype_lower(mb_substr($string, 0, 1, static::ENCODING));
5556
$string = str_replace(['-', '_'], ' ', $string);
5657
$string = ucwords($string);
5758
$string = str_replace(' ', '', $string);
59+
if ($firstCharIsLowerCase) {
60+
$string = static::lowerFirst($string);
61+
}
5862
return $string;
5963
}
6064

6165
public static function snakeCase(string $string): string
6266
{
67+
$string = static::camelCase($string);
6368
$string = preg_replace('/([a-z])([A-Z])/', '$1_$2', $string);
69+
$string = str_replace([' ', '-'], '_', $string);
6470
$string = strtolower($string);
6571
return $string;
6672
}
6773

6874
public static function kebabCase(string $string): string
6975
{
70-
$string = preg_replace('/([a-z])([A-Z])/', '$1-$2', $string);
71-
$string = strtolower($string);
76+
$string = static::snakeCase($string);
77+
$string = str_replace('_', '-', $string);
7278
return $string;
7379
}
7480

0 commit comments

Comments
 (0)