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 2.0.3 to 2.0.4

50

app.js

@@ -172,4 +172,4 @@ var request = require('request'),

that = this;
this.validateVars(options.url, options.timeout, function (inputUrlFlag, inputUrl, inputTimeoutFlag, inputTimeout) {
if (inputUrlFlag && inputUrlFlag === true && inputTimeoutFlag && inputTimeoutFlag === true) {
this.validateVars(options.url, options.timeout, function (inputUrl, inputTimeout) {
if (inputUrl) {
options.url = inputUrl;

@@ -221,26 +221,14 @@ options.timeout = inputTimeout;

exports.validateVars = function (inputUrl, inputTimeout, callback) {
var returnInputUrl,
returnInputUrlFlag,
returnInputTimeout,
returnInputTimeoutFlag;
if (inputUrl === null || typeof inputUrl === 'undefined' || !inputUrl || inputUrl.length < 1) {
returnInputUrlFlag = false;
returnInputUrl = '';
} else {
returnInputUrlFlag = true;
var returnInputUrl = null,
returnInputTimeout = 2000; // time defaults to 2000ms
if (!(inputUrl === null || typeof inputUrl === 'undefined' || !inputUrl || inputUrl.length < 1)) {
returnInputUrl = this.validateUrl(inputUrl);
}
if (inputTimeout === null || typeof inputTimeout === 'undefined' || !inputTimeout || typeof inputTimeout !== 'number' || inputTimeout.length < 1) {
returnInputTimeoutFlag = true;
returnInputTimeout = 2000; //time default to 2000ms
} else {
if (this.validateTimeout(inputTimeout)) {
returnInputTimeoutFlag = true;
returnInputTimeout = inputTimeout;
} else {
returnInputTimeoutFlag = true;
returnInputTimeout = 2000; //time default to 2000ms
}
if (!(inputTimeout === null || typeof inputTimeout === 'undefined' || !inputTimeout || typeof inputTimeout !== 'number' || inputTimeout.length < 1) && this.validateTimeout(inputTimeout)) {
returnInputTimeout = inputTimeout;
}
callback(returnInputUrlFlag, returnInputUrl, returnInputTimeoutFlag, returnInputTimeout);
callback(returnInputUrl, returnInputTimeout);
};

@@ -339,6 +327,14 @@

//example of how to get the title tag
// $('title').map(function(i, info) {
// console.log('title:',info.children[0].data);
// });
// Check for 'only get open graph info'
if (!options.onlyGetOpenGraphInfo) {
// Get title tag if og title was not provided
if (!ogObject.ogTitle && $("title").text() && $("title").text().length > 0) {
ogObject.ogTitle = $("title").text();
}
// Get meta description tag if og description was not provided
if (!ogObject.ogDescription && $('meta[name="description"]').attr('content') && $('meta[name="description"]').attr('content').length > 0) {
ogObject.ogDescription = $('meta[name="description"]').attr('content');
}
}
//console.log('ogObject',ogObject);

@@ -345,0 +341,0 @@ callback(null, ogObject);

{
"name": "open-graph-scraper",
"description": "Node.js scraper service for Open Graph info",
"version": "2.0.3",
"version": "2.0.4",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "app.js",

@@ -17,7 +17,7 @@ openGraphScraper

ogs(options, function (err, results) {
console.log('err:', err); // This is returns true or false. True if there was a error. The error it self is inside the results object.
console.log('err:', err); // This is returns true or false. True if there was a error. The error it self is inside the results object.
console.log('results:', results);
});
```
You can also set a timeout flag like...
You can also set a timeout flag like... Example four seconds:
```

@@ -27,3 +27,3 @@ var ogs = require('open-graph-scraper');

ogs(options, function (err, results) {
console.log('err:', err); // This is returns true or false. True if there was a error. The error it self is inside the results object.
console.log('err:', err); // This is returns true or false. True if there was a error. The error it self is inside the results object.
console.log('results:', results);

@@ -33,3 +33,5 @@ });

### Result JSON
Note: By default if page dose not have something like a `og:title` tag it will try and look for it in other places and return that. If you truely only want open graph info you can use the option `onlyGetOpenGraphInfo` and set it to `true`.
### Results JSON
Check the return for a ```success``` flag. If success is set to true, then the url input was valid. Otherwise it will be set to false. The above eample will return something like...

@@ -36,0 +38,0 @@ ```

@@ -68,2 +68,13 @@ var app = require('../app'),

// test getting only open graph tags
var options15 = {
'url': 'http://www.wikipedia.org/',
'onlyGetOpenGraphInfo': true
};
// test getting the description from meta tags
var options16 = {
'url': 'https://twitter.com/',
}
// test videos

@@ -103,3 +114,3 @@ var optionsYoutube = {

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -112,3 +123,3 @@ });

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -121,3 +132,3 @@ });

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -130,3 +141,3 @@ });

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -139,3 +150,3 @@ });

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -172,3 +183,3 @@ });

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -181,3 +192,3 @@ });

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -190,3 +201,3 @@ });

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -199,3 +210,3 @@ });

expect(result.success).to.be(true);
expect(result.data).to.be.empty();
expect(result.data.ogTitle).to.be('Wikipedia');
done();

@@ -228,2 +239,19 @@ });

});
it('Valid Call - only get open graph info', function (done) {
app(options15, function (err, result) {
expect(err).to.be(false);
expect(result.success).to.be(true);
expect(result.data).to.be.empty();
done();
});
});
it('Valid Call - test getting the description from meta tags', function (done) {
app(options16, function (err, result) {
expect(err).to.be(false);
expect(result.success).to.be(true);
expect(result.data.ogTitle).to.be('Twitter');
expect(result.data.ogDescription).to.be('Connect with your friends &#8212; and other fascinating people. Get in-the-moment updates on the things that interest you. And watch events unfold, in real time, from every angle.');
done();
});
});
it('Valid Call - Test Youtube Video - Should Return correct Open Graph Info', function (done) {

@@ -230,0 +258,0 @@ app(optionsYoutube, function (err, result) {

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