UNPKG

@tubular/astronomy

Version:

Astronomical calculations for planetary positions, moon phases, eclipses, rise, transit, and set times, and more.

47 lines 1.58 kB
// makeRequest function derived from https://stackoverflow.com/questions/30008114/how-do-i-promisify-native-xhr function makeRequest(url, responseType) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open('GET', url); xhr.responseType = responseType; xhr.onload = function () { if (this.status >= 200 && this.status < 300) { resolve(xhr.response); } else { // eslint-disable-next-line prefer-promise-reject-errors reject({ status: this.status, statusText: xhr.statusText }); } }; xhr.onerror = function () { // eslint-disable-next-line prefer-promise-reject-errors reject({ status: this.status, statusText: xhr.statusText }); }; xhr.send(); }); } export class SimpleAstroDataService { // eslint-disable-next-line no-useless-constructor constructor(baseUrl) { this.baseUrl = baseUrl; } getStars() { return makeRequest(this.baseUrl + 'stars.dat', 'arraybuffer'); } getGrsData() { return makeRequest(this.baseUrl + 'grs_longitude.txt', 'arraybuffer'); } getAsteroidData() { return makeRequest(this.baseUrl + 'asteroids.json', 'json'); } getCometData() { return makeRequest(this.baseUrl + 'comets.json', 'json'); } } //# sourceMappingURL=simple-astro-data.service.js.map