from typing import Optional
from typing import Union
import json


def _jsify_dict(d: dict, stringify: Optional[bool] = False) -> Union[dict, str]:
    """
    JavaScript-ify Python dicts: use camelCase string keys.
    """
    def _snake2camel(s: str) -> str:
        s_split = s.split("_")
        return "".join([s_split[0]] + [e.capitalize() for e in s_split[1:]])

    d2 = dict(
        (_snake2camel(str(k)), _jsify_dict(v) if isinstance(v, dict) else v)
        for k, v in d.items())
    return d2 if not stringify else json.dumps(
        d2, separators=(',', ':')).replace("\"", "'")