Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

twitter-text

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twitter-text - npm Package Compare versions

Comparing version 1.5.2 to 1.6.0

pkg/twitter-text-1.6.0.js

2

component.json
{
"name": "twitter-text",
"version": "1.5.2",
"version": "1.6.0",
"main": ["./twitter-text.js"],

@@ -5,0 +5,0 @@ "dependencies": {

{
"name": "twitter-text"
, "description": "official twitter text linkification"
, "version": "1.5.2"
, "version": "1.6.0"
, "main": "./twitter-text.js"

@@ -6,0 +6,0 @@ , "homepage": "https://github.com/twitter/twitter-text-js"

@@ -19,3 +19,3 @@ # twitter-text-js

// basic extraction
var usernames = twttr.txt.extract_mentioned_screen_names("Mentioning @twitter and @jack")
var usernames = twttr.txt.extractMentions("Mentioning @twitter and @jack")
// usernames == ["twitter", "jack"]

@@ -22,0 +22,0 @@

@@ -154,2 +154,6 @@ module("twttr.txt");

// test targetBlank
ok(!twttr.txt.autoLink("#hash @mention").match(/target="_blank"/), "target=\"blank\" attribute should not be added to link");
ok(twttr.txt.autoLink("#hash @mention", { targetBlank: true }).match(/target="_blank"/), "target=\"blank\" attribute should be added to link");
// test linkTextBlock

@@ -174,2 +178,6 @@ autoLinkResult = twttr.txt.autoLink("#hash @mention", {

// extractUrlsWithoutProtocol (the default mode of extractEntitiesWithIndices)
same(twttr.txt.autoLinkEntities("twitter.com", twttr.txt.extractEntitiesWithIndices("twitter.com")),
"<a href=\"http://twitter.com\" rel=\"nofollow\">twitter.com</a>", "AutoLink with extractUrlsWithoutProtocol");
// url entities

@@ -241,2 +249,8 @@ autoLinkResult = twttr.txt.autoLink("http://t.co/0JG5Mcq", {

"Autolink hashtag/mentionURL w/ Supplementary character");
// handle the @ character in the URL
var testUrl = "http://twitter.com?var=@val";
same(twttr.txt.autoLink(testUrl), "<a href=\"" + testUrl + "\" rel=\"nofollow\">" + testUrl + "</a>", "Autolink with special char params");
// handle the @ character in the URL and an @mention at the same time
same(twttr.txt.autoLink(testUrl + " @mention"), "<a href=\"" + testUrl + "\" rel=\"nofollow\">" + testUrl + "</a> @<a class=\"tweet-url username\" href=\"https://twitter.com/mention\" data-screen-name=\"mention\" rel=\"nofollow\">mention</a>", "Autolink with special char params and mentions");
});

@@ -290,1 +304,8 @@

});
test("twttr.txt.extractUrls", function() {
var message_with_hyphenated_url = "Message with hyphenated-url.com";
var message_with_www_hyphenated_url = "Message with www.123-hyphenated-url.com";
equal(twttr.txt.extractUrls(message_with_hyphenated_url)[0], "hyphenated-url.com", "Should extract full url with hyphen.");
equal(twttr.txt.extractUrls(message_with_www_hyphenated_url)[0], "www.123-hyphenated-url.com", "Should extract full url with hyphen.");
});

@@ -1,12 +0,6 @@

if (typeof window === "undefined" || window === null) {
window = { twttr: {} };
}
if (window.twttr == null) {
window.twttr = {};
}
if (typeof twttr === "undefined" || twttr === null) {
twttr = {};
}
(function() {
if (typeof twttr === "undefined" || twttr === null) {
var twttr = {};
}
(function() {
twttr.txt = {};

@@ -109,2 +103,3 @@ twttr.txt.regexen = {};

twttr.txt.regexen.rtl_chars = /[\u0600-\u06FF]|[\u0750-\u077F]|[\u0590-\u05FF]|[\uFE70-\uFEFF]/mg;
twttr.txt.regexen.non_bmp_code_pairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/mg;

@@ -242,3 +237,3 @@ var nonLatinHashtagChars = [];

twttr.txt.regexen.validDomain = regexSupplant(/(?:#{validSubdomain}*#{validDomainName}(?:#{validGTLD}|#{validCCTLD}|#{validPunycode}))/);
twttr.txt.regexen.validAsciiDomain = regexSupplant(/(?:(?:[a-z0-9#{latinAccentChars}]+)\.)+(?:#{validGTLD}|#{validCCTLD}|#{validPunycode})/gi);
twttr.txt.regexen.validAsciiDomain = regexSupplant(/(?:(?:[\-a-z0-9#{latinAccentChars}]+)\.)+(?:#{validGTLD}|#{validCCTLD}|#{validPunycode})/gi);
twttr.txt.regexen.invalidShortDomain = regexSupplant(/^#{validDomainName}#{validCCTLD}$/);

@@ -248,3 +243,3 @@

twttr.txt.regexen.validGeneralUrlPathChars = regexSupplant(/[a-z0-9!\*';:=\+,\.\$\/%#\[\]\-_~|&#{latinAccentChars}]/i);
twttr.txt.regexen.validGeneralUrlPathChars = regexSupplant(/[a-z0-9!\*';:=\+,\.\$\/%#\[\]\-_~@|&#{latinAccentChars}]/i);
// Allow URL paths to contain balanced parens

@@ -266,3 +261,3 @@ // 1. Used in Wikipedia URLs like /Primer_(film)

twttr.txt.regexen.validUrlQueryChars = /[a-z0-9!?\*'\(\);:&=\+\$\/%#\[\]\-_\.,~|]/i;
twttr.txt.regexen.validUrlQueryChars = /[a-z0-9!?\*'@\(\);:&=\+\$\/%#\[\]\-_\.,~|]/i;
twttr.txt.regexen.validUrlQueryEndingChars = /[a-z0-9_&=#\/]/i;

@@ -283,2 +278,4 @@ twttr.txt.regexen.extractUrl = regexSupplant(

twttr.txt.regexen.validTcoUrl = /^https?:\/\/t\.co\/[a-z0-9]+/i;
twttr.txt.regexen.urlHasProtocol = /^https?:\/\//i;
twttr.txt.regexen.urlHasHttps = /^https:\/\//i;

@@ -389,6 +386,7 @@ // cashtag related regex

'usernameUrlBlock':true, 'listUrlBlock':true, 'hashtagUrlBlock':true, 'linkUrlBlock':true,
'usernameIncludeSymbol':true, 'suppressLists':true, 'suppressNoFollow':true,
'usernameIncludeSymbol':true, 'suppressLists':true, 'suppressNoFollow':true, 'targetBlank':true,
'suppressDataScreenName':true, 'urlEntities':true, 'symbolTag':true, 'textWithSymbolTag':true, 'urlTarget':true,
'invisibleTagAttrs':true, 'linkAttributeBlock':true, 'linkTextBlock': true, 'htmlEscapeNonEntities': true
};
var BOOLEAN_ATTRIBUTES = {'disabled':true, 'readonly':true, 'multiple':true, 'checked':true};

@@ -462,2 +460,5 @@

}
if (options.targetBlank) {
attrs.target = '_blank';
}

@@ -473,2 +474,5 @@ return twttr.txt.linkToTextWithSymbol(entity, hash, hashtag, attrs, options);

attrs["class"] = options.cashtagClass;
if (options.targetBlank) {
attrs.target = '_blank';
}

@@ -489,2 +493,5 @@ return twttr.txt.linkToTextWithSymbol(entity, "$", cashtag, attrs, options);

}
if (options.targetBlank) {
attrs.target = '_blank';
}

@@ -508,4 +515,12 @@ return twttr.txt.linkToTextWithSymbol(entity, at, isList ? user + slashListname : user, attrs, options);

var attrs = clone(options.htmlAttrs || {});
if (!url.match(twttr.txt.regexen.urlHasProtocol)) {
url = "http://" + url;
}
attrs.href = url;
if (options.targetBlank) {
attrs.target = '_blank';
}
// set class only if urlClass is specified.

@@ -688,3 +703,3 @@ if (options.urlClass) {

twttr.txt.autoLink = function(text, options) {
var entities = twttr.txt.extractEntitiesWithIndices(text, {extractUrlWithoutProtocol: false});
var entities = twttr.txt.extractEntitiesWithIndices(text, {extractUrlsWithoutProtocol: false});
return twttr.txt.autoLinkEntities(text, entities, options);

@@ -709,3 +724,3 @@ };

twttr.txt.autoLinkUrlsCustom = function(text, options) {
var entities = twttr.txt.extractUrlsWithIndices(text, {extractUrlWithoutProtocol: false});
var entities = twttr.txt.extractUrlsWithIndices(text, {extractUrlsWithoutProtocol: false});
return twttr.txt.autoLinkEntities(text, entities, options);

@@ -755,4 +770,5 @@ };

twttr.txt.extractMentionsWithIndices = function(text) {
var mentions = [];
var mentionsOrLists = twttr.txt.extractMentionsOrListsWithIndices(text);
var mentions = [],
mentionOrList,
mentionsOrLists = twttr.txt.extractMentionsOrListsWithIndices(text);

@@ -781,3 +797,4 @@ for (var i = 0 ; i < mentionsOrLists.length; i++) {

var possibleNames = [];
var possibleNames = [],
slashListname;

@@ -987,2 +1004,6 @@ text.replace(twttr.txt.regexen.validMentionOrList, function(match, before, atSign, screenName, slashListname, offset, chunk) {

twttr.txt.getUnicodeTextLength = function(text) {
return text.replace(twttr.txt.regexen.non_bmp_code_pairs, ' ').length;
};
twttr.txt.convertUnicodeIndices = function(text, entities, indicesInUTF16) {

@@ -1160,11 +1181,15 @@ if (entities.length == 0) {

// Returns the length of Tweet text with consideration to t.co URL replacement
// and chars outside the basic multilingual plane that use 2 UTF16 code points
twttr.txt.getTweetLength = function(text, options) {
if (!options) {
options = {
short_url_length: 20,
short_url_length_https: 21
// These come from https://api.twitter.com/1/help/configuration.json
// described by https://dev.twitter.com/docs/api/1/get/help/configuration
short_url_length: 22,
short_url_length_https: 23
};
}
var textLength = text.length;
var urlsWithIndices = twttr.txt.extractUrlsWithIndices(text);
var textLength = twttr.txt.getUnicodeTextLength(text),
urlsWithIndices = twttr.txt.extractUrlsWithIndices(text);
twttr.txt.modifyIndicesFromUTF16ToUnicode(text, urlsWithIndices);

@@ -1175,5 +1200,5 @@ for (var i = 0; i < urlsWithIndices.length; i++) {

// Add 21 characters for URL starting with https://
// Otherwise add 20 characters
if (urlsWithIndices[i].url.toLowerCase().match(/^https:\/\//)) {
// Add 23 characters for URL starting with https://
// Otherwise add 22 characters
if (urlsWithIndices[i].url.toLowerCase().match(twttr.txt.regexen.urlHasHttps)) {
textLength += options.short_url_length_https;

@@ -1304,2 +1329,11 @@ } else {

}());
if (typeof window != 'undefined') {
if (window.twttr) {
for (var prop in twttr) {
window.twttr[prop] = twttr[prop];
}
} else {
window.twttr = twttr;
}
}
})();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc