@transloadit/enrich-tweet
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21
1619
0
103874
1
+ Addedclone-regexp@3.0.0(transitive)
+ Addedconvert-hrtime@5.0.0(transitive)
+ Addedfunction-timeout@0.1.1(transitive)
+ Addedget-urls@12.1.0(transitive)
+ Addedis-regexp@3.1.0(transitive)
+ Addednormalize-url@8.0.1(transitive)
+ Addedsuper-regex@0.2.0(transitive)
+ Addedtime-span@5.1.0(transitive)
+ Addedurl-regex-safe@4.0.0(transitive)
- Removed@isaacs/cliui@8.0.2(transitive)
- Removed@npmcli/agent@2.2.2(transitive)
- Removed@npmcli/fs@3.1.1(transitive)
- Removed@pkgjs/parseargs@0.11.0(transitive)
- Removedabbrev@2.0.0(transitive)
- Removedagent-base@7.1.1(transitive)
- Removedaggregate-error@3.1.0(transitive)
- Removedansi-regex@5.0.16.1.0(transitive)
- Removedansi-styles@4.3.06.2.1(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@2.0.1(transitive)
- Removedcacache@18.0.4(transitive)
- Removedchownr@2.0.0(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removedcross-spawn@7.0.6(transitive)
- Removeddebug@4.3.7(transitive)
- Removedeastasianwidth@0.2.0(transitive)
- Removedemoji-regex@8.0.09.2.2(transitive)
- Removedencoding@0.1.13(transitive)
- Removedenv-paths@2.2.1(transitive)
- Removederr-code@2.0.3(transitive)
- Removedexponential-backoff@3.1.1(transitive)
- Removedforeground-child@3.3.0(transitive)
- Removedfs-minipass@2.1.03.0.3(transitive)
- Removedget-urls@10.0.1(transitive)
- Removedglob@10.4.5(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhttp-cache-semantics@4.1.1(transitive)
- Removedhttp-proxy-agent@7.0.2(transitive)
- Removedhttps-proxy-agent@7.0.5(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedinstall-artifact-from-github@1.3.5(transitive)
- Removedip-address@9.0.5(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-lambda@1.0.1(transitive)
- Removedisexe@2.0.03.1.1(transitive)
- Removedjackspeak@3.4.3(transitive)
- Removedjsbn@1.1.0(transitive)
- Removedlru-cache@10.4.3(transitive)
- Removedmake-fetch-happen@13.0.1(transitive)
- Removedminimatch@9.0.5(transitive)
- Removedminipass@3.3.65.0.07.1.2(transitive)
- Removedminipass-collect@2.0.1(transitive)
- Removedminipass-fetch@3.0.5(transitive)
- Removedminipass-flush@1.0.5(transitive)
- Removedminipass-pipeline@1.2.4(transitive)
- Removedminipass-sized@1.0.3(transitive)
- Removedminizlib@2.1.2(transitive)
- Removedmkdirp@1.0.4(transitive)
- Removedms@2.1.3(transitive)
- Removednegotiator@0.6.4(transitive)
- Removednode-gyp@10.2.0(transitive)
- Removednopt@7.2.1(transitive)
- Removednormalize-url@5.3.1(transitive)
- Removedp-map@4.0.0(transitive)
- Removedpackage-json-from-dist@1.0.1(transitive)
- Removedpath-key@3.1.1(transitive)
- Removedpath-scurry@1.11.1(transitive)
- Removedproc-log@4.2.0(transitive)
- Removedpromise-retry@2.0.1(transitive)
- Removedre2@1.21.4(transitive)
- Removedretry@0.12.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsemver@7.6.3(transitive)
- Removedshebang-command@2.0.0(transitive)
- Removedshebang-regex@3.0.0(transitive)
- Removedsignal-exit@4.1.0(transitive)
- Removedsmart-buffer@4.2.0(transitive)
- Removedsocks@2.8.3(transitive)
- Removedsocks-proxy-agent@8.0.4(transitive)
- Removedsprintf-js@1.1.3(transitive)
- Removedssri@10.0.6(transitive)
- Removedstring-width@4.2.35.1.2(transitive)
- Removedstrip-ansi@6.0.17.1.0(transitive)
- Removedtar@6.2.1(transitive)
- Removedunique-filename@3.0.0(transitive)
- Removedunique-slug@4.0.0(transitive)
- Removedurl-regex-safe@2.1.0(transitive)
- Removedwhich@2.0.24.0.0(transitive)
- Removedwrap-ansi@7.0.08.1.0(transitive)
- Removedyallist@4.0.0(transitive)
Updatedget-urls@^12.1.0
Updatednan@^2.19.0