Created
November 9, 2021 11:21
-
-
Save viduraperera/fb3bed4746df893d97ea080bb6f49ba6 to your computer and use it in GitHub Desktop.
get Data function
This file contains hidden or 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
| function getData(val){ | |
| if(!val) return; | |
| const URL_REGEX = /(((https?:\/\/)|(www\.))[^\s]+)/g; | |
| let textSubject = val.target.value; | |
| return setData(textSubject.replace(URL_REGEX, (url)=>{ | |
| let hyperLink = url; | |
| if(!hyperLink.match('^https?:\/\/')){ | |
| hyperLink = 'http://' + hyperLink; | |
| } | |
| setPrint(false) | |
| return `<a href="${hyperLink.toLowerCase().lastIndexOf('www.', 0) === 0 ? `//${hyperLink}` : hyperLink}">${hyperLink}</a>` | |
| })); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment