jy.bridge
Python portals to JS
- class jy.bridge.JsBridge[source]
The default class to make instances that will contain methods that mirror JS function calls
- jy.bridge.add_js_funcs(js_code: str, *, obj: Any = None, name: str | None = None, encoding: str | None = None, forbidden_method_names=(), apply_defaults=True, value_trans=<function dflt_py_to_js_value_trans>)[source]
Add js call functions as attributes to an object.
If object is not given,
add_js_funcswill use a newJsBridgeinstance.>>> js_code = """ ... function foo(a, b="hello", c= 3) { ... return a + b.length * c ... } ... const bar = (y, z = 1) => y * z ... func.assigned.to.nested.prop = function (x) { ... return x + 3 ... } ... """ >>> js = add_js_funcs(js_code) >>> from inspect import signature >>> list(vars(js)) ['foo', 'bar', 'prop'] >>> signature(js.foo) <Sig (a, b='hello', c=3)> >>> js.foo(1, 'hi') 'foo(1, "hi", 3)' >>> js.prop('up') 'func.assigned.to.nested.prop("up")'
- jy.bridge.iskeyword()
x.__contains__(y) <==> y in x.