How to use the twitter-text.regexen 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
}

    // 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.
          if (textLength == 0) {
            if (urls.indexOf(chunk.toLowerCase()) > -1) {
              e.sender.send('surfbird:hook:fail:tweet')
              return console.error('Error! Can\'t segment URL!')
            } else {
              length = 140 - (tweet.length + textLength + 1 + mentionsLength)
              chunks.unshift(chunk.substr(length))
              tweet.push(chunk.substr(0, length))
              textLength += length
              break
            }
          } else { // push it to the next tweet
github silentroach / twic3-archived / test / src / vendor.js View on Github external
it('should extract correct regexps', function() {
			const tt = require('twitter-text');
			const generated = require('vendor/twitter-text');

			assert.equal(tt.regexen.extractUrl.source, generated.url.source);
			assert.equal(tt.regexen.validHashtag.source, generated.hash.source);
			assert.equal(tt.regexen.validMentionOrList.source, generated.mention.source);
		});
github silentroach / twic3-archived / test / src / vendor.js View on Github external
it('should extract correct regexps', function() {
			const tt = require('twitter-text');
			const generated = require('vendor/twitter-text');

			assert.equal(tt.regexen.extractUrl.source, generated.url.source);
			assert.equal(tt.regexen.validHashtag.source, generated.hash.source);
			assert.equal(tt.regexen.validMentionOrList.source, generated.mention.source);
		});
github silentroach / twic3-archived / src / base / gulp / vendor / twitter-text.js View on Github external
}, function(twitterTextRegexpName, regexpName) {
			const regexp = twitterText.regexen[twitterTextRegexpName];

			if (undefined === regexp) {
				throw new Error('Failed to find regexp ' + twitterTextRegexpName);
			}

			const escaped = jsStringEscape(regexp);
			const parts = escaped.match(/\/(.*)\/([^\/]*)/);

			content.push(
				'regexps.' + regexpName + ' = new RegExp("' + parts[1] + '", "' + parts[2] + '");'
			);
		} );