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

link-preview-js

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

link-preview-js - npm Package Compare versions

Comparing version 2.1.17 to 2.1.19

3

build/index.d.ts

@@ -6,4 +6,5 @@ interface ILinkPreviewOptions {

timeout?: number;
followRedirects?: boolean;
followRedirects?: `follow` | `error` | `manual`;
resolveDNSHost?: (url: string) => Promise<string>;
handleRedirects?: (baseURL: string, forwardedURL: string) => boolean;
}

@@ -10,0 +11,0 @@ interface IPreFetchedResource {

@@ -324,8 +324,8 @@ "use strict";

function getLinkPreview(text, options) {
var _a, _b;
var _a, _b, _c;
return __awaiter(this, void 0, void 0, function () {
var detectedUrl, resolvedUrl, timeout, controller, timeoutCounter, fetchOptions, fetchUrl, response, headers, normalizedResponse;
var _c;
return __generator(this, function (_d) {
switch (_d.label) {
var _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:

@@ -342,8 +342,11 @@ if (!text || typeof text !== "string") {

}
if ((options === null || options === void 0 ? void 0 : options.followRedirects) === "manual" && !(options === null || options === void 0 ? void 0 : options.handleRedirects)) {
throw new Error("link-preview-js followRedirects is set to manual, but no handleRedirects function was provided");
}
if (!!!(options === null || options === void 0 ? void 0 : options.resolveDNSHost)) return [3 /*break*/, 2];
return [4 /*yield*/, options.resolveDNSHost(detectedUrl)];
case 1:
resolvedUrl = _d.sent();
resolvedUrl = _e.sent();
throwOnLoopback(resolvedUrl);
_d.label = 2;
_e.label = 2;
case 2:

@@ -355,5 +358,3 @@ timeout = (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 3000;

headers: (_b = options === null || options === void 0 ? void 0 : options.headers) !== null && _b !== void 0 ? _b : {},
redirect: (options === null || options === void 0 ? void 0 : options.followRedirects)
? "follow"
: "error",
redirect: (_c = options === null || options === void 0 ? void 0 : options.followRedirects) !== null && _c !== void 0 ? _c : "error",
signal: controller.signal,

@@ -364,3 +365,15 @@ };

: detectedUrl;
return [4 /*yield*/, (0, cross_fetch_1.fetch)(fetchUrl, fetchOptions).catch(function (e) {
return [4 /*yield*/, (0, cross_fetch_1.fetch)(fetchUrl, fetchOptions)
.then(function (res) {
if ((res.status === 301 || res.status === 302) &&
fetchOptions.redirect === "manual" &&
(options === null || options === void 0 ? void 0 : options.handleRedirects)) {
if (!options.handleRedirects(fetchUrl, (res.headers.get("location") || ""))) {
throw new Error("link-preview-js could not handle redirect");
}
return (0, cross_fetch_1.fetch)(res.headers.get("location") || "", fetchOptions);
}
return res;
})
.catch(function (e) {
if (e.name === "AbortError") {

@@ -372,3 +385,3 @@ throw new Error("Request timeout");

case 3:
response = _d.sent();
response = _e.sent();
clearTimeout(timeoutCounter);

@@ -379,3 +392,3 @@ headers = {};

});
_c = {
_d = {
url: (options === null || options === void 0 ? void 0 : options.proxyUrl)

@@ -388,4 +401,4 @@ ? response.url.replace(options.proxyUrl, "")

case 4:
normalizedResponse = (_c.data = _d.sent(),
_c);
normalizedResponse = (_d.data = _e.sent(),
_d);
return [2 /*return*/, parseResponse(normalizedResponse, options)];

@@ -392,0 +405,0 @@ }

{
"name": "link-preview-js",
"version": "2.1.17",
"version": "2.1.19",
"description": "Javascript module to extract and fetch HTTP link information from blocks of text.",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -115,3 +115,4 @@ <h1 align="center">Link Preview JS</h1>

return new Promise((resolve, reject) => {
dns.lookup(url, (err, address, family) => {
const hostname = new URL(url).hostname;
dns.lookup(hostname, (err, address, family) => {
if (err) {

@@ -118,0 +119,0 @@ reject(err);

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