!function(r,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Fahrplan=t():r.Fahrplan=t()}(this,function(){return function(r){function t(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=r,t.c=e,t.p="",t(0)}([function(r,t,e){!function(t,e){r.exports=e()}(this,function(){return function(r){function t(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=r,t.c=e,t.p="",t(0)}([function(r,t,e){!function(t,e){r.exports=e()}(this,function(){return function(r){function t(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=r,t.c=e,t.p="",t(0)}([function(r,t,e){!function(t,e){r.exports=e()}(this,function(){return function(r){function t(n){if(e[n])return e[n].exports;var o=e[n]={exports:{},id:n,loaded:!1};return r[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var e={};return t.m=r,t.c=e,t.p="",t(0)}([function(r,t,e){"use strict";function n(r){function t(t){return a(s+"/location.name?"+o.stringify({authKey:r,input:t,format:"json"})).then(function(r){return r.api=f,r}).then(i.station)}function e(r){return t(r).then(function(r){return r.stations.length?r.stations[0]:null})}function n(t,n,c){var d;if("departures"===t)d="/departureBoard";else{if("arrivals"!==t)throw new Error('Type must be either "departures" or "arrivals"');d="/arrivalBoard"}c||(c=Date.now());var l;return l=n.id&&u.test(n.id)?n:u.test(n)?{id:n}:"function"==typeof n.then?n:e(n.name?n.name:""+n),Promise.resolve(l).then(function(t){return a(s+d+"?"+o.stringify({authKey:r,id:t.id,date:p.formatDate(c),time:p.formatTime(c),format:"json"}))}).then(function(r){return r.api=f,r}).then(i.stationBoard)}function c(r){return a(r).then(function(r){return r.api=f,r}).then(i.itinerary)}if(!r)throw new Error("No API key provided");var f={station:{find:t,get:e},departure:{find:function(r,t){return n("departures",r,t)}},arrival:{find:function(r,t){return n("arrivals",r,t)}},itinerary:{get:c}};return f}var o=e(1),a=e(2),i=e(4),p=e(5),s="http://open-api.bahn.de/bin/rest.exe",u=/^\d{9}$/;r.exports=n},function(r,t){"use strict";r.exports={stringify:function(r,t,e){function n(r,t){return encodeURIComponent(r)+e+encodeURIComponent(t)}t||(t="&"),e||(e="=");var o=[],a=Object.keys(r);return a.forEach(function(t){var e=r[t];Array.isArray(e)?e.forEach(function(r){o.push(n(t,r))}):o.push(n(t,e))}),o.join(t)}}},function(r,t,e){"use strict";r.exports=e(3)},function(r,t){"use strict";r.exports=function(r){return new Promise(function(t,e){var n=new XMLHttpRequest,o=r.split(":").shift().toLowerCase();if("https"!==o&&"http"!==o)throw new Error("Unsupported protocol ("+o+")");n.open("GET",r,!0),n.onload=function(){t({data:n.responseText})},n.onerror=e,n.send()})}},function(r,t,e){"use strict";function n(r,t){var e={};return e.name=r.name,e.latitude=parseFloat(r.lat),e.longitude=parseFloat(r.lon),r.id&&(e.id=r.id),r.type&&(e.type=r.type),t&&"number"!=typeof t&&(e.departure={find:function(r){return t.departure.find(e.id,r)}},e.arrival={find:function(r){return t.arrival.find(e.id,r)}}),e}function o(r,t){var e={};return e.name=r.name,e.type=r.type,e.station={name:r.stop,id:r.stopid},t===p&&(e.arrival=i.parse(r.date,r.time)),t===s&&(e.departure=i.parse(r.date,r.time)),r.origin&&(e.origin=r.origin),r.direction&&(e.destination=r.direction),e.platform=r.track,e}function a(r){var t={};return Object.keys(r).forEach(function(e){if(r.hasOwnProperty(e)){var n=r[e];"routeIdxFrom"===e?t.fromIndex=parseInt(n,10):"routeIdxTo"===e?t.toIndex=parseInt(n,10):"priority"===e?t.priority=parseInt(n,10):"$"===e?t.description=n:t[e]=n}}),t}var i=e(5),p="ARRIVAL",s="DEPARTURE";r.exports={station:function(r){if(!r.hasOwnProperty("data"))throw new Error("Expected a response object with a data property");var t=JSON.parse(r.data),e=t.LocationList.StopLocation||[],o=t.LocationList.CoordLocation||[];e.hasOwnProperty("length")||(e=[e]),o.hasOwnProperty("length")||(o=[o]);var a={stations:e.map(function(t){return n(t,r.api)}),places:o.map(n)};return a},stationBoard:function(r){if(!r.hasOwnProperty("data"))throw new Error("Expected a response object with a data property");var t,e,n,a=JSON.parse(r.data);if(a.ArrivalBoard)t=a.ArrivalBoard.Arrival,e=p;else if(a.DepartureBoard)t=a.DepartureBoard.Departure,e=s;else{if(!a.Error)throw new Error("Expected an ArrivalBoard or DepartureBoard, got "+a);n=new Error("API Error ("+a.Error.code+")"),n.code=a.Error.code,n.data=a.Error}return t||(t=[]),t.hasOwnProperty("length")||(t=[t]),t.map(function(t){var n=o(t,e);return r.api&&t.JourneyDetailRef&&(n.itinerary={get:function(){return r.api.itinerary.get(t.JourneyDetailRef.ref)}}),n})},itinerary:function(r){if(!r.hasOwnProperty("data"))throw new Error("Expected a response object with a data property");var t,e,o,p,s,u=JSON.parse(r.data);try{t=u.JourneyDetail.Stops.Stop}catch(c){t=[]}try{e=u.JourneyDetail.Names.Name}catch(c){e=[]}try{o=u.JourneyDetail.Types.Type}catch(c){o=[]}try{p=u.JourneyDetail.Operators.Operator}catch(c){p=[]}try{s=u.JourneyDetail.Notes.Note}catch(c){s=[]}return t.hasOwnProperty("length")||(t=[t]),e.hasOwnProperty("length")||(e=[e]),o.hasOwnProperty("length")||(o=[o]),p.hasOwnProperty("length")||(p=[p]),s.hasOwnProperty("length")||(s=[s]),t=t.map(function(t){var e={station:n(t,r.api),index:parseInt(t.routeIdx),platform:t.track};return t.depTime&&(e.departure=i.parse(t.depDate,t.depTime)),t.arrTime&&(e.arrival=i.parse(t.arrDate,t.arrTime)),e}),{stops:t,names:e.map(a),types:o.map(a),operators:p.map(a),notes:s.map(a)}}}},function(r,t){"use strict";function e(r,t){for(void 0===t&&(t=2),r=""+r;r.length