string-to-url
v1.1.0
Published
Utility to handle strings containing urls
Downloads
2
Maintainers
Readme
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
import { getUrls } from 'string-to-url';
console.log(getUrls('abc www.google.com www.apple.com');
output:
["http://www.google.com", "mailto:[email protected]"]
example2
//somePage.js
import { getHTMLText } from 'string-to-url';
console.log(getHTMLText('abc www.google.com');
output:
abc <a href="http://www.google.com">www.google.com</a>
example3
//somePage.js
import { getHTMLText } from 'string-to-url';
console.log(getHTMLText('abc www.google.com', { target: '__blank' });
output:
abc <a target="__blank" href="http://www.google.com">www.google.com</a>