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

@transloadit/enrich-tweet

Package Overview
Dependencies
Maintainers
6
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.1.4 to 0.2.0

2

dist/enrichTweet.d.ts
type Tweet = {
full_text: string;
full_text?: string;
entities?: {

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

"use strict";
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) {

@@ -18,59 +9,55 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

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;
}
});
async function tryUnshorten(url, unshorten) {
if (!unshorten)
return url;
try {
return await (0, tall_1.tall)(url);
}
catch (err) {
return url;
}
}
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);
}
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);
}
}
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 = (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 urls = (0, get_urls_1.default)(text);
for (const subUrl3 of urls) {
if (!subUrl3.match(/^https?:\/\/bit\.ly/)) {
continue;
}
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;
});
const unshortened3 = await tryUnshorten(subUrl3, unshorten);
text = text.replace(`${subUrl3}`, `${unshortened3}`);
}
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",
"license": "AGPL-3.0-only",
"version": "0.1.4",
"version": "0.2.0",
"publishConfig": {

@@ -14,3 +14,3 @@ "access": "public"

"main": "dist/enrichTweet.js",
"typings": "dist/enrichTweet.d.ts",
"types": "dist/enrichTweet.d.ts",
"files": [

@@ -35,5 +35,5 @@ "dist"

"devDependencies": {
"@types/twitter-text": "^3.1.2"
"@types/twitter-text": "^3.1.9"
},
"gitHead": "b9159b6f037336d9325656c35b9b15023d5c1ce7"
"gitHead": "3fbbb8c4c18eeb9b9de5e3a5c022d46a7cc40800"
}

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