UNPKG

chayns-components

Version:

A set of beautiful React components for developing chayns® applications.

32 lines (30 loc) 949 B
"use strict"; exports.__esModule = true; exports.default = void 0; const URL_REGEX = /(\s|^)(?:http(s)?:\/\/|www\.)[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=.]+/gi; const makeLinks = txt => { let text = txt; let urls = text.match(URL_REGEX); if (chayns.utils.isArray(urls)) { const indexArray = []; urls = urls.map(url => url.trim()); urls.forEach(url => { indexArray.push(text.indexOf(url)); text = text.replace(url, ''); }); urls.reverse(); indexArray.reverse(); urls.forEach((url, index) => { let link = url; if (!link.startsWith('http')) { link = `https://${url}`; } const position = indexArray[index]; text = [text.slice(0, position), `<a onclick="chayns.openUrlInBrowser('${link}')">${url}</a>`, text.slice(position)].join(''); }); } return text; }; var _default = makeLinks; exports.default = _default; //# sourceMappingURL=createLinks.js.map