Coder Social home page Coder Social logo

deuglifyjs's Introduction

Deuglify

A utiltiy for reversing minified JS files, not simply formating whitespaces but also tries to make code much more readable.

Usage

CLI

$ npm install -g deuglify
$ deuglify source.js > source.demin.js
$ cat source.js | deuglify > source.demin.js

Module

const { deuglify } = require('deuglify')
const sourceCode = 'console.log("hello")'
const { code, ast } = deuglify(sourceCode)

Feature

  • Expand sequence expression into seperate statement
  • Split variable declaration to seperate declaration
  • Expand conditional expression and logical expresssion into if statement
  • Move irrelevant variable delcaration out of for statemet init expression
  • Transform !0 to true and !1 to false
  • Rename one letter variables to globally unique variable name (disabled when eval or with statement exists)

Example

Original source:

!(function (global, factory) {
  if (module && typeof module === 'object' && module.exports) {
    module.exports = factory();
  } else {
    global.fibonacci = factory();
  }
})(this, function () {
  var table = [1, 1];
  function fibonacci (n) {
    if (!table[n]) {
      table[n] = fibonacci(n - 1) + fibonacci(n - 2);
    }
    return table[n];
  }
  return fibonacci;
});

Minified:

!function(a,b){module&&"object"==typeof module&&module.exports?module.exports=b():a.fibonacci=b()}(this,function(){function a(c){return b[c]||(b[c]=a(c-1)+a(c-2)),b[c]}var b=[1,1];return a});

Formatted (with chrome):

!function(a, b) {
    module && "object" == typeof module && module.exports ? module.exports = b() : a.fibonacci = b()
}(this, function() {
    function a(c) {
        return b[c] || (b[c] = a(c - 1) + a(c - 2)),
        b[c]
    }
    var b = [1, 1];
    return a
});

Deuglified:

!function (a__q, b__w) {
  if (module && "object" == typeof module && module.exports) {
    module.exports = b__w();
  } else {
    a__q.fibonacci = b__w();
  }
}(this, function () {
  function a__e(c__t) {
    if (!b__r[c__t]) {
      b__r[c__t] = a__e(c__t - 1) + a__e(c__t - 2);
    }

    return b__r[c__t];
  }

  var b__r = [1, 1];
  return a__e;
});

deuglifyjs's People

Contributors

davidaq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  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.