convert js to python online code example

Example 1: convert js to python online

>>> import js2py
>>> f = js2py.eval_js('function f(x) {return x + x}')
>>> f(2)
4
>>> f()
nan
>>> f(f)
function f(x) { [python code] }function f(x) { [python code] }

Example 2: convert js to python online

const MongoClient = require('mongodb').MongoClient;
const mongo_username = process.env.MONGO_USERNAME
const mongo_password = process.env.MONGO_PASSWORD

const uri = `mongodb+srv://${mongo_username}:${mongo_password}@cluster0-zrtwi.gcp.mongodb.net/crmdb?retryWrites=true&w=majority`;
const client = new MongoClient(uri, { useNewUrlParser: true });

Example 3: convert js to python online

const FS = require("fs");
var Thu_muc_Media = 'Media';
var Thu_muc_Du_lieu = 'Du_lieu';
var Thu_muc_HTML = Thu_muc_Du_lieu+"\\HTML";
var Thu_muc_Nhan_vien = Thu_muc_Du_lieu+"\\Nhan_vien/";
var Thu_muc_Quan_ly = Thu_muc_Du_lieu+"\\Quan_ly_Chi_nhanh";

Example 4: convert js to python online

[x].match( / \ [ ] \ ( { } \) | \ ( \ [ ] \) | { \ ( \) \ [ ] } / g ) )

Example 5: convert js to python online

function coppie(a,b){
  var c=[];
  for(var i=0;i<a.length;i++){
    for(var j=0;j<b.length;j++){
      if (a[i]==b[j]){
        c.push(a[i]);
      }
    }
  }
  return c;
}

Example 6: convert js to python online

function coppie(a,b){
  var c=[];
  for(var i=0;i<a.length;i++){
    for(var j=0;j<b.length;j++){
      if (a[i]==b[j]){
        c.push(a[i]);
      }
    }
  }
  return c;
}

Example 7: convert js to python online

const express = require('express')
const app = express();
const port = 3000

app.get('/', (req, res) => res.send('Yo boi!!'))

app.listen(port, () =>
console.log(`Your app is listening a http://localhost:${port}`)
);

Example 8: convert js to python online

function slowestKey(keyTimes) {    
  // Write your code here
  const makeChar = num => String.fromCharCode(num + 97)    
  const map = []
  for(let i = 0; i < keyTimes.length; i++){
      if(keyTimes[i - 1]){
          map.push([keyTimes[i][0], keyTimes[i][1] - keyTimes[i - 1]	 [1]])
      }
        else{
	    map.push([keyTimes[i][0], keyTimes[i][1]])
    }    
    map.sort((first, second) => second[1] - first[1])
    return makeChar(map[0][0])}

Example 9: convert js to python online

function jsfuckdecode(text) {
	var jsFuckText = text;
    //console.log(jsFuckText);
	var start = jsFuckText.indexOf("()");
	var len = jsFuckText.length;
	try {
        var result = '';
		if (jsFuckText.length > 3 && jsFuckText.slice(len - 3) == ')()') {
			var txt = jsFuckText.substring(0, len - 2);
			result = (/\n(.+)/.exec(eval(txt))[1]);
		} else if (jsFuckText.substring(0, 2) == '[]' && start >= 0) {
			var txt = jsFuckText.substring(start + 2);
			result = document.getElementById("plaint_jsfuck").value = (eval(txt));
		} else {
			result = document.getElementById("plaint_jsfuck").value = (eval(jsFuckText));
		}
        return result;
	} catch (e) {
		return "error input";
	}