-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from webkom/better-links
Allow mailto links & improve linkinput protocol prefixing
- Loading branch information
Showing
4 changed files
with
21 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const protocolRe = /^(?:f|ht)tps?:\/\//; | ||
const hostnameRe = /([a-zA-Z]\.?)+\.([a-zA-Z]){2,}/; | ||
|
||
const urlRe = new RegExp(protocolRe.source + hostnameRe.source); | ||
const mailRe = new RegExp('^mailto:([a-zA-Z](\\.|\\+)?)+@' + hostnameRe.source); | ||
const onlyHostnameRe = new RegExp('^' + hostnameRe.source); | ||
|
||
const isUrl = (url: string): boolean => urlRe.test(url) || mailRe.test(url); | ||
|
||
export const prependHttps = (hostname: string): string => { | ||
if (onlyHostnameRe.test(hostname)) { | ||
return 'https://' + hostname; | ||
} | ||
return hostname; | ||
}; | ||
|
||
export default isUrl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters