markthethomas / find-iphone-7

Simple CLI to find iphone 7's available in your area and alert you when they are
MIT License
2 stars 0 forks source link

yargs Incorrectly parses zip codes starting with a '0' #1

Open chasingtheflow opened 7 years ago

chasingtheflow commented 7 years ago

Zip codes which start with a "0" (zero) are incorrectly parsed and the leading zero is dropped from the result. E.g. 01234 becomes 1234 which is no longer a valid zip code.

I was also getting errors that I was missing an iphone7.yaml file until I stubbed one out even though I was not using the notify flag.

Cool script though! Nice job

 ~> find-iphone-7 --zip 07030 --model plus --color black --capacity 128 --carrier att

argv:  { _: [],
  zip: 7030,
  model: 'plus',
  color: 'black',
  capacity: 128,
  carrier: 'att',
  '$0': '/usr/local/bin/find-iphone-7' }
⠹ Searching for iphones...
availability payload: { overlayInitiatedFromWarmStart: false,
  viewMoreHoursLinkText: 'View more hours',
  little: true,
  errorMessage: 'Invalid Zip Code or City/State.',
  location: '7030' }
TypeError: Cannot read property 'filter' of undefined
    at axios.get.then (/usr/local/lib/node_modules/find-iphone-7/index.js:111:47)
    at process._tickCallback (internal/process/next_tick.js:103:7)
⠧ Searching for iphones...⏎                                                     

 ~> find-iphone-7 --zip '07030' --model plus --color black --capacity 128 --carrier att

argv:  { _: [],
  zip: 7030,
  model: 'plus',
  color: 'black',
  capacity: 128,
  carrier: 'att',
  '$0': '/usr/local/bin/find-iphone-7' }
⠙ Searching for iphones...
availability payload: { overlayInitiatedFromWarmStart: false,
  viewMoreHoursLinkText: 'View more hours',
  little: true,
  errorMessage: 'Invalid Zip Code or City/State.',
  location: '7030' }
TypeError: Cannot read property 'filter' of undefined
    at axios.get.then (/usr/local/lib/node_modules/find-iphone-7/index.js:111:47)
    at process._tickCallback (internal/process/next_tick.js:103:7)
⠦ Searching for iphones...^C⏎                                                   
 ~>

Above you can see two trials where I'm logging out the argv variable and the api response. Only difference between the two trials is the second wraps the zip arg in single quotes. Both incorrectly parse the zip code and the error returned from the API refers to the incorrect zip code.

markthethomas commented 7 years ago

@chasingtheflow thanks for your note and good point(s)! I'm super swamped for time rt now, any chance you could patch these in a PR? happy to merge :)