<commit_before><!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>FlightHop</title>
    <meta name="description" content="Flight search via Google Flight API with Facebook login">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
    <!-- <link rel="stylesheet" href="style.css"> -->
  </head>
  <body>
    <div id="app"></div>
<script>
/* global axios, X2JS */
let x2js;

const getAirportCodesFromGeo = (geo, dist) => {
  const lng = geo[0] || -122.4411147;
  const lat = geo[1] || 37.7718305;
  dist = dist || 20;

  // could add &fields=station_id param
  const url = `http://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=stations&requestType=retrieve&format=xml&radialDistance=${dist};${lng},${lat}`;

  return axios.get(url, { validateStatus: status => status === 200 })
  .then((resXml) => {
    const resJson = x2js.xml_str2json(resXml.data).response.data.Station;
    return Array.isArray(resJson) ?
      resJson.map(station => station.station_id.slice(1)) :
      resJson.station_id.slice(1);
  });
};

const onAllDependenciesLoaded = () => {
  x2js = new X2JS();
  getAirportCodesFromGeo([])
  .then((res) => {
    console.log('res', res);
  });
};

const loadDependency = url => new Promise((resolve, reject) => {
  const scr = document.createElement('script');
  scr.onload = resolve;
  scr.src = url;
  document.body.appendChild(scr);
});

const dependencies = [
  'https://cdnjs.cloudflare.com/ajax/libs/axios/0.15.3/axios.min.js',
  'https://cdnjs.cloudflare.com/ajax/libs/x2js/1.2.0/xml2json.min.js',
];

Promise.all(dependencies.map(loadDependency))
.then(onAllDependenciesLoaded);
<commit_msg>Refactor for concision, get user location from browser<commit_after><!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>FlightHop</title>
    <meta name="description" content="Flight search via Google Flight API with Facebook login">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
    <!-- <link rel="stylesheet" href="style.css"> -->
  </head>
  <body>
    <div id="app"></div>
<script>
/* global axios, X2JS */
let x2js;

const getUserLoc = () => new Promise((resolve, reject) =>
  navigator.geolocation.getCurrentPosition(({ coords }) =>
    resolve([coords.latitude, coords.longitude])));

const getAirportCodes = (geo, dist) => {
  const lat = geo[0] || 37.7718305;
  const lng = geo[1] || -122.4411147;
  dist = dist || 20;

  x2js = new X2JS();

  // could add &fields=station_id param
  const url = `http://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=stations&requestType=retrieve&format=xml&radialDistance=${dist};${lng},${lat}`;

  return axios.get(url, { validateStatus: status => status === 200 })
  .then((resXml) => {
    const resJson = x2js.xml_str2json(resXml.data).response.data.Station;
    return Array.isArray(resJson) ?
      resJson.map(station => station.station_id.slice(1)) :
      resJson.station_id.slice(1);
  });
};

const loadDependency = url => new Promise((resolve, reject) => {
  const scr = document.createElement('script');
  scr.onload = resolve;
  scr.src = url;
  document.body.appendChild(scr);
});

const dependencies = [
  'https://cdnjs.cloudflare.com/ajax/libs/axios/0.15.3/axios.min.js',
  'https://cdnjs.cloudflare.com/ajax/libs/x2js/1.2.0/xml2json.min.js',
];

Promise.all(dependencies.map(loadDependency))
.then(getUserLoc)
.then(getAirportCodes)
.then(console.log);

{'fraction_non_alphanumeric': 0.1788775228089577, 'fraction_numerical': 0.024882499308819462, 'mean_word_length': 4.3759286775631505, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 52, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1040713', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1269, 'n_words': 220}