jscode#


Utility classes and functions for JavaScript code generation

class JsCode[source]#

Bases: ABC

abstract get_js_code()[source]#
class JsCodeLiteral(js_code: str)[source]#

Bases: JsCode

get_js_code()[source]#
class JsValue[source]#

Bases: JsCode, ABC

classmethod from_python(value: Union[str, int, bool, float])[source]#
classmethod from_value(value: Union[JsValue, str, int, bool, float])[source]#
is_undefined()[source]#
static string_value(s: str)[source]#
static int_value(value: int)[source]#
static float_value(value: Union[float, int])[source]#
static bool_value(value: bool)[source]#
static undefined()[source]#
static null()[source]#
class JsValueLiteral(js_code: str)[source]#

Bases: JsValue

get_js_code()[source]#
js_value(value: Union[JsValue, str, int, bool, float]) JsValue[source]#
js_arg_list(*args: Union[JsValue, str, int, bool, float], drop_trailing_undefined=True) JsCode[source]#
Parameters:
  • args – arguments that are either JsValue instances or (supported) Python values

  • drop_trailing_undefined – whether to drop trailing arguments that are undefined/None

Returns:

the JsCode

class JsObject[source]#

Bases: JsValue

add(key: str, value: Union[JsValue, str, int, bool, float])[source]#
add_string(key: str, value: str)[source]#
add_code_literal(key: str, value: str)[source]#
add_float(key: str, value: Union[float, int])[source]#
add_json(key: str, value: Any)[source]#
Parameters:
  • key – key within the object

  • value – any Python object which can be converted to JSON

get_js_code()[source]#
class JsClassInstance(class_name, *args: Union[JsValue, str, int, bool, float])[source]#

Bases: JsValueLiteral

class JsList(*values: Union[JsValue, str, int, bool, float])[source]#

Bases: JsValueLiteral