!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators")):"function"==typeof define&&define.amd?define("angular-2-local-storage",["exports","@angular/core","rxjs","rxjs/operators"],t):t(e["angular-2-local-storage"]={},e.ng.core,e.rxjs,e.rxjs.operators)}(this,function(e,r,a,p){"use strict";var n=new r.InjectionToken("LOCAL_STORAGE_SERVICE_CONFIG"),t=function(){function t(){}return t.forRoot=function(e){return void 0===e&&(e={}),{ngModule:t,providers:[{provide:n,useValue:e}]}},t.decorators=[{type:r.NgModule}],t}(),o="LOCAL_STORAGE_NOT_SUPPORTED",s=function(){function e(e){void 0===e&&(e={});var t=this;this.isSupported=!1,this.notifyOptions={setItem:!1,removeItem:!1},this.prefix="ls",this.storageType="localStorage",this.errors=new a.Subscriber,this.removeItems=new a.Subscriber,this.setItems=new a.Subscriber,this.warnings=new a.Subscriber;var r=e.notifyOptions,n=e.prefix,s=e.storageType;if(null!=r){var i=r.setItem,o=r.removeItem;this.setNotify(!!i,!!o)}null!=n&&this.setPrefix(n),null!=s&&this.setStorageType(s),this.errors$=new a.Observable(function(e){return t.errors=e}).pipe(p.share()),this.removeItems$=new a.Observable(function(e){return t.removeItems=e}).pipe(p.share()),this.setItems$=new a.Observable(function(e){return t.setItems=e}).pipe(p.share()),this.warnings$=new a.Observable(function(e){return t.warnings=e}).pipe(p.share()),this.isSupported=this.checkSupport()}return e.prototype.add=function(e,t){return console&&console.warn&&(console.warn("This function is deprecated."),console.warn("Use `LocalStorageService.set` instead.")),this.set(e,t)},e.prototype.clearAll=function(e){var t=this.prefix?new RegExp("^"+this.prefix):new RegExp(""),r=e?new RegExp(e):new RegExp("");if(!this.isSupported)return this.warnings.next(o),!1;var n=this.prefix.length;for(var s in this.webStorage)if(t.test(s)&&r.test(s.substr(n)))try{this.remove(s.substr(n))}catch(i){return this.errors.next(i.message),!1}return!0},e.prototype.deriveKey=function(e){return""+this.prefix+e},e.prototype.get=function(e){if(!this.isSupported)return this.warnings.next(o),null;var t=this.webStorage?this.webStorage.getItem(this.deriveKey(e)):null;if(!t||"null"===t)return null;try{return JSON.parse(t)}catch(r){return null}},e.prototype.getStorageType=function(){return this.storageType},e.prototype.keys=function(){if(!this.isSupported)return this.warnings.next(o),[];var e=this.prefix.length,t=[];for(var r in this.webStorage)if(r.substr(0,e)===this.prefix)try{t.push(r.substr(e))}catch(n){return this.errors.next(n.message),[]}return t},e.prototype.length=function(){for(var e=0,t=this.webStorage,r=0;r<t.length;r++)0===t.key(r).indexOf(this.prefix)&&(e+=1);return e},e.prototype.remove=function(){for(var r=this,e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=!0;return e.forEach(function(e){r.isSupported||(r.warnings.next(o),n=!1);try{r.webStorage.removeItem(r.deriveKey(e)),r.notifyOptions.removeItem&&r.removeItems.next({key:e,storageType:r.storageType})}catch(t){r.errors.next(t.message),n=!1}}),n},e.prototype.set=function(e,t){if(t=t===undefined?null:JSON.stringify(t),!this.isSupported)return this.warnings.next(o),!1;try{this.webStorage&&this.webStorage.setItem(this.deriveKey(e),t),this.notifyOptions.setItem&&this.setItems.next({key:e,newvalue:t,storageType:this.storageType})}catch(r){return this.errors.next(r.message),!1}return!0},e.prototype.checkSupport=function(){try{var e=this.storageType in window&&null!==window[this.storageType];if(e){this.webStorage=window[this.storageType];var t=this.deriveKey("__"+Math.round(1e7*Math.random()));this.webStorage.setItem(t,""),this.webStorage.removeItem(t)}return e}catch(r){return this.errors.next(r.message),!1}},e.prototype.setPrefix=function(e){this.prefix=e;this.prefix&&!this.prefix.endsWith(".")&&(this.prefix=this.prefix?this.prefix+".":"")},e.prototype.setStorageType=function(e){this.storageType=e},e.prototype.setNotify=function(e,t){null!=e&&(this.notifyOptions.setItem=e),null!=t&&(this.notifyOptions.removeItem=t)},e.decorators=[{type:r.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:undefined,decorators:[{type:r.Optional},{type:r.Inject,args:[n]}]}]},e.ngInjectableDef=r.defineInjectable({factory:function(){return new e(r.inject(n,8))},token:e,providedIn:"root"}),e}();e.LocalStorageModule=t,e.LocalStorageService=s,e.ɵa=n,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=angular-2-local-storage.umd.min.js.map