MCPcopy Create free account
hub / github.com/dot-agent/nextpy / to_camel_case

Function to_camel_case

nextpy/utils/format.py:131–149  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

129
130
131def 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
152def to_title_case(text: str) -> str:

Callers 3

createMethod · 0.90
_renderMethod · 0.90
_renderMethod · 0.90

Calls 2

splitMethod · 0.80
joinMethod · 0.80

Tested by

no test coverage detected