New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

link-preview-js

Package Overview
Dependencies
Maintainers
1
Versions
41
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 3.0.4 to 3.0.5

49

build/__tests__/index.spec.js

@@ -47,7 +47,8 @@ "use strict";

var linkInfo;
return __generator(this, function (_a) {
switch (_a.label) {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, (0, index_1.getLinkPreview)("https://www.youtube.com/watch?v=wuClZjOdT30", { headers: { "Accept-Language": "en-US" } })];
case 1:
linkInfo = _a.sent();
linkInfo = _b.sent();
expect(linkInfo.url).toEqual("https://www.youtube.com/watch?v=wuClZjOdT30");

@@ -63,2 +64,3 @@ expect(linkInfo.siteName).toEqual("YouTube");

expect(linkInfo.contentType.toLowerCase()).toEqual("text/html");
expect((_a = linkInfo.charset) === null || _a === void 0 ? void 0 : _a.toLowerCase()).toEqual("utf-8");
return [2 /*return*/];

@@ -68,2 +70,17 @@ }

}); });
it("returns charset of website", function () { return __awaiter(void 0, void 0, void 0, function () {
var linkInfo;
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, (0, index_1.getLinkPreview)("https://www.pravda.com.ua")];
case 1:
linkInfo = _b.sent();
expect(linkInfo.url).toEqual("https://www.pravda.com.ua/");
expect(linkInfo.contentType.toLowerCase()).toEqual("text/html");
expect((_a = linkInfo.charset) === null || _a === void 0 ? void 0 : _a.toLowerCase()).toEqual("windows-1251");
return [2 /*return*/];
}
});
}); });
it("should extract link info from a URL with a newline", function () { return __awaiter(void 0, void 0, void 0, function () {

@@ -361,3 +378,3 @@ var linkInfo;

}); });
it('should handle video tags without type or secure_url tags', function () { return __awaiter(void 0, void 0, void 0, function () {
it("should handle video tags without type or secure_url tags", function () { return __awaiter(void 0, void 0, void 0, function () {
var res;

@@ -406,10 +423,16 @@ return __generator(this, function (_a) {

});
// describe(`simple test`, () => {
// it("fetch my repo", async () => {
// const linkInfo: any = await getLinkPreview(
// "https://github.com/ospfranco/link-preview-js"
// );
// console.warn({ linkInfo });
// expect(1).toEqual(2);
// });
// });
xdescribe("simple test", function () {
it("fetch my repo", function () { return __awaiter(void 0, void 0, void 0, function () {
var linkInfo;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, (0, index_1.getLinkPreview)("https://www.pravda.com.ua")];
case 1:
linkInfo = _a.sent();
console.warn({ linkInfo: linkInfo });
expect(1).toEqual(2);
return [2 /*return*/];
}
});
}); });
});

@@ -27,6 +27,24 @@ interface ILinkPreviewOptions {

url: string;
title: string;
siteName: string | undefined;
description: string | undefined;
mediaType: string;
contentType: string | undefined;
images: string[];
videos: {
url: string | undefined;
secureUrl: string | null | undefined;
type: string | null | undefined;
width: string | undefined;
height: string | undefined;
}[];
favicons: string[];
} | {
charset: string | null;
url: string;
mediaType: string;
contentType: string;
favicons: string[];
} | {
charset: string | null;
url: string;

@@ -57,6 +75,24 @@ title: string;

url: string;
title: string;
siteName: string | undefined;
description: string | undefined;
mediaType: string;
contentType: string | undefined;
images: string[];
videos: {
url: string | undefined;
secureUrl: string | null | undefined;
type: string | null | undefined;
width: string | undefined;
height: string | undefined;
}[];
favicons: string[];
} | {
charset: string | null;
url: string;
mediaType: string;
contentType: string;
favicons: string[];
} | {
charset: string | null;
url: string;

@@ -63,0 +99,0 @@ title: string;

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

@@ -278,35 +289,38 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }

try {
// console.log("[link-preview-js] response", response);
var contentType = response.headers["content-type"];
// console.warn(`original content type`, contentType);
if (contentType === null || contentType === void 0 ? void 0 : contentType.indexOf(";")) {
// eslint-disable-next-line prefer-destructuring
contentType = contentType.split(";")[0];
// console.warn(`splitting content type`, contentType);
}
var contentTypeTokens = [];
var charset = null;
if (!contentType) {
return parseUnknownResponse(response.data, response.url, options);
}
if (contentType instanceof Array) {
// eslint-disable-next-line no-param-reassign, prefer-destructuring
contentType = contentType[0];
if (contentType.includes(";")) {
contentTypeTokens = contentType.split(";");
contentType = contentTypeTokens[0];
for (var _i = 0, contentTypeTokens_1 = contentTypeTokens; _i < contentTypeTokens_1.length; _i++) {
var token = contentTypeTokens_1[_i];
if (token.indexOf("charset=") !== -1) {
charset = token.split("=")[1];
}
}
}
// parse response depending on content type
if (constants_1.CONSTANTS.REGEX_CONTENT_TYPE_IMAGE.test(contentType)) {
return parseImageResponse(response.url, contentType);
return __assign(__assign({}, parseImageResponse(response.url, contentType)), { charset: charset });
}
if (constants_1.CONSTANTS.REGEX_CONTENT_TYPE_AUDIO.test(contentType)) {
return parseAudioResponse(response.url, contentType);
return __assign(__assign({}, parseAudioResponse(response.url, contentType)), { charset: charset });
}
if (constants_1.CONSTANTS.REGEX_CONTENT_TYPE_VIDEO.test(contentType)) {
return parseVideoResponse(response.url, contentType);
return __assign(__assign({}, parseVideoResponse(response.url, contentType)), { charset: charset });
}
if (constants_1.CONSTANTS.REGEX_CONTENT_TYPE_TEXT.test(contentType)) {
var htmlString_1 = response.data;
return parseTextResponse(htmlString_1, response.url, options, contentType);
return __assign(__assign({}, parseTextResponse(htmlString_1, response.url, options, contentType)), { charset: charset });
}
if (constants_1.CONSTANTS.REGEX_CONTENT_TYPE_APPLICATION.test(contentType)) {
return parseApplicationResponse(response.url, contentType);
return __assign(__assign({}, parseApplicationResponse(response.url, contentType)), { charset: charset });
}
var htmlString = response.data;
return parseUnknownResponse(htmlString, response.url, options);
return __assign(__assign({}, parseUnknownResponse(htmlString, response.url, options)), { charset: charset });
}

@@ -313,0 +327,0 @@ catch (e) {

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

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

@@ -0,1 +1,5 @@

# Repo no longer maintained
Sorry! No energy or time. Feel free to fork it and publish your own version.
<h1 align="center">Link Preview JS</h1>

@@ -25,7 +29,7 @@

- Unless HTML or the OpenGraph standard change, the library will not break
- If the target website you are trying to preview redirects you to a login page **the preview will "fail"**, becuase it will parse the login page
- If the target website does not have OpenGraph tags **the preview will most likely "fail"**, there are some fallbacks but in general it will not work
- If the target website you are trying to preview redirects you to a login page **the preview will fail**, because it will parse the login page
- If the target website does not have OpenGraph tags **the preview will most likely fail**, there are some fallbacks but in general it will not work
- **You cannot preview (fetch) another web page from YOUR web page. This is an intentional security feature of browsers called CORS**
Any opened issue that does not take this points into account will just be closed.
If you use this library and find it useful please consider [sponsoring me](https://github.com/sponsors/ospfranco), open source takes a lot of time and effort.

@@ -32,0 +36,0 @@ # Link Preview

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