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.4 to 2.1.5

36

build/index.d.ts

@@ -28,14 +28,14 @@ interface ILinkPreviewOptions {

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

@@ -58,14 +58,14 @@ favicons: string[];

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

@@ -72,0 +72,0 @@ favicons: string[];

@@ -51,5 +51,8 @@ "use strict";

};
var metaTagContent = function (doc, type, attr) { return doc("meta[" + attr + "='" + type + "']").attr("content"); };
var metaTagContent = function (doc, type, attr) {
return doc("meta[" + attr + "='" + type + "']").attr("content");
};
function getTitle(doc) {
var title = metaTagContent(doc, "og:title", "property") || metaTagContent(doc, "og:title", "name");
var title = metaTagContent(doc, "og:title", "property") ||
metaTagContent(doc, "og:title", "name");
if (!title) {

@@ -61,7 +64,10 @@ title = doc("title").text();

function getSiteName(doc) {
var siteName = metaTagContent(doc, "og:site_name", "property") || metaTagContent(doc, "og:site_name", "name");
var siteName = metaTagContent(doc, "og:site_name", "property") ||
metaTagContent(doc, "og:site_name", "name");
return siteName;
}
function getDescription(doc) {
var description = metaTagContent(doc, "description", "name") || metaTagContent(doc, "Description", "name") || metaTagContent(doc, "og:description", "property");
var description = metaTagContent(doc, "description", "name") ||
metaTagContent(doc, "Description", "name") ||
metaTagContent(doc, "og:description", "property");
return description;

@@ -75,3 +81,4 @@ }

}
return (metaTagContent(doc, "og:type", "property") || metaTagContent(doc, "og:type", "name"));
return (metaTagContent(doc, "og:type", "property") ||
metaTagContent(doc, "og:type", "name"));
}

@@ -84,9 +91,13 @@ function getImages(doc, rootUrl, imagesPropertyType) {

var imagePropertyType = imagesPropertyType !== null && imagesPropertyType !== void 0 ? imagesPropertyType : "og";
nodes = metaTag(doc, imagePropertyType + ":image", "property") || metaTag(doc, imagePropertyType + ":image", "name");
nodes =
metaTag(doc, imagePropertyType + ":image", "property") ||
metaTag(doc, imagePropertyType + ":image", "name");
if (nodes) {
nodes.each(function (_, node) {
src = node.attribs.content;
if (src) {
src = url_1.default.resolve(rootUrl, src);
images.push(src);
if (node.type === "tag") {
src = node.attribs.content;
if (src) {
src = url_1.default.resolve(rootUrl, src);
images.push(src);
}
}

@@ -107,3 +118,4 @@ });

nodes.each(function (_, node) {
src = node.attribs.src;
if (node.type === "tag")
src = node.attribs.src;
if (src && !dic[src]) {

@@ -136,12 +148,24 @@ dic[src] = true;

if (nodes === null || nodes === void 0 ? void 0 : nodes.length) {
nodeTypes = metaTag(doc, "og:video:type", "property") || metaTag(doc, "og:video:type", "name");
nodeSecureUrls = metaTag(doc, "og:video:secure_url", "property") || metaTag(doc, "og:video:secure_url", "name");
width = metaTagContent(doc, "og:video:width", "property") || metaTagContent(doc, "og:video:width", "name");
height = metaTagContent(doc, "og:video:height", "property") || metaTagContent(doc, "og:video:height", "name");
nodeTypes =
metaTag(doc, "og:video:type", "property") ||
metaTag(doc, "og:video:type", "name");
nodeSecureUrls =
metaTag(doc, "og:video:secure_url", "property") ||
metaTag(doc, "og:video:secure_url", "name");
width =
metaTagContent(doc, "og:video:width", "property") ||
metaTagContent(doc, "og:video:width", "name");
height =
metaTagContent(doc, "og:video:height", "property") ||
metaTagContent(doc, "og:video:height", "name");
for (index = 0; index < nodes.length; index += 1) {
video = nodes[index].attribs.content;
var node = nodes[index];
if (node.type === "tag")
video = node.attribs.content;
nodeType = nodeTypes[index];
videoType = nodeType ? nodeType.attribs.content : null;
if (nodeType.type === "tag")
videoType = nodeType ? nodeType.attribs.content : null;
nodeSecureUrl = nodeSecureUrls[index];
videoSecureUrl = nodeSecureUrl ? nodeSecureUrl.attribs.content : null;
if (nodeSecureUrl.type === "tag")
videoSecureUrl = nodeSecureUrl ? nodeSecureUrl.attribs.content : null;
videoObj = {

@@ -184,3 +208,4 @@ url: video,

nodes.each(function (_, node) {
src = node.attribs.href;
if (node.type === "tag")
src = node.attribs.href;
if (src) {

@@ -308,3 +333,6 @@ src = url_1.default.resolve(rootUrl, src);

}
detectedUrl = text.replace(/\n/g, " ").split(" ").find(function (token) { return constants_1.CONSTANTS.REGEX_VALID_URL.test(token); });
detectedUrl = text
.replace(/\n/g, " ")
.split(" ")
.find(function (token) { return constants_1.CONSTANTS.REGEX_VALID_URL.test(token); });
if (!detectedUrl) {

@@ -317,3 +345,4 @@ throw new Error("link-preview-js did not receive a valid a url or text");

};
fetchUrl = (options === null || options === void 0 ? void 0 : options.proxyUrl) ? options.proxyUrl.concat(detectedUrl) : detectedUrl;
fetchUrl = (options === null || options === void 0 ? void 0 : options.proxyUrl) ? options.proxyUrl.concat(detectedUrl)
: detectedUrl;
return [4 /*yield*/, cross_fetch_1.fetch(fetchUrl, fetchOptions)];

@@ -320,0 +349,0 @@ case 1:

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

@@ -37,2 +37,3 @@ "main": "build/index.js",

"@skypack/package-check": "^0.2.2",
"@types/cheerio": "0.22.24",
"@types/jest": "^26.0.19",

@@ -52,2 +53,3 @@ "@typescript-eslint/eslint-plugin": "^2.15.0",

"jest": "^26.6.3",
"prettier": "2.2.1",
"ts-jest": "^26.4.4",

@@ -54,0 +56,0 @@ "typescript": "^4.1.3"

# Link Preview JS
Typescript library (29.2kb unpacked) that allows you to extract information from a HTTP url/link and/or parse text and retrieve information from the first available link.
Allows you to extract information from a HTTP url/link (or parse a HTML document) and retrieve meta information such as title, description, images, videos, etc. Written in Typescript.

@@ -15,4 +15,10 @@ ## CORS

As Google continues to wage war upon the internet and break it on all the ways only convenient to Google, sometimes it's domains break the standards, to be more specific: www.google.com does not return a required meta data and YouTube does funny re-directions on mobile which also causes this library to return wrong data... 🖕 Google, feel free to submit a PR if you want to accommodate the trillion dollar corporation.
As Google continues to wage war upon the internet and break it on all the ways only convenient to Google, sometimes its domains break the standards, to be more specific: www.google.com does not return a required meta data and YouTube does funny re-directions on mobile which also causes this library to return wrong data. The trillion dollar corporations are not your friends.
Created by **Oscar Franco**
<img src="https://github.com/ospfranco/tempomat/blob/main/src/assets/image/profile.jpg?raw=true?raw=true" height=60 width=60/>
Follow me on [Twitter](www.twitter.com/ospfranco) or please consider [sponsoring](https://github.com/sponsors/ospfranco) to support the development.
## How to use

@@ -19,0 +25,0 @@

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