text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core")):"function"==typeof define&&define.amd?define(["exports","@angular/core"],t):(e=e||self,t(e.ng2Webstorage={},e.ng.core))}(this,function(e,t){"use strict";function r(e){return 0===e.indexOf(d+b)}function n(e,t,r){return void 0===r&&(r=null),function(n,i){o(e,t,n,i,r)}}function o(e,t,r,n,o){var i=e||n;if(Object.defineProperty(r,n,{get:function(){var e=S.genKey(i);return I.retrieve(t,e)},set:function(e){var r=S.genKey(i);this[r]=e,I.store(t,r,e)}}),null===r[n]&&void 0!==o)var a=m.storageInit$.subscribe(function(){r[n]=o,a.unsubscribe()})}function i(e,t){return function(r,n){o(e,c.local,r,n,t)}}function a(e,t){return function(r,n){o(e,c.session,r,n,t)}}function s(e){return new W(e)}var c;!function(e){e[e.local=0]="local",e[e.session=1]="session"}(c||(c={}));var u,f,l,g="ng2-webstorage",p="|",v=!1,y=(u={},u[c.local]="local",u[c.session]="session",u),d=g,b=p,h=v,S=function(){function e(){}return e.isManagedKey=function(e){return 0===e.indexOf(d+b)},e.retrieveKeysFromStorage=function(e){return Object.keys(e).filter(r)},e.genKey=function(e){if("string"!=typeof e)throw Error("attempt to generate a storage key with a non string value");return""+d+b+this.formatKey(e)},e.formatKey=function(e){var t=e.toString();return h?t:t.toLowerCase()},e.setStorageKeyPrefix=function(e){void 0===e&&(e=g),d=e},e.setCaseSensitivity=function(e){void 0===e&&(e=v),h=e},e.setStorageKeySeparator=function(e){void 0===e&&(e=p),b=e},e}(),m=function(){function e(){}return e.observe=function(e,r){var n=this.genObserverKey(e,r);return n in this.observers?this.observers[n]:this.observers[n]=new t.EventEmitter},e.emit=function(e,t,r){var n=this.genObserverKey(e,t);n in this.observers&&this.observers[n].emit(r)},e.genObserverKey=function(e,t){return e+"|"+t},e.initStorage=function(){e.storageInitStream.emit(!0)},e.observers={},e.storageInitStream=new t.EventEmitter,e.storageInit$=e.storageInitStream.asObservable(),e}(),O=function(){function e(){}return e.isSecuredField=function(t){return!!~e.securedFields.indexOf(t)},e.getStorage=function(t){return this.mockStorages[t]||(this.mockStorages[t]=e.generateStorage()),this.mockStorages[t]},e.generateStorage=function(){var t={};return Object.defineProperties(t,{setItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t,r){e.isSecuredField(t)||(this[t]=r)}},getItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t){return e.isSecuredField(t)?null:this[t]||null}},removeItem:{writable:!1,enumerable:!1,configurable:!1,value:function(t){e.isSecuredField(t)||delete this[t]}},length:{enumerable:!1,configurable:!1,get:function(){return Object.keys(this).length}}}),t},e.securedFields=["setItem","getItem","removeItem","length"],e.mockStorages={},e}(),w=(f={},f[c.local]={},f[c.session]={},f),j=(l={},l[c.local]=null,l[c.session]=null,l),I=function(){function e(){}return e.store=function(e,t,r){this.getStorage(e).setItem(t,JSON.stringify(r)),w[e][t]=r,m.emit(e,t,r)},e.retrieve=function(t,r){if(r in w[t])return w[t][r];var n=e.retrieveFromStorage(t,r);return null!==n&&(w[t][r]=n),n},e.retrieveFromStorage=function(e,t){var r=null;try{r=JSON.parse(this.getStorage(e).getItem(t))}catch(e){console.warn("invalid value for "+t)}return r},e.refresh=function(t,r){if(S.isManagedKey(r)){var n=e.retrieveFromStorage(t,r);null===n?(delete w[t][r],m.emit(t,r,null)):n!==w[t][r]&&(w[t][r]=n,m.emit(t,r,n))}},e.refreshAll=function(t){Object.keys(w[t]).forEach(function(r){return e.refresh(t,r)})},e.clearAll=function(e){var t=this.getStorage(e);S.retrieveKeysFromStorage(t).forEach(function(r){t.removeItem(r),delete w[e][r],m.emit(e,r,null)})},e.clear=function(e,t){this.getStorage(e).removeItem(t),delete w[e][t],m.emit(e,t,null)},e.getStorage=function(e){return this.isStorageAvailable(e)?this.getWStorage(e):O.getStorage(e)},e.getWStorage=function(e){var t;switch(e){case c.local:t=localStorage;break;case c.session:t=sessionStorage;break;default:throw Error("invalid storage type")}return t},e.isStorageAvailable=function(e){if("boolean"==typeof j[e])return j[e];var t,r=!0;try{t=this.getWStorage(e),"object"==typeof t?(t.setItem("test-storage","foobar"),t.removeItem("test-storage")):r=!1}catch(e){r=!1}return r||console.warn(y[e]+" storage unavailable, Ng2Webstorage will use a fallback strategy instead"),j[e]=r},e}(),R=function(){function e(e){void 0===e&&(e=null),this.sType=e,this.sType=e}return e.prototype.store=function(e,t){var r=S.genKey(e);I.store(this.sType,r,t)},e.prototype.retrieve=function(e){var t=S.genKey(e);return I.retrieve(this.sType,t)},e.prototype.clear=function(e){e?I.clear(this.sType,S.genKey(e)):I.clearAll(this.sType)},e.prototype.observe=function(e){var t=S.genKey(e);return m.observe(this.sType,t)},e.prototype.isStorageAvailable=function(){return I.isStorageAvailable(this.sType)},e}(),K=function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(t,r)};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),_=function(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a},P=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},k=function(e){function r(){return e.call(this,c.local)||this}return K(r,e),r=_([t.Injectable(),P("design:paramtypes",[])],r)}(R),F=function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(t,r)};return function(t,r){function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),x=function(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a},A=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},E=function(e){function r(){return e.call(this,c.session)||this}return F(r,e),r=x([t.Injectable(),A("design:paramtypes",[])],r)}(R),W=function(){function e(e){this.prefix=g,this.separator=p,this.caseSensitive=v,e&&void 0!==e.prefix&&(this.prefix=e.prefix),e&&void 0!==e.separator&&(this.separator=e.separator),e&&void 0!==e.caseSensitive&&(this.caseSensitive=e.caseSensitive)}return e}(),T=function(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a},N=function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)},C=function(e,t){return function(r,n){t(r,n,e)}},L=new t.InjectionToken("WEBSTORAGE_CONFIG"),M=function(){function e(e,t){this.ngZone=e,t&&(S.setStorageKeyPrefix(t.prefix),S.setStorageKeySeparator(t.separator),S.setCaseSensitivity(t.caseSensitive)),this.initStorageListener(),m.initStorage()}r=e,e.forRoot=function(e){return{ngModule:r,providers:[{provide:L,useValue:e},{provide:W,useFactory:s,deps:[L]}]}},e.prototype.initStorageListener=function(){var e=this;"undefined"!=typeof window&&window.addEventListener("storage",function(t){return e.ngZone.run(function(){var e=window.sessionStorage===t.storageArea?c.session:c.local;null===t.key?I.refreshAll(e):I.refresh(e,t.key)})})};var r;return e=r=T([t.NgModule({declarations:[],providers:[E,k],imports:[]}),C(1,t.Optional()),C(1,t.Inject(W)),N("design:paramtypes",[t.NgZone,W])],e)}();e.WEBSTORAGE_CONFIG=L,e.Ng2Webstorage=M,e.provideConfig=s,e.WebstorageConfig=W,e.LocalStorage=i,e.SessionStorage=a,e.WebStorage=n,e.WebStorageDecorator=o,e.WebStorageService=R,e.LocalStorageService=k,e.SessionStorageService=E,Object.defineProperty(e,"__esModule",{value:!0})});