How to use the twitter-text.extractEntitiesWithIndices function in twitter-text

To help you get started, we’ve selected a few twitter-text examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / twitter-text / twitter-text-tests.ts View on Github external
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;
}
github DefinitelyTyped / DefinitelyTyped / twitter-text / twitter-text-tests.ts View on Github external
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;
}
github r7kamura / retro-twitter-client / src / renderer / components / tweet-body.js View on Github external
getEntities() {
    return twitterText.extractEntitiesWithIndices(
      this.props.tweet.text,
      { extractUrlsWithoutProtocol: false }
    );
  }
github nyxtom / salient / lib / salient / tokenizers / tweet_tokenizer.js View on Github external
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);
github tec27 / seatcamp / lib / chat-sockets.js View on Github external
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
}