Skip to content

Commit d6fc234

Browse files
Merge branch 'master' into stats-badge
2 parents 2752f45 + 18842c0 commit d6fc234

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

dist/cep-promise-browser.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var index = typeof fetch == 'function' ? fetch.bind() : function (url, options)
7878
return new Promise(function (resolve, reject) {
7979
var request = new XMLHttpRequest();
8080

81-
request.open(options.method || 'get', url);
81+
request.open(options.method || 'get', url, true);
8282

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

9393
request.onerror = reject;
9494

95-
request.send(options.body);
95+
request.send(options.body || null);
9696

9797
function response() {
9898
var _keys = [],
9999
all = [],
100100
headers = {},
101101
header;
102102

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

110110
return {
111-
ok: (request.status / 200 | 0) == 1, // 200-299
111+
ok: (request.status / 100 | 0) == 2, // 200-299
112112
status: request.status,
113113
statusText: request.statusText,
114114
url: request.responseURL,
@@ -358,15 +358,20 @@ function throwApplicationError$2(error) {
358358
throw serviceError;
359359
}
360360

361+
/* istanbul ignore next */
362+
function isBrowser() {
363+
return typeof window !== 'undefined';
364+
}
365+
361366
/* istanbul ignore next */
362367
function injectProxy(Service) {
363368
return function (cepWithLeftPad) {
364369
return Service(cepWithLeftPad, PROXY_URL);
365370
};
366371
}
367372

368-
var CepAbertoService = typeof process === 'undefined' ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
369-
var CorreiosService = typeof process === 'undefined' ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
373+
var CepAbertoService = isBrowser() ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
374+
var CorreiosService = isBrowser() ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
370375
var ViaCepService = fetchViaCepService;
371376

372377
var reverse = function reverse(promise) {

dist/cep-promise-browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cep-promise.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,20 @@ function throwApplicationError$2(error) {
283283
throw serviceError;
284284
}
285285

286+
/* istanbul ignore next */
287+
function isBrowser() {
288+
return typeof window !== 'undefined';
289+
}
290+
286291
/* istanbul ignore next */
287292
function injectProxy(Service) {
288293
return function (cepWithLeftPad) {
289294
return Service(cepWithLeftPad, PROXY_URL);
290295
};
291296
}
292297

293-
var CepAbertoService = typeof process === 'undefined' ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
294-
var CorreiosService = typeof process === 'undefined' ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
298+
var CepAbertoService = isBrowser() ? injectProxy(fetchCepAbertoService) : fetchCepAbertoService;
299+
var CorreiosService = isBrowser() ? injectProxy(fetchCorreiosService) : fetchCorreiosService;
295300
var ViaCepService = fetchViaCepService;
296301

297302
var reverse = function reverse(promise) {

0 commit comments

Comments
 (0)