@martyganz/ngx-cookie
Version:
Implementation of Angular 1.x $cookies service to Angular
17 lines (15 loc) • 5.67 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common"),require("@nguniversal/express-engine/tokens")):"function"==typeof define&&define.amd?define("@martyganz/ngx-cookie",["exports","@angular/core","@angular/common","@nguniversal/express-engine/tokens"],t):t(((e=e||self).martyganz=e.martyganz||{},e.martyganz["ngx-cookie"]={}),e.ng.core,e.ng.common,e.tokens)}(this,(function(e,t,o,n){"use strict";function r(e){return null==e}function i(e){return null!=e}function c(e){return"string"==typeof e}function s(e,t){return t?{path:i(t.path)?t.path:e.path,domain:i(t.domain)?t.domain:e.domain,expires:i(t.expires)?t.expires:e.expires,secure:i(t.secure)?t.secure:e.secure,httpOnly:i(t.httpOnly)?t.httpOnly:e.httpOnly,storeUnencoded:i(t.storeUnencoded)?t.storeUnencoded:e.storeUnencoded}:e}function u(e){try{return decodeURIComponent(e)}catch(t){return e}}function p(e){try{return JSON.parse(e)}catch(t){return e}}var a=new t.InjectionToken("COOKIE_OPTIONS"),d=function(){function e(e,t){void 0===e&&(e={}),this._injector=t,this.defaultOptions={path:this._injector.get(o.APP_BASE_HREF,"/"),domain:null,expires:null,secure:!1,httpOnly:!1},this._options=s(this.defaultOptions,e)}return Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),e}();d.decorators=[{type:t.Injectable}],d.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[a]}]},{type:t.Injector}]};var f=function(){function e(e){this._optionsProvider=e,this.options=this._optionsProvider.options}return Object.defineProperty(e.prototype,"cookieString",{get:function(){return document.cookie||""},set:function(e){document.cookie=e},enumerable:!1,configurable:!0}),e.prototype.get=function(e){return this._cookieReader()[e]},e.prototype.getObject=function(e){var t=this.get(e);return t?p(t):t},e.prototype.getAll=function(){return this._cookieReader()},e.prototype.put=function(e,t,o){this._cookieWriter()(e,t,o)},e.prototype.putObject=function(e,t,o){this.put(e,JSON.stringify(t),o)},e.prototype.remove=function(e,t){this._cookieWriter()(e,void 0,t)},e.prototype.removeAll=function(e){var t=this,o=this.getAll();Object.keys(o).forEach((function(o){t.remove(o,e)}))},e.prototype._cookieReader=function(){var e,t,o,n,i,c={},s="",p=this.cookieString;if(p!==s)for(e=(s=p).split("; "),c={},o=0;o<e.length;o++)(n=(t=e[o]).indexOf("="))>0&&r(c[i=u(t.substring(0,n))])&&(c[i]=u(t.substring(n+1)));return c},e.prototype._cookieWriter=function(){var e=this;return function(t,o,n){e.cookieString=e._buildCookieString(t,o,n)}},e.prototype._buildCookieString=function(e,t,o){var n=s(this.options,o),i=n.expires;r(t)&&(i="Thu, 01 Jan 1970 00:00:00 GMT",t=""),c(i)&&(i=new Date(i));var u=n.storeUnencoded?t:encodeURIComponent(t),p=encodeURIComponent(e)+"="+u;p+=n.path?";path="+n.path:"",p+=n.domain?";domain="+n.domain:"",p+=i?";expires="+i.toUTCString():"",p+=n.secure?";secure":"";var a=(p+=n.httpOnly?"; HttpOnly":"").length+1;return a>4096&&console.log("Cookie '"+e+"' possibly not set or overflowed because it was too large ("+a+" > 4096 bytes)!"),p},e}();f.decorators=[{type:t.Injectable}],f.ctorParameters=function(){return[{type:d}]};
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var l=function(e,t){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(e,t)};Object.create;Object.create;var y=function(e){function t(t,o,n){var r=e.call(this,n)||this;return r.request=t,r.response=o,r}return function(e,t){function o(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}(t,e),Object.defineProperty(t.prototype,"cookieString",{get:function(){return this.request.cookie||""},set:function(e){this.request.cookie=e,this.response.cookie=e},enumerable:!1,configurable:!0}),t}(f);function g(e){return new f(e)}y.decorators=[{type:t.Injectable}],y.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[n.REQUEST]}]},{type:void 0,decorators:[{type:t.Inject,args:[n.RESPONSE]}]},{type:d}]};var h=function(){function e(){}return e.forRoot=function(t){return void 0===t&&(t={}),{ngModule:e,providers:[{provide:a,useValue:t},{provide:f,useFactory:g,deps:[d]}]}},e.forChild=function(t){return void 0===t&&(t={}),{ngModule:e,providers:[{provide:a,useValue:t},{provide:f,useFactory:g,deps:[d]}]}},e}();h.decorators=[{type:t.NgModule,args:[{providers:[d]}]}],e.COOKIE_OPTIONS=a,e.CookieBackendService=y,e.CookieModule=h,e.CookieOptionsProvider=d,e.CookieService=f,e.cookieServiceFactory=g,e.isBlank=r,e.isPresent=i,e.isString=c,e.mergeOptions=s,e.safeDecodeURIComponent=u,e.safeJsonParse=p,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=martyganz-ngx-cookie.umd.min.js.map