1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
class Parser:
@staticmethod
def dict_for_js(object_to_parse: dict) -> dict:
return_dict = {}
for key, value in object_to_parse.items():
if isinstance(value, bool):
return_dict[key] = str(value).lower()
continue
return_dict[key] = value
return return_dict
@staticmethod
def js_for_dict(object_to_parse: dict) -> dict:
return_dict = {}
for key, value in object_to_parse.items():
if isinstance(value, str):
value: str
if value.lower() in ["true", "false"]:
return_dict[key] = True if value.lower() == "true" else False
continue
return_dict[key] = value
return return_dict
|