Skip to content

Commit

Permalink
Merge branch 'master' into stats-badge
Browse files Browse the repository at this point in the history
  • Loading branch information
filipedeschamps authored Feb 6, 2019
2 parents 2752f45 + 18842c0 commit d6fc234
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
17 changes: 11 additions & 6 deletions dist/cep-promise-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options)
return new Promise(function (resolve, reject) {
var request = new XMLHttpRequest();

request.open(options.method || 'get', url);
request.open(options.method || 'get', url, true);

for (var i in options.headers) {
request.setRequestHeader(i, options.headers[i]);
Expand All @@ -92,23 +92,23 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options)

request.onerror = reject;

request.send(options.body);
request.send(options.body || null);

function response() {
var _keys = [],
all = [],
headers = {},
header;

request.getAllResponseHeaders().replace(/^(.*?):\s*([\s\S]*?)$/gm, function (m, key, value) {
request.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (m, key, value) {
_keys.push(key = key.toLowerCase());
all.push([key, value]);
header = headers[key];
headers[key] = header ? header + "," + value : value;
});

return {
ok: (request.status / 200 | 0) == 1, // 200-299
ok: (request.status / 100 | 0) == 2, // 200-299
status: request.status,
statusText: request.statusText,
url: request.responseURL,
Expand Down Expand Up @@ -358,15 +358,20 @@ function throwApplicationError$2(error) {
throw serviceError;
}

/* istanbul ignore next */
function isBrowser() {
return typeof window !== 'undefined';
}

/* istanbul ignore next */
function injectProxy(Service) {
return function (cepWithLeftPad) {
return Service(cepWithLeftPad, PROXY_URL);
};
}

var CepAbertoService = typeof process === 'undefined' ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
var CorreiosService = typeof process === 'undefined' ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
var CepAbertoService = isBrowser() ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
var CorreiosService = isBrowser() ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
var ViaCepService = fetchViaCepService;

var reverse = function reverse(promise) {
Expand Down
2 changes: 1 addition & 1 deletion dist/cep-promise-browser.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions dist/cep-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,20 @@ function throwApplicationError$2(error) {
throw serviceError;
}

/* istanbul ignore next */
function isBrowser() {
return typeof window !== 'undefined';
}

/* istanbul ignore next */
function injectProxy(Service) {
return function (cepWithLeftPad) {
return Service(cepWithLeftPad, PROXY_URL);
};
}

var CepAbertoService = typeof process === 'undefined' ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
var CorreiosService = typeof process === 'undefined' ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
var CepAbertoService = isBrowser() ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
var CorreiosService = isBrowser() ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
var ViaCepService = fetchViaCepService;

var reverse = function reverse(promise) {
Expand Down
Loading

0 comments on commit d6fc234

Please sign in to comment.