Skip to content

code4fukui/js2py

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Converts JavaScript to Python ES modules

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

Usage

in JavaScript

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));

as a command

deno run -A cli.js example.js

Test

cd test
deno test JS2Py.spec.js 

Support Libraries

Similar Projects

About

Convert JavaScript to Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%