Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ngx-cookie-service

Package Overview
Dependencies
Maintainers
1
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngx-cookie-service - npm Package Compare versions

Comparing version 2.4.0 to 3.0.0

esm2015/lib/cookie.service.js

497

bundles/ngx-cookie-service.umd.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define(['exports', '@angular/core', '@angular/common'], factory) :
(factory((global['ngx-cookie-service'] = {}),global.ng.core,global.ng.common));
}(this, (function (exports,core,common) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('ngx-cookie-service', ['exports', '@angular/core', '@angular/common'], factory) :
(global = global || self, factory(global['ngx-cookie-service'] = {}, global.ng.core, global.ng.common));
}(this, (function (exports, core, common) { 'use strict';
// This service is based on the `ng2-cookies` package which sadly is not a service and does
// not use `DOCUMENT` injection and therefore doesn't work well with AoT production builds.
// Package: https://github.com/BCJTI/ng2-cookies
var CookieService = (function () {
/**
* @param {?} document
* @param {?} platformId
*/
function CookieService(document, platformId) {
this.document = document;
this.platformId = platformId;
this.documentIsAccessible = common.isPlatformBrowser(this.platformId);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
/**
* @param {?} name Cookie name
* @return {?}
*/
CookieService.prototype.check = function (name) {
if (!this.documentIsAccessible) {
return false;
}
name = encodeURIComponent(name);
var /** @type {?} */ regExp = this.getCookieRegExp(name);
var /** @type {?} */ exists = regExp.test(this.document.cookie);
return exists;
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
/**
* @param {?} name Cookie name
* @return {?}
*/
CookieService.prototype.get = function (name) {
if (this.documentIsAccessible && this.check(name)) {
name = encodeURIComponent(name);
var /** @type {?} */ regExp = this.getCookieRegExp(name);
var /** @type {?} */ result = regExp.exec(this.document.cookie);
return decodeURIComponent(result[1]);
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
else {
return '';
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
};
/**
* @return {?}
*/
CookieService.prototype.getAll = function () {
if (!this.documentIsAccessible) {
return {};
}
var /** @type {?} */ cookies = {};
var /** @type {?} */ document = this.document;
if (document.cookie && document.cookie !== '') {
var /** @type {?} */ split = document.cookie.split(';');
for (var /** @type {?} */ i = 0; i < split.length; i += 1) {
var /** @type {?} */ currentCookie = split[i].split('=');
currentCookie[0] = currentCookie[0].replace(/^ /, '');
cookies[decodeURIComponent(currentCookie[0])] = decodeURIComponent(currentCookie[1]);
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return cookies;
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
/**
* @param {?} name Cookie name
* @param {?} value Cookie value
* @param {?=} expires Number of days until the cookies expires or an actual `Date`
* @param {?=} path Cookie path
* @param {?=} domain Cookie domain
* @param {?=} secure Secure flag
* @param {?=} sameSite OWASP samesite token `Lax`, `None`, or `Strict`. Defaults to `None`
* @return {?}
*/
CookieService.prototype.set = function (name, value, expires, path, domain, secure, sameSite) {
if (sameSite === void 0) { sameSite = 'None'; }
if (!this.documentIsAccessible) {
return;
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
var /** @type {?} */ cookieString = encodeURIComponent(name) + '=' + encodeURIComponent(value) + ';';
if (expires) {
if (typeof expires === 'number') {
var /** @type {?} */ dateExpires = new Date(new Date().getTime() + expires * 1000 * 60 * 60 * 24);
cookieString += 'expires=' + dateExpires.toUTCString() + ';';
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
var CookieService = /** @class */ (function () {
function CookieService(
// The type `Document` may not be used here. Although a fix is on its way,
// we will go with `any` for now to support Angular 2.4.x projects.
// Issue: https://github.com/angular/angular/issues/12631
// Fix: https://github.com/angular/angular/pull/14894
document,
// Get the `PLATFORM_ID` so we can check if we're in a browser.
platformId) {
this.document = document;
this.platformId = platformId;
this.documentIsAccessible = common.isPlatformBrowser(this.platformId);
}
/**
* @param name Cookie name
* @returns boolean - whether cookie with specified name exists
*/
CookieService.prototype.check = function (name) {
if (!this.documentIsAccessible) {
return false;
}
name = encodeURIComponent(name);
var regExp = this.getCookieRegExp(name);
var exists = regExp.test(this.document.cookie);
return exists;
};
/**
* @param name Cookie name
* @returns property value
*/
CookieService.prototype.get = function (name) {
if (this.documentIsAccessible && this.check(name)) {
name = encodeURIComponent(name);
var regExp = this.getCookieRegExp(name);
var result = regExp.exec(this.document.cookie);
try {
return decodeURIComponent(result[1]);
}
catch (error) {
// the cookie probably is not uri encoded. return as is
return result[1];
}
}
else {
cookieString += 'expires=' + expires.toUTCString() + ';';
return '';
}
}
if (path) {
cookieString += 'path=' + path + ';';
}
if (domain) {
cookieString += 'domain=' + domain + ';';
}
if (secure) {
cookieString += 'secure;';
}
cookieString += 'sameSite=' + sameSite + ';';
this.document.cookie = cookieString;
};
/**
* @param {?} name Cookie name
* @param {?=} path Cookie path
* @param {?=} domain Cookie domain
* @return {?}
*/
CookieService.prototype.delete = function (name, path, domain) {
if (!this.documentIsAccessible) {
return;
}
this.set(name, '', new Date('Thu, 01 Jan 1970 00:00:01 GMT'), path, domain, undefined, 'Lax');
};
/**
* @param {?=} path Cookie path
* @param {?=} domain Cookie domain
* @return {?}
*/
CookieService.prototype.deleteAll = function (path, domain) {
if (!this.documentIsAccessible) {
return;
}
var /** @type {?} */ cookies = this.getAll();
for (var /** @type {?} */ cookieName in cookies) {
if (cookies.hasOwnProperty(cookieName)) {
this.delete(cookieName, path, domain);
};
/**
* @returns all the cookies in json
*/
CookieService.prototype.getAll = function () {
if (!this.documentIsAccessible) {
return {};
}
}
};
/**
* @param {?} name Cookie name
* @return {?}
*/
CookieService.prototype.getCookieRegExp = function (name) {
var /** @type {?} */ escapedName = name.replace(/([\[\]\{\}\(\)\|\=\;\+\?\,\.\*\^\$])/ig, '\\$1');
return new RegExp('(?:^' + escapedName + '|;\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');
};
return CookieService;
}());
CookieService.decorators = [
{ type: core.Injectable },
];
/**
* @nocollapse
*/
CookieService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] },] },
{ type: core.InjectionToken, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] },] },
]; };
var cookies = {};
var document = this.document;
if (document.cookie && document.cookie !== '') {
document.cookie.split(';').forEach(function (currentCookie) {
var _a = __read(currentCookie.split('='), 2), cookieName = _a[0], cookieValue = _a[1];
cookies[decodeURIComponent(cookieName.replace(/^ /, ''))] = decodeURIComponent(cookieValue);
});
}
return cookies;
};
/**
* @param name Cookie name
* @param value Cookie value
* @param expires Number of days until the cookies expires or an actual `Date`
* @param path Cookie path
* @param domain Cookie domain
* @param secure Secure flag
* @param sameSite OWASP samesite token `Lax`, `None`, or `Strict`. Defaults to `None`
*/
CookieService.prototype.set = function (name, value, expires, path, domain, secure, sameSite) {
if (sameSite === void 0) { sameSite = 'None'; }
if (!this.documentIsAccessible) {
return;
}
var cookieString = encodeURIComponent(name) + '=' + encodeURIComponent(value) + ';';
if (expires) {
if (typeof expires === 'number') {
var dateExpires = new Date(new Date().getTime() + expires * 1000 * 60 * 60 * 24);
cookieString += 'expires=' + dateExpires.toUTCString() + ';';
}
else {
cookieString += 'expires=' + expires.toUTCString() + ';';
}
}
if (path) {
cookieString += 'path=' + path + ';';
}
if (domain) {
cookieString += 'domain=' + domain + ';';
}
if (secure) {
cookieString += 'secure;';
}
cookieString += 'sameSite=' + sameSite + ';';
this.document.cookie = cookieString;
};
/**
* @param name Cookie name
* @param path Cookie path
* @param domain Cookie domain
*/
CookieService.prototype.delete = function (name, path, domain, secure, sameSite) {
if (sameSite === void 0) { sameSite = 'None'; }
if (!this.documentIsAccessible) {
return;
}
this.set(name, '', new Date('Thu, 01 Jan 1970 00:00:01 GMT'), path, domain, secure, sameSite);
};
/**
* @param path Cookie path
* @param domain Cookie domain
*/
CookieService.prototype.deleteAll = function (path, domain, secure, sameSite) {
if (sameSite === void 0) { sameSite = 'None'; }
if (!this.documentIsAccessible) {
return;
}
var cookies = this.getAll();
for (var cookieName in cookies) {
if (cookies.hasOwnProperty(cookieName)) {
this.delete(cookieName, path, domain, secure, sameSite);
}
}
};
/**
* @param name Cookie name
* @returns property RegExp
*/
CookieService.prototype.getCookieRegExp = function (name) {
var escapedName = name.replace(/([\[\]\{\}\(\)\|\=\;\+\?\,\.\*\^\$])/ig, '\\$1');
return new RegExp('(?:^' + escapedName + '|;\\s*' + escapedName + ')=(.*?)(?:;|$)', 'g');
};
CookieService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] },
{ type: core.InjectionToken, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] }
]; };
CookieService.ɵprov = core["ɵɵdefineInjectable"]({ factory: function CookieService_Factory() { return new CookieService(core["ɵɵinject"](common.DOCUMENT), core["ɵɵinject"](core.PLATFORM_ID)); }, token: CookieService, providedIn: "root" });
CookieService = __decorate([
core.Injectable({
providedIn: 'root'
}),
__param(0, core.Inject(common.DOCUMENT)),
__param(1, core.Inject(core.PLATFORM_ID))
], CookieService);
return CookieService;
}());
exports.CookieService = CookieService;
exports.CookieService = CookieService;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngx-cookie-service.umd.js.map

@@ -1,2 +0,16 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define(["exports","@angular/core","@angular/common"],t):t(e["ngx-cookie-service"]={},e.ng.core,e.ng.common)}(this,function(e,t,o){"use strict";var n=function(){function e(e,t){this.document=e,this.platformId=t,this.documentIsAccessible=o.isPlatformBrowser(this.platformId)}return e.prototype.check=function(e){return!!this.documentIsAccessible&&(e=encodeURIComponent(e),this.getCookieRegExp(e).test(this.document.cookie))},e.prototype.get=function(e){if(this.documentIsAccessible&&this.check(e)){e=encodeURIComponent(e);var t=this.getCookieRegExp(e).exec(this.document.cookie);return decodeURIComponent(t[1])}return""},e.prototype.getAll=function(){if(!this.documentIsAccessible)return{};var e={},t=this.document;if(t.cookie&&""!==t.cookie)for(var o=t.cookie.split(";"),n=0;n<o.length;n+=1){var i=o[n].split("=");i[0]=i[0].replace(/^ /,""),e[decodeURIComponent(i[0])]=decodeURIComponent(i[1])}return e},e.prototype.set=function(e,t,o,n,i,c,r){if(void 0===r&&(r="None"),this.documentIsAccessible){var s=encodeURIComponent(e)+"="+encodeURIComponent(t)+";";if(o)if("number"==typeof o)s+="expires="+new Date((new Date).getTime()+1e3*o*60*60*24).toUTCString()+";";else s+="expires="+o.toUTCString()+";";n&&(s+="path="+n+";"),i&&(s+="domain="+i+";"),c&&(s+="secure;"),s+="sameSite="+r+";",this.document.cookie=s}},e.prototype["delete"]=function(e,t,o){this.documentIsAccessible&&this.set(e,"",new Date("Thu, 01 Jan 1970 00:00:01 GMT"),t,o,undefined,"Lax")},e.prototype.deleteAll=function(e,t){if(this.documentIsAccessible){var o=this.getAll();for(var n in o)o.hasOwnProperty(n)&&this["delete"](n,e,t)}},e.prototype.getCookieRegExp=function(e){var t=e.replace(/([\[\]\{\}\(\)\|\=\;\+\?\,\.\*\^\$])/gi,"\\$1");return new RegExp("(?:^"+t+"|;\\s*"+t+")=(.*?)(?:;|$)","g")},e}();n.decorators=[{type:t.Injectable}],n.ctorParameters=function(){return[{type:undefined,decorators:[{type:t.Inject,args:[o.DOCUMENT]}]},{type:t.InjectionToken,decorators:[{type:t.Inject,args:[t.PLATFORM_ID]}]}]},e.CookieService=n,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-cookie-service.umd.min.js.map
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-cookie-service",["exports","@angular/core","@angular/common"],t):t((e=e||self)["ngx-cookie-service"]={},e.ng.core,e.ng.common)}(this,(function(e,t,o){"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */function n(e,t){return function(o,n){t(o,n,e)}}function r(e,t){var o="function"==typeof Symbol&&e[Symbol.iterator];if(!o)return e;var n,r,c=o.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(n=c.next()).done;)i.push(n.value)}catch(e){r={error:e}}finally{try{n&&!n.done&&(o=c.return)&&o.call(c)}finally{if(r)throw r.error}}return i}var c=function(){function e(e,t){this.document=e,this.platformId=t,this.documentIsAccessible=o.isPlatformBrowser(this.platformId)}return e.prototype.check=function(e){return!!this.documentIsAccessible&&(e=encodeURIComponent(e),this.getCookieRegExp(e).test(this.document.cookie))},e.prototype.get=function(e){if(!this.documentIsAccessible||!this.check(e))return"";e=encodeURIComponent(e);var t=this.getCookieRegExp(e).exec(this.document.cookie);try{return decodeURIComponent(t[1])}catch(e){return t[1]}},e.prototype.getAll=function(){if(!this.documentIsAccessible)return{};var e={},t=this.document;return t.cookie&&""!==t.cookie&&t.cookie.split(";").forEach((function(t){var o=r(t.split("="),2),n=o[0],c=o[1];e[decodeURIComponent(n.replace(/^ /,""))]=decodeURIComponent(c)})),e},e.prototype.set=function(e,t,o,n,r,c,i){if(void 0===i&&(i="None"),this.documentIsAccessible){var s=encodeURIComponent(e)+"="+encodeURIComponent(t)+";";if(o)if("number"==typeof o)s+="expires="+new Date((new Date).getTime()+1e3*o*60*60*24).toUTCString()+";";else s+="expires="+o.toUTCString()+";";n&&(s+="path="+n+";"),r&&(s+="domain="+r+";"),c&&(s+="secure;"),s+="sameSite="+i+";",this.document.cookie=s}},e.prototype.delete=function(e,t,o,n,r){void 0===r&&(r="None"),this.documentIsAccessible&&this.set(e,"",new Date("Thu, 01 Jan 1970 00:00:01 GMT"),t,o,n,r)},e.prototype.deleteAll=function(e,t,o,n){if(void 0===n&&(n="None"),this.documentIsAccessible){var r=this.getAll();for(var c in r)r.hasOwnProperty(c)&&this.delete(c,e,t,o,n)}},e.prototype.getCookieRegExp=function(e){var t=e.replace(/([\[\]\{\}\(\)\|\=\;\+\?\,\.\*\^\$])/gi,"\\$1");return new RegExp("(?:^"+t+"|;\\s*"+t+")=(.*?)(?:;|$)","g")},e.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[o.DOCUMENT]}]},{type:t.InjectionToken,decorators:[{type:t.Inject,args:[t.PLATFORM_ID]}]}]},e.ɵprov=t["ɵɵdefineInjectable"]({factory:function(){return new e(t["ɵɵinject"](o.DOCUMENT),t["ɵɵinject"](t.PLATFORM_ID))},token:e,providedIn:"root"}),e=function(e,t,o,n){var r,c=arguments.length,i=c<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,o,n);else for(var s=e.length-1;s>=0;s--)(r=e[s])&&(i=(c<3?r(i):c>3?r(t,o,i):r(t,o))||i);return c>3&&i&&Object.defineProperty(t,o,i),i}([t.Injectable({providedIn:"root"}),n(0,t.Inject(o.DOCUMENT)),n(1,t.Inject(t.PLATFORM_ID))],e)}();e.CookieService=c,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=ngx-cookie-service.umd.min.js.map
/**
* Generated bundle index. Do not edit.
*/
export * from './index';
export * from './public-api';

@@ -1,1 +0,1 @@

{"__symbolic":"module","version":3,"metadata":{"CookieService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable"}}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject"},"arguments":[{"__symbolic":"reference","module":"@angular/common","name":"DOCUMENT"}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject"},"arguments":[{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID"}]}]],"parameters":[{"__symbolic":"reference","name":"any"},{"__symbolic":"reference","name":"InjectionToken","module":"@angular/core","arguments":[{"__symbolic":"reference","name":"Object"}]}]}],"check":[{"__symbolic":"method"}],"get":[{"__symbolic":"method"}],"getAll":[{"__symbolic":"method"}],"set":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"deleteAll":[{"__symbolic":"method"}],"getCookieRegExp":[{"__symbolic":"method"}]}}},"origins":{"CookieService":"./cookie-service/cookie.service"},"importAs":"ngx-cookie-service"}
{"__symbolic":"module","version":4,"metadata":{"CookieService":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Injectable","line":7,"character":1},"arguments":[{"providedIn":"root"}]}],"members":{"__ctor__":[{"__symbolic":"constructor","parameterDecorators":[[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":18,"character":5},"arguments":[{"__symbolic":"reference","module":"@angular/common","name":"DOCUMENT","line":18,"character":13}]}],[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Inject","line":20,"character":5},"arguments":[{"__symbolic":"reference","module":"@angular/core","name":"PLATFORM_ID","line":20,"character":13}]}]],"parameters":[{"__symbolic":"reference","name":"any"},{"__symbolic":"reference","name":"InjectionToken","module":"@angular/core","arguments":[{"__symbolic":"error","message":"Expression form not supported","line":20,"character":62,"module":"./lib/cookie.service"}]}]}],"check":[{"__symbolic":"method"}],"get":[{"__symbolic":"method"}],"getAll":[{"__symbolic":"method"}],"set":[{"__symbolic":"method"}],"delete":[{"__symbolic":"method"}],"deleteAll":[{"__symbolic":"method"}],"getCookieRegExp":[{"__symbolic":"method"}]},"statics":{"ɵprov":{}}}},"origins":{"CookieService":"./lib/cookie.service"},"importAs":"ngx-cookie-service"}

@@ -1,1 +0,86 @@

{"name":"ngx-cookie-service","description":"an (aot ready) angular (4.2+) cookie service","version":"2.4.0","license":"MIT","author":"7leads GmbH <info@7leads.org>","keywords":["angular","angular2","angular4","angular5","angular-2","angular-4","angular-5","angular-6","angular-7","angular-8","aot","aot-compatible","aot-compilation","ngx","ng2","ng","service","angular-service","cookie-service","cookie","cookies"],"contributors":[{"name":"Stepan Suvorov","email":"stepan@studytube.nl"},{"name":"Christopher Parotat","email":"c.parotat@7leads.org"},{"name":"Stefan Bauer","email":"bauer.stefan@live.de"},{"name":"Kristian Thy","email":"thy@42.dk"},{"name":"Jared Clemence"},{"name":"flakolefluk"},{"name":"mattbanks"},{"name":"DBaker85"},{"name":"Matt Lewis","email":"npm@mattlewis.me"},{"name":"IceBreakerG"}],"scripts":{"ng":"ng","start":"npm run compile && ng serve","build":"npm run compile && ng build","test":"npm run compile && ng test","lint":"npm run compile && ng lint","e2e":"npm run compile && ng e2e","compile":"ng-packagr -p ng-package.json","publish:dist":"npm run compile && npm publish dist-lib"},"repository":{"type":"git","url":"https://github.com/stevermeister/ngx-cookie-service.git"},"bugs":{"url":"https://github.com/stevermeister/ngx-cookie-service/issues","email":"stepan@studytube.nl"},"peerDependencies":{"@angular/core":">=4.2.0","@angular/platform-browser":">=4.2.0","@angular/platform-browser-dynamic":">=4.2.0"},"devDependencies":{"@angular/cli":"1.0.0","@angular/common":"^4.0.0","@angular/compiler":"^4.0.0","@angular/compiler-cli":"^4.0.0","@angular/core":"^4.0.0","@angular/forms":"^4.0.0","@angular/http":"^4.0.0","@angular/platform-browser":"^4.0.0","@angular/platform-browser-dynamic":"^4.0.0","@angular/platform-server":"^4.0.0","@angular/router":"^4.0.0","@types/jasmine":"2.5.38","@types/node":"~6.0.60","async":"^2.3.0","codelyzer":"~2.0.0","core-js":"^2.4.1","jasmine-core":"~2.5.2","jasmine-spec-reporter":"~3.2.0","karma":"~1.4.1","karma-chrome-launcher":"~2.0.0","karma-cli":"~1.0.1","karma-coverage-istanbul-reporter":"^0.2.0","karma-jasmine":"~1.1.0","karma-jasmine-html-reporter":"^0.2.2","ng-packagr":"^1.7.0","protractor":"~5.1.0","rimraf":"^2.6.1","rxjs":"^5.1.0","ts-node":"~2.0.0","tslint":"~4.5.0","typescript":"~2.2.0","zone.js":"^0.8.4"},"main":"bundles/ngx-cookie-service.umd.js","module":"ngx-cookie-service.es5.js","es2015":"ngx-cookie-service.js","typings":"ngx-cookie-service.d.ts","metadata":"ngx-cookie-service.metadata.json"}
{
"name": "ngx-cookie-service",
"description": "an (aot ready) angular (4.2+) cookie service",
"version": "3.0.0",
"license": "MIT",
"author": "Stepan Suvorov <stevermeister@gmail.com>",
"keywords": [
"angular",
"angular2",
"angular4",
"angular5",
"angular-2",
"angular-4",
"angular-5",
"angular-6",
"angular-7",
"angular-8",
"aot",
"aot-compatible",
"aot-compilation",
"ngx",
"ng2",
"ng",
"service",
"angular-service",
"cookie-service",
"cookie",
"cookies"
],
"contributors": [
{
"name": "Christopher Parotat",
"email": "c.parotat@7leads.org"
},
{
"name": "Stefan Bauer",
"email": "bauer.stefan@live.de"
},
{
"name": "Kristian Thy",
"email": "thy@42.dk"
},
{
"name": "Jared Clemence"
},
{
"name": "flakolefluk"
},
{
"name": "mattbanks"
},
{
"name": "DBaker85"
},
{
"name": "Matt Lewis",
"email": "npm@mattlewis.me"
},
{
"name": "IceBreakerG"
}
],
"repository": {
"type": "git",
"url": "https://github.com/stevermeister/ngx-cookie-service.git"
},
"bugs": {
"url": "https://github.com/stevermeister/ngx-cookie-service/issues",
"email": "stepan@studytube.nl"
},
"peerDependencies": {
"@angular/common": "^9.0.5",
"@angular/core": "^9.0.5",
"tslib": "^1.10.0"
},
"main": "bundles/ngx-cookie-service.umd.js",
"module": "fesm5/ngx-cookie-service.js",
"es2015": "fesm2015/ngx-cookie-service.js",
"esm5": "esm5/ngx-cookie-service.js",
"esm2015": "esm2015/ngx-cookie-service.js",
"fesm5": "fesm5/ngx-cookie-service.js",
"fesm2015": "fesm2015/ngx-cookie-service.js",
"typings": "ngx-cookie-service.d.ts",
"metadata": "ngx-cookie-service.metadata.json",
"sideEffects": false
}

@@ -1,195 +0,24 @@

# NGX Cookie Service
# NgxCookieService
An (AOT ready) Angular (4.2+) service for cookies. Originally based on the [ng2-cookies](https://www.npmjs.com/package/ng2-cookies) library.
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.0.5.
# :cookie: Announcement: New maintainer
## Code scaffolding
Many people were interested in taking over the maintenance of the `ngx-cookie-service` package, and we would like to shoot all of you a big thank you.
Run `ng generate component component-name --project ngx-cookie-service` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ngx-cookie-service`.
> Note: Don't forget to add `--project ngx-cookie-service` or else it will be added to the default project in your `angular.json` file.
The experienced team behind [Studytube](https://www.studytube.nl/) will take care of our cookie service from now on. Thank you, and also thanks to everyone else for your patience.
## Build
# Installation
Run `ng build ngx-cookie-service` to build the project. The build artifacts will be stored in the `dist/` directory.
```bash
npm install ngx-cookie-service --save
## Publishing
# or
After building your library with `ng build ngx-cookie-service`, go to the dist folder `cd dist/ngx-cookie-service` and run `npm publish`.
yarn add ngx-cookie-service
```
## Running unit tests
Add the cookie service to your `app.module.ts` as a provider:
Run `ng test ngx-cookie-service` to execute the unit tests via [Karma](https://karma-runner.github.io).
```typescript
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
## Further help
import { AppComponent } from './app.component';
import { CookieService } from 'ngx-cookie-service';
@NgModule({
declarations: [ AppComponent ],
imports: [ BrowserModule, FormsModule, HttpModule ],
providers: [ CookieService ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
```
Then, import and inject it into a component:
```typescript
import { Component, OnInit } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
@Component({
selector: 'demo-root',
templateUrl: './app.component.html',
styleUrls: [ './app.component.scss' ]
})
export class AppComponent implements OnInit {
cookieValue = 'UNKNOWN';
constructor( private cookieService: CookieService ) { }
ngOnInit(): void {
this.cookieService.set( 'Test', 'Hello World' );
this.cookieValue = this.cookieService.get('Test');
}
}
```
That's it!
# What to do now?
* Run `npm run test` to run the tests for the cookie service (located in the `demo-app` folder)
* Have a look at and play around with the `demo-app` to get to know the cookie service with `npm run start` (open `http://localhost:4200/` in your favourite browser)
* If you do not want to install this via [NPM](http://npmjs.com/), you can run `npm run compile` and use the `*.d.ts` and `*.js` files in the `dist-lib` folder
# Methods
## check( name: string ): boolean;
```typescript
const cookieExists: boolean = cookieService.check('test');
```
Checks if a cookie with the given`name` can be accessed or found.
## get( name: string ): string;
```typescript
const value: string = cookieService.get('test');
```
Gets the value of the cookie with the specified `name`.
## getAll(): {};
```typescript
const allCookies: {} = cookieService.getAll();
```
Returns a map of key-value pairs for cookies that can be accessed.
## set( name: string, value: string, expires?: number | Date, path?: string, domain?: string, secure?: boolean, sameSite?: 'Lax' | 'Strict' | 'None' ): void;
```typescript
cookieService.set( 'test', 'Hello World' );
```
Sets a cookie with the specified `name` and `value`. It is good practice to specify a path. If you are unsure about the path value, use `'/'`. If no path or domain is explicitly defined, the current location is assumed. `sameSite` defaults to `None`.
**Important:** For security reasons, it is not possible to define cookies for other domains. Browsers do not allow this. Read [this](https://stackoverflow.com/a/1063760) and [this](https://stackoverflow.com/a/17777005/1007003) StackOverflow answer for a more in-depth explanation.
## delete( name: string, path?: string, domain?: string ): void;
```typescript
cookieService.delete('test');
```
Deletes a cookie with the specified `name`. It is best practice to always define a path. If you are unsure about the path value, use `'/'`.
**Important:** For security reasons, it is not possible to delete cookies for other domains. Browsers do not allow this. Read [this](https://stackoverflow.com/a/1063760) and [this](https://stackoverflow.com/a/17777005/1007003) StackOverflow answer for a more in-depth explanation.
## deleteAll( path?: string, domain?: string ): void;
```typescript
cookieService.deleteAll();
```
Deletes all cookies that can currently be accessed. It is best practice to always define a path. If you are unsure about the path value, use `'/'`.
# FAQ
## General tips
Checking out the following resources usually solves most of the problems people seem to have with this cookie service:
* [article about cookies in general @MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies) (recommended read!)
* [common localhost problems @StackOverflow](https://stackoverflow.com/questions/1134290/cookies-on-localhost-with-explicit-domain)
* [problems with secure cookies @StackOverflow](https://stackoverflow.com/questions/8064318/how-to-read-a-secure-cookie-using-javascript)
* [how do browser cookie domains work? @StackOverflow](https://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work)
* [get cookies from different paths](https://github.com/7leads/ngx-cookie-service/issues/7#issuecomment-351321518)
The following general steps are usually very helpful when debugging problems with this cookie service or cookies in general:
* check out if there are any [open](https://github.com/7leads/ngx-cookie-service/issues) or [closed](https://github.com/7leads/ngx-cookie-service/issues?q=is%3Aissue+is%3Aclosed) issues that answer your question
* check out the actual value(s) of `document.cookie`
* does it work if you use `document.cookie` manually (i.e. in a console of your choice)?
* set explicit paths for your cookies
* [explain to your local rubber duck why your code should work and why it (probably) does not](https://en.wikipedia.org/wiki/Rubber_duck_debugging)
# I am always getting a "token missing" or "no provider" error.
Package managers are a well known source of frustration. If you have "token missing" or "no provider" errors, a simple re-installation of your node modules might suffice:
```
rm -rf node_modules
yarn # or `npm install`
```
## I have a problem with framework X or library Y. What can I do?
Please be aware that we cannot help you with problems that are out of scope. For example, we cannot debug a Symfony or Springboot application for you. In that case, you are better off asking the nice folks over at [StackOverflow](https://stackoverflow.com/) for help.
## Do you support Angular Universal?
There is an [issue](https://github.com/7leads/ngx-cookie-service/issues/1) for that. Check out [this comment](https://github.com/7leads/ngx-cookie-service/issues/1#issuecomment-361150174) for more information about future support.
# Opening issues
Please make sure to check out our FAQ before you open a new issue. Also, try to give us as much information as you can when you open an issue. Maybe you can even supply a test environment or test cases, if necessary?
# Contributing
We are happy to accept pull requests or test cases for things that do not work. Feel free to submit one of those.
However, we will only accept pull requests that pass all tests and include some new ones (as long as it makes sense to add them, of course).
* [Open a new pull request](https://github.com/7leads/ngx-cookie-service/compare)
# Author
This cookie service is brought to you by [7leads GmbH](http://www.7leads.org/). We built it for one of our apps, because the other cookie packages we found were either not designed "the Angular way" or caused trouble during AOT compilation.
# Contributors
Thanks to all contributors:
* [paroe](https://github.com/paroe)
* [CunningFatalist](https://github.com/CunningFatalist)
* [kthy](https://github.com/kthy)
* [JaredClemence](https://github.com/JaredClemence)
* [flakolefluk](https://github.com/flakolefluk)
* [mattbanks](https://github.com/mattbanks)
* [DBaker85](https://github.com/DBaker85)
* [mattlewis92](https://github.com/mattlewis92)
* [IceBreakerG](https://github.com/IceBreakerG)
# License
[MIT](https://github.com/7leads/ngx-cookie-service/blob/master/LICENSE)
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc