0

I have a js file with the following code:

(function(module, exports) {

eval("module.exports = function(module) {\n\tif (!module.webpackPolyfill) {\n\t\tmodule.deprecate = function() {};\n\t\tmodule.paths = [];\n\t\t// module.parent = undefined by default\n\t\tif (!module.children) module.children = [];\n\t\tObject.defineProperty(module, \"loaded\", {\n\t\t\tenumerable: true,\n\t\t\tget: function() {\n\t\t\t\treturn module.l;\n\t\t\t}\n\t\t});\n\t\tObject.defineProperty(module, \"id\", {\n\t\t\tenumerable: true,\n\t\t\tget: function() {\n\t\t\t\treturn module.i;\n\t\t\t}\n\t\t});\n\t\tmodule.webpackPolyfill = 1;\n\t}\n\treturn module;\n};\n\n\n//# sourceURL=webpack:///(webpack)/buildin/module.js?");

/***/ })

How to beautify The string in the eval function? I tried using js beautifer websites but it doesn't work on the string inside eval function. Basically, the \n in the code should be converted to new lines for easier understanding off the code.

dc09
  • 386
  • 2
  • 17
  • Have you looked at this: https://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript – Eriks Klotins Nov 15 '19 at 12:30
  • 1
    Copy that line to another file. Replace `eval` with `console.log`. Then execute that other file by running `node another_file.js`. If you are on Linux or OSX or linux on Windows or run in gitbash or some other posix terminal in windows you can save the code to a file by typing `node another_file.js > beautiful_code.js` – slebetman Nov 15 '19 at 12:35

1 Answers1

0

You can use the back-tick character instead of quotes

eval(
  `module.exports = function(module) {
    if (!module.webpackPolyfill) {
      module.deprecate = function() {};
      module.paths = [];
      // module.parent = undefined by default
      if (!module.children) module.children = [];
      Object.defineProperty(module, "loaded", {
        enumerable: true,
        get: function() {
          return module.l;
        }
      });
      Object.defineProperty(module, "id", {
        enumerable: true,
        get: function() {
          return module.i;
        }
      });
      module.webpackPolyfill = 1;
    }
    return module;
  };


  //# sourceURL=webpack:///(webpack)/buildin/module.js?`
);

That way you don't have to use \n or \t