lib/geo-from-ip.js
/**
 * get all data about an IP
 * @param  {String} ip ip address
 * @return {Object}    result object containing all the data
 */
get all data about an IP
@param  {String} ip ip address
@return {Object}    result object containing all the data
get all data about an IP @param { String } ip ip address @return { Object } result object containing all the data
function allData (ip) {
  debug(`allData function called with ip: ${ip}`)
  const geodata = city.getGeoDataSync(ip)
  const result = {
    code: {}
  }
  if (geodata) {
    debug(`got location, consolidating`)
    if (geodata.city) {
      result.city = geodata.city.names.en
    } else {
      result.city = null
    }
    if (geodata.subdivisions) {
      result.state = geodata.subdivisions[0].names.en
      result.code.state = geodata.subdivisions[0].iso_code
    } else {
      result.state = null
      result.code.state = null
    }
    if (geodata.country) {
      result.country = geodata.country.names.en
      result.code.country = geodata.country.iso_code
    }
    if (geodata.continent) {
      result.continent = geodata.continent.names.en
      result.code.continent = geodata.continent.code
    }
    if (geodata.postal) {
      result.postal = geodata.postal.code
    }
    if (geodata.location) {
      result.location = geodata.location
    }
  } else {
    debug(`🚨 could not get location, sorry!`)
    result.error = 'NA'
    result.ip = ip
  }
  debug(`returning location result: ${JSON.stringify(result)}`)
  return result
}
function allData ( ip ) { debug ( ` ${ ip } ` ) const geodata = city . getGeoDataSync ( ip ) const result = { code : { } } if ( geodata ) { debug ( ` ` ) if ( geodata . city ) { result . city = geodata . city . names . en } else { result . city = null } if ( geodata . subdivisions ) { result . state = geodata . subdivisions [ 0 ] . names . en result . code . state = geodata . subdivisions [ 0 ] . iso_code } else { result . state = null result . code . state = null } if ( geodata . country ) { result . country = geodata . country . names . en result . code . country = geodata . country . iso_code } if ( geodata . continent ) { result . continent = geodata . continent . names . en result . code . continent = geodata . continent . code } if ( geodata . postal ) { result . postal = geodata . postal . code } if ( geodata . location ) { result . location = geodata . location } } else { debug ( ` result . error = 'NA' result . ip = ip } debug ( ` ${ JSON . stringify ( result ) } ` ) return result }
get all data about an IP
 @param  {String} ip ip address
 @return {Object}    result object containing all the data
get all data about an IP @param { String } ip ip address @return { Object } result object containing all the data
// get all data for ip // consolidate data based on type // city // state // country // continent // postal // location // error // return result