PatNeedham/google-it

Options array object not being read correctly

Opened this issue · 2 comments

jwday commented

Version of google-it
1.6.2

Versions of npm and node
npm 7.6.3
node v12.4.0

Describe the bug
Attempting to use options in code, as follows:

const  googleIt = require('google-it')

const options = {
  'limit': 3
};
googleIt({options, 'query': 'covfefe irony'}).then(results => {
  // access to results object here
}).catch(e => {
  // any possible errors that might have occurred (like no Internet connection)
})

Expected behavior
I expect only the first three results to be returned and displayed in the console. Instead the default 10 appears.

Additional context
I have also tried other options such as 'no-display': true and those listed in optionsDefinitions.js, to no avail (e.g. 'no-display': true continues to display the results in the console). Oddly, the only option that seems to work is 'proxy:' (as per the readme example), and that is not one of the options listed in optionsDefinitions.js.

I have found, however, that putting the options directly in the command path does work, e.g.:

googleIt({'limit': 3, 'no-display': true, 'query': 'covfefe irony'}).then(results => {
  // access to results object here
}).catch(e => {
  // any possible errors that might have occurred (like no Internet connection)
})

The code behaves as expected when written in this form. My guess is that it has something to do with how the options are unpacked inside the googleIt function.

Thank you @jwday for spotting this - I don't think it's an issue with the code itself, but rather the documentation being somewhat misleading.

In addition to updating the readme page to include more examples, I think I'll also modify the getResponse function where it uses that options object to check if any of the fields inside of it should not be there (for example those that should instead be sibling fields). So in that case it could return an error detailing the misplacement.

jwday commented

Thanks for the timely feedback! Much appreciated. 👍