Socket
Socket
Sign inDemoInstall

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.5 to 1.0.6

40

index.js

@@ -12,5 +12,21 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.fetch = void 0;
exports.fetch = exports.metaTags = void 0;
const axios_1 = require("axios");
exports.metaTags = {
title: 'title',
description: 'description',
ogUrl: 'og:url',
ogType: 'og:type',
ogTitle: 'og:title',
ogDescription: 'og:description',
ogImage: 'og:image',
twitterCard: 'twitter:card',
twitterDomain: 'twitter:domain',
twitterUrl: 'twitter:url',
twitterTitle: 'twitter:title',
twitterDescription: 'twitter:description',
twitterImage: 'twitter:image'
};
const fetch = (url) => __awaiter(void 0, void 0, void 0, function* () {
const { title, description, ogUrl, ogType, ogTitle, ogDescription, ogImage, twitterCard, twitterDomain, twitterUrl, twitterTitle, twitterDescription, twitterImage } = exports.metaTags;
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {

@@ -45,3 +61,3 @@ try {

// This is to prevent an possible endless loop,
// avoid "If path not taken" from code coverage since you're unable to reproduce
// avoid "If path not taken" from code coverage since you're unable to reproduce this and it's required to prevent endless loops
/* istanbul ignore next */

@@ -53,8 +69,8 @@ if (match.index === regex.lastIndex)

} while (match);
if (properties.name &&
properties.name.match(/(title|description|twitter:card|twitter:title|twitter:description|twitter:image)/)) {
const reName = new RegExp(`(${title}|${description}|${twitterCard}|${twitterTitle}|${twitterDescription}|${twitterImage})`);
if (properties.name && properties.name.match(reName)) {
og.push({ name: properties.name, value: properties.content });
}
if (properties.property &&
properties.property.match(/(og[:]url|og.type|og\:title|og\:description|og\:image|twitter\:domain|twitter\:url)/)) {
const reProperty = new RegExp(`(${ogUrl}|${ogType}|${ogTitle}|${ogDescription}|${ogImage}|${twitterDomain}|${twitterUrl})`);
if (properties.property && properties.property.match(reProperty)) {
og.push({ name: properties.property, value: properties.content });

@@ -65,4 +81,12 @@ }

const result = og.reduce((chain, meta) => (Object.assign(Object.assign({}, chain), { [meta.name]: meta.value })), {});
result.image = result['og:image'] ? result['og:image'] : result['twitter:image'] ? result['twitter:image'] : null;
result.url = result['og:url'] ? result['og:url'] : result['twitter:url'] ? result['twitter:url'] : url;
result.image = result[ogImage]
? result[ogImage]
: result[twitterImage]
? result[twitterImage]
: null;
result.url = result[ogUrl]
? result[ogUrl]
: result[twitterUrl]
? result[twitterUrl]
: url;
return resolve(result);

@@ -69,0 +93,0 @@ }

2

package.json
{
"name": "fetch-opengraph",
"version": "1.0.5",
"version": "1.0.6",
"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