fetch-opengraph
Advanced tools
Comparing version 1.0.25 to 1.0.26
@@ -16,2 +16,3 @@ export declare const metaTags: { | ||
}; | ||
export declare const queryParams: (str: string) => {}; | ||
export declare const fetch: (url: string, headers?: any) => Promise<any>; | ||
@@ -18,0 +19,0 @@ declare const _default: { |
24
index.js
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.fetch = exports.metaTags = void 0; | ||
exports.fetch = exports.queryParams = exports.metaTags = void 0; | ||
const axios_1 = require("axios"); | ||
@@ -31,2 +31,21 @@ const html_entities_1 = require("html-entities"); | ||
}; | ||
const queryParams = (str) => { | ||
const url = str.replace(/^([^#]*).*/, "$1").replace(/^[^?]*\??(.*)/, "$1"); | ||
let result = {}; | ||
const regex = /([^=]+)=([^&]+)&?/g; | ||
let match; | ||
do { | ||
match = regex.exec(url); | ||
if (match) { | ||
// This is to prevent an possible endless loop, | ||
// 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 */ | ||
if (match.index === regex.lastIndex) | ||
regex.lastIndex++; | ||
result = Object.assign(Object.assign({}, result), { [match[1]]: match[2] }); | ||
} | ||
} while (match); | ||
return result; | ||
}; | ||
exports.queryParams = queryParams; | ||
const fetch = (url, headers) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -36,3 +55,4 @@ const { title, description, ogUrl, ogType, ogTitle, ogDescription, ogImage, twitterCard, twitterDomain, twitterUrl, twitterTitle, twitterDescription, twitterImage } = exports.metaTags; | ||
try { | ||
const response = yield axios_1.default.get(url, { | ||
const response = yield axios_1.default.get(url.replace(/^([^?#]*).*/, "$1"), { | ||
params: exports.queryParams(url), | ||
headers: Object.assign({ 'User-Agent': 'OpenGraph', 'Cache-Control': 'no-cache', Accept: '*/*', Connection: 'keep-alive' }, headers) | ||
@@ -39,0 +59,0 @@ }); |
{ | ||
"name": "fetch-opengraph", | ||
"version": "1.0.25", | ||
"version": "1.0.26", | ||
"description": "Fetch opengraph information from an url", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
13289
184