Skip to content

Commit 8219d0c

Browse files
committed
feat: add camel case util
1 parent 509a77f commit 8219d0c

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎src/osw/utils/strings.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
# Functions
2+
3+
4+
def camel_case(st: str) -> str:
5+
"""converts a string to camelCase
6+
7+
Parameters
8+
----------
9+
st
10+
the string to convert to camelCase
11+
12+
Returns
13+
-------
14+
The string in camelCase
15+
"""
16+
if not st.isalnum():
17+
st = "".join(x for x in st.title() if x.isalnum())
18+
return st[0].lower() + st[1:]
19+
20+
221
def pascal_case(st: str) -> str:
322
"""converts a string to PascalCase
423

‎tests/utils/utils_test.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import osw.model.entity as model
44
from osw.utils.regex import count_match_groups
5-
from osw.utils.strings import pascal_case
5+
from osw.utils.strings import camel_case, pascal_case
66
from osw.utils.wiki import (
77
get_full_title,
88
get_namespace,
@@ -112,6 +112,12 @@ def test_strings_pascalcase():
112112
assert pascal_case("MyString") == "MyString"
113113

114114

115+
def test_strings_camelcase():
116+
assert camel_case("my string") == "myString"
117+
assert camel_case("my_string") == "myString"
118+
assert camel_case("MyString") == "myString"
119+
120+
115121
# osw.utils.regex_pattern
116122
def test_regex_pattern():
117123
"""This tests the regex pattern library. For all patterns in the library, the

0 commit comments

Comments
 (0)