fetch-opengraph
Advanced tools
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 @@ } |
{ | ||
"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", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10066
95