A Python to JavaScript two way converter. Your client side done in a Jiphy.
Project description
Write your client side code in a Jiphy! Jiphy is a two-way Python->JavaScript converter. It’s not meant to create runnable Python code from complex JavaScript files, or runnable JavaScript from complex Python projects. Instead, Jiphy enables Python programmers to more easily write JavaScript code by allowing them to use more familiar syntax, and even JavaScript developers to more easily write Python code.
As a Python developer you can convert existing code in someone else’s project from JavasScript into Python, edit it, and then convert it back before submitting.
Jiphy’s Design Objectives:
Reduce the context switching necessary for a Python developer to write JavaScript code and vice versa.
Always output 1:1 line mappings (a line of Python produces a line of JavaScript) so source maps are not necessary.
Be usable for a single developer on a project (No mass buy-in needed).
Should be easy to write text-editor plugins that expose Jiphy within IDEs for on-the-spot conversion.
Quickly run over many files.
Change syntax only
Write:
import underscore as _
def my_function(argument1, argument2):
if argument1:
del argument2
elif argument2:
print(argument2)
if somevar is someothervar And x is not b: pass
Get:
var _ = require('_');
function my_function(argument1, argument2) {
if (argument1) {
delete argument2;
} else if (argument2) {
console.log(argument2);
}
if (somevar === someothervar && x !== b) {}
}
in a jiphy.
Important things to know when writing Python for conversion to JavaScript
Every indented block must have a line after it.
For instance:
if something is True:
do_something()
print("done")
Is valid as the if statement has a new line after it. However:
if something is True:
do_something()
print("done")
is NOT valid in Jiphy. The lack of a new line makes it impossible to do a 1:1 conversion and still be nicely formatted JS code.
Jiphy isn’t smart enough to know when to create a var
For now, you still have to write var in front of new variables in Jiphy. Jiphy simply does not yet have the smarts to know when it is and when it is not required.
Jiphy does not implement stdlib components, classes, etc. It’s SYNTAX ONLY.
Syntax / Contstructs Jiphy Suppports
Python |
JavaScript |
Supported To JavaScript |
Supported To Python |
|---|---|---|---|
def (…): |
function(…) {} |
✓ |
✓ |
if …: |
if (…) {} |
✓ |
✓ |
elif …: |
} else if (…) { |
✓ |
✓ |
else: |
} else { |
✓ |
✓ |
pass |
{} |
✓ |
✓ |
print(…) |
console.log(…) |
✓ |
✓ |
True |
true |
✓ |
✓ |
False |
false |
✓ |
✓ |
None |
null |
✓ |
✓ |
Or |
|| |
✓ |
✓ |
And |
&& |
✓ |
✓ |
Unset |
undefined |
✓ |
✓ |
not |
! |
✓ |
✓ |
is |
=== |
✓ |
✓ |
del |
delete |
✓ |
✓ |
; |
✓ |
✓ |
|
# comment |
// comment |
✓ |
✓ |
import x |
var x = require(x) |
✓ |
|
import x as _ |
var _ = require(x) |
✓ |
|
“String” |
‘String’ |
✓ |
|
“””String””” |
‘Str’ + ‘ing’ |
✓ |
|
Installing jiphy
Installing jiphy is as simple as:
pip install jiphy
or if you prefer
easy_install jiphy
Using jiphy
from the command line:
jiphy mypythonfile.py mypythonfile2.py
or recursively:
jiphy -rc .
which is equivalent to
jiphy **/*.py
or to see the proposed changes without applying them
jiphy mypythonfile.py --diff
from within Python:
import jiphy jiphy.to.javascript(python_code) jiphy.to.python(javascript_code)
Why jiphy?
jiphy (pronounced: jiffy) simply stands for JavaScript In, Python Out.
Thanks and I hope you find jiphy useful!
~Timothy Crosley
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jiphy-1.0.0.tar.gz.
File metadata
- Download URL: jiphy-1.0.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f12d328a8c125d438c62cd6177a3ed24bd5c53adfc86a2baf88fc416de47463
|
|
| MD5 |
bcbc8884a174e85d7afe8f084c4d47b4
|
|
| BLAKE2b-256 |
65c3ab46d303dc4128085f08e0cabb4d073ada55b714e2927e86d25af2b408bb
|
File details
Details for the file jiphy-1.0.0-py2.py3-none-any.whl.
File metadata
- Download URL: jiphy-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
798bebed9c9d3b4df771a819d39faff0754fa14e66512cf7d2df2dc83d9124e3
|
|
| MD5 |
63a32863caeafa29a030999b78651227
|
|
| BLAKE2b-256 |
cca2b188f2595e87998cac68f06c3375e41b6bfbc20190c4274098af0fddd56d
|