Skip to content

Commit af4f973

Browse files
committed
Chore: Change code samples following the Runkit pattern
1 parent 69aa725 commit af4f973

File tree

6 files changed

+44
-43
lines changed

6 files changed

+44
-43
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ Teste e aprenda <a href="https://npm.runkit.com/cep-promise" target="_blank">aqu
4848
Por ser multifornecedor, a biblioteca irá resolver a Promise com o fornecedor que **mais rápido** lhe responder.
4949

5050
``` js
51-
import cep from 'cep-promise'
51+
import cepPromise from 'cep-promise'
5252

53-
cep('05010000')
53+
cepPromise('05010000')
5454
.then(console.log)
5555

5656
// {
@@ -68,10 +68,10 @@ cep('05010000')
6868
Em muitos sistemas o CEP é utilizado erroneamente como um Inteiro (e com isto cortando todos os zeros à esquerda). Caso este seja o seu caso, não há problema, pois a biblioteca irá preencher os caracteres faltantes na String, por exemplo:
6969

7070
``` js
71-
import cep from 'cep-promise'
71+
import cepPromise from 'cep-promise'
7272

7373
// enviando sem ter um zero à esquerda do CEP "05010000"
74-
cep(5010000)
74+
cepPromise(5010000)
7575
.then(console.log)
7676

7777
// {
@@ -88,9 +88,9 @@ cep(5010000)
8888
Neste caso será retornado um `"service_error"` e por ser multifornecedor, a biblioteca irá rejeitar a Promise apenas quando tiver a resposta negativa de todos os fornecedores.
8989

9090
``` js
91-
import cep from 'cep-promise'
91+
import cepPromise from 'cep-promise'
9292

93-
cep('99999999')
93+
cepPromise('99999999')
9494
.catch(console.log)
9595

9696
// {
@@ -116,9 +116,9 @@ cep('99999999')
116116
Neste caso será retornado um `"validation_error"` e a biblioteca irá rejeitar imediatamente a Promise, sem chegar a consultar nenhum fornecedor.
117117

118118
``` js
119-
import cep from 'cep-promise'
119+
import cepPromise from 'cep-promise'
120120

121-
cep('123456789123456789')
121+
cepPromise('123456789123456789')
122122
.catch(console.log)
123123

124124
// {
@@ -157,7 +157,7 @@ $ bower install --save cep-promise
157157
``` ts
158158
import * as cep from 'cep-promise'
159159

160-
cep('05010000')
160+
cepPromise('05010000')
161161
.then(console.log)
162162
```
163163

dist/cep-promise-browser.js

Lines changed: 4 additions & 4 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, true);
81+
request.open(options.method || 'get', url);
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 || null);
95+
request.send(options.body);
9696

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

103-
request.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm, function (m, key, value) {
103+
request.getAllResponseHeaders().replace(/^(.*?):\s*([\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 / 100 | 0) == 2, // 200-299
111+
ok: (request.status / 200 | 0) == 1, // 200-299
112112
status: request.status,
113113
statusText: request.statusText,
114114
url: request.responseURL,

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.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"zipcode",
3535
"zip",
3636
"promise",
37-
"viacep"
37+
"viacep",
38+
"cepPromise"
3839
],
3940
"homepage": "https://github.com/filipedeschamps/cep-promise",
4041
"devDependencies": {

test/e2e/cep-promise.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import chai from 'chai'
44
import chaiAsPromised from 'chai-as-promised'
55
import chaiSubset from 'chai-subset'
66

7-
import cep from '../../src/cep-promise.js'
7+
import cepPromise from '../../src/cep-promise.js'
88
import CepPromiseError from '../../src/errors/cep-promise.js'
99

1010
chai.use(chaiAsPromised)
@@ -15,7 +15,7 @@ let expect = chai.expect
1515
describe('cep-promise (E2E)', () => {
1616
describe('when invoked with a valid "05010000" string', () => {
1717
it('should fulfill with correct address', () => {
18-
return expect(cep('05010000')).to.eventually.deep.equal({
18+
return expect(cepPromise('05010000')).to.eventually.deep.equal({
1919
cep: '05010000',
2020
state: 'SP',
2121
city: 'São Paulo',
@@ -27,7 +27,7 @@ describe('cep-promise (E2E)', () => {
2727

2828
describe('when invoked with a valid 5010000 number', () => {
2929
it('should fulfill with correct address', () => {
30-
return expect(cep(5010000)).to.eventually.deep.equal({
30+
return expect(cepPromise(5010000)).to.eventually.deep.equal({
3131
cep: '05010000',
3232
state: 'SP',
3333
city: 'São Paulo',
@@ -39,7 +39,7 @@ describe('cep-promise (E2E)', () => {
3939

4040
describe('when invoked with an inexistent "99999999" CEP', () => {
4141
it('should reject with "service_error"', () => {
42-
return cep('99999999')
42+
return cepPromise('99999999')
4343
.catch((error) => {
4444
return expect(error)
4545
.to.be.an.instanceOf(CepPromiseError)
@@ -61,7 +61,7 @@ describe('cep-promise (E2E)', () => {
6161

6262
describe('when invoked with an invalid "123456789" CEP', () => {
6363
it('should reject with "validation_error"', () => {
64-
return cep('123456789')
64+
return cepPromise('123456789')
6565
.catch((error) => {
6666
return expect(error)
6767
.to.be.an.instanceOf(CepPromiseError)

0 commit comments

Comments
 (0)