toolleeo / cli-apps

The largest Awesome Curated list of CLI/TUI applications with source data organized into CSV files
1.43k stars 73 forks source link

Added programming util minify.js #48

Closed adamlui closed 5 months ago

vitorhcl commented 5 months ago

I asked ChatGPT if .min.js was different format than .js is how I ended up there, but programming indeed seems a better fit

@adamlui yeah, I asked ChatGPT (probably in a more complete way), see its response:

User Is a.min.js file just a .js file with unnecessary characters removed or it can be considered another file format?

ChatGPT A .min.js file is typically a minified version of a .js file, where unnecessary characters like whitespace, comments, and sometimes variable names are removed to reduce file size and improve load times. It's still considered a JavaScript file but optimized for production use.

adamlui commented 5 months ago

@vitorhcl my ChatGPT never claimed it wasn't JavaScript either, nor does yours claim it isn't a distinct file format. I asked again and it confirms both are true:

image

Just like .mp3 and .mp4 are both MPEG files, they are different file formats so not all programs can read them alike (audio players will mostly not output the video from .mp4s).

Similarly, .js and .min.js are both JavaScipt files, but interestingly while machines mostly can read them alike (if top-level name mangling is applied for example, globals may not be accessible from calling scripts in equal manners), humans outright cannot read both alike.

I asked ChatGPT yet again, this time it said:

image

But it points out something important, the formatting is different, so regardless of tradition should be considered different format based on this fact alone that it is formatted differently so how can it be same format.

But based on tradition and human intuition, programming is probably the better fit for category for the CLI app, so visitors don't find items that don't match expectations in categories thus leading to better UX

vitorhcl commented 5 months ago

@adamlui Yeah, we agree that it fits better in the programming category, it's more intuitive indeed.

However, IMO we can consider a minifier similar to a formatter/beautifier such as https://www.npmjs.com/package/js-beautify, but not a converter, because we can say that what defines a different file format is the machine reading, not the human reading.

We could also consider a obfuscator (like https://github.com/javascript-obfuscator/javascript-obfuscator) a "formatter" too, it kinda does the inverse of beautifiers.

Regardly of function or variable renaming, a JavaScript engine that was implemented correctly can equally read a human-readable JavaScript file and a minified version of it, just like it can equally read a JavaScript code with a bad formatting, a beautified JavaScript code and a obfuscated code :)

adamlui commented 5 months ago

Regardly of function or variable renaming, a JavaScript engine that was implemented correctly can equally read a human-readable JavaScript file and a minified version of it, just like it can equally read a JavaScript code with a bad formatting, a beautified JavaScript code and a obfuscated code :)

But even correctly coded minifiers allow for level of minification that can break calling scripts that referenced fully-named top-level globals prior to minification of imported script, but it's not a bug just a feature to cram max minification, so if the program author relied on import of unminified version before and switched, program breaks unless they (minimally) edit their program is what I mean the machine no longer reads it the same

Yeah, we agree that it fits better in the programming category, it's more intuitive indeed. However, IMO we can consider a minifier similar to a formatter/beautifier

So what is the verdict? Shall it go under programming, or a new section for formatter/beautifier/uglifier?

adamlui commented 5 months ago

But even correctly coded minifiers allow for level of minification that can break calling scripts that referenced fully-named top-level globals prior to minification of imported script, but it's not a bug just a feature to cram max minification, so if the program author relied on import of unminified version before and switched, program breaks unless they (minimally) edit their program is what I mean the machine no longer reads it the same

To expand on this, media converted to compressed format is rendered by machine as different outputs (especially noticeable if lossy) so it can also be said, compressed JS is similarly rendered by machine to possibly output differently-named globals (that require human intervention to unbreak calling code that referenced old globals).

And in both cases, bits and bytes were changed to different formatting, and both gain a new file extension that indicates a new file type (but with .min.js the change is still JS, so the extension's similarity makes sense), and both resulted in human noticing something changed, so both changed file format IMO since the consequences quintessential of changing formats are so strikingly similar

vitorhcl commented 5 months ago

But even correctly coded minifiers allow for level of minification that can break calling scripts that referenced fully-named top-level globals prior to minification of imported script, but it's not a bug just a feature to cram max minification, so if the program author relied on import of unminified version before and switched, program breaks unless they (minimally) edit their program is what I mean the machine no longer reads it the same

Yeah, but this has no relation with changing the file format. A huge refactoring can also break so much code, but it doesn't mean that it changed the file format.

To expand on this, media converted to compressed format is rendered by machine as different outputs (especially noticeable if lossy) so it can also be said, compressed JS is similarly rendered by machine to possibly output differently-named globals (that require human intervention to unbreak calling code that referenced old globals).

This isn't a equivalent comparation. For example, the same code that reads a WAV file (uncompressed format) can't read a MP3 files, they are different file formats. However, the same code of a JavaScript engine can read both unminified codes and minified ones, they follow the same rules of the language parsing, so both are the same file formats.

Again, human intervation does not implies a file format changing, just a huge (or not) change in the code.

And in both cases, bits and bytes were changed to different formatting, and both gain a new file extension that indicates a new file type (but with .min.js the change is still JS, so the extension's similarity makes sense), and both resulted in human noticing something changed, so both changed file format IMO since the consequences quintessential of changing formats are so strikingly similar

Well, human noticing something changed isn't a so relevant factor here, the key factor is that the same code can read both minified and unminified code.

Any change causes bits and bytes changes, so that doesn't really count. Aditionally, not all minifiers add an extension to the minified file (e.g. https://github.com/coderaiser/minify), it is a choice of the minifier.

Look at how radically different is an obfuscated code:

(function(_0x11bb4c,_0x2cc0ad){var _0x1ac648=_0x1d8c,_0x3fbe0a=_0x11bb4c();while(!![]){try{var _0x492326=-parseInt(_0x1ac648(0x1ca))/0x1*(-parseInt(_0x1ac648(0x1cb))/0x2)+parseInt(_0x1ac648(0x1c7))/0x3+-parseInt(_0x1ac648(0x1ce))/0x4*(parseInt(_0x1ac648(0x1cf))/0x5)+-parseInt(_0x1ac648(0x1cc))/0x6*(parseInt(_0x1ac648(0x1c5))/0x7)+-parseInt(_0x1ac648(0x1c8))/0x8*(-parseInt(_0x1ac648(0x1c3))/0x9)+-parseInt(_0x1ac648(0x1cd))/0xa*(parseInt(_0x1ac648(0x1c4))/0xb)+-parseInt(_0x1ac648(0x1c9))/0xc*(-parseInt(_0x1ac648(0x1c6))/0xd);if(_0x492326===_0x2cc0ad)break;else _0x3fbe0a['push'](_0x3fbe0a['shift']());}catch(_0xcb3bed){_0x3fbe0a['push'](_0x3fbe0a['shift']());}}}(_0x573f,0x882b6));function hi(){var _0x327b21=_0x1d8c;console[_0x327b21(0x1d0)]('Hello\x20World!');}function _0x1d8c(_0x16c872,_0x4a9823){var _0x573f64=_0x573f();return _0x1d8c=function(_0x1d8cb6,_0x170d8c){_0x1d8cb6=_0x1d8cb6-0x1c3;var _0x1189bb=_0x573f64[_0x1d8cb6];return _0x1189bb;},_0x1d8c(_0x16c872,_0x4a9823);}function _0x573f(){var _0x590300=['log','63XKArJp','2574xQXuOm','28INYAPr','195fdmpgU','1532970sNHCPV','287968ydkkzN','658524DYsVGH','46126FlKTse','34CNUyKI','1502028SYDPSd','5220AOkxvq','4948QSvrzp','2785bxLijs'];_0x573f=function(){return _0x590300;};return _0x573f();}hi();

Even with this huge change, an obfuscated code can be read by a normal JavaScript engine and I'm not aware of any obfuscator that changes the format of a .js to a obs.js for example, so a huge change is not relevant for defining a file format change either. I think my previous point of the code is a good way to get an idea about this.

vitorhcl commented 5 months ago

So what is the verdict? Shall it go under programming, or a new section for formatter/beautifier/uglifier?

I think we can move it to a "reformaters" category or something like that when we add more similar tools. For now, I think it's the only tool of this category, so "programming" is fine.

adamlui commented 5 months ago

Yeah, but this has no relation with changing the file format. A huge refactoring can also break so much code, but it doesn't mean that it changed the file format.

Refactoring didn't change formatting like ChatGPT even acknowledges minifying does, refactor changes the factor only, not re-format same factor (new factor is used)

This isn't a equivalent comparation. For example, the same code that reads a WAV file (uncompressed format) can't read a MP3 files, they are different file formats. However, the same code of a JavaScript engine can read both unminified codes and minified ones, they follow the same rules of the language parsing, so both are the same file formats.

The comparison is only to show a file after compression gained new filetype extension and output differently from the previous version potentially breaking code, so it's not really the same format anymore. But I agree that your traditional understanding of what defines a format, that a WAV reader can't read MP3 is all it takes to define new file format traditionally

Again, human intervation does not implies a file format changing, just a huge (or not) change in the code.

Well refactor is a huge change but re-formatting didn't occur, unlike minifying which re-formats code without changing factor. Just like if you take .html file and rewrite tags to make it .md but without changing content. That is a re-format. When you refactor code, you are changing the logic for same outcome, not reformatting existing code. When you minify, you are re-formatting existing code without re-factoring the logic, so just like the .html to .md re-formatting, content didn't change

Well, human noticing something changed isn't a so relevant factor here, the key factor is that the same code can read both minified and unminified code.

This is not true though, it often cannot read without error with change (global names can change) and was direct result of different formatting (not refactor) so "can read" is not same as "read and execute successfully as before" (if result of refactor, then it absolutely did not change formatting, but it is not a refactor)

Any change causes bits and bytes changes, so that doesn't really count.

That is a good point, I was merely using it to emphasize a change occurred for sure

Even with this huge change, an obfuscated code can be read by a normal JavaScript engine and I'm not aware of any obfuscator that changes the format of a .js to a obs.js for example, so a huge change is not relevant for defining a file format change either. I think my previous point of the code is a good way to get an idea about this.

Well IMO a re-formatting 100% occurred since it was not a refactor, and since it potentially breaks things without logic changing if names got mangled, it should not retain .js like that since it is a new file with a different formatting (the ones that append .min.js understand this is why they choose new file extension)

adamlui commented 5 months ago

For example, if I re-format a Word document with bold italics etc., the content stayed the same. It is the same file format, because there is no breaking change. But if I re-format (not refactor) JS, user also expects content (code produce some result) to stay the same. But because this is not always the case (unlike Word re-formatting) since it is potentially breaking change, people use new filetype extension .min.js because the formatting is so radical things can break. Just like if the bold button in Word editor can radically alter contents like change "apple" to "orange" it is too radical of re-formatting so it is a new type of file for some code out there to be supposedly able to not see "orange" but "apple" then it should be like .doc2 even though Microsoft chose to keep it .doc with this new formatting technique intended to change format only not content, which is same with minification (so if content changes too without even a refactor, then it is really not the same type of file anymore)

adamlui commented 5 months ago

I'm saying not in the traditional sense btw. Yes traditionally JPG viewer opening GIF is all it takes. I'm saying, just like if JPG tries to view GIF will see garbled nonsense, or DOC viewer opens hypothetical DOC2 and sees "orange" instead of "apple", calling script importing .min.js version of supposedly same .js but re-formatted will see different global names and can break, and it was a direct result of this new formatting, just like when JPG got converted to GIF and sees garbled nonsense and fails to generate expected output. The one common cause is a file changed, what change? The formatting, so file + format changed = file format changed (this is new age definition not traditional)

adamlui commented 5 months ago

@vitorhcl for some reason I thought your suggested change was an actual change, if you have edit access you could change it to programming

vitorhcl commented 5 months ago

@vitorhcl for some reason I thought your suggested change was an actual change, if you have edit access you could change it to programming

I don't, @toolleeo could you change the category please?

toolleeo commented 5 months ago

Done. Thanks for having pointed that it out.