Skip to content

Commit

Permalink
Merge pull request #477 from SwabianCoder/feature/474-ngx-toolset-dat…
Browse files Browse the repository at this point in the history
…e-interceptors-should-make-use-of-functional-interceptor-api

Feature/474 ngx toolset date interceptors should make use of functional interceptor api
  • Loading branch information
SwabianCoder authored Nov 12, 2023
2 parents 571634f + 68d680e commit 76f6cbf
Show file tree
Hide file tree
Showing 13 changed files with 332 additions and 1,286 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"start": "ng serve",
"build:api-token-interceptor": "ng b @ngx-toolset/api-token-interceptor",
"build:api-token-interceptor:watch": "npm run build:api-token-interceptor -- --watch -c development",
"build:date-interceptors": "ng b @ngx-toolset/date-interceptors && cd ./projects/date-interceptors && npm run build",
"build:date-interceptors": "ng b @ngx-toolset/date-interceptors",
"build:date-interceptors:watch": "npm run build:date-interceptors -- --watch -c development",
"build:template-type-checker": "ng b @ngx-toolset/template-type-checker",
"build:template-type-checker:watch": "npm run build:template-type-checker -- --watch -c development",
Expand Down
14 changes: 14 additions & 0 deletions projects/date-interceptors/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.0] - 2023-11-11

### Added

- support for Angular's functional API

### Changed

- README to show how to integrate package using functional API

### Removed

- NgModule support

## [1.0.1] - 2023-08-26

### Fixed
Expand Down
80 changes: 75 additions & 5 deletions projects/date-interceptors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
- [@ngx-toolset/date-interceptors](#ngx-toolsetdate-interceptors)
- [Features](#features)
- [Installation](#installation)
- [NPM](#npm)
- [Usage](#usage)
- [Module Import](#module-import)
- [Provide Injection Tokens](#provide-injection-tokens)
- [Injection Tokens](#injection-tokens)
- [API_DATE_FORMAT](#api_date_format)
Expand All @@ -26,16 +28,84 @@
## Installation

```
ng add @ngx-toolset/date-interceptors
```
### NPM

`npm install @ngx-toolset/date-interceptors --save`

Choose the version corresponding to your Angular version:

| Angular | @ngx-toolset/date-interceptors |
|---------|--------------------------------|
| 14.x.x | >=0.0.1 <=1.0.0-rc.11 |
| 15.x.x | 1.0.0-rc.12 |
| 16.x.x | >=1.0.0-rc.13 <=2.0.0 |

## Usage

### Provide HTTP client with Interceptors

Provide the HTTP client with the `requestBodyDateFormatInterceptor` and `responseBodyDateParseInterceptor` in your `main.ts`:

```ts
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import {
requestBodyDateFormatInterceptor,
responseBodyDateParseInterceptor
} from '@ngx-toolset/date-interceptors';

bootstrapApplication(AppComponent, {
providers: [
provideHttpClient(
withInterceptors([
requestBodyDateFormatInterceptor,
responseBodyDateParseInterceptor
])
)
]
});
```

### Provide Injection Tokens

Provide proper values for automatically added `API_DATE_FORMAT`, `API_URL_REGEX` and `DATE_STRING_REGEX`
injection tokens in your `AppModule`.
Provide `API_DATE_FORMAT`, `API_URL_REGEX` and `DATE_STRING_REGEX` in your `main.ts`:

```ts
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app/app.component';
import {
requestBodyDateFormatInterceptor,
responseBodyDateParseInterceptor,
API_URL_REGEX,
DATE_STRING_REGEX,
API_DATE_FORMAT
} from '@ngx-toolset/date-interceptors';

bootstrapApplication(AppComponent, {
providers: [
provideHttpClient(
withInterceptors([
requestBodyDateFormatInterceptor,
responseBodyDateParseInterceptor
])
),
{
provide: API_URL_REGEX,
useValue: /^https:\/\/test-url.com/
},
{
provide: DATE_STRING_REGEX,
useValue: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
},
{
provide: API_DATE_FORMAT,
useValue: "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
}
]
});
```

> 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).
## Injection Tokens

Expand Down
10 changes: 1 addition & 9 deletions projects/date-interceptors/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
{
"name": "@ngx-toolset/date-interceptors",
"version": "1.0.1",
"scripts": {
"build": "tsc -p tsconfig.schematics.json",
"postbuild": "copyfiles schematics/*/schema.json schematics/*/files/** schematics/collection.json ../../dist/date-interceptors/"
},
"schematics": "./schematics/collection.json",
"ng-add": {
"save": "dependencies"
},
"version": "2.0.0",
"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)",
"homepage": "https://github.com/SwabianCoder/ngx-toolset",
"license": "MIT",
Expand Down
9 changes: 0 additions & 9 deletions projects/date-interceptors/schematics/collection.json

This file was deleted.

83 changes: 0 additions & 83 deletions projects/date-interceptors/schematics/ng-add/index.ts

This file was deleted.

Loading

0 comments on commit 76f6cbf

Please sign in to comment.