-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 [#165] changed expand snake_case query params to camelCase
- Loading branch information
1 parent
d05ccab
commit 4626b9d
Showing
5 changed files
with
74 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import re | ||
|
||
|
||
def camel_to_snake_converter(value): | ||
pattern = re.compile(r"(?<!^)(?=[A-Z])") | ||
return pattern.sub("_", value).lower() | ||
|
||
|
||
def snake_to_camel_converter(value): | ||
init, *temp = value.split("_") | ||
return "".join([init.lower(), *map(str.title, temp)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.test import TestCase | ||
|
||
from ..converters import camel_to_snake_converter, snake_to_camel_converter | ||
|
||
|
||
class ConverterTests(TestCase): | ||
def test_camel_to_snake_converter(self): | ||
self.assertEqual( | ||
camel_to_snake_converter("snakeCaseTestString"), "snake_case_test_string" | ||
) | ||
|
||
def test_snake_to_camel_converter(self): | ||
self.assertEqual( | ||
snake_to_camel_converter("camel_case_test_string"), "camelCaseTestString" | ||
) |