Merge pull request #10 from MillenniumEarl/deepsource-transform-f614955a
Format code with prettierpull/11/head
commit
060387127f
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// Public modules from npm
|
// Public modules from npm
|
||||||
const ky = require("ky-universal").create({
|
const ky = require("ky-universal").create({
|
||||||
throwHttpErrors: false
|
throwHttpErrors: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Modules from file
|
// Modules from file
|
||||||
|
@ -25,14 +25,14 @@ module.exports.isF95URL = function (url) {
|
||||||
* @param {String} url String to check for correctness
|
* @param {String} url String to check for correctness
|
||||||
* @returns {Boolean} true if the string is a valid URL, false otherwise
|
* @returns {Boolean} true if the string is a valid URL, false otherwise
|
||||||
*/
|
*/
|
||||||
module.exports.isStringAValidURL = function(url) {
|
module.exports.isStringAValidURL = function (url) {
|
||||||
try {
|
try {
|
||||||
new URL(url);
|
new URL(url);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @public
|
* @public
|
||||||
|
@ -41,20 +41,20 @@ module.exports.isStringAValidURL = function(url) {
|
||||||
* @param {Boolean} checkRedirect If true, the function will consider redirects a violation and return false
|
* @param {Boolean} checkRedirect If true, the function will consider redirects a violation and return false
|
||||||
* @returns {Promise<Boolean>} true if the URL exists, false otherwise
|
* @returns {Promise<Boolean>} true if the URL exists, false otherwise
|
||||||
*/
|
*/
|
||||||
module.exports.urlExists = async function(url, checkRedirect) {
|
module.exports.urlExists = async function (url, checkRedirect) {
|
||||||
if (!this.isStringAValidURL(url)) {
|
if (!this.isStringAValidURL(url)) {
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await ky.head(url);
|
const response = await ky.head(url);
|
||||||
let valid = response !== undefined && !/4\d\d/.test(response.status);
|
let valid = response !== undefined && !/4\d\d/.test(response.status);
|
||||||
|
|
||||||
if(!valid) return false;
|
if (!valid) return false;
|
||||||
|
|
||||||
if(checkRedirect) {
|
if (checkRedirect) {
|
||||||
if (response.url === url) valid = true;
|
if (response.url === url) valid = true;
|
||||||
else valid = false;
|
else valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
return valid;
|
||||||
}
|
};
|
||||||
|
|
Loading…
Reference in New Issue