Skip to content

Commit

Permalink
Introduce camel case (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstandiford committed Mar 17, 2023
1 parent 639097c commit b69f3d7
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/Helpers/String_Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ public static function pluarize( $singular, $count, $plural = 's' ) {
return $singular . $plural;
}

/**
* Converts the given string to use camelCase
*
* @param string $subject
*
* @return string
*/
public static function camel_case(string $subject): string
{
return lcfirst(static::pascal_case($subject));
}

/**
* Converts the given string to use PascalCase
*
* @param string $subject
*
* @return string
*/
public static function pascal_case(string $subject) : string
{
return Array_Helper::process(explode(' ', str_replace(['-', '_'], ' ', $subject)))
->map(fn (string $piece) => ucfirst($piece))
->set_separator('')
->to_string();
}

/**
* Creates a 32 character hash from the provided value.
*
Expand Down

0 comments on commit b69f3d7

Please sign in to comment.