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

fetch-opengraph

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-opengraph - npm Package Compare versions

Comparing version 1.0.17 to 1.0.19

43

index.js

@@ -33,7 +33,17 @@ "use strict";

try {
const response = yield axios_1.default.get(url);
const response = yield axios_1.default.get(url, {
headers: {
'Cache-Control': 'no-cache',
'User-Agent': 'PostmanRuntime/7.26.10',
Accept: '*/*',
Connection: 'keep-alive'
}
});
if (response.status >= 400) {
throw response;
}
let siteTitle = '';
const html = yield response.data;
const tagTitle = html.match(/<title[^>]*>[\r\n\t\s]*([^<]+)[\r\n\t\s]*<\/title>/gim);
siteTitle = tagTitle[0].replace(/<title[^>]*>[\r\n\t\s]*([^<]+)[\r\n\t\s]*<\/title>/gim, '$1');
const metas = html.match(/<meta[^>]+>/gim);

@@ -79,2 +89,7 @@ const og = [];

const result = og.reduce((chain, meta) => (Object.assign(Object.assign({}, chain), { [meta.name]: meta.value })), {});
// Image
result[ogImage] = result[ogImage] ? result[ogImage] : null;
result[twitterImage] = result[twitterImage]
? result[twitterImage]
: result[ogImage];
result.image = result[ogImage]

@@ -85,7 +100,23 @@ ? result[ogImage]

: null;
result.url = result[ogUrl]
? result[ogUrl]
: result[twitterUrl]
? result[twitterUrl]
: url;
// URL
result[ogUrl] = result[ogUrl] ? result[ogUrl] : url;
result[twitterUrl] = result[twitterUrl]
? result[twitterUrl]
: result[ogUrl];
result.url = result[ogUrl];
// Description
result[ogDescription] = result[ogDescription]
? result[ogDescription]
: result.description;
result[twitterDescription] = result[twitterDescription]
? result[twitterDescription]
: result[ogDescription];
// Title
result[ogTitle] = result[ogTitle] ? result[ogTitle] : siteTitle;
result[twitterTitle] = result[twitterTitle]
? result[twitterTitle]
: result[ogTitle];
result.title = result[ogTitle];
// Type
result[ogType] = result[ogType] ? result[ogType] : 'website';
return resolve(result);

@@ -92,0 +123,0 @@ }

2

package.json
{
"name": "fetch-opengraph",
"version": "1.0.17",
"version": "1.0.19",
"description": "Fetch opengraph information from an url",

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

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