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

link-preview-js

Package Overview
Dependencies
Maintainers
0
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 3.0.5 to 3.0.6

14

build/__tests__/index.spec.js

@@ -78,3 +78,3 @@ "use strict";

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

@@ -126,8 +126,8 @@ }

}); });
it("should make request with different languages", function () { return __awaiter(void 0, void 0, void 0, function () {
xit("should make request with different languages", 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.hsbc.ca/", {
headers: { "Accept-Language": "fr" },
case 0: return [4 /*yield*/, (0, index_1.getLinkPreview)("https://www.wikipedia.org/", {
headers: { "Accept-Language": "es" },
followRedirects: "follow",

@@ -137,7 +137,7 @@ })];

linkInfo = _a.sent();
expect(linkInfo.title).toEqual("Particuliers | HSBC Canada");
return [4 /*yield*/, (0, index_1.getLinkPreview)("https://www.hsbc.ca/")];
expect(linkInfo.title).toContain("Wikipedia, la enciclopedia libre");
return [4 /*yield*/, (0, index_1.getLinkPreview)("https://www.wikipedia.org/")];
case 2:
linkInfo = _a.sent();
expect(linkInfo.title).toEqual("HSBC Personal Banking | HSBC Canada");
expect(linkInfo.title).toContain("Wikipedia");
return [2 /*return*/];

@@ -144,0 +144,0 @@ }

@@ -75,3 +75,3 @@ "use strict";

if (!title) {
title = doc("title").text();
title = doc("head > title").text();
}

@@ -78,0 +78,0 @@ return title;

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

@@ -49,3 +49,4 @@ "main": "build/index.js",

"typescript": "^4.7.4"
}
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}

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

# 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>

@@ -27,6 +23,6 @@

- It's very simple; fetch html, parse html, look for OpenGraph html tags.
- It's very simple; fetch HTML, parse HTML, and search for OpenGraph HTML tags.
- 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**, 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
- 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**

@@ -38,7 +34,7 @@

Allows you to extract information from a HTTP url/link (or parse a HTML string) and retrieve meta information such as title, description, images, videos, etc. via **OpenGraph** tags.
Allows you to extract information from an HTTP URL/link (or parse an HTML string) and retrieve meta information such as title, description, images, videos, etc. via **OpenGraph** tags.
## GOTCHAs
- You cannot request a different domain from your web app (Browsers block cross-origin-requests). If you don't know how _same-origin-policy_ works, [here is a good intro](https://dev.to/lydiahallie/cs-visualized-cors-5b8h), therefore **this library works on node (back-end environments) and certain mobile run-times (cordova or react-native)**.
- You cannot request a different domain from your web app (Browsers block cross-origin-requests). If you don't know how _same-origin-policy_ works, [here is a good intro](https://dev.to/lydiahallie/cs-visualized-cors-5b8h), therefore **this library works on Node.js and certain mobile run-times (Cordova or React-Native)**.
- **This library acts as if the user would visit the page, sites might re-direct you to sign-up pages, consent screens, etc.** You can try to change the user-agent header (try with `google-bot` or with `Twitterbot`), but you need to work around these issues yourself.

@@ -48,5 +44,5 @@

`getLinkPreview`: you have to pass a string, doesn't matter if it is just a URL or a piece of text that contains a URL, the library will take care of parsing it and returning the info of first valid HTTP(S) URL info it finds.
`getLinkPreview`: you have to pass a string, doesn't matter if it is just a URL or a piece of text that contains a URL, the library will take care of parsing it and returning the info o the first valid HTTP(S) URL info it finds.
`getPreviewFromContent`: useful for passing a pre-fetched Response object from an existing async/etc. call. Refer to example below for required object values.
`getPreviewFromContent`: useful for passing a pre-fetched Response object from an existing async/etc. call. Refer to the example below for required object values.

@@ -89,3 +85,3 @@ ```typescript

Additionally you can pass an options object which should add more functionality to the parsing of the link
Additionally, you can pass an options object which should add more functionality to the parsing of the link

@@ -105,3 +101,3 @@ | Property Name | Result |

headers: {
"user-agent": "googlebot" // fetches with googlebot crawler user agent
"user-agent": "googlebot", // fetches with googlebot crawler user agent
"Accept-Language": "fr-CA", // fetches site for French language

@@ -116,3 +112,3 @@ // ...other optional HTTP request headers

Doing requests on behalf of your users or using user provided URLs is dangerous. One of such attacks is a trying to fetch a domain which redirects to localhost and so the users getting the contents of your server (doesn't affect mobile runtimes). In order to mittigate this attack you can use the resolveDNSHost option:
Doing requests on behalf of your users or using user-provided URLs is dangerous. One of such attack is trying to fetch a domain that redirects to localhost so the users get the contents of your server (doesn't affect mobile runtimes). To mitigate this attack you can use the resolveDNSHost option:

@@ -145,3 +141,3 @@ ```ts

Same as SSRF, following redirections is dangerous, the library errors by default when the response tries to redirect the user. There are however some simple redirections which are valid (e.g. http to https) and you might want to allow, you can do it via:
Same to SSRF, following redirections is dangerous, the library errors by default when the response tries to redirect the user. There are however some simple redirections that are valid (e.g. HTTP to HTTPS) and you might want to allow them, you can do it via:

@@ -171,3 +167,3 @@ ```ts

The info object returned varies depending on the content type (MIME type) returned
in the HTTP response (see below for variations of response). Rejects with an error if response can not be parsed or if there was no URL in the text provided.
in the HTTP response (see below for variations of response). Rejects with an error if the response can not be parsed or if there was no URL in the text provided.

@@ -184,3 +180,4 @@ ### Text/HTML URL

mediaType: "video.other",
contentType: "text/html; charset=utf-8",
contentType: "text/html",
charset: "utf-8"
videos: [],

@@ -187,0 +184,0 @@ favicons:["https://www.youtube.com/yts/img/favicon_32-vflOogEID.png","https://www.youtube.com/yts/img/favicon_48-vflVjB_Qk.png","https://www.youtube.com/yts/img/favicon_96-vflW9Ec0w.png","https://www.youtube.com/yts/img/favicon_144-vfliLAfaB.png","https://s.ytimg.com/yts/img/favicon-vfl8qSV2F.ico"]

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