Comparing version 1.4.2 to 1.4.3
@@ -11,5 +11,11 @@ "use strict"; | ||
exports.getResults = getResults; | ||
exports.getResponseBody = getResponseBody; | ||
exports.getResponse = getResponse; | ||
exports.default = void 0; | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/* eslint-disable no-console */ | ||
@@ -135,3 +141,3 @@ | ||
function getResponseBody(_ref2) { | ||
function getResponse(_ref2) { | ||
var filePath = _ref2.fromFile, | ||
@@ -160,3 +166,3 @@ options = _ref2.options, | ||
}); | ||
request(Object.assign({}, defaultOptions, options), function (error, response, body) { | ||
request(_objectSpread({}, defaultOptions, {}, options), function (error, response, body) { | ||
if (error) { | ||
@@ -167,3 +173,6 @@ reject(new Error("Error making web request: ".concat(error))); | ||
saveResponse(response, htmlFileOutputPath); | ||
resolve(body); | ||
resolve({ | ||
body: body, | ||
response: response | ||
}); | ||
}); | ||
@@ -181,5 +190,8 @@ } | ||
snippetSelector = config.snippetSelector, | ||
start = config.start; | ||
start = config.start, | ||
diagnostics = config.diagnostics; | ||
return new Promise(function (resolve, reject) { | ||
getResponseBody(config).then(function (body) { | ||
getResponse(config).then(function (_ref3) { | ||
var body = _ref3.body, | ||
response = _ref3.response; | ||
var results = getResults({ | ||
@@ -195,9 +207,16 @@ data: body, | ||
}); | ||
var statusCode = response.statusCode; | ||
if (results.length === 0 && statusCode !== 200 && !diagnostics) { | ||
reject(new Error("Error in response: statusCode ".concat(statusCode, ". To see the raw response object, please include the 'diagnostics: true' as part of the options object (or -d if using command line)"))); | ||
} | ||
saveToFile(output, results); | ||
openInBrowser(open, results); | ||
if (returnHtmlBody) { | ||
if (returnHtmlBody || diagnostics) { | ||
return resolve({ | ||
results: results, | ||
body: body | ||
body: body, | ||
response: response | ||
}); | ||
@@ -204,0 +223,0 @@ } |
@@ -88,3 +88,8 @@ "use strict"; | ||
type: String | ||
}, // allows for googleIt result object to include raw network request's response | ||
{ | ||
name: 'diagnostics', | ||
alias: 'd', | ||
type: Boolean | ||
}]; | ||
module.exports = optionDefinitions; |
{ | ||
"name": "google-it", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "A CLI and Node.js library to help retrieve, display, and store Google search results", | ||
@@ -5,0 +5,0 @@ "main": "./lib/main.js", |
@@ -40,3 +40,3 @@ /* eslint-disable no-console */ | ||
if (!child.data) { | ||
return child.children.map(c => c.data); | ||
return child.children.map((c) => c.data); | ||
} | ||
@@ -102,3 +102,3 @@ return child.data; | ||
if (onlyUrls) { | ||
results = results.map(r => ({ link: r.link })); | ||
results = results.map((r) => ({ link: r.link })); | ||
} | ||
@@ -111,3 +111,3 @@ if (!noDisplay) { | ||
export function getResponseBody({ | ||
export function getResponse({ | ||
fromFile: filePath, options, htmlFileOutputPath, query, limit, userAgent, start, | ||
@@ -127,3 +127,3 @@ }) { | ||
}); | ||
request(Object.assign({}, defaultOptions, options), (error, response, body) => { | ||
request({ ...defaultOptions, ...options }, (error, response, body) => { | ||
if (error) { | ||
@@ -133,3 +133,3 @@ reject(new Error(`Error making web request: ${error}`)); | ||
saveResponse(response, htmlFileOutputPath); | ||
resolve(body); | ||
resolve({ body, response }); | ||
}); | ||
@@ -149,5 +149,6 @@ } | ||
start, | ||
diagnostics, | ||
} = config; | ||
return new Promise((resolve, reject) => { | ||
getResponseBody(config).then((body) => { | ||
getResponse(config).then(({ body, response }) => { | ||
const results = getResults({ | ||
@@ -163,6 +164,10 @@ data: body, | ||
}); | ||
const { statusCode } = response; | ||
if (results.length === 0 && statusCode !== 200 && !diagnostics) { | ||
reject(new Error(`Error in response: statusCode ${statusCode}. To see the raw response object, please include the 'diagnostics: true' as part of the options object (or -d if using command line)`)); | ||
} | ||
saveToFile(output, results); | ||
openInBrowser(open, results); | ||
if (returnHtmlBody) { | ||
return resolve({ results, body }); | ||
if (returnHtmlBody || diagnostics) { | ||
return resolve({ results, body, response }); | ||
} | ||
@@ -169,0 +174,0 @@ return resolve(results); |
@@ -54,4 +54,7 @@ const optionDefinitions = [ | ||
{ name: 'snippetSelector', type: String }, | ||
// allows for googleIt result object to include raw network request's response | ||
{ name: 'diagnostics', alias: 'd', type: Boolean }, | ||
]; | ||
module.exports = optionDefinitions; |
@@ -37,11 +37,11 @@ /* eslint-disable no-console */ | ||
const getTitleSelector = passedValue => ( | ||
const getTitleSelector = (passedValue) => ( | ||
passedValue || GOOGLE_IT_TITLE_SELECTOR || titleSelector | ||
); | ||
const getLinkSelector = passedValue => ( | ||
const getLinkSelector = (passedValue) => ( | ||
passedValue || GOOGLE_IT_LINK_SELECTOR || linkSelector | ||
); | ||
const getSnippetSelector = passedValue => ( | ||
const getSnippetSelector = (passedValue) => ( | ||
passedValue || GOOGLE_IT_SNIPPET_SELECTOR || snippetSelector | ||
@@ -48,0 +48,0 @@ ); |
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
38085
780