@subsocial/utils
Version:
JavaScript utils for Subsocial blockchain.
32 lines (31 loc) • 1.24 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTwitterURL = exports.parseTwitterTextToMarkdown = void 0;
const autolinker_1 = __importDefault(require("autolinker"));
const BASE_TWITTER_URL = 'https://twitter.com';
/** Parse plain text to markdown with resolved twitter links (hashtag and mention) */
const parseTwitterTextToMarkdown = (text) => {
const parsed = autolinker_1.default.link(text, {
mention: 'twitter',
hashtag: 'twitter',
stripPrefix: false,
phone: false,
email: false,
sanitizeHtml: true,
replaceFn: function (match) {
const href = match.getAnchorHref();
const text = match.getAnchorText();
return `[${text}](${href})`;
},
});
return parsed;
};
exports.parseTwitterTextToMarkdown = parseTwitterTextToMarkdown;
/** Create twitter url with given username and tweet id */
const createTwitterURL = (tweet) => {
return `${BASE_TWITTER_URL}/${tweet.username}/status/${tweet.id}`;
};
exports.createTwitterURL = createTwitterURL;