Skip to content

Commit 76f6cbf

Browse files
authored
Merge pull request #477 from SwabianCoder/feature/474-ngx-toolset-date-interceptors-should-make-use-of-functional-interceptor-api
Feature/474 ngx toolset date interceptors should make use of functional interceptor api
2 parents 571634f + 68d680e commit 76f6cbf

13 files changed

+332
-1286
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"start": "ng serve",
66
"build:api-token-interceptor": "ng b @ngx-toolset/api-token-interceptor",
77
"build:api-token-interceptor:watch": "npm run build:api-token-interceptor -- --watch -c development",
8-
"build:date-interceptors": "ng b @ngx-toolset/date-interceptors && cd ./projects/date-interceptors && npm run build",
8+
"build:date-interceptors": "ng b @ngx-toolset/date-interceptors",
99
"build:date-interceptors:watch": "npm run build:date-interceptors -- --watch -c development",
1010
"build:template-type-checker": "ng b @ngx-toolset/template-type-checker",
1111
"build:template-type-checker:watch": "npm run build:template-type-checker -- --watch -c development",

projects/date-interceptors/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.0] - 2023-11-11
9+
10+
### Added
11+
12+
- support for Angular's functional API
13+
14+
### Changed
15+
16+
- README to show how to integrate package using functional API
17+
18+
### Removed
19+
20+
- NgModule support
21+
822
## [1.0.1] - 2023-08-26
923

1024
### Fixed

projects/date-interceptors/README.md

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
- [@ngx-toolset/date-interceptors](#ngx-toolsetdate-interceptors)
1111
- [Features](#features)
1212
- [Installation](#installation)
13+
- [NPM](#npm)
1314
- [Usage](#usage)
15+
- [Module Import](#module-import)
1416
- [Provide Injection Tokens](#provide-injection-tokens)
1517
- [Injection Tokens](#injection-tokens)
1618
- [API_DATE_FORMAT](#api_date_format)
@@ -26,16 +28,84 @@
2628
2729
## Installation
2830

29-
```
30-
ng add @ngx-toolset/date-interceptors
31-
```
31+
### NPM
32+
33+
`npm install @ngx-toolset/date-interceptors --save`
34+
35+
Choose the version corresponding to your Angular version:
36+
37+
| Angular | @ngx-toolset/date-interceptors |
38+
|---------|--------------------------------|
39+
| 14.x.x | >=0.0.1 <=1.0.0-rc.11 |
40+
| 15.x.x | 1.0.0-rc.12 |
41+
| 16.x.x | >=1.0.0-rc.13 <=2.0.0 |
3242

3343
## Usage
3444

45+
### Provide HTTP client with Interceptors
46+
47+
Provide the HTTP client with the `requestBodyDateFormatInterceptor` and `responseBodyDateParseInterceptor` in your `main.ts`:
48+
49+
```ts
50+
import { bootstrapApplication } from '@angular/platform-browser';
51+
import { AppComponent } from './app/app.component';
52+
import {
53+
requestBodyDateFormatInterceptor,
54+
responseBodyDateParseInterceptor
55+
} from '@ngx-toolset/date-interceptors';
56+
57+
bootstrapApplication(AppComponent, {
58+
providers: [
59+
provideHttpClient(
60+
withInterceptors([
61+
requestBodyDateFormatInterceptor,
62+
responseBodyDateParseInterceptor
63+
])
64+
)
65+
]
66+
});
67+
```
68+
3569
### Provide Injection Tokens
3670

37-
Provide proper values for automatically added `API_DATE_FORMAT`, `API_URL_REGEX` and `DATE_STRING_REGEX`
38-
injection tokens in your `AppModule`.
71+
Provide `API_DATE_FORMAT`, `API_URL_REGEX` and `DATE_STRING_REGEX` in your `main.ts`:
72+
73+
```ts
74+
import { bootstrapApplication } from '@angular/platform-browser';
75+
import { AppComponent } from './app/app.component';
76+
import {
77+
requestBodyDateFormatInterceptor,
78+
responseBodyDateParseInterceptor,
79+
API_URL_REGEX,
80+
DATE_STRING_REGEX,
81+
API_DATE_FORMAT
82+
} from '@ngx-toolset/date-interceptors';
83+
84+
bootstrapApplication(AppComponent, {
85+
providers: [
86+
provideHttpClient(
87+
withInterceptors([
88+
requestBodyDateFormatInterceptor,
89+
responseBodyDateParseInterceptor
90+
])
91+
),
92+
{
93+
provide: API_URL_REGEX,
94+
useValue: /^https:\/\/test-url.com/
95+
},
96+
{
97+
provide: DATE_STRING_REGEX,
98+
useValue: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
99+
},
100+
{
101+
provide: API_DATE_FORMAT,
102+
useValue: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
103+
}
104+
]
105+
});
106+
```
107+
108+
> Hint: The list of options to provide `API_DATE_FORMAT` value could be found here: [date-fns documentation](https://date-fns.org/v2.29.1/docs/parse).
39109
40110
## Injection Tokens
41111

projects/date-interceptors/package.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
{
22
"name": "@ngx-toolset/date-interceptors",
3-
"version": "1.0.1",
4-
"scripts": {
5-
"build": "tsc -p tsconfig.schematics.json",
6-
"postbuild": "copyfiles schematics/*/schema.json schematics/*/files/** schematics/collection.json ../../dist/date-interceptors/"
7-
},
8-
"schematics": "./schematics/collection.json",
9-
"ng-add": {
10-
"save": "dependencies"
11-
},
3+
"version": "2.0.0",
124
"description": "Angular date interceptors (parses HTTP response body date strings to date objects and converts HTTP request body date objects to date strings of given format)",
135
"homepage": "https://github.com/SwabianCoder/ngx-toolset",
146
"license": "MIT",

projects/date-interceptors/schematics/collection.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

projects/date-interceptors/schematics/ng-add/index.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)