angular-kladr
Version:
Angular 4+ package for better experience using kladr api service
221 lines (207 loc) • 7.46 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/platform-browser'), require('@angular/common/http'), require('@angular/http'), require('rxjs/operators'), require('@angular/core')) :
typeof define === 'function' && define.amd ? define('angular-kladr', ['exports', '@angular/common', '@angular/platform-browser', '@angular/common/http', '@angular/http', 'rxjs/operators', '@angular/core'], factory) :
(factory((global['angular-kladr'] = {}),global.ng.common,global.ng.platformBrowser,global.ng.common.http,global.ng.http,global.rxjs.operators,global.ng.core));
}(this, (function (exports,common,platformBrowser,http,i1,operators,i0) { 'use strict';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @enum {string} */
var KladrContentType = {
region: 'region',
district: 'district',
city: 'city',
street: 'street',
building: 'building',
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @enum {number} */
var KladrWithParent = {
/**
* Выдача с родительскими объектами
* @type {number}
*/
with: 1,
/**
* Выдача без родительских объектов
* @type {number}
*/
without: 0,
};
KladrWithParent[KladrWithParent.with] = 'with';
KladrWithParent[KladrWithParent.without] = 'without';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @enum {number} */
var KladrCodeType = {
/**
* города
* @type {number}
*/
cities: 1,
/**
* поселки
* @type {number}
*/
townships: 2,
/**
* деревни
* @type {number}
*/
villages: 4,
};
KladrCodeType[KladrCodeType.cities] = 'cities';
KladrCodeType[KladrCodeType.townships] = 'townships';
KladrCodeType[KladrCodeType.villages] = 'villages';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @enum {number} */
var KladrOneString = {
true: 1,
false: 0,
};
KladrOneString[KladrOneString.true] = 'true';
KladrOneString[KladrOneString.false] = 'false';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/** @type {?} */
var KLADR_OPTIONS = new i0.InjectionToken('KLADR_OPTIONS');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var Options = /** @class */ (function () {
function Options() {
this.isSecure = false;
}
return Options;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var KladrService = /** @class */ (function () {
function KladrService(jsonp, options) {
this.jsonp = jsonp;
this.options = options;
this.baseUrl = 'kladr-api.ru/api.php';
this.HTTP = 'http://';
this.HTTPS = 'https://';
this.url = options.isSecure ? this.HTTPS + this.baseUrl : this.HTTP + this.baseUrl;
}
/**
* Makes api request
* @param query of type KladrRequestParams
* @returns Observable<KladrResponse> Observable with received data or error message
*/
/**
* Makes api request
* @param {?} query of type KladrRequestParams
* @return {?} Observable<KladrResponse> Observable with received data or error message
*/
KladrService.prototype.api = /**
* Makes api request
* @param {?} query of type KladrRequestParams
* @return {?} Observable<KladrResponse> Observable with received data or error message
*/
function (query) {
/** @type {?} */
var apiUrl = this.url + '?';
Object.keys(query).forEach(function (key) {
apiUrl += key + "=" + query[key] + "&";
});
apiUrl += 'callback=JSONP_CALLBACK';
return this.jsonp.request(apiUrl).pipe(operators.map(function (response) {
return ( /** @type {?} */(response.json())) || response.json();
}));
};
KladrService.decorators = [
{ type: i0.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
KladrService.ctorParameters = function () {
return [
{ type: i1.Jsonp },
{ type: Options, decorators: [{ type: i0.Inject, args: [KLADR_OPTIONS,] }] }
];
};
/** @nocollapse */ KladrService.ngInjectableDef = i0.defineInjectable({ factory: function KladrService_Factory() { return new KladrService(i0.inject(i1.Jsonp), i0.inject(KLADR_OPTIONS)); }, token: KladrService, providedIn: "root" });
return KladrService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var KladrModule = /** @class */ (function () {
function KladrModule() {
}
/**
* @param {?=} options
* @return {?}
*/
KladrModule.forRoot = /**
* @param {?=} options
* @return {?}
*/
function (options) {
if (options === void 0) {
options = undefined;
}
return {
providers: [
{
provide: KLADR_OPTIONS,
useValue: options
}
],
ngModule: KladrModule
};
};
KladrModule.decorators = [
{ type: i0.NgModule, args: [{
declarations: [],
imports: [
common.CommonModule,
platformBrowser.BrowserModule,
i1.JsonpModule,
http.HttpClientJsonpModule,
http.HttpClientModule
],
providers: [
KladrService
]
},] }
];
return KladrModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
exports.KladrContentType = KladrContentType;
exports.KladrWithParent = KladrWithParent;
exports.KladrCodeType = KladrCodeType;
exports.KladrOneString = KladrOneString;
exports.KladrModule = KladrModule;
exports.KladrService = KladrService;
exports.Options = Options;
exports.KLADR_OPTIONS = KLADR_OPTIONS;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=angular-kladr.umd.js.map