To camel case fix (#2205)
This commit is contained in:
parent
c5c2ca2b7b
commit
7f810ece21
@ -137,9 +137,11 @@ def to_camel_case(text: str) -> str:
|
|||||||
Returns:
|
Returns:
|
||||||
The camel case string.
|
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
|
# 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:
|
def to_title_case(text: str) -> str:
|
||||||
|
@ -142,6 +142,11 @@ def test_to_snake_case(input: str, output: str):
|
|||||||
("kebab-case", "kebabCase"),
|
("kebab-case", "kebabCase"),
|
||||||
("kebab-case-two", "kebabCaseTwo"),
|
("kebab-case-two", "kebabCaseTwo"),
|
||||||
("snake_kebab-case", "snakeKebabCase"),
|
("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):
|
def test_to_camel_case(input: str, output: str):
|
||||||
|
Loading…
Reference in New Issue
Block a user