-
-
Save eramdam/d743452c916e90ff7b42720f4384088e to your computer and use it in GitHub Desktop.
This file contains 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
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nπ‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘Lorem ipsum dolor sitππππππππππππππππππππππLorem ipsum dolor sit amet, consecteturππππππππππ | |
AAUID: 234567876543456 | |
Sent via: abcd://abcdeghi.com |
This file contains 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
'use strict'; | |
const linkify = require('linkify-it')(); | |
const BufferBuilder = require('buffer-builder'); | |
linkify.set({fuzzyLink: true}); | |
const BaseFunc = module.exports = function (text, options) { | |
if (!options) | |
options = {}; | |
const res = new BufferBuilder(); | |
const matches = linkify.match(text) || []; | |
console.log('test'); | |
const textMode = options.textMode; | |
const decode = options.decode; | |
let last = 0; | |
matches.forEach((match) => { | |
if (last < match.index) | |
res.appendString(text.slice(last, match.index)); | |
res.appendString(makeLinkTag(match, textMode, decode)); | |
last = match.lastIndex; | |
}); | |
res.appendString(text.slice(last)); | |
return res.get().toString(); | |
}; | |
function makeLinkTag(match) { | |
return `<a href="${match.url}" target="_blank">${truncUrl(match.text)}</a>`; | |
} | |
function truncUrl(url) { | |
return url.length < 120 ? url : url.slice(0, 120) + 'β¦'; | |
} | |
console.time('linkify'); | |
const res = BaseFunc(`Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nπ‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘Lorem ipsum dolor sitππππππππππππππππππππππLorem ipsum dolor sit amet, consecteturππππππππππ | |
AAUID: 234567876543456 | |
Sent via: abcd://abcdeghi.com`); | |
console.timeEnd('linkify'); | |
console.log(res); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment