UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

32 lines 1.08 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.parseLinksFromText = void 0; var _linkifyjs = require("linkifyjs"); var removeMarkdownLinksFromText = input => input.replace(/\[.*\]\(.*\)/g, ''); var removeUserNamesWithEmailFromText = input => input.replace(/@(\w+(\.\w+)?)(@\w+\.\w+)/g, ''); var parseLinksFromText = input => { if (!input) { return []; } var strippedInput = [removeMarkdownLinksFromText, removeUserNamesWithEmailFromText].reduce((acc, fn) => fn(acc), input); var links = (0, _linkifyjs.find)(strippedInput, 'url'); var emails = (0, _linkifyjs.find)(strippedInput, 'email'); var result = [...links, ...emails].map(({ href, value }) => { var hrefWithProtocol = href; var pattern = new RegExp(/^(mailto:|tel:|sms:|\S+:\/\/)/); if (!pattern.test(hrefWithProtocol)) { hrefWithProtocol = 'http://' + hrefWithProtocol; } return { raw: value, url: hrefWithProtocol }; }); return result; }; exports.parseLinksFromText = parseLinksFromText; //# sourceMappingURL=parseLinks.js.map