JS to Python Converter

A VS Code extension that converts JavaScript code to Python with intelligent syntax transformations. This extension helps developers quickly translate JavaScript snippets to Python, making it easier to work across both languages.
🚀 Features
This extension provides an intelligent way to convert JavaScript code snippets to their Python equivalents. It handles common JavaScript constructs and converts them to idiomatic Python code with proper indentation and syntax.
✨ Supported Conversions
- Variable declarations:
let x = 5;
/ const name = "John";
/ var flag = true;
→ x = 5
/ name = "John"
/ flag = True
- Console output:
console.log("Hello World");
→ print("Hello World")
- Boolean values:
true
/ false
→ True
/ False
- Null/undefined:
null
/ undefined
→ None
- Function declarations:
function greet(name) { ... }
→ def greet(name): ...
- Arrow functions:
const add = (a, b) => { ... }
→ def add(a, b): ...
- Control structures:
if (condition) { ... }
→ if condition: ...
else if (condition) { ... }
→ elif condition: ...
else { ... }
→ else: ...
while (condition) { ... }
→ while condition: ...
for (let i = 0; i < n; i++) { ... }
→ for i in range(0, n): ...
- Comments:
// comment
→ # comment
- Arrays: JavaScript arrays are preserved as Python lists
- Basic objects: Simple object syntax conversion to Python dictionaries
📋 Example Conversion
JavaScript Input:
function calculateSum(numbers) {
let total = 0;
for (let i = 0; i < numbers.length; i++) {
total += numbers[i];
}
console.log("Total:", total);
return total;
}
let nums = [1, 2, 3, 4, 5];
let result = calculateSum(nums);
Python Output:
def calculateSum(numbers):
total = 0
for i in range(0, numbers.length):
total += numbers[i]
print("Total:", total)
return total
nums = [1, 2, 3, 4, 5]
result = calculateSum(nums)
🎯 Usage
- Select JavaScript code in any file (or position cursor in a JavaScript file to convert entire file)
- Right-click and select "Convert JavaScript to Python" from the context menu
- The converted Python code will open in a new tab beside your current file
Method 2: Command Palette
- Open Command Palette (
Ctrl+Shift+P
on Windows/Linux, Cmd+Shift+P
on macOS)
- Type "Convert JavaScript to Python" and select the command
- Ensure you have JavaScript code selected or are in a JavaScript file
Method 3: Keyboard Shortcut
- The extension integrates with VS Code's command system, so you can assign a custom keyboard shortcut through VS Code's keyboard shortcuts settings
📋 Requirements
- VS Code: Version 1.80.0 or higher
- Operating System: Cross-platform (Windows, macOS, Linux)
⚙️ Extension Settings
This extension works out of the box with no additional configuration required. It automatically activates when you use the conversion command.
Currently, this extension does not contribute any VS Code settings, but future versions may include customization options for:
- Indentation preferences
- Comment style conversion
- Advanced syntax transformation rules
🐛 Known Issues
- Complex nested structures: Very complex nested objects and advanced JavaScript features may not convert perfectly
- ES6+ features: Some modern JavaScript features (destructuring, template literals, etc.) are not yet fully supported
- Async/await: Asynchronous JavaScript patterns require manual adjustment in Python
- For loop variations: Only basic
for
loops with numeric counters are automatically converted
📝 Release Notes
1.0.0 - Initial Release
Added:
- Core JavaScript to Python conversion functionality
- Support for basic syntax transformations (variables, functions, control structures)
- Context menu integration
- Command palette support
- Comprehensive test suite
- Boolean, null, and undefined value conversions
- Comment style conversion (// to #)
- Basic indentation handling
Features:
- Convert variable declarations (let, const, var)
- Convert function declarations and arrow functions
- Convert console.log to print statements
- Convert control structures (if/else, loops)
- Proper Python indentation
- Side-by-side result display
🚀 Installation
From VSIX Package
- Download the
js-to-python-convert-1.0.0.vsix
file
- Open VS Code
- Press
Ctrl+Shift+P
(Windows/Linux) or Cmd+Shift+P
(macOS)
- Type "Extensions: Install from VSIX"
- Select the downloaded
.vsix
file
Manual Installation
code --install-extension js-to-python-convert-1.0.0.vsix
🛠️ Development
If you want to contribute or modify this extension:
# Clone the repository
git clone <repository-url>
cd js-to-python-converter
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch for changes during development
npm run watch
# Run tests
npm test
# Lint code
npm run lint
# Package extension
vsce package --allow-missing-repository
🤝 Contributing
Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.
📄 License
This extension is licensed under the MIT License.
🔗 Keywords
javascript
, python
, converter
, transpiler
, syntax-transformation
, code-conversion
Enjoy converting your JavaScript code to Python! 🐍✨