How to use the twitter-text.extractUrls 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 pixeldesu / surfbird / src / twitter / actions.js View on Github external
} else {
        chunks.unshift(chunk)
        break
      }
    }
    if (chunks.length == 0) { // only has mentions???
      mentions = chunks
      mentions = []
      mentionsLength = 0
    } else if (mentionsLength > 140) {
      e.sender.send('surfbird:hook:fail:tweet')
      return console.error('Too many mentions!')
    }

    // map urls
    var urls = twittxt.extractUrls(tweet.text, {extractUrlsWithoutProtocol: false}).map(function (it) {
      return it.toLowerCase()
    })

    while (chunks.length > 0) {
      var tweet = [].concat(mentions)
      var textLength = 0
      while (tweet.length + textLength + mentionsLength - 1 < 140 && chunks.length > 0) {
        var chunk = chunks.shift()
        var length = chunk.length
        // check if it's a url
        if (urls.indexOf(chunk.toLowerCase()) > -1) {
          length = chunk.match(twittxt.regexen.urlHasHttps) ? 23 : 23 // TODO: Use configuration.
        }
        // chunk if overflow
        if (tweet.length + textLength + mentionsLength + length > 140) {
          // word is too long, split it up.
github hainproject / hain / app / main / plugins / hain-plugin-url / index.js View on Github external
function parseUrlForIndexer(query) {
    const query_trim = query.trim();
    if (query_trim.length <= 2) return;

    const urls = twitter.extractUrls(query_trim);
    if (urls.length === 0) return;

    const url = lo_first(urls);
    const ratio = url.length / query_trim.length;
    if (ratio <= 0.9) return;

    return {
      id: url,
      primaryText: url,
      secondaryText: url,
      group: 'Link'
    };
  }
github kenforthewin / mentat / assets / js / components / App.js View on Github external
this.typeTimeout = setTimeout(this.typeTimeoutFn, 1000);
    }

    if (e.key === "Enter") {
      e.preventDefault();
      this.typing = false;
      clearTimeout(this.typeTimeout);
      this.channel.push("new_typing", {uuid: this.props.userReducer.uuid, typing: false});

      if(e.target.value.length > 0 ) {
        if (e.target.value[0] === '#' && !e.target.value.includes(" ")) {
          return this.processTagFromInput(e);
        }
        const message = e.target.value;
        let allTags = this.state.tags.slice(0,1);
        const urls = this.props.userReducer.urlPreviews ? twitter.extractUrls(message).map((url) => url.startsWith('http') ? url : 'https://' + url) : [];
        const extractedTags = twitter.extractHashtags(message);
        extractedTags.forEach((extractedTag) => {
          const downcaseTag = extractedTag.toLowerCase();
          allTags = allTags.includes(downcaseTag) ? allTags : [
            ...allTags,
            downcaseTag
          ]
        })

        this.pubKeyObj = this.pubKeyObj || openpgp.key.readArmored(this.props.cryptoReducer.groups[this.room].publicKey).keys
        const options = {
          data: message,
          publicKeys: this.pubKeyObj,
          armored: false
        };
github nyxtom / salient / lib / salient / tokenizers / url_tokenizer.js View on Github external
UrlTokenizer.prototype.tokenize = function (s) {
    if (!s || s.length == 0)
        return [];

    if (this.includeIndices) {
        return twitter.extractUrlsWithIndices(s);
    }
    else {
        return twitter.extractUrls(s);
    }
};