File tree Expand file tree Collapse file tree 1 file changed +11
-6
lines changed
packages/v1-components/src/common Expand file tree Collapse file tree 1 file changed +11
-6
lines changed Original file line number Diff line number Diff line change 1- export const isURL = ( href : string ) : boolean => {
1+ export const isURL = ( href : string , loose = true ) : boolean => {
22 try {
3- const normalizedHref = href . includes ( '://' ) ? href : `http:// ${ href } `
3+ const url = new URL ( href )
44
5- const url = new URL ( normalizedHref )
5+ return / ^ ( h t t p s ? : \/ \/ ) ? ( [ a - z A - Z 0 - 9 - ] + \. ) + [ a - z A - Z ] { 2 , } ( \S * ) $ / . test ( url . href )
6+ } catch {
7+ if ( loose ) {
8+ if ( ! href . startsWith ( '/' ) ) return false
69
7- const urlPattern = / ^ ( h t t p s ? : \/ \/ ) ? ( [ a - z A - Z 0 - 9 - ] + \. ) + [ a - z A - Z ] { 2 , } ( \S * ) $ /
10+ return [
11+ href . includes ( '://' ) ? href : `https://${ href } ` ,
12+ `https://example.com${ href } ` ,
13+ ] . some ( href => isURL ( href , false ) )
14+ }
815
9- return urlPattern . test ( url . href )
10- } catch {
1116 return false
1217 }
1318}
You can’t perform that action at this time.
0 commit comments