To camel case fix (#2205)

This commit is contained in:
Elijah Ahianyo 2023-11-20 19:33:48 +00:00 committed by GitHub
parent c5c2ca2b7b
commit 7f810ece21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -137,9 +137,11 @@ def to_camel_case(text: str) -> str:
Returns:
The camel case string.
"""
words = re.split("[_-]", text)
words = re.split("[_-]", text.lstrip("-_"))
leading_underscores_or_hyphens = "".join(re.findall(r"^[_-]+", text))
# Capitalize the first letter of each word except the first one
return words[0] + "".join(x.capitalize() for x in words[1:])
converted_word = words[0] + "".join(x.capitalize() for x in words[1:])
return leading_underscores_or_hyphens + converted_word
def to_title_case(text: str) -> str:

View File

@ -142,6 +142,11 @@ def test_to_snake_case(input: str, output: str):
("kebab-case", "kebabCase"),
("kebab-case-two", "kebabCaseTwo"),
("snake_kebab-case", "snakeKebabCase"),
("_hover", "_hover"),
("-starts-with-hyphen", "-startsWithHyphen"),
("--starts-with-double-hyphen", "--startsWithDoubleHyphen"),
("_starts_with_underscore", "_startsWithUnderscore"),
("__starts_with_double_underscore", "__startsWithDoubleUnderscore"),
],
)
def test_to_camel_case(input: str, output: str):