@ksakira10/ngx-via-cep
Version:
A Angular package for ViaCEP (https://viacep.com.br/)
2 lines • 3.25 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("rxjs"),require("@angular/common/http"),require("@angular/core")):"function"==typeof define&&define.amd?define("@ksakira10/ngx-via-cep",["exports","rxjs","@angular/common/http","@angular/core"],t):t((e.ksakira10=e.ksakira10||{},e.ksakira10["ngx-via-cep"]={}),e.rxjs,e.ng.common.http,e.ng.core)}(this,function(e,o,s,n){"use strict";var t=new n.InjectionToken("basePath"),i=function(){function e(e){void 0===e&&(e={}),this.apiKeys=e.apiKeys,this.username=e.username,this.password=e.password,this.accessToken=e.accessToken,this.basePath=e.basePath,this.withCredentials=e.withCredentials}return e.prototype.selectHeaderContentType=function(e){var t=this;if(0==e.length)return undefined;var n=e.find(function(e){return t.isJsonMime(e)});return n===undefined?e[0]:n},e.prototype.selectHeaderAccept=function(e){var t=this;if(0==e.length)return undefined;var n=e.find(function(e){return t.isJsonMime(e)});return n===undefined?e[0]:n},e.prototype.isJsonMime=function(e){var t=new RegExp("^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$","i");return null!=e&&(t.test(e)||"application/json-patch+json"===e.toLowerCase())},e}(),r=function(){function e(e,t,n){var r=this;this.http=e,this.basePath="https://viacep.com.br/ws",this.defaultHeaders=new s.HttpHeaders,this.configuration=new i,this.urlFetchByCEP=function(e){return r.basePath+"/"+e+"/json/"},this.urlFetchByAddressSP=function(e,t,n){return void 0===t&&(t="SP"),void 0===n&&(n="São Paulo"),r.basePath+"/"+encodeURIComponent(t)+"/"+encodeURIComponent(n)+"/"+encodeURIComponent(e)+"/json/"},this.fetchByCEP=function(e){var t=new o.Subject;return e=e.replace(/[!@#$%^&*a-zA-Z.-]/gi,""),/\d{8}/.test(e)?r.http.get(r.urlFetchByCEP(e)):(t.error(new s.HttpErrorResponse({status:412,statusText:"Precondition failed",error:{code:1,message:"length must be equals 8"}})),t.asObservable())},this.fetchByAddressSaoPaulo=function(e){return r.http.get(r.urlFetchByAddressSP(e))},this.fetchByAddress=function(e,t,n){return r.http.get(r.urlFetchByAddressSP(n,e,t))},t&&(this.basePath=t),n&&(this.configuration=n,this.basePath=t||n.basePath||this.basePath)}return e.decorators=[{type:n.Injectable}],e.ctorParameters=function(){return[{type:s.HttpClient},{type:String,decorators:[{type:n.Optional},{type:n.Inject,args:[t]}]},{type:i,decorators:[{type:n.Optional}]}]},e}(),a=function(){function t(e,t){if(e)throw new Error("NgxViaCepModule is already loaded. Import in your base AppModule only.");if(!t)throw new Error("You need to import the HttpClientModule in your AppModule! \nSee also https://github.com/angular/angular/issues/20575")}return t.forRoot=function(e){return{ngModule:t,providers:[{provide:i,useFactory:e}]}},t.decorators=[{type:n.NgModule,args:[{declarations:[],imports:[],exports:[],providers:[r]}]}],t.ctorParameters=function(){return[{type:t,decorators:[{type:n.Optional},{type:n.SkipSelf}]},{type:s.HttpClient,decorators:[{type:n.Optional}]}]},t}();e.BASE_PATH=t,e.COLLECTION_FORMATS={csv:",",tsv:" ",ssv:" ",pipes:"|"},e.NgxViaCepConfiguration=i,e.NgxViaCepService=r,e.NgxViaCepModule=a,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ksakira10-ngx-via-cep.umd.min.js.map