{"_id":"ngy-cookie","_rev":"1-f83ac22f054e15e89c2a9c06cb23820a","name":"ngy-cookie","dist-tags":{"latest":"6.0.1000"},"versions":{"6.0.999":{"name":"ngy-cookie","version":"6.0.999","description":"Implementation of Angular 1.x $cookies service to Angular","scripts":{"ng":"ng","start":"ng serve","build":"ng build ngx-cookie --configuration production && ng build ngx-cookie-backend --configuration production","test":"ng test --watch=false","lint":"ng lint","e2e":"ng e2e","e2e:test-app":"ng run test-app:e2e","e2e:backend-test-app":"ng run backend-test-app:e2e","dev:ssr":"ng run backend-test-app:serve-ssr","serve:ssr":"node dist/backend-test-app/server/main.js","build:ssr":"ng build backend-test-app --configuration production && ng run backend-test-app:server:production","prerender":"ng run backend-test-app:prerender","cypress:open":"cypress open","cypress:run":"cypress run"},"repository":{"type":"git","url":"git+https://github.com/salemdar/ngx-cookie.git"},"keywords":["angular2","angular","ng2","ng","cookie","cookies","angular2-cookie","angular2-cookies","ng2-cookies","ng2-cookie","ng-cookies","ng-cookie","ngx-cookie","ngx-cookies"],"author":{"name":"Samet Alemdar","email":"sa.alemdar@hotmail.com"},"license":"MIT","homepage":"https://github.com/salemdar/ngx-cookie#readme","bugs":{"url":"https://github.com/salemdar/ngx-cookie/issues"},"dependencies":{"@angular/animations":"^15.1.4","@angular/common":"^15.1.4","@angular/compiler":"^15.1.4","@angular/core":"^15.1.4","@angular/forms":"^15.1.4","@angular/platform-browser":"^15.1.4","@angular/platform-browser-dynamic":"^15.1.4","@angular/platform-server":"^15.1.4","@angular/router":"^15.1.4","@nguniversal/express-engine":"^15.1.0","express":"^4.15.2","rxjs":"~7.5.5","tslib":"^2.0.0","zone.js":"~0.11.4"},"devDependencies":{"@angular-devkit/build-angular":"^15.1.5","@angular-eslint/builder":"15.2.1","@angular-eslint/eslint-plugin":"15.2.1","@angular-eslint/eslint-plugin-template":"15.2.1","@angular-eslint/schematics":"15.2.1","@angular-eslint/template-parser":"15.2.1","@angular/cli":"^15.1.5","@angular/compiler-cli":"^15.1.4","@angular/language-service":"^15.1.4","@cypress/schematic":"2.0.0","@nguniversal/builders":"^15.1.0","@types/express":"^4.17.8","@types/jasmine":"~4.0.3","@types/jasminewd2":"~2.0.3","@types/node":"^18.13.0","@typescript-eslint/eslint-plugin":"^5.43.0","@typescript-eslint/parser":"^5.43.0","cypress":"^10.3.0","eslint":"^8.28.0","eslint-plugin-import":"^2.26.0","eslint-plugin-jsdoc":"39.3.3","eslint-plugin-prefer-arrow":"^1.2.3","jasmine-core":"~4.2.0","karma":"~6.4.0","karma-chrome-launcher":"~3.1.0","karma-coverage":"^2.2.0","karma-jasmine":"~5.1.0","karma-jasmine-html-reporter":"^2.0.0","ng-packagr":"^15.1.2","ts-node":"~10.8.1","typescript":"~4.9.5"},"_id":"ngy-cookie@6.0.999","gitHead":"ca9113ac7ed70dbe4a07bc97fe4ce09e57eec19c","_nodeVersion":"20.6.1","_npmVersion":"9.8.1","dist":{"integrity":"sha512-s91xQj4EaleI5vOlw8+cW0/LObB46Pv8k/s49skVVl/qCmc3FMIoXdNh7XUv0lKZ/70BWR/zw9alqzxplFb2Qg==","shasum":"c36a56b40e69858e85f13128e7af04fe24e5e9f5","tarball":"https://registry.npmjs.org/ngy-cookie/-/ngy-cookie-6.0.999.tgz","fileCount":101,"unpackedSize":120358,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC60ozEkWVYwhRz4V1Jp3M/OrJfDQmmv+zar/dZnVZBkgIgQw1CS4YVh8aapgya4GATFZ77Ya0xj+g4ZKrcu6qKE3o="}]},"_npmUser":{"name":"bkimminich","email":"npmjs.org@kimminich.de"},"directories":{},"maintainers":[{"name":"bkimminich","email":"npmjs.org@kimminich.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ngy-cookie_6.0.999_1708951235482_0.14024220227537754"},"_hasShrinkwrap":false},"6.0.1000":{"name":"ngy-cookie","version":"6.0.1000","description":"Implementation of Angular 1.x $cookies service to Angular","repository":{"type":"git","url":"git+https://github.com/salemdar/ngx-cookie.git"},"keywords":["angular2","angular","ng2","ng","cookie","cookies","angular2-cookie","angular2-cookies","ng2-cookies","ng2-cookie","ng-cookies","ng-cookie","ngx-cookie","ngx-cookies"],"author":{"name":"Samet Alemdar","email":"sa.alemdar@hotmail.com"},"license":"MIT","homepage":"https://github.com/salemdar/ngx-cookie#readme","bugs":{"url":"https://github.com/salemdar/ngx-cookie/issues"},"peerDependencies":{"@angular/common":">=12.0.0","@angular/core":">=12.0.0"},"dependencies":{"tslib":"^2.0.0"},"module":"fesm2015/ngx-cookie.mjs","es2020":"fesm2020/ngx-cookie.mjs","esm2020":"esm2020/ngx-cookie.mjs","fesm2020":"fesm2020/ngx-cookie.mjs","fesm2015":"fesm2015/ngx-cookie.mjs","typings":"index.d.ts","exports":{"./package.json":{"default":"./package.json"},".":{"types":"./index.d.ts","esm2020":"./esm2020/ngx-cookie.mjs","es2020":"./fesm2020/ngx-cookie.mjs","es2015":"./fesm2015/ngx-cookie.mjs","node":"./fesm2015/ngx-cookie.mjs","default":"./fesm2020/ngx-cookie.mjs"}},"sideEffects":false,"_id":"ngy-cookie@6.0.1000","gitHead":"723dc50b7a940e8419b2ba5960301b86e15af338","_nodeVersion":"20.6.1","_npmVersion":"9.8.1","dist":{"integrity":"sha512-UeC0FmBc6ljWINDFGqhOugoBdZ1a2GHykfRC5FogpsT1Lw9ODEKMKw1f8pqqdoh1nLTaVS43MU+uhpLwUKrZxg==","shasum":"e74c47ea4e3950266b89cc3de9a99b5e13c60c8d","tarball":"https://registry.npmjs.org/ngy-cookie/-/ngy-cookie-6.0.1000.tgz","fileCount":27,"unpackedSize":136840,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD2qP2HMrJQX9+x24nDIEX32+RovEmdjvckYrLLV5eKkQIhAL7jtptHqw/qYaa9wwL4jKL6yrLT955oSl5mJ8+4w8I2"}]},"_npmUser":{"name":"bkimminich","email":"npmjs.org@kimminich.de"},"directories":{},"maintainers":[{"name":"bkimminich","email":"npmjs.org@kimminich.de"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ngy-cookie_6.0.1000_1708962925051_0.31315929224115613"},"_hasShrinkwrap":false}},"time":{"created":"2024-02-26T12:40:35.481Z","6.0.999":"2024-02-26T12:40:35.645Z","modified":"2024-02-26T15:55:25.658Z","6.0.1000":"2024-02-26T15:55:25.229Z"},"maintainers":[{"name":"bkimminich","email":"npmjs.org@kimminich.de"}],"description":"Implementation of Angular 1.x $cookies service to Angular","homepage":"https://github.com/salemdar/ngx-cookie#readme","keywords":["angular2","angular","ng2","ng","cookie","cookies","angular2-cookie","angular2-cookies","ng2-cookies","ng2-cookie","ng-cookies","ng-cookie","ngx-cookie","ngx-cookies"],"repository":{"type":"git","url":"git+https://github.com/salemdar/ngx-cookie.git"},"author":{"name":"Samet Alemdar","email":"sa.alemdar@hotmail.com"},"bugs":{"url":"https://github.com/salemdar/ngx-cookie/issues"},"license":"MIT","readme":"# ngx-cookie  [![CI](https://github.com/salemdar/ngx-cookie/workflows/CI/badge.svg)](https://github.com/salemdar/ngx-cookie/actions?query=workflow%3ACI) [![npm version](https://img.shields.io/npm/v/ngx-cookie.svg)](https://www.npmjs.com/package/ngx-cookie) [![Downloads](http://img.shields.io/npm/dm/ngx-cookie.svg)](https://npmjs.org/package/ngx-cookie)\r\n\r\n\r\n> Implementation of Angular 1.x $cookies service to Angular\r\n\r\n## Table of contents:\r\n- [Get Started](#get-started)\r\n  - [Installation](#installation)\r\n  - [Usage](#usage)\r\n  - [Server Side Rendering](#ssr)\r\n  - [Examples](#examples)\r\n- [CookieService](#cookieservice)\r\n  - [get()](#get)\r\n  - [getObject()](#getobject)\r\n  - [getAll()](#getall)\r\n  - [put()](#put)\r\n  - [putObject()](#putobject)\r\n  - [remove()](#remove)\r\n  - [removeAll()](#removeall)\r\n- [Options](#options)\r\n\r\n## <a name=\"get-started\"></a> Get Started\r\n\r\n### <a name=\"installation\"></a> Installation\r\n\r\nYou can install this package locally with npm.\r\n\r\n```bash\r\n# To get the latest stable version and update package.json file:\r\nyarn add ngx-cookie\r\n# or\r\n# npm install ngx-cookie --save\r\n```\r\n\r\n### <a name=\"usage\"></a> Usage\r\n\r\n`CookieModule` should be registered in angular module with `withOptions()` static method.\r\nThese methods accept `CookieOptions` objects as well. Leave it blank for the defaults.\r\n\r\n```typescript\r\nimport { NgModule }      from '@angular/core';\r\nimport { BrowserModule } from '@angular/platform-browser';\r\n\r\nimport { CookieModule } from 'ngx-cookie';\r\n\r\nimport { AppComponent }  from './app.component';\r\n\r\n@NgModule({\r\n  imports: [ BrowserModule, CookieModule.withOptions() ],\r\n  declarations: [ AppComponent ],\r\n  bootstrap: [ AppComponent ]\r\n})\r\nexport class AppModule { }\r\n```\r\n\r\n```typescript\r\nimport { Component } from '@angular/core';\r\nimport { CookieService } from 'ngx-cookie';\r\n\r\n@Component({\r\n    selector: 'my-very-cool-app',\r\n    template: '<h1>My Angular App with Cookies</h1>'\r\n})\r\n\r\nexport class AppComponent { \r\n  constructor(private cookieService: CookieService){}\r\n  \r\n  getCookie(key: string){\r\n    return this.cookieService.get(key);\r\n  }\r\n}\r\n```\r\n\r\n### <a name=\"ssr\"></a> Server Side Rendering\r\n\r\n`ngx-cookie` supports usage during Server Side Rendering (SSR / Angular Universal). Getting Server Side Rendering itself set up the first time can be tricky and is outside the scope of this guide. Here, we'll assume that you've got a working SSR setup similar to the [Angular Universal Starter project](https://github.com/angular/universal-starter), and you're just trying to get `ngx-cookie` working with SSR.\r\n\r\nNote: during normal, client side usage, `ngx-cookie` manipulates the client cookies attached to the `document` object. During SSR, `ngx-cookie` will manipulate cookies in http request or response headers._\r\n\r\n#### Setup\r\n\r\nInstall `ngx-cookie-backend` library:\r\n```shell script\r\nyarn add ngx-cookie-backend\r\n# or\r\n# npm install ngx-cookie-backend --save\r\n```\r\n\r\nThen edit `app.server.module.ts` and add `CookieBackendModule.withOptions()` to imports:\r\n\r\n```typescript\r\n/* app.server.module.ts */\r\n\r\nimport { CookieBackendModule } from 'ngx-cookie';\r\n\r\n@NgModule({\r\n  imports: [\r\n    AppModule,\r\n    ServerModule,\r\n    CookieBackendModule.withOptions()\r\n  ],\r\n  bootstrap: [AppComponent]\r\n})\r\nexport class AppServerModule {}\r\n```\r\nNext, we need to make providers for the `'REQUEST'` and `'RESPONSE'` objects created by the expressjs server during SSR. To do this, edit `server.ts` to create providers for `'REQUEST'` AND `'RESPONSE'`.\r\n\r\n```typescript\r\n/* server.ts */\r\n// All regular routes use the Universal engine\r\nserver.get('*', (req, res) => {\r\n  res.render(indexHtml, {\r\n    req,\r\n    res,\r\n    providers: [\r\n      {provide: APP_BASE_HREF, useValue: req.baseUrl},\r\n      {provide: REQUEST, useValue: req},\r\n      {provide: RESPONSE, useValue: res}\r\n    ]\r\n  });\r\n});\r\n```\r\n\r\nAnd that's it! all your application's calls to `CookieService` should now work properly during SSR!\r\n\r\n### <a name=\"examples\"></a> Examples\r\n\r\nNormal usage example is under `projects/test-app`\r\n\r\nSSR usage example is under `projects/backend-test-app`\r\n\r\n\r\n## <a name=\"cookieservice\"></a> CookieService\r\n\r\nThere are 7 methods available in the `CookieService` (6 standard methods from **Angular 1** and 1 extra `removeAll()` method for convenience)\r\n\r\n### <a name=\"get\"></a> get()\r\nReturns the value of given cookie key.\r\n\r\n```typescript\r\n/**\r\n * @param {string} key Id to use for lookup.\r\n * @returns {string} Raw cookie value.\r\n */\r\nget(key: string): string;\r\n```\r\n\r\n### <a name=\"getobject\"></a> getObject()\r\nReturns the deserialized value of given cookie key.\r\n\r\n```typescript\r\n/**\r\n * @param {string} key Id to use for lookup.\r\n * @returns {Object} Deserialized cookie value.\r\n */\r\ngetObject(key: string): Object;\r\n```\r\n\r\n### <a name=\"getall\"></a> getAll()\r\nReturns a key value object with all the cookies.\r\n\r\n```typescript\r\n/**\r\n * @returns {Object} All cookies\r\n */\r\ngetAll(): any;\r\n```\r\n\r\n### <a name=\"put\"></a> put()\r\nSets a value for given cookie key.\r\n\r\n```typescript\r\n/**\r\n * @param {string} key Id for the `value`.\r\n * @param {string} value Raw value to be stored.\r\n * @param {CookieOptions} options (Optional) Options object.\r\n */\r\nput(key: string, value: string, options?: CookieOptions): void;\r\n```\r\n\r\n### <a name=\"putobject\"></a> putObject()\r\nSerializes and sets a value for given cookie key.\r\n\r\n```typescript\r\n/**\r\n * @param {string} key Id for the `value`.\r\n * @param {Object} value Value to be stored.\r\n * @param {CookieOptions} options (Optional) Options object.\r\n */\r\nputObject(key: string, value: Object, options?: CookieOptions): void;\r\n```\r\n\r\n### <a name=\"remove\"></a> remove()\r\nRemove given cookie.\r\n\r\n```typescript\r\n/**\r\n * @param {string} key Id of the key-value pair to delete.\r\n * @param {CookieOptions} options (Optional) Options object.\r\n */\r\nremove(key: string, options?: CookieOptions): void;\r\n```\r\n\r\n### <a name=\"removeall\"></a> removeAll()\r\nRemove all cookies.\r\n\r\n```typescript\r\n/**\r\n */\r\nremoveAll(): void;\r\n```\r\n\r\n## <a name=\"options\"></a> Options\r\n\r\nOptions object should be a type of `CookieOptions` interface. The object may have following properties:\r\n\r\n- **path** - {string} - The cookie will be available only for this path and its sub-paths. By default, this is the URL that appears in your `<base>` tag.\r\n- **domain** - {string} - The cookie will be available only for this domain and its sub-domains. For security reasons the user agent will not accept the cookie if the current domain is not a sub-domain of this domain or equal to it.\r\n- **expires** - {string|Date} - String of the form \"Wdy, DD Mon YYYY HH:MM:SS GMT\" or a Date object indicating the exact date/time this cookie will expire.\r\n- **secure** - {boolean} - If `true`, then the cookie will only be available through a secured connection.\r\n- **sameSite** - {\"Lax\"|\"Strict\"|\"None\"} - Designates cookie for first party (Lax|Strict) or third party contexts.\r\n- **httpOnly** - {boolean} - If `true`, then the cookie will be set with the `HttpOnly` flag, and will only be accessible from the remote server. Helps to prevent against XSS attacks.\r\n- **storeUnencoded** - {boolean} - If `true`, then the cookie value will not be encoded and will be stored as provided. \r\n","readmeFilename":"README.md"}