string-to-url
Installation
Install string-to-url
into to your project via npm
:
$ npm install string-to-url --save-dev
Usage
getUrls -- will give the array of urls present in the string
getHTMLText -- return HTML text converting all links to anchor tags.
Pass options object with all required properties if needed ex: target, title. e.t.c
ex: { target: '__blank' }
example1
//somePage.js; console
output:
["http://www.google.com", "mailto:gmail@gmail.com"]
example2
//somePage.js; console
output:
abc <a href="http://www.google.com">www.google.com</a>
example3
//somePage.js; console
output:
abc <a target="__blank" href="http://www.google.com">www.google.com</a>