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

open-graph-scraper

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

open-graph-scraper - npm Package Compare versions

Comparing version 5.1.0 to 5.1.1

dist/lib/types.js

6

CHANGELOG.md
# Change Log
## 5.1.1
- Fix issue where using `import` would cause typescript errors
- Updating the `urlValidatorSettings` defaults to match `validatorjs`
- Updating Dependencies
## 5.1.0

@@ -4,0 +10,0 @@

5

dist/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable max-len */
// eslint-disable-next-line import/no-import-module-exports
/* eslint-disable max-len, import/no-import-module-exports */
const openGraphScraper_1 = require("./lib/openGraphScraper");

@@ -21,3 +20,3 @@ /**

* @param {number | false} [options.downloadLimit] - Maximum size of the content downloaded from the server, in bytes.
* @param {object} [options.urlValidatorSettings] - Sets the options used by validator.js for testing the URL
* @param {object} [options.ValidatorSettings] - Sets the options used by validator.js for testing the URL
* @param {boolean} [options.decompress] - Set the accept-encoding to `gzip, deflate, br` (default: `true`).

@@ -24,0 +23,0 @@ * @param {boolean} [options.followRedirect] - Defines if redirect responses should be followed automatically. (default: `true`).

3

dist/lib/extract.js

@@ -11,3 +11,3 @@ "use strict";

*
* @param {object} body - the body of the got request
* @param {sting} body - the body of the got request
* @param {object} options - options for ogs

@@ -54,2 +54,3 @@ * @return {object} object with ogs results

}
// TODO: Is this still needed?
// removes any undefs

@@ -56,0 +57,0 @@ ogObject = utils.removeNestedUndefinedValues(ogObject);

@@ -6,23 +6,23 @@ "use strict";

const mediaMapperTwitterImage = (item) => ({
alt: item[3],
height: item[2],
url: item[0],
width: item[1],
height: item[2],
alt: item[3],
});
const mediaMapperTwitterPlayer = (item) => ({
height: item[2],
stream: item[3],
url: item[0],
width: item[1],
height: item[2],
stream: item[3],
});
const mediaMapperMusicSong = (item) => ({
disc: item[2],
track: item[1],
url: item[0],
track: item[1],
disc: item[2],
});
const mediaMapper = (item) => ({
height: item[2],
type: item[3],
url: item[0],
width: item[1],
height: item[2],
type: item[3],
});

@@ -74,3 +74,3 @@ const mediaSorter = (a, b) => {

// sets ogImage image/width/height/type to null if one these exists
if (ogObject.ogImage || ogObject.ogImageWidth || ogObject.twitterImageHeight || ogObject.ogImageType) {
if (ogObject.ogImage || ogObject.ogImageWidth || ogObject.ogImageHeight || ogObject.ogImageType) {
ogObject.ogImage = ogObject.ogImage ? ogObject.ogImage : [null];

@@ -77,0 +77,0 @@ ogObject.ogImageWidth = ogObject.ogImageWidth ? ogObject.ogImageWidth : [null];

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.gotClient = exports.optionSetupAndSplit = exports.removeNestedUndefinedValues = exports.isThisANonHTMLUrl = exports.isImageTypeValid = exports.findImageTypeFromUrl = exports.validateAndFormatURL = exports.isUrlValid = void 0;
const validator = require("validator");
const validator_1 = require("validator");
/**

@@ -14,3 +14,3 @@ * Checks if URL is valid

function isUrlValid(url, urlValidatorSettings) {
return typeof url === 'string' && url.length > 0 && validator.isURL(url, urlValidatorSettings);
return typeof url === 'string' && url.length > 0 && validator_1.default.isURL(url, urlValidatorSettings);
}

@@ -27,3 +27,3 @@ exports.isUrlValid = isUrlValid;

/**
* validates and formats url
* Validates and formats url
*

@@ -36,7 +36,7 @@ * @param {string} url - url to be checked and formatted

function validateAndFormatURL(url, urlValidatorSettings) {
return { url: this.isUrlValid(url, urlValidatorSettings) ? coerceUrl(url) : null };
return { url: isUrlValid(url, urlValidatorSettings) ? coerceUrl(url) : null };
}
exports.validateAndFormatURL = validateAndFormatURL;
/**
* finds the image type from a given url
* Finds the image type from a given url
*

@@ -54,3 +54,3 @@ * @param {string} url - url to be checked

/**
* checks if image type is valid
* Checks if image type is valid
*

@@ -67,3 +67,3 @@ * @param {string} type - type to be checked

/**
* checks if URL is a non html page
* Checks if URL is a non html page
*

@@ -76,3 +76,3 @@ * @param {string} url - url to be checked

const invalidImageTypes = ['.doc', '.docx', '.xls', '.xlsx', '.ppt', '.pptx', '.3gp', '.avi', '.mov', '.mp4', '.m4v', '.m4a', '.mp3', '.mkv', '.ogv', '.ogm', '.ogg', '.oga', '.webm', '.wav', '.bmp', '.gif', '.jpg', '.jpeg', '.png', '.webp', '.zip', '.rar', '.tar', '.tar.gz', '.tgz', '.tar.bz2', '.tbz2', '.txt', '.pdf'];
const extension = this.findImageTypeFromUrl(url);
const extension = findImageTypeFromUrl(url);
return invalidImageTypes.some((type) => `.${extension}`.includes(type));

@@ -82,3 +82,3 @@ }

/**
* find and delete nested undefs
* Find and delete nested undefs
*

@@ -92,3 +92,3 @@ * @param {object} object - object to be cleaned

if (value && typeof value === 'object')
this.removeNestedUndefinedValues(value);
removeNestedUndefinedValues(value);
else if (value === undefined)

@@ -101,3 +101,3 @@ delete object[key];

/**
* split the options object into ogs and got option objects
* Split the options object into ogs and got option objects
*

@@ -121,9 +121,10 @@ * @param {object} options - options that need to be split

require_host: true,
require_port: false,
require_valid_protocol: true,
allow_underscores: false,
host_whitelist: false,
host_blacklist: false,
allow_trailing_dot: false,
allow_protocol_relative_urls: false,
disallow_auth: false,
allow_fragments: true,
allow_query_components: true,
validate_length: true,
},

@@ -169,7 +170,5 @@ ...options,

if (options.isStream) {
// @ts-ignore
promiseOrStream.destroy(new Error(message));
return;
}
// @ts-ignore
promiseOrStream.cancel(message);

@@ -176,0 +175,0 @@ };

@@ -1,4 +0,7 @@

/* eslint-disable max-len */
// eslint-disable-next-line import/no-import-module-exports
/* eslint-disable max-len, import/no-import-module-exports */
import setOptionsAndReturnOpenGraphResults from './lib/openGraphScraper';
import {
OpenGraphScraperOptions,
OgObject,
} from './lib/types';

@@ -20,3 +23,3 @@ /**

* @param {number | false} [options.downloadLimit] - Maximum size of the content downloaded from the server, in bytes.
* @param {object} [options.urlValidatorSettings] - Sets the options used by validator.js for testing the URL
* @param {object} [options.ValidatorSettings] - Sets the options used by validator.js for testing the URL
* @param {boolean} [options.decompress] - Set the accept-encoding to `gzip, deflate, br` (default: `true`).

@@ -59,58 +62,5 @@ * @param {boolean} [options.followRedirect] - Defines if redirect responses should be followed automatically. (default: `true`).

type OpenGraphScraperOptions = {
url: string;
html?: string;
blacklist?: string[];
onlyGetOpenGraphInfo?: boolean;
ogImageFallback?: boolean;
customMetaTags?: CustomMetaTags[];
allMedia?: boolean;
peekSize?: number;
downloadLimit?: number | false;
urlValidatorSettings?: ValidatorSettings;
decompress?: boolean;
followRedirect?: boolean;
headers?: {
[x: string]: string;
};
maxRedirects?: number;
retry?: object;
timeout?: object;
};
type CustomMetaTags = {
/**
* - is there more than one of these tags on a page (normally this is false)
*/
multiple: boolean;
/**
* - meta tag name/property attribute
*/
property: string;
/**
* - name of the result variable
*/
fieldName: string;
};
/**
* You can find the `isUrl` settings details at https://github.com/validatorjs/validator.js
*/
type ValidatorSettings = {
protocols: string[];
require_tld: boolean;
require_protocol: boolean;
require_host: boolean;
require_valid_protocol: boolean;
allow_underscores: boolean;
host_whitelist: boolean;
host_blacklist: boolean;
allow_trailing_dot: boolean;
allow_protocol_relative_urls: boolean;
disallow_auth: boolean;
};
type SuccessResult = {
error: boolean;
result: SuccessResultObject;
result: OgObject;
response: object;

@@ -121,375 +71,4 @@ };

error: boolean;
result: ErrorResultObject;
result: OgObject;
response: undefined;
};
type ImageObject = {
height?: string | number;
type: string;
url: string;
width?: string | number;
};
type TwitterImageObject = {
height?: string | number;
alt?: string;
url: string;
width?: string | number;
};
type TwitterPlayerObject = {
height?: string | number;
stream?: string;
url?: string;
width?: string | number;
};
type SuccessResultObject = {
error?: undefined;
errorDetails?: undefined;
alAndroidAppName?: string | undefined;
alAndroidClass?: string | undefined;
alAndroidPackage?: string | undefined;
alAndroidUrl?: string | undefined;
alIosAppName?: string | undefined;
alIosAppStoreId?: string | undefined;
alIosUrl?: string | undefined;
alIpadAppName?: string | undefined;
alIpadAppStoreId?: string | undefined;
alIpadUrl?: string | undefined;
alIphoneAppName?: string | undefined;
alIphoneAppStoreId?: string | undefined;
alIphoneUrl?: string | undefined;
alWebShouldFallback?: string | undefined;
alWebUrl?: string | undefined;
alWindowsAppId?: string | undefined;
alWindowsAppName?: string | undefined;
alWindowsPhoneAppId?: string | undefined;
alWindowsPhoneAppName?: string | undefined;
alWindowsPhoneUrl?: string | undefined;
alWindowsUniversalAppId?: string | undefined;
alWindowsUniversalAppName?: string | undefined;
alWindowsUniversalUrl?: string | undefined;
alWindowsUrl?: string | undefined;
articleAuthor?: string | undefined;
articleExpirationTime?: string | undefined;
articleModifiedTime?: string | undefined;
articlePublishedTime?: string | undefined;
articlePublisher?: string | undefined;
articleSection?: string | undefined;
articleTag?: string | undefined;
author?: string | undefined;
bookAuthor?: string | undefined;
bookCanonicalName?: string | undefined;
bookIsbn?: string | undefined;
bookReleaseDate?: string | undefined;
booksBook?: string | undefined;
booksRatingScale?: string | undefined;
booksRatingValue?: string | undefined;
bookTag?: string | undefined;
businessContactDataCountryName?: string | undefined;
businessContactDataLocality?: string | undefined;
businessContactDataPostalCode?: string | undefined;
businessContactDataRegion?: string | undefined;
businessContactDataStreetAddress?: string | undefined;
dcContributor?: string | undefined;
dcCoverage?: string | undefined;
dcCreator?: string | undefined;
dcDate?: string | undefined;
dcDateCreated?: string | undefined;
dcDateIssued?: string | undefined;
dcDescription?: string | undefined;
dcFormatMedia?: string | undefined;
dcFormatSize?: string | undefined;
dcIdentifier?: string | undefined;
dcLanguage?: string | undefined;
dcPublisher?: string | undefined;
dcRelation?: string | undefined;
dcRights?: string | undefined;
dcSource?: string | undefined;
dcSubject?: string | undefined;
dcTitle?: string | undefined;
dcType?: string | undefined;
modifiedTime?: string | undefined;
musicAlbum?: string | undefined;
musicAlbumDisc?: string | undefined;
musicAlbumTrack?: string | undefined;
musicAlbumUrl?: string | undefined;
musicCreator?: string | undefined;
musicDuration?: string | undefined;
musicMusician?: string | undefined;
musicReleaseDate?: string | undefined;
musicSong?: string | undefined;
musicSongDisc?: string | undefined;
musicSongTrack?: string | undefined;
musicSongUrl?: string | undefined;
ogArticleAuthor?: string | undefined;
ogArticleExpirationTime?: string | undefined;
ogArticleModifiedTime?: string | undefined;
ogArticlePublishedTime?: string | undefined;
ogArticlePublisher?: string | undefined;
ogArticleSection?: string | undefined;
ogArticleTag?: string | undefined;
ogAudio?: string | undefined;
ogAudioSecureURL?: string | undefined;
ogAudioType?: string | undefined;
ogAudioURL?: string | undefined;
ogAvailability?: string | undefined;
ogDate?: string | undefined;
ogDescription?: string | undefined;
ogDeterminer?: string | undefined;
ogImage?: string | ImageObject | ImageObject[] | undefined;
ogImageHeight?: string | undefined;
ogImageSecureURL?: string | undefined;
ogImageType?: string | undefined;
ogImageURL?: string | undefined;
ogImageWidth?: string | undefined;
ogLocale?: string | undefined;
ogLocaleAlternate?: string | undefined;
ogLogo?: string | undefined;
ogPriceAmount?: string | undefined;
ogPriceCurrency?: string | undefined;
ogProductAvailability?: string | undefined;
ogProductCondition?: string | undefined;
ogProductPriceAmount?: string | undefined;
ogProductPriceCurrency?: string | undefined;
ogProductRetailerItemId?: string | undefined;
ogSiteName?: string | undefined;
ogTitle?: string | undefined;
ogType?: string | undefined;
ogUrl?: string | undefined;
ogVideo?: string | undefined;
ogVideoActorId?: string | undefined;
ogVideoHeight?: string | undefined;
ogVideoSecureURL?: string | undefined;
ogVideoType?: string | undefined;
ogVideoWidth?: string | undefined;
placeLocationLatitude?: string | undefined;
placeLocationLongitude?: string | undefined;
profileFirstName?: string | undefined;
profileGender?: string | undefined;
profileLastName?: string | undefined;
profileUsername?: string | undefined;
publishedTime?: string | undefined;
releaseDate?: string | undefined;
restaurantContactInfoCountryName?: string | undefined;
restaurantContactInfoEmail?: string | undefined;
restaurantContactInfoLocality?: string | undefined;
restaurantContactInfoPhoneNumber?: string | undefined;
restaurantContactInfoPostalCode?: string | undefined;
restaurantContactInfoRegion?: string | undefined;
restaurantContactInfoStreetAddress?: string | undefined;
restaurantContactInfoWebsite?: string | undefined;
restaurantMenu?: string | undefined;
restaurantRestaurant?: string | undefined;
restaurantSection?: string | undefined;
restaurantVariationPriceAmount?: string | undefined;
restaurantVariationPriceCurrency?: string | undefined;
twitterAppIdGooglePlay?: string | undefined;
twitterAppIdiPad?: string | undefined;
twitterAppIdiPhone?: string | undefined;
twitterAppNameGooglePlay?: string | undefined;
twitterAppNameiPad?: string | undefined;
twitterAppNameiPhone?: string | undefined;
twitterAppUrlGooglePlay?: string | undefined;
twitterAppUrliPad?: string | undefined;
twitterAppUrliPhone?: string | undefined;
twitterCard?: string | undefined;
twitterCreator?: string | undefined;
twitterCreatorId?: string | undefined;
twitterDescription?: string | undefined;
twitterImage?: string | TwitterImageObject | TwitterImageObject[] | undefined;
twitterImageAlt?: string | undefined;
twitterImageHeight?: string | undefined;
twitterImageSrc?: string | undefined;
twitterImageWidth?: string | undefined;
twitterPlayer?: string | TwitterPlayerObject | TwitterPlayerObject[] | undefined;
twitterPlayerHeight?: string | undefined;
twitterPlayerStream?: string | undefined;
twitterPlayerStreamContentType?: string | undefined;
twitterPlayerWidth?: string | undefined;
twitterSite?: string | undefined;
twitterSiteId?: string | undefined;
twitterTitle?: string | undefined;
twitterUrl?: string | undefined;
updatedTime?: string | undefined;
requestUrl?: string;
success?: boolean;
charset?: string | undefined;
favicon?: string | undefined;
};
type ErrorResultObject = {
error: string;
errorDetails: Error;
alAndroidAppName?: undefined;
alAndroidClass?: undefined;
alAndroidPackage?: undefined;
alAndroidUrl?: undefined;
alIosAppName?: undefined;
alIosAppStoreId?: undefined;
alIosUrl?: undefined;
alIpadAppName?: undefined;
alIpadAppStoreId?: undefined;
alIpadUrl?: undefined;
alIphoneAppName?: undefined;
alIphoneAppStoreId?: undefined;
alIphoneUrl?: undefined;
alWebShouldFallback?: undefined;
alWebUrl?: undefined;
alWindowsAppId?: undefined;
alWindowsAppName?: undefined;
alWindowsPhoneAppId?: undefined;
alWindowsPhoneAppName?: undefined;
alWindowsPhoneUrl?: undefined;
alWindowsUniversalAppId?: undefined;
alWindowsUniversalAppName?: undefined;
alWindowsUniversalUrl?: undefined;
alWindowsUrl?: undefined;
articleAuthor?: undefined;
articleExpirationTime?: undefined;
articleModifiedTime?: undefined;
articlePublishedTime?: undefined;
articlePublisher?: undefined;
articleSection?: undefined;
articleTag?: undefined;
author?: undefined;
bookAuthor?: undefined;
bookCanonicalName?: undefined;
bookIsbn?: undefined;
bookReleaseDate?: undefined;
booksBook?: undefined;
booksRatingScale?: undefined;
booksRatingValue?: undefined;
bookTag?: undefined;
businessContactDataCountryName?: undefined;
businessContactDataLocality?: undefined;
businessContactDataPostalCode?: undefined;
businessContactDataRegion?: undefined;
businessContactDataStreetAddress?: undefined;
dcContributor?: undefined;
dcCoverage?: undefined;
dcCreator?: undefined;
dcDate?: undefined;
dcDateCreated?: undefined;
dcDateIssued?: undefined;
dcDescription?: undefined;
dcFormatMedia?: undefined;
dcFormatSize?: undefined;
dcIdentifier?: undefined;
dcLanguage?: undefined;
dcPublisher?: undefined;
dcRelation?: undefined;
dcRights?: undefined;
dcSource?: undefined;
dcSubject?: undefined;
dcTitle?: undefined;
dcType?: undefined;
modifiedTime?: undefined;
musicAlbum?: undefined;
musicAlbumDisc?: undefined;
musicAlbumTrack?: undefined;
musicAlbumUrl?: undefined;
musicCreator?: undefined;
musicDuration?: undefined;
musicMusician?: undefined;
musicReleaseDate?: undefined;
musicSong?: undefined;
musicSongDisc?: undefined;
musicSongTrack?: undefined;
musicSongUrl?: undefined;
ogArticleAuthor?: undefined;
ogArticleExpirationTime?: undefined;
ogArticleModifiedTime?: undefined;
ogArticlePublishedTime?: undefined;
ogArticlePublisher?: undefined;
ogArticleSection?: undefined;
ogArticleTag?: undefined;
ogAudio?: undefined;
ogAudioSecureURL?: undefined;
ogAudioType?: undefined;
ogAudioURL?: undefined;
ogAvailability?: undefined;
ogDate?: undefined;
ogDescription?: undefined;
ogDeterminer?: undefined;
ogImage?: undefined;
ogImageHeight?: undefined;
ogImageSecureURL?: undefined;
ogImageType?: undefined;
ogImageURL?: undefined;
ogImageWidth?: undefined;
ogLocale?: undefined;
ogLocaleAlternate?: undefined;
ogLogo?: undefined;
ogPriceAmount?: undefined;
ogPriceCurrency?: undefined;
ogProductAvailability?: undefined;
ogProductCondition?: undefined;
ogProductPriceAmount?: undefined;
ogProductPriceCurrency?: undefined;
ogProductRetailerItemId?: undefined;
ogSiteName?: undefined;
ogTitle?: undefined;
ogType?: undefined;
ogUrl?: undefined;
ogVideo?: undefined;
ogVideoActorId?: undefined;
ogVideoHeight?: undefined;
ogVideoSecureURL?: undefined;
ogVideoType?: undefined;
ogVideoWidth?: undefined;
placeLocationLatitude?: undefined;
placeLocationLongitude?: undefined;
profileFirstName?: undefined;
profileGender?: undefined;
profileLastName?: undefined;
profileUsername?: undefined;
publishedTime?: undefined;
releaseDate?: undefined;
restaurantContactInfoCountryName?: undefined;
restaurantContactInfoEmail?: undefined;
restaurantContactInfoLocality?: undefined;
restaurantContactInfoPhoneNumber?: undefined;
restaurantContactInfoPostalCode?: undefined;
restaurantContactInfoRegion?: undefined;
restaurantContactInfoStreetAddress?: undefined;
restaurantContactInfoWebsite?: undefined;
restaurantMenu?: undefined;
restaurantRestaurant?: undefined;
restaurantSection?: undefined;
restaurantVariationPriceAmount?: undefined;
restaurantVariationPriceCurrency?: undefined;
twitterAppIdGooglePlay?: undefined;
twitterAppIdiPad?: undefined;
twitterAppIdiPhone?: undefined;
twitterAppNameGooglePlay?: undefined;
twitterAppNameiPad?: undefined;
twitterAppNameiPhone?: undefined;
twitterAppUrlGooglePlay?: undefined;
twitterAppUrliPad?: undefined;
twitterAppUrliPhone?: undefined;
twitterCard?: undefined;
twitterCreator?: undefined;
twitterCreatorId?: undefined;
twitterDescription?: undefined;
twitterImage?: undefined;
twitterImageAlt?: undefined;
twitterImageHeight?: undefined;
twitterImageSrc?: undefined;
twitterImageWidth?: undefined;
twitterPlayer?: undefined;
twitterPlayerHeight?: undefined;
twitterPlayerStream?: undefined;
twitterPlayerStreamContentType?: undefined;
twitterPlayerWidth?: undefined;
twitterSite?: undefined;
twitterSiteId?: undefined;
twitterTitle?: undefined;
twitterUrl?: undefined;
updatedTime?: undefined;
requestUrl?: string;
success?: boolean;
charset?: undefined;
favicon?: undefined;
};
{
"name": "open-graph-scraper",
"description": "Node.js scraper module for Open Graph and Twitter Card info",
"version": "5.1.0",
"version": "5.1.1",
"license": "MIT",

@@ -29,3 +29,3 @@ "main": "./dist/index.js",

"cheerio": "^1.0.0-rc.12",
"got": "^12.5.3",
"got": "^12.6.0",
"iconv-lite": "^0.6.3",

@@ -35,2 +35,3 @@ "validator": "^13.9.0"

"files": [
"/lib",
"/dist",

@@ -41,8 +42,8 @@ "CHANGELOG.md",

"devDependencies": {
"@snyk/protect": "^1.1100.0",
"@types/node": "^18.13.0",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"@snyk/protect": "^1.1111.0",
"@types/node": "^18.14.6",
"@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0",
"chai": "^4.3.7",
"eslint": "^8.34.0",
"eslint": "^8.35.0",
"eslint-config-airbnb-base": "^15.0.0",

@@ -49,0 +50,0 @@ "eslint-config-airbnb-typescript": "^17.0.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