Skip to main content

esprimajs is a es6-compatible javascript minifier written by python. esprimajs uses esprima-python as javascript parser library

Features

  • ES6 support

  • Mangling function and variable names

  • Ident output

  • Obfuscate strings

Installation

pip install esprimajs

Examples

Example javascript file

const Aconst = Math.PI, Bconst = "Bconst";
const Cconst = "Cconst";

function add(a, b){
        function foo(){
                return a+b;
        }
        return foo();
}

const Dconst="Dconst";

function mul(a, b){
        return a*b;
}


const Econst="Econst";
let Alet="Alet";
const Fconst="Fconst", Gconst="Gconst";

Rearrange and mangle variables:

python -m esprimajs -r -mv 2 test.js
const Aconst=Math.PI,Bconst="Bconst",Cconst="Cconst";
function add($a,$b){
  function foo(){
    return $a+$b;
  }
  return foo();
}
const Dconst="Dconst";
function mul($a,$b){
  return $a*$b;
}
const Econst="Econst",Fconst="Fconst",Gconst="Gconst";
let Alet="Alet";

Rearrange variables and mangle variables (include top-level) and function names (except top-level):

python -m esprimajs -r -mv 1 --mf 2 test.js
const $a=Math.PI,$b="Bconst",$c="Cconst";
function add($d,$e){
  function $f(){
    return $d+$e;
  }
  return $f();
}
const $d="Dconst";
function mul($e,$f){
  return $e*$f;
}
const $e="Econst",$f="Fconst",$g="Gconst";
let $h="Alet";

Rearrange variables and mangle variables and function names (include top level) without identing:

python -m esprimajs -i 0 -r -mf 1 -mf 1 test.js
const $a=Math.PI,$b="Bconst",$c="Cconst";function $d($e,$f){function $g(){return $e+$f;}return $g();}const $e="Dconst";function $f($g,$h){return $g*$h;}const $g="Econst",$h="Fconst",$i="Gconst";let $j="Alet";

Obfuscate string and integers:

echo 'const A=100,B=200; console.log(`a+b=${A+B}`);' | python -m esprimajs -os -oi -mv 1 -i 0
const $a=0x64,$b=0o310;console.log(`\x61\x2b\x62\x3d${$a+$b}`);

API

Minify javascript string:

>>> from esprimajs import Minifier
>>> c = Minifier(rearrange=True, mangle_variables=1)
>>> js = """
... const A=1;
... const B=2;
... let C=3;
...
... class TestClass extends Object{
...   constructor(a, b){
...     this._a=a;
...     this.b=b;
...   }
...   static get a(){
...     return this._a;
...   }
...   set b(b){
...     this.b=b;
...   }
...
...   static async sum(){
...     return this.a+this.b
...   }
... }
... """
>>> buf = c.minify(js)
>>> print(buf.read())
const $a=1,$b=2;
let $c=3;
class TestClass extends Object{
  constructor($d,$e){
    this._a=$d;
    this.b=$e;
  }
  static get a(){
    return this._a;
  }
  set b($d){
    this.b=$d;
  }
  static async sum(){
    return this.a+this.b;
  }
}
>>>

Metadata

Release files for esprimajs-x 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for esprimajs-x 0.1.0
File Size Uploaded Provenance Actions
esprimajs_x-0.1.0.tar.gz 13.5 kB Without provenance Details for esprimajs_x-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for esprimajs-x 0.1.0
File Interpreter ABI Platform Actions
esprimajs_x-0.1.0-py3-none-any.whl Python 3 none any Details for esprimajs_x-0.1.0-py3-none-any.whl

Total release size: 40.2 kB

Release files / esprimajs_x-0.1.0.tar.gz

Download URL esprimajs_x-0.1.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bc8efb79589925f5a4ef56578a6903bab02cf36e8d424716db84ed622b426411
BLAKE2b-256 checksum
How to use checksums
28fcf9445f9f15c84136e618f8953a37c99db8a8eb553137dadc3bc2780f419b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / esprimajs_x-0.1.0-py3-none-any.whl

Download URL esprimajs_x-0.1.0-py3-none-any.whl
Size 26.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dff48b1c12a73372771792d1f7b51b46364311702918cf8a0f219994ad8494fc
BLAKE2b-256 checksum
How to use checksums
d9bb4f72f45d2f647820680fbd5a6176779dfc6fed1ca20c31e1e34d8bcc57ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Security for esprimajs-x 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page