chore: simplify validUrl fn
This commit is contained in:
parent
41d1af6fd5
commit
5ae00abb2a
1 changed files with 14 additions and 16 deletions
12
ui/src/utils.ts
vendored
12
ui/src/utils.ts
vendored
|
@ -116,13 +116,11 @@ export function isVideo(url: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validURL(str: string) {
|
export function validURL(str: string) {
|
||||||
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
|
try {
|
||||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
|
return !!new URL(str);
|
||||||
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
|
} catch {
|
||||||
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
|
return false;
|
||||||
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
|
}
|
||||||
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator
|
|
||||||
return !!pattern.test(str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function capitalizeFirstLetter(str: string): string {
|
export function capitalizeFirstLetter(str: string): string {
|
||||||
|
|
Reference in a new issue