Skip to content

Commit

Permalink
Chore: Change code samples following the Runkit pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
lnfnunes committed Mar 10, 2019
1 parent 69aa725 commit af4f973
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 43 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Teste e aprenda <a href="https://npm.runkit.com/cep-promise" target="_blank">aqu
Por ser multifornecedor, a biblioteca irá resolver a Promise com o fornecedor que **mais rápido** lhe responder.

``` js
import cep from 'cep-promise'
import cepPromise from 'cep-promise'

cep('05010000')
cepPromise('05010000')
.then(console.log)

// {
Expand All @@ -68,10 +68,10 @@ cep('05010000')
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:

``` js
import cep from 'cep-promise'
import cepPromise from 'cep-promise'

// enviando sem ter um zero à esquerda do CEP "05010000"
cep(5010000)
cepPromise(5010000)
.then(console.log)

// {
Expand All @@ -88,9 +88,9 @@ cep(5010000)
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.

``` js
import cep from 'cep-promise'
import cepPromise from 'cep-promise'

cep('99999999')
cepPromise('99999999')
.catch(console.log)

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

``` js
import cep from 'cep-promise'
import cepPromise from 'cep-promise'

cep('123456789123456789')
cepPromise('123456789123456789')
.catch(console.log)

// {
Expand Down Expand Up @@ -157,7 +157,7 @@ $ bower install --save cep-promise
``` ts
import * as cep from 'cep-promise'

cep('05010000')
cepPromise('05010000')
.then(console.log)
```

Expand Down
8 changes: 4 additions & 4 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, true);
request.open(options.method || 'get', url);

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 || null);
request.send(options.body);

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

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"zipcode",
"zip",
"promise",
"viacep"
"viacep",
"cepPromise"
],
"homepage": "https://github.com/filipedeschamps/cep-promise",
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/cep-promise.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import chaiSubset from 'chai-subset'

import cep from '../../src/cep-promise.js'
import cepPromise from '../../src/cep-promise.js'
import CepPromiseError from '../../src/errors/cep-promise.js'

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

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

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

describe('when invoked with an invalid "123456789" CEP', () => {
it('should reject with "validation_error"', () => {
return cep('123456789')
return cepPromise('123456789')
.catch((error) => {
return expect(error)
.to.be.an.instanceOf(CepPromiseError)
Expand Down
Loading

0 comments on commit af4f973

Please sign in to comment.