Skip to content

Commit e0380bd

Browse files
author
Anton Barada
committed
update version, tags and readme
1 parent 3ab7fe7 commit e0380bd

File tree

2 files changed

+41
-44
lines changed

2 files changed

+41
-44
lines changed

README.md

+38-41
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@ Example in [@ngx-utils/universal-starter](https://github.com/ngx-utils/universal
88

99
## Table of contents:
1010

11-
* [Prerequisites](#prerequisites)
12-
* [Getting started](#getting-started)
13-
* [Installation](#installation)
14-
* [browser.module.ts](#browsermodulets)
15-
* [server.module.ts](#servermodulets)
16-
* [Cookies options](#cookies-options)
17-
* [API](#api)
18-
* [Example of usage](#example-of-usage)
19-
* [License](#license)
11+
- [Prerequisites](#prerequisites)
12+
- [Getting started](#getting-started)
13+
- [Installation](#installation)
14+
- [browser.module.ts](#browsermodulets)
15+
- [server.module.ts](#servermodulets)
16+
- [Cookies options](#cookies-options)
17+
- [API](#api)
18+
- [Example of usage](#example-of-usage)
19+
- [License](#license)
2020

2121
## Prerequisites
2222

23-
This package depends on `@angular v5.0.0`.
24-
25-
And if you want to manage cookies on server side and you're using express as server you need install:
26-
`npm i -S cookie-parser @nguniversal/module-map-ngfactory-loader`
23+
This package depends on `@angular v9.0.0`.
2724

2825
## Getting started
2926

@@ -111,37 +108,37 @@ ServerCookiesModule.forRoot({
111108

112109
`CookieService` has following methods:
113110

114-
* `put(key: string, value: string, options?: CookiesOptions): void` put some value to cookies;
115-
* `putObject(key: string, value: Object, options?: CookiesOptions): void` put object value to cookies;
116-
* `get(key: string): string` get some value from cookies by `key`;
117-
* `getObject(key: string): { [key: string]: string } | string` get object value from cookies by `key`;
118-
* `getAll(): { [key: string]: string }` get all cookies ;
119-
* `remove(key: string, options?: CookiesOptions): void` remove cookie by `key`;
120-
* `removeAll(): void` remove all cookies;
111+
- `put(key: string, value: string, options?: CookiesOptions): void` put some value to cookies;
112+
- `putObject(key: string, value: Object, options?: CookiesOptions): void` put object value to cookies;
113+
- `get(key: string): string` get some value from cookies by `key`;
114+
- `getObject(key: string): { [key: string]: string } | string` get object value from cookies by `key`;
115+
- `getAll(): { [key: string]: string }` get all cookies ;
116+
- `remove(key: string, options?: CookiesOptions): void` remove cookie by `key`;
117+
- `removeAll(): void` remove all cookies;
121118

122119
## Example of usage
123120

124121
If you're using `express` as server then add following code to your `server.ts`:
125122

126123
```ts
127-
import { renderModuleFactory } from '@angular/platform-server';
128-
import { provideModuleMap } from '@nguniversal/module-map-ngfactory-loader';
129-
import * as cookieParser from 'cookie-parser';
124+
import { renderModuleFactory } from "@angular/platform-server";
125+
import { provideModuleMap } from "@nguniversal/module-map-ngfactory-loader";
126+
import * as cookieParser from "cookie-parser";
130127

131-
app.use(cookieParser('Your private token'));
128+
app.use(cookieParser("Your private token"));
132129

133-
app.engine('html', (_, options, callback) => {
130+
app.engine("html", (_, options, callback) => {
134131
renderModuleFactory(AppServerModuleNgFactory, {
135132
document: template,
136133
url: options.req.url,
137134
extraProviders: [
138135
provideModuleMap(LAZY_MODULE_MAP),
139136
{
140-
provide: 'REQUEST',
137+
provide: "REQUEST",
141138
useValue: options.req
142139
},
143140
{
144-
provide: 'RESPONSE',
141+
provide: "RESPONSE",
145142
useValue: options.req.res
146143
}
147144
]
@@ -154,24 +151,24 @@ app.engine('html', (_, options, callback) => {
154151
Then just import `CookiesService` from `@ngx-utils/cookies` and use it:
155152

156153
```ts
157-
import { Component, OnInit } from '@angular/core';
158-
import { CookiesService } from '@ngx-utils/cookies';
154+
import { Component, OnInit } from "@angular/core";
155+
import { CookiesService } from "@ngx-utils/cookies";
159156

160157
@Component({
161-
selector: 'app-root',
162-
templateUrl: './app.component.html',
163-
styleUrls: ['./app.component.scss']
158+
selector: "app-root",
159+
templateUrl: "./app.component.html",
160+
styleUrls: ["./app.component.scss"]
164161
})
165162
export class AppComponent implements OnInit {
166163
constructor(private cookies: CookiesService) {}
167164

168165
ngOnInit() {
169-
this.cookies.put('some_cookie', 'some_cookie');
170-
this.cookies.put('http_only_cookie', 'http_only_cookie', {
166+
this.cookies.put("some_cookie", "some_cookie");
167+
this.cookies.put("http_only_cookie", "http_only_cookie", {
171168
httpOnly: true
172169
});
173-
console.log(this.cookies.get('some_cookie'), ' => some_cookie');
174-
console.log(this.cookies.get('http_only_cookie'), ' => undefined');
170+
console.log(this.cookies.get("some_cookie"), " => some_cookie");
171+
console.log(this.cookies.get("http_only_cookie"), " => undefined");
175172
console.log(this.cookies.getAll());
176173
}
177174
}
@@ -189,7 +186,7 @@ app.use(async (ctx: Context) => {
189186
extraProviders: [
190187
provideModuleMap(LAZY_MODULE_MAP),
191188
{
192-
provide: 'KOA_CONTEXT',
189+
provide: "KOA_CONTEXT",
193190
useValue: ctx
194191
}
195192
]
@@ -200,21 +197,21 @@ app.use(async (ctx: Context) => {
200197
Then create `server-cookies.service.ts`:
201198

202199
```ts
203-
import { Context } from 'koa';
204-
import { Inject, Injectable } from '@angular/core';
200+
import { Context } from "koa";
201+
import { Inject, Injectable } from "@angular/core";
205202
import {
206203
CookiesService,
207204
CookiesOptionsService,
208205
CookiesOptions
209-
} from '@ngx-utils/cookies';
206+
} from "@ngx-utils/cookies";
210207

211208
@Injectable()
212209
export class ServerCookiesService extends CookiesService {
213210
private newCookies: { [name: string]: string | undefined } = {};
214211

215212
constructor(
216213
cookiesOptions: CookiesOptionsService,
217-
@Inject('KOA_CONTEXT') private ctx: Context
214+
@Inject("KOA_CONTEXT") private ctx: Context
218215
) {
219216
super(cookiesOptions);
220217
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@ngx-utils/cookies",
3-
"version": "3.0.2",
3+
"version": "4.0.0",
44
"description": "Manage your cookies on client and server side (Angular Universal)",
55
"keywords": [
66
"angular",
7-
"angular4",
8-
"angular 4",
97
"angular universal",
8+
"angular ssr",
9+
"ssr",
1010
"cookie",
1111
"cookies"
1212
],

0 commit comments

Comments
 (0)