Coder Social home page Coder Social logo

id-uglifier's Introduction

Description

id-uglifier is a 2-pass brute force code uglifier.

It works based on the raw assumption that every identifier that ends
with _UG is subject to uglification. It also accepts a table of identifiers to be uglified.

id-uglifier is language agnostic and not only uglifies source code but also
css, html, text and whatever you feed it.
In essence, you provide it a file tree and it will generate and output file tree
where every id that matches a pattern will be replace with ug_NNNN.

At first glance, it might look like that it's too blind for industrial-strength projects,
but the probability of running into an external library where the ids end with _UG is very low.
And, if such case occurs, id-uglifier allows to define another id suffix.

id-uglifier isn't built for existing projects, but instead of projects
where the business logic is prepared from inception for id uglification,
the extra prefix will give clues to the developers that
that id will be changed in the final output.

Installation

[sudo] npm install -g id-uglifier

Usage

id-uglifier [options] input-file-globs

input-file-globs is a list of glob patterns https://www.npmjs.com/package/glob
or if starts with @ it will be read from a file with same rules as -idfile
id-uglifier has a safety mechanism to never overwrite the input

Where the options are:

    -in pattern      input filename regex pattern  
    -out pattern     output filename pattern  
    -e exclude-files this is a glob pattern [https://github.com/isaacs/minimatch]  
                     that excludes files from being processed.  
                     Use multiple times to exclude multiple patterns or  
                     start with @ to retrieve from a file  
    -off             disabled the processing  
    -noopt           doesn't optimizes output ids by frequency  
    -m|-mapfile      name of map to generate with a list in-ids=out-ids  
                     if the mapfile ends with .json it will output a json format  
    -idfile          input filename with the list of ids,  
                     separated by LF or CRLF to be uglified  
                     lines starting with # will be discarded  
    -ins|-insuffix   input id suffix. default is _UG.  
                     use '.' to deactivates the default input suffix  
    -outp|-outprefix output id prefix. default is ug_  
    -v               verbose  
    -version         version  

Examples

id-uglifier -in in-folder -out out-folder -m test/outmap.txt test/in-folder/**

Reads test/in-folder/**, processes the ids,
outputs the to test/out-folder/**
and writes the id map to test/outmap.txt
If out-folder doesn't exists, it creates it on the fly

id-uglifier -noopt -in in-folder -out out-folder -ins . -ous ug__ -idfile test/idlist.txt -m test/outmap.json -e '*.css' test/in-folder/**

Same as above but deactivates order id by frequency,
the out map is in .json format,
loads an idlist file to uglify,
the output prefix is ug__ instead of ug_,
excludes all the '.css' files
and disactivates the default input prefix

id-uglifier -noopt -in '\\.(\\w+)$' -out '.out.$1' test/in-folder/**

Writes the output to the same folder but adds .out to the extension
input is test/in-folder/**
output will be test/in-folder/test-input.out.js

Example Input/Output

Input

function testFunc() {  
    var _thisisavar_UG = 3;  
    var highfreq_UG = 7;  
    highfreq_UG++;  
    highfreq_UG++;  
}

Output

function testFunc() {  
    var ug_1 = 3;  
    var ug_0 = 7;  
    ug_0++;  
    ug_0++;  
}

License

MIT License+uuid License

Copyrights

(c) 2018 Alexandre Bento Freire

id-uglifier's People

Contributors

a-bentofreire avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.