File tree Expand file tree Collapse file tree 3 files changed +18
-27
lines changed Expand file tree Collapse file tree 3 files changed +18
-27
lines changed Original file line number Diff line number Diff line change 11'use strict'
22
33import CepPromiseError from './errors/cep-promise.js'
4- import {
5- CorreiosService ,
6- ViaCepService ,
7- WideNetService ,
8- BrasilAPIService
9- } from './services/index.js'
4+ import { getAvailableServices } from './services/index.js'
105import Promise from './utils/promise-any.js'
116
127const CEP_SIZE = 8
@@ -112,12 +107,7 @@ function validateInputLength (cepWithLeftPad) {
112107}
113108
114109function fetchCepFromServices ( cepWithLeftPad , configurations ) {
115- const providersServices = {
116- brasilapi : BrasilAPIService ,
117- viacep : ViaCepService ,
118- widenet : WideNetService ,
119- correios : CorreiosService
120- }
110+ let providersServices = getAvailableServices ( )
121111
122112 if ( configurations . providers . length === 0 ) {
123113 return Promise . any (
Original file line number Diff line number Diff line change @@ -2,19 +2,22 @@ import Correios from './correios'
22import ViaCep from './viacep'
33import WideNet from './widenet'
44import BrasilAPI from './brasilapi.js'
5- import { PROXY_URL } from '../utils/consts'
65
7- /* istanbul ignore next */
8- function isBrowser ( ) {
9- return typeof window !== 'undefined'
10- }
6+ export function getAvailableServices ( ) {
7+ const isBrowser = typeof window !== 'undefined'
118
12- /* istanbul ignore next */
13- function injectProxy ( Service ) {
14- return cepWithLeftPad => Service ( cepWithLeftPad , PROXY_URL )
15- }
9+ if ( isBrowser ) {
10+ return {
11+ brasilapi : BrasilAPI ,
12+ viacep : ViaCep ,
13+ widenet : WideNet ,
14+ }
15+ }
1616
17- export const CorreiosService = isBrowser ( ) ? injectProxy ( Correios ) : Correios
18- export const ViaCepService = ViaCep
19- export const WideNetService = WideNet
20- export const BrasilAPIService = BrasilAPI
17+ return {
18+ brasilapi : BrasilAPI ,
19+ viacep : ViaCep ,
20+ widenet : WideNet ,
21+ correios : Correios
22+ }
23+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments