Proof of concept, converting JS to Python in Pure JavaScript ES modules, for example:
import { BigNumber as BigN } from "https://unpkg.com/bignumber.js@latest/bignumber.mjs";
class MathDevice {}
class Calculator extends MathDevice {
constructor(args = []) {
super({})
}
static max(a, b) {
return BigN.max(a, b)
}
}
into
class MathDevice:
pass
class Calculator(MathDevice):
def __init__(self, args = []):
super().__init__({})
def add(self, a, b):
return max(a, b)
BigN is a special name for bignumber.js
import { JS2Py } from "https://code4fukui.github.io/js2py/src/JS2Py.js";
const f = new JS2Py()
const js = `for (let i = 0; i < 10; i++) { for (let j = 0; j < i; j++) { i + j }}`;
console.log(f.convert(js));
deno run -A cli.js example.js
cd test
deno test JS2Py.spec.js