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

@transloadit/enrich-tweet

Package Overview
Dependencies
Maintainers
5
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@transloadit/enrich-tweet - npm Package Compare versions

Comparing version 0.4.1 to 0.4.2

dist/enrichTweet.test.d.ts

10

dist/enrichTweet.d.ts

@@ -1,3 +0,3 @@

interface Tweet {
full_text?: string;
type Tweet = {
full_text: string;
entities?: {

@@ -19,4 +19,4 @@ urls: {

};
}
declare const _default: (tweet: Tweet, unshorten?: boolean) => Promise<string | undefined>;
export = _default;
};
export default function enrichTweet(tweet: Tweet, unshorten?: boolean): Promise<string | undefined>;
export {};
"use strict";
const twttr = require("twitter-text");
const tall = require("tall");
const getUrls = require("get-urls");
async function tryUnshorten(url, unshorten) {
if (!unshorten)
return url;
try {
return await tall.tall(url);
}
catch (err) {
return url;
}
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const twitter_text_1 = __importDefault(require("twitter-text"));
const tall_1 = require("tall");
const get_urls_1 = __importDefault(require("get-urls"));
function tryUnshorten(url, unshorten) {
return __awaiter(this, void 0, void 0, function* () {
if (!unshorten)
return url;
try {
return yield (0, tall_1.tall)(url);
}
catch (err) {
return url;
}
});
}
module.exports = async function enrichTweet(tweet, unshorten = true) {
if (!tweet)
return;
let text = tweet.full_text ?? '';
if (tweet.entities && tweet.entities.urls.length) {
const subUrls = tweet.entities.urls;
for (const subUrl1 of subUrls) {
const unshortened = await tryUnshorten(subUrl1.expanded_url, unshorten);
const friends1 = [subUrl1.display_url, subUrl1.url, subUrl1.expanded_url];
for (const friend1 of friends1) {
text = text.replace(`http://www.${friend1}`, unshortened);
text = text.replace(`https://www.${friend1}`, unshortened);
text = text.replace(`http://${friend1}`, unshortened);
text = text.replace(`https://${friend1}`, unshortened);
text = text.replace(`${friend1}`, unshortened);
function enrichTweet(tweet, unshorten = true) {
return __awaiter(this, void 0, void 0, function* () {
if (!tweet)
return;
let text = tweet.full_text;
if (tweet.entities && tweet.entities.urls.length) {
const subUrls = tweet.entities.urls;
for (const subUrl1 of subUrls) {
const unshortened = yield tryUnshorten(subUrl1.expanded_url, unshorten);
const friends1 = [subUrl1.display_url, subUrl1.url, subUrl1.expanded_url];
for (const friend1 of friends1) {
text = text.replace(`http://www.${friend1}`, unshortened);
text = text.replace(`https://www.${friend1}`, unshortened);
text = text.replace(`http://${friend1}`, unshortened);
text = text.replace(`https://${friend1}`, unshortened);
text = text.replace(`${friend1}`, unshortened);
}
}
}
}
if (tweet.extended_entities && tweet.extended_entities.media.length) {
for (const subUrl2 of tweet.extended_entities.media) {
const friends2 = [subUrl2.display_url, subUrl2.url, subUrl2.media_url, subUrl2.expanded_url];
for (const friend2 of friends2) {
text = text.replace(`http://${friend2}`, `${subUrl2.media_url_https}`);
text = text.replace(`https://${friend2}`, `${subUrl2.media_url_https}`);
text = text.replace(`${friend2}`, `${subUrl2.media_url_https}`);
if (tweet.extended_entities && tweet.extended_entities.media.length) {
for (const subUrl2 of tweet.extended_entities.media) {
const friends2 = [subUrl2.display_url, subUrl2.url, subUrl2.media_url, subUrl2.expanded_url];
for (const friend2 of friends2) {
text = text.replace(`http://${friend2}`, `${subUrl2.media_url_https}`);
text = text.replace(`https://${friend2}`, `${subUrl2.media_url_https}`);
text = text.replace(`${friend2}`, `${subUrl2.media_url_https}`);
}
}
}
}
const urls = getUrls(text);
for (const subUrl3 of urls) {
if (!subUrl3.match(/^https?:\/\/bit\.ly/)) {
continue;
const urls = (0, get_urls_1.default)(text);
for (const subUrl3 of urls) {
if (!subUrl3.match(/^https?:\/\/bit\.ly/)) {
continue;
}
const unshortened3 = yield tryUnshorten(subUrl3, unshorten);
text = text.replace(`${subUrl3}`, `${unshortened3}`);
}
const unshortened3 = await tryUnshorten(subUrl3, unshorten);
text = text.replace(`${subUrl3}`, `${unshortened3}`);
}
text = twttr.autoLink(text);
text = text.replace(/>(https:\/\/pbs\.twimg\.com\/[^<]+)</g, `><img class="tweet-media" src="$1" /><`);
text = text.replace(`<a href="https://pbs.twimg.com/`, `\n\n<a href="https://pbs.twimg.com/`);
text = text.replace(/@<a\s+class="tweet-url username"\s+href="https:\/\/twitter.com\/([^"]+)"\s+data-screen-name="([^"]+)"\s+rel="nofollow">([^<]+)<\/a>/g, '<a class="tweet-url username" href="https://twitter.com/$1" data-screen-name="$2" rel="nofollow">@$3</a>');
return text;
};
text = twitter_text_1.default.autoLink(text);
text = text.replace(/>(https:\/\/pbs\.twimg\.com\/[^<]+)</g, `><img class="tweet-media" src="$1" /><`);
text = text.replace(`<a href="https://pbs.twimg.com/`, `\n\n<a href="https://pbs.twimg.com/`);
text = text.replace(/@<a\s+class="tweet-url username"\s+href="https:\/\/twitter.com\/([^"]+)"\s+data-screen-name="([^"]+)"\s+rel="nofollow">([^<]+)<\/a>/g, '<a class="tweet-url username" href="https://twitter.com/$1" data-screen-name="$2" rel="nofollow">@$3</a>');
return text;
});
}
exports.default = enrichTweet;
//# sourceMappingURL=enrichTweet.js.map
{
"name": "@transloadit/enrich-tweet",
"version": "0.4.1",
"version": "0.4.2",
"repository": {

@@ -21,4 +21,4 @@ "type": "git",

"dependencies": {
"get-urls": "10.0.1",
"nan": "^2.18.0",
"get-urls": "^12.1.0",
"nan": "^2.19.0",
"re2": "patch:re2@npm%3A1.20.9#~/.yarn/patches/re2-npm-1.20.9-65a014d791.patch",

@@ -29,3 +29,3 @@ "tall": "^8.0.0",

"devDependencies": {
"@types/twitter-text": "^3.1.9"
"@types/twitter-text": "^3.1.10"
},

@@ -35,3 +35,3 @@ "publishConfig": {

},
"gitHead": "0a3041d61326d5de201cb1728e1a1a2d7a0cd5bc"
"gitHead": "412a97c914bd1a8c6d21df01c9f7e18ab19b218a"
}

@@ -5,5 +5,5 @@ {

"outDir": "dist/",
"rootDir": "src/",
"rootDir": "src/"
},
"include": ["src/"],
"include": ["src/"]
}

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