From fd71b0221d740eb38730b4a220baa51b1c09d287 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Wed, 4 Dec 2024 01:09:47 -0800 Subject: [PATCH] Add pascal to snake case helper method --- .../src/python/_utils.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/_topics/08-reproducible-research-practices/src/python/_utils.py b/_topics/08-reproducible-research-practices/src/python/_utils.py index 5ed81d9..b939036 100644 --- a/_topics/08-reproducible-research-practices/src/python/_utils.py +++ b/_topics/08-reproducible-research-practices/src/python/_utils.py @@ -191,8 +191,8 @@ def export_schema( return json_model -def screaming_snake_case_to_pascal_case(s: str) -> str: - words = s.split("_") +def screaming_snake_case_to_pascal_case(value: str) -> str: + words = value.split("_") return "".join(word.capitalize() for word in words) @@ -243,3 +243,15 @@ def bonsai_sgen( cmd_string += " --serializer" cmd_string += " ".join([f" {sr.value}" for sr in serializer]) return run(cmd_string, shell=True, check=True) + + +def pascal_to_snake_case(value: str) -> str: + result = "" + for i, char in enumerate(value): + if char.isupper(): + if i != 0: + result += "_" + result += char.lower() + else: + result += char + return result \ No newline at end of file