2019-11-23 18:59:55 +00:00
|
|
|
class MessageFormatter {
|
|
|
|
constructor(message) {
|
|
|
|
this.message = message || '';
|
|
|
|
}
|
|
|
|
|
|
|
|
formatMessage() {
|
|
|
|
const linkifiedMessage = this.linkify();
|
|
|
|
return linkifiedMessage.replace(/\n/g, '<br>');
|
|
|
|
}
|
|
|
|
|
|
|
|
linkify() {
|
|
|
|
if (!this.message) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
|
|
|
return this.message.replace(
|
|
|
|
urlRegex,
|
2020-04-02 06:58:38 +00:00
|
|
|
url =>
|
|
|
|
`<a rel="noreferrer noopener nofollow" href="${url}" target="_blank">${url}</a>`
|
2019-11-23 18:59:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
get formattedMessage() {
|
|
|
|
return this.formatMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MessageFormatter;
|