js-module-extractor is a lightweight Python CLI tool that extracts and beautifies JavaScript modules from a plain text file. It scans for lines using the pattern __d("moduleName", ...), extracts the module name, formats the code, and writes each module to a separate .js file.
- Detects JavaScript module definitions in
__d("...")format - Extracts and saves each module into its own file
- Beautifies the code using jsbeautifier
- CLI usage via
js-module-extractorcommand
Install directly from the GitHub repository:
pip install git+https://github.com/maxipalacios/js-module-extractor.gitAfter installing, you can run it from the command line:
js-module-extractor input_file.txtinput_file.txt: A UTF-8 encoded text file with one or more__d("moduleName", ...)lines.
The tool will create a folder named output_modules/ (if not already present) and generate one file per module:
output_modules/
└── MyModule.js
Each file contains beautified code extracted from the original input.
Input line:
__d("MyModule", function(global, require, module, exports) { /* code */ }, 123);Command:
js-module-extractor modules.txtResult:
output_modules/
└── MyModule.js
Clone the repo and install in editable mode:
git clone https://github.com/maxipalacios/js-module-extractor.git
cd js-module-extractor
pip install -e .Run locally:
js-module-extractor path/to/input.txtThis tool is provided under an open license for educational and practical use. Feel free to modify or extend it to fit your needs.