Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as twitter from "twitter-text";
const text: string = twitter.htmlEscape("@you #hello < @world > https://github.com");
const entities = twitter.extractEntitiesWithIndices(text);
function isHashtagEntity(e: twitter.EntityWithIndices): e is twitter.HashtagWithIndices {
return "hashtag" in e;
}
function isUrlEntity(e: twitter.EntityWithIndices): e is twitter.UrlWithIndices {
return "url" in e;
}
function isMentionEntity(e: twitter.EntityWithIndices): e is twitter.MentionWithIndices {
return "screenName" in e;
}
function isCashtagEntity(e: twitter.EntityWithIndices): e is twitter.CashtagWithIndices {
return "cashtag" in e;
}
import * as twitter from "twitter-text";
const text: string = twitter.htmlEscape("@you #hello < @world > https://github.com");
const entities = twitter.extractEntitiesWithIndices(text);
function isHashtagEntity(e: twitter.EntityWithIndices): e is twitter.HashtagWithIndices {
return "hashtag" in e;
}
function isUrlEntity(e: twitter.EntityWithIndices): e is twitter.UrlWithIndices {
return "url" in e;
}
function isMentionEntity(e: twitter.EntityWithIndices): e is twitter.MentionWithIndices {
return "screenName" in e;
}
function isCashtagEntity(e: twitter.EntityWithIndices): e is twitter.CashtagWithIndices {
return "cashtag" in e;
}
getEntities() {
return twitterText.extractEntitiesWithIndices(
this.props.tweet.text,
{ extractUrlsWithoutProtocol: false }
);
}
TweetTokenizer.prototype.tokenize = function (s) {
if (!s || s.length == 0)
return [];
if (!this.tokenizer) {
this._initializeTokenizers();
}
s = s.replace('’', '\'');
var entities = twitter.extractEntitiesWithIndices(s);
var tokens = [];
var index = 0;
if (entities.length > 0) {
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var indices = entity.indices;
if (index < indices[0] && index < s.length) {
var t = s.substring(index, indices[0]);
var results = this.tokenizer.tokenize(t);
tokens = tokens.concat(results);
}
if (entity.screenName) {
tokens.push('@' + entity.screenName);
}
else if (entity.hashtag) {
tokens.push('#' + entity.hashtag);
function transformText(text) {
const sanitized = text.slice(0, 250).replace(/[\r\n\t]/, '')
const entities = twitterText.extractEntitiesWithIndices(sanitized, {
extractUrlsWithoutProtocol: true,
})
const linkified = twitterText.autoLinkEntities(sanitized, entities, {
htmlEscapeNonEntities: true,
targetBlank: true,
usernameIncludeSymbol: true,
})
return linkified
}