Skip to content

Commit dadaa67

Browse files
authored
Text is URL (#69)
* Text is URL * Fix
1 parent 6aa005c commit dadaa67

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/columns/is-url.ts

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
});

0 commit comments

Comments
 (0)