File tree 1 file changed +30
-0
lines changed
1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as glide from "../glide" ;
2
+
3
+ export default glide
4
+ . columnNamed ( "Text is URL" )
5
+ . withCategory ( "Text" )
6
+ . withReleased ( "direct" )
7
+ . withDescription ( `Indicates whether text is a URL.` )
8
+
9
+ . withStringParam ( "url" )
10
+ . withBooleanParam ( "requireProtocol" , "Require Protocol (e.g. 'https://')" )
11
+ . withBooleanResult ( )
12
+
13
+ . withTest ( { url : `google.com` , requireProtocol : false } , true )
14
+ . withTest ( { url : `google.com` } , false )
15
+ . withTest ( { url : `https://www.google.com` } , true )
16
+
17
+ . run ( ( { url, requireProtocol = true } ) => {
18
+ if ( url === undefined ) return false ;
19
+
20
+ let fullUrl = url ;
21
+ if ( ! requireProtocol && ! fullUrl ?. includes ( ":" ) ) {
22
+ fullUrl = "https://" + fullUrl ;
23
+ }
24
+ try {
25
+ new URL ( fullUrl ) ;
26
+ return true ;
27
+ } catch {
28
+ return false ;
29
+ }
30
+ } ) ;
You can’t perform that action at this time.
0 commit comments