python-js-files
This is a collection of Python functions for manipulating JavaScript "data files" -- that is, JavaScript files that define a single variable with a JSON value.
This is an example of a JavaScript data file:
const shape = { "sides": 5, "colour": "red" };
Think of this module as the JSON module, but for JavaScript files.
Usage
- You can read a JavaScript file with
read_js(path, varname) - You can write a JavaScript file with
write_js(path, value, varname) - You can append an item to a JavaScript array with
append_to_js_array(path, value) - You can append a key-value pair to a JavaScript object with
append_to_js_object(path, key, value)
Installation
You have two options:
-
Copy the file
src/javascriptfolder into your project. You probably want to copy the tests as well. -
Install the package using pip:
$ pip install alexwlchan-python-js-files
Why not use JSON files?
If you've opening an HTML file from disk, you can load data from a local JavaScript file, for example:
<script src="file://users/alexwlchan/repos/python-js-files/data.js"></script>
This is the only way to load data from an external file from an HTML file you've opened locally -- you can't do this with a JSON file, for example.
I have a lot of HTML files and local sites I build with an HTML viewer and metadata in a JavaScript file. The convenience of this approach outweighs the mild annoyance of having to store data in JavaScript, not JSON.
License
MIT.
Metadata
Release files for alexwlchan-python-js-files 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| alexwlchan_python_js_files-1.0.1.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| alexwlchan_python_js_files-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / alexwlchan_python_js_files-1.0.1.tar.gz
| Download URL | alexwlchan_python_js_files-1.0.1.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8463e71d82d24fee4316423ae362cbcbce38db894c3a5e734cdf22c62240b7e5
|
|
BLAKE2b-256 checksum How to use checksums |
08d401af1eb7545240e2b83ea774c0d352b3192459b4e0420760f48abdd9cd09
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.0
|
Release files / alexwlchan_python_js_files-1.0.1-py3-none-any.whl
| Download URL | alexwlchan_python_js_files-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6dd268ce96d34785579c670c6eeb6ef17a2ec62b0eaf7493febc7b23894967c3
|
|
BLAKE2b-256 checksum How to use checksums |
2e49184e405f12e46e32fbc9887a9ced72ccde698f6cfeae3459afa12d5c4f48
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.0
|