Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// 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
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);
});
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);
});
}, 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] + '");'
);
} );