UNPKG

ip-api-fetch-info

Version:
47 lines (37 loc) 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.asXml = exports.asJson = exports.asCsv = exports.FAIL = exports.SUCCESS = void 0; var BASE_URL = 'http://ip-api.com'; var fetch = window.fetch; var baseFetch = function baseFetch(type) { return function (url) { return fetch("".concat(BASE_URL, "/").concat(type, "/").concat(url)); }; }; var csvFetch = baseFetch('csv'); var jsonFetch = baseFetch('json'); var xmlFetch = baseFetch('xml'); var SUCCESS = 'success'; exports.SUCCESS = SUCCESS; var FAIL = 'fail'; exports.FAIL = FAIL; var asCsv = function asCsv(ip) { return csvFetch(ip).then(function (response) { return response.text(); }); }; exports.asCsv = asCsv; var asJson = function asJson(ip) { return jsonFetch(ip).then(function (response) { return response.json(); }); }; exports.asJson = asJson; var asXml = function asXml(ip) { return xmlFetch(ip).then(function (response) { return response.text(); }); }; exports.asXml = asXml;