You can use this : http://jsbeautifier.org/ But it depends on the minify method you are using, this one only formats the code, it doesn't change variable names, nor uncompress base62 encoding.
edit: in fact it can unpack "packed" scripts (packed with Dean Edward's packer : http://dean.edwards.name/packer/)
Answer from Fabien Ménager on Stack OverflowVideos
I found some large JS files online that I'd really like to peel back and learn from. However, the code is minified/obfuscated (whichever you'd describe it). From what I could get out of searching around it might be done by a bundler of some sort. Below is a snippet of what I'm working with.
P.S. Just to clarify I'm not doing this to learn HOW to write javascript, I've used javascript for most of my projects. I sometimes like to see how some of my favorite apps/websites do what they do.
(() => {
"use strict";
var e,
t,
n,
r = {
8029: function (e, t, n) {
var r = (this && this.__importDefault) || function (e) { return e && e.__esModule ? e : { default: e }; };
Object.defineProperty(t, "__esModule", { value: !0 }), (t.TotalStats = t.WebsiteStats = void 0);
const a = r(n(7294)), l = r(n(932)), o = n(2247), u = n(5761), i = n(2540),
s = l.default.div`
display: flex;
flex-direction: column;
gap: ${(e) => e.theme.spaces.minimal};
margin-bottom: 15px;
`;
(t.WebsiteStats = function (e) { const { t } = (0, o.useTranslation)(), { summary: n } = (0, u.useSummarizedOpenAttempts)(e.website.host), r = e.website.name; return a.default.createElement(
s, null, a.default.createElement(i.Round.Large, null, n.last24HoursAttempts.length), a.default.createElement(i.Paragraph.Small, null, t("interventions.basicBreath.last24Hours", { subject: r })));
}), (t.TotalStats = function () { const { t: e } = (0, o.useTranslation)(), { preventedAttemptsIndication: t, populatedEnough: n } = (0, u.useWebsitesStatsSummary)(),
r = Math.round(60 * t * 3), l = (0, u.useFormatDuration)(); return n ? a.default.createElement( i.Paragraph.Small,
{ style: { textAlign: "center" } }, e("popup.totalTimeSaved", { time: l(r) })
) : null;
});
},
...
}
...
}
)();Does anyone know how to unminify JavaScript code in VS Code? Currently my JS code looks like. I've found several different suggestions online, but none have worked:
-
ctrl-k, followed by ctrl-d
-
ctrl-e, followed by d
-
alt+shift+f
-
right click on code and select 'format'
I realize I might not be able to recover all data, but I'm looking to at least format the code in a more readable manner.
Thanks in advance.
Install a prettifier extension from the market. They’re sometimes called beautifiers, too.
Shift + Alt + F should have gotten you close. Does it only partially format it?
Another solution worth trying might be using the Prettifier extension. That might make the auto formatting better.
After you format it the first time you can manually format parts on your own and rerun the formatter to see if it gets any closer. Using regular expressions for find replace can also do a lot of work for you.
You can use this : http://jsbeautifier.org/ But it depends on the minify method you are using, this one only formats the code, it doesn't change variable names, nor uncompress base62 encoding.
edit: in fact it can unpack "packed" scripts (packed with Dean Edward's packer : http://dean.edwards.name/packer/)
Chrome developer tools has this feature built-in. Bring up the developer tools (pressing F12 is one way), in the Sources tab, the bottom left bar has a set of icons. The "{}" icon is "Pretty print" and does this conversion on demand.
UPDATE: IE9 "F12 developer tools" also has a "Format JavaScript" feature in the Script tab under the Tools icon there. (see Tip #4 in F12 The best kept web debugging secret)

There have been plenty of times when I have seen a cool web app or site and wondered how it worked. I want to see the CSS or the JS and see if I can work out what's going on.
I hit the dev console or give Firefox a Ctrl+u and am greeted by a massive wall of text - it's minified (I assume) for speed/efficiency reasons. But I want to read it!
I've been trying to figure out a way to de-minify stuff. I've been looking in the dev console and VSCode. But if there is a way to do this it's not obvious to me.
Is there any way?
Edit - Just want to say that I really appreciate this subreddit and want to thank everyone for their patience with those of us who are really, really new to web development.
Tool to Unminify / Decompress JavaScript
You cannot truly unminify javascript, as minified javascript replaces variable names with letters, as well as removing code comments - these cannot be "undone" as the original information no longer exists.
It appears that you can at least recreate appropriate spacing, but "real" minified javascript cannot be undone.
You can use Prettier https://prettier.io/docs/en/install.html, to get the script slightly human readable.
If you are having problem with vs code you can add this in your settings.json
"[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode" },
It works for me for mega file...