Skip to main content

A port of Javascript API to python. Useful for interoperability, porting js code and more...

Project description


JavaScript
JS API in python 3!

PyPI version Downloads Python version Build status Python package

Contains

javascript : js API in python 3 😳
• JSON : utils for loading / decorating / transforming

See the docs/code for more features... https://JavaScript.readthedocs.io/

or examples in the repo...

API

from JavaScript import Math
print(Math.random())

from JavaScript import Array
myArr=Array(1,2,3)
print(myArr.splice(1))

from JavaScript import URL
url = URL('https://somesite.com/blog/article-one#some-hash')
print(url.protocol)
print(url.host)
print(url.pathname)
print(url.hash)

# you can use Global class to import all the js methods from the global namespace i.e
# from JavaScript.javascript import Global
# Global.decodeURIComponent(...
# Global.encodeComponent(...
# Global.setInterval(...

# from JavaScript.javascript import Date, String, Number
# etc..

You can use setInterval and clearInterval with params

from JavaScript import setInterval, clearInterval

x=0

def hi(inc):
    global x
    x = x+inc
    print(x)

test = setInterval(hi, 1000, 2)
import time
time.sleep(5)
clearInterval(test)
print(f"Final value of x:{x}")

Or for a single delayed function call use setTimeout, clearTimeout

from JavaScript import setTimeout, clearTimeout

timeoutID = setTimeout(hi, 1000)

DOCS

https://JavaScript.readthedocs.io/

notes

Do some notes here

CLI

There's a few args you can pass to JavaScript on the command line to help you out.

To launch the docs for a quick reference to the APIs use:

python3 -m JavaScript -h

This command will attempt to generate a template from a webpage. (only simple pages for now)

python3 -m JavaScript -d http://eventual.technology

Then you can edit/tweak it to get what you need and build new components quicker.

EXAMPLE PROJECTS

There's several useage examples in the domonic repo so pull and have a look.

Join-In

Feel free to contribute if you find it useful.

Email me, message me directly if you like or create a discussion on here.

If there are any methods you want that are missing or not complete yet or you think you can help make it better just update the code and send a pull request.

I'll merge and releaese asap.

run tests

There are tests used during dev. They are useful as code examples and to see what still needs doing.

See Makefile to run all tests:

make test

or to test a single function:

python -m unittest tests.test_javascript.TestCase.test_javascript_array

or to test a whole module

python -m unittest tests.test_javascript

to see coverage

coverage run -m unittest discover tests/
coverage report

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

esx-0.0.1.tar.gz (37.0 kB view hashes)

Uploaded Source

Built Distribution

esx-0.0.1-py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page