obsws-python/obsstudio_sdk/util.py

27 lines
552 B
Python
Raw Normal View History

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):
2022-07-28 11:55:05 +01:00
def attrs():
return list(to_snake_case(k) for k in data.keys())
2022-07-28 11:55:05 +01:00
return dataclass(
type(
f"{identifier}Dataclass",
(),
2022-07-28 11:55:05 +01:00
{
"attrs": attrs,
**{to_snake_case(k): v for k, v in data.items()},
},
)
)