Skip to content

Commit

Permalink
feat(core/utils): add to_snake_case() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
aravinda0 committed May 1, 2024
1 parent ced2fc5 commit 1147ddd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/qtile_bonsai/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,12 @@ def rewrap(

def _replace_with_hard_space(match):
return len(match.group(0)) * " "


def to_snake_case(name: str) -> str:
"""Convert the provided string to snake case.
Stolen from https://stackoverflow.com/a/46493824
"""
words = re.findall(r"[A-Z]?[a-z]+|[A-Z]{2,}(?=[A-Z][a-z]|\d|\W|$)|\d+", name)
return "_".join(map(str.lower, words))

0 comments on commit 1147ddd

Please sign in to comment.