Convert a string to camel case. The first word in the text is converted to lowercase and the rest of the words are converted to title case, removing underscores. Args: text: The string to convert. allow_hyphens: Whether to allow hyphens in the string. Returns:
(text: str, allow_hyphens: bool = False)
| 129 | |
| 130 | |
| 131 | def to_camel_case(text: str, allow_hyphens: bool = False) -> str: |
| 132 | """Convert a string to camel case. |
| 133 | |
| 134 | The first word in the text is converted to lowercase and |
| 135 | the rest of the words are converted to title case, removing underscores. |
| 136 | |
| 137 | Args: |
| 138 | text: The string to convert. |
| 139 | allow_hyphens: Whether to allow hyphens in the string. |
| 140 | |
| 141 | Returns: |
| 142 | The camel case string. |
| 143 | """ |
| 144 | char = "_" if allow_hyphens else "-_" |
| 145 | words = re.split(f"[{char}]", text.lstrip(char)) |
| 146 | leading_underscores_or_hyphens = "".join(re.findall(rf"^[{char}]+", text)) |
| 147 | # Capitalize the first letter of each word except the first one |
| 148 | converted_word = words[0] + "".join(x.capitalize() for x in words[1:]) |
| 149 | return leading_underscores_or_hyphens + converted_word |
| 150 | |
| 151 | |
| 152 | def to_title_case(text: str) -> str: |