diff --git a/index.js b/index.js index 99be0ea..b99c559 100644 --- a/index.js +++ b/index.js @@ -4,8 +4,12 @@ const request = require("request"); const path = require("path"); const colors = require("colors"); const fs = require("fs"); -const regex = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g +const linkRegex = /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g +const goodRegex = /\-\-good/; +const badRegex = /\-\-bad/; +const allRegex = /\-\-all/; let exitFlag = true; +let statusFlag = 1; // 1: all, 2: good, 3: bad // If the user doesn't enter any arguments/filenames, it exits the process if (process.argv.length === 2) { @@ -36,6 +40,14 @@ for (let i = 2; i < process.argv.length; i++) { console.log("Version: 0.1") } } + + if (arg.match(goodRegex)) { + statusFlag = 2; + } else if (arg.match(badRegex)) { + statusFlag = 3; + } else if (arg.match(allRegex)) { + statusFlag = 1; + } } // If the user enters any arguments/filenames, starts process. @@ -50,7 +62,7 @@ for (let i = 2; i < process.argv.length; i++) { exitFlag = false; process.exit(1); } - let links = data.match(regex); + let links = data.match(linkRegex); for (let i = 0; i < links.length; i++) { let link = links[i]; if (link.startsWith("https://")) { @@ -80,15 +92,23 @@ function checkUrl(url) { request({ method: 'HEAD', uri: url }, function (err, res, body) { if (err) { exitFlag = false; - console.log(colors.yellow(`${err} ${url}`)); + if (statusFlag != 2) { + console.log(colors.yellow(`${err} ${url}`)); + } } else if (res.statusCode == 200) { - console.log(colors.green(`[PASSED] [200] ${url}`)); + if (statusFlag != 3) { + console.log(colors.green(`[PASSED] [200] ${url}`)); + } } else if (res.statusCode == 404 || res.statusCode == 400) { exitFlag = false; - console.log(colors.red(`[FAILED] [${res.statusCode}] ${url}`)); + if (statusFlag != 2) { + console.log(colors.red(`[FAILED] [${res.statusCode}] ${url}`)); + } } else { exitFlag = false; - console.log(colors.grey(`[UNKNOWN] [${res.statusCode}] ${url}`)) + if (statusFlag != 2) { + console.log(colors.grey(`[UNKNOWN] [${res.statusCode}] ${url}`)) + } } }) } diff --git a/package-lock.json b/package-lock.json index 226d5f0..99b7ee5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -163,6 +163,11 @@ "sshpk": "^1.7.0" } }, + "inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -222,11 +227,25 @@ "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" }, + "path": { + "version": "0.12.7", + "resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz", + "integrity": "sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8=", + "requires": { + "process": "^0.11.1", + "util": "^0.10.3" + } + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" }, + "process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI=" + }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -325,6 +344,14 @@ "punycode": "^2.1.0" } }, + "util": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz", + "integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==", + "requires": { + "inherits": "2.0.3" + } + }, "uuid": { "version": "3.4.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",