Skip to content

Commit b69f3d7

Browse files
Introduce camel case (#58)
1 parent 639097c commit b69f3d7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/Helpers/String_Helper.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,33 @@ public static function pluarize( $singular, $count, $plural = 's' ) {
1919
return $singular . $plural;
2020
}
2121

22+
/**
23+
* Converts the given string to use camelCase
24+
*
25+
* @param string $subject
26+
*
27+
* @return string
28+
*/
29+
public static function camel_case(string $subject): string
30+
{
31+
return lcfirst(static::pascal_case($subject));
32+
}
33+
34+
/**
35+
* Converts the given string to use PascalCase
36+
*
37+
* @param string $subject
38+
*
39+
* @return string
40+
*/
41+
public static function pascal_case(string $subject) : string
42+
{
43+
return Array_Helper::process(explode(' ', str_replace(['-', '_'], ' ', $subject)))
44+
->map(fn (string $piece) => ucfirst($piece))
45+
->set_separator('')
46+
->to_string();
47+
}
48+
2249
/**
2350
* Creates a 32 character hash from the provided value.
2451
*

0 commit comments

Comments
 (0)