-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
39 lines (28 loc) · 1.22 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
console.log('👨💻 Author: Saurav Hathi \n🌟 GitHub: https://github.com/sauravhathi');
function removeCommentsAndLineSpacesAndEmptyLines(str, lineSpace, emptyLine, lineBreak) {
str = str.replace(/\/\/.*|\/\*[\s\S]*?\*\/|< !--[\s\S ]*?- ->|#.*|--.*|\/\*[\s\S]*?\*\//g, "");
if (lineSpace) {
str = str.replace(/^\s+|\s+$/gm, "");
}
if (emptyLine) {
str = str.replace(/^\s*[\r\n]/gm, "");
}
if (lineBreak) {
str = str.replace(/(\r\n|\n|\r)/gm, "");
}
return str;
}
function showOutput() {
let input = document.getElementById("input").value;
if (input == "") {
alert("Please enter some code");
return;
}
let removeLineSpace = document.getElementById("removeLineSpace").checked;
let removeNewLineSpace = document.getElementById("removeNewLineSpace").checked;
let removeLineBreak = document.getElementById("removeLineBreak").checked;
let output = removeCommentsAndLineSpacesAndEmptyLines(input, removeLineSpace, removeNewLineSpace, removeLineBreak);
document.getElementById("inputSize").innerHTML = input.length;
document.getElementById("outputSize").innerHTML = output.length;
document.getElementById("output").value = output;
}