Skip to content

pdkpavankumar/string-to-url

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

string-to-url

Build Status dependencies Status devDependencies Status License: MIT

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:gmail@gmail.com"]

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>