jscode

Utility classes and functions for JavaScript code generation

class JsCode[source]

Bases: abc.ABC

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

Bases: sensai.util.jscode.JsCode

__init__(js_code: str)
get_js_code()
class JsValue[source]

Bases: sensai.util.jscode.JsCode, abc.ABC

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

Bases: sensai.util.jscode.JsValue

__init__(js_code: str)
get_js_code()
js_value(value: Union[sensai.util.jscode.JsValue, str, int, bool, float]) sensai.util.jscode.JsValue[source]
js_arg_list(*args: Union[sensai.util.jscode.JsValue, str, int, bool, float], drop_trailing_undefined=True) sensai.util.jscode.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: sensai.util.jscode.JsValue

__init__()
add(key: str, value: Union[sensai.util.jscode.JsValue, str, int, bool, float])
add_string(key: str, value: str)
add_code_literal(key: str, value: str)
add_float(key: str, value: Union[float, int])
add_json(key: str, value: Any)
Parameters
  • key – key within the object

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

get_js_code()
class JsClassInstance(class_name, *args: Union[sensai.util.jscode.JsValue, str, int, bool, float])[source]

Bases: sensai.util.jscode.JsValueLiteral

__init__(class_name, *args: Union[sensai.util.jscode.JsValue, str, int, bool, float])
class JsList(*values: Union[sensai.util.jscode.JsValue, str, int, bool, float])[source]

Bases: sensai.util.jscode.JsValueLiteral

__init__(*values: Union[sensai.util.jscode.JsValue, str, int, bool, float])