add function to test valid URL
This commit is contained in:
parent
4f07cb5b5d
commit
16e57f45fc
1 changed files with 26 additions and 7 deletions
|
@ -11,6 +11,25 @@ class URLs {
|
||||||
static clean(URL) {
|
static clean(URL) {
|
||||||
return((URL.trim().replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]);
|
return((URL.trim().replace(/(^\w+:|^)\/\//, ``).split(`?`))[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Check if the URL is valid through checking its patterns.
|
||||||
|
|
||||||
|
@param {string} location the URL to check
|
||||||
|
@return {boolean} the state
|
||||||
|
*/
|
||||||
|
static test(location) {
|
||||||
|
let STATE = false;
|
||||||
|
|
||||||
|
// Convert to URL object.
|
||||||
|
try {
|
||||||
|
STATE = !!(new URL(location));
|
||||||
|
} catch(err) {
|
||||||
|
STATE = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return STATE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {URLs};
|
export {URLs};
|
Loading…
Add table
Add a link
Reference in a new issue