mirror of
https://github.com/onyx-and-iris/obsws-python.git
synced 2026-04-18 05:53:32 +00:00
namechange ops
This commit is contained in:
26
obsws_python/util.py
Normal file
26
obsws_python/util.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
def to_camel_case(s):
|
||||
return "".join(word.title() for word in s.split("_"))
|
||||
|
||||
|
||||
def to_snake_case(s):
|
||||
return re.sub(r"(?<!^)(?=[A-Z])", "_", s).lower()
|
||||
|
||||
|
||||
def as_dataclass(identifier, data):
|
||||
def attrs():
|
||||
return list(to_snake_case(k) for k in data.keys())
|
||||
|
||||
return dataclass(
|
||||
type(
|
||||
f"{identifier}Dataclass",
|
||||
(),
|
||||
{
|
||||
"attrs": attrs,
|
||||
**{to_snake_case(k): v for k, v in data.items()},
|
||||
},
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user