npm-text-parser
Text parser which receives text data as input and replaces the urls with clickable links (anchor tags), emails as clickable mail:to tags and also replaces hash tags (#tag) empty clickable anchor tag.
Installation
npm i npm-text-parser
Usage
var parseText = ;
parseUrl(text)
Receives the input text and replaces all the url matches with clickable anchor links
var inputString = "This is awesome it parses the url's dude and http://krishcdbry.com done !" parseText; // This is awesome it parses the url's dude and <a href="http://krishcdbry.com" // target="_blank">http://krishcdbry.com</a> done !
parseEmail(text)
Receives the input text and replaces all the email matches with clickable mail:to anchor links
var inputString = "This is awesome it parses the email's dude and krishcdbry@gmail.com done !" parseText; // This is awesome it parses the email's dude and // <a href="mailto:krishcdbry@gmail.com">krishcdbry@gmail.com</a> done !
parseHash(text)
Receives the input text and replaces all the hashtag matches with clickable empty anchor links
var inputString = "This is awesome it parses the hash tag's dude and #krishcdbry done !" parseText; // This is awesome it parses the hash tag's dude and <a href="javascript:;">#krishcdbry</a> done !
parse(text)
Receives the input text and replaces the urls with clickable links (anchor tags), emails as clickable mail:to tags and also replaces hash tags (#tag) with empty clickable anchor tags
var inputString = "his is awesome it parses the url's , email's and hash tag's dude http://krishcdbry@gmail.com and email krishcdbry@gmail.com also #krishcdbry done !" parseText // This is awesome it parses the url's , email's and hash tag's dude // <a href="http://krishcdbry@gmail.com" target="_blank">http://krishcdbry@gmail.com</a> // and email <a href="mailto:krishcdbry@gmail.com">krishcdbry@gmail.com</a> // also <a href="javascript:;">#krishcdbry</a> done !
getUrls(text)
(Array of url occurrences) - Receives the input text, reads all the Urls in it and returns
and array of all url occurrences
var inputString = 'This is awesome http://krishcdbry.com and www.heartynote.com done !' textParser // ['http://krishcdbry.com', 'www.heartynote.com']
getEmails(text)
(Array of email occurrences) - Receives the input text, reads all the emails in it and returns
and array of all email occurrences
var inputString = 'This is awesome krishcdbry@gmail.com and heartynote@gmail.com done !' textParser // ['krishcdbry@gmail.com', 'heartynote@gmail.com']
getHashtags(text)
(Array of hashtags occurrences) - Receives the input text, reads all the hashtagss in it and returns
and array of all hashtags occurrences
var inputString = 'This is awesome #krishcdbry, #heartynote and #node done !' textParser // ['#krishcdbry', '#heartynote', '#node']
getAll(text)
All occurrences includes (Urls, emails and hashtags)
var inputString = 'This is awesome krishcdbry@gmail.com and also http://nmpjs.org, www.krishcdbry.com and #heartynote and #node done !' textParser // { // parsed_text: 'This is awesome <a href="mailto:krishcdbry@gmail.com">krishcdbry@gmail.com</a> and also <a href="http://nmpjs.org" target="_blank">http://nmpjs.org</a>, <a href="www.krishcdbry.com" target="_blank">www.krishcdbry.com</a> and<a href="javascript:;" target="_blank"> #heartynote</a> and<a href="javascript:;" target="_blank"> #node</a> done !', // urls: [ 'http://nmpjs.org', 'www.krishcdbry.com' ], // emails: [ 'krishcdbry@gmail.com' ], // hashtags: [ ' #heartynote', ' #node' ] // }
Demo
Demo @npm-text-parser | https://tonicdev.com/npm/npm-text-parser
Author
Krishcdbry [krishcdbry@gmail.com]
Licence
MIT @krishcdbry