Skip to content

Commit

Permalink
bank information functionality and some bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszwpasternak committed Nov 27, 2019
1 parent 19fd944 commit 29e2e82
Show file tree
Hide file tree
Showing 14 changed files with 593 additions and 25 deletions.
132 changes: 113 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

![Travis (.org)](https://img.shields.io/travis/tomaszwpasternak/ng2-iban)
[![Coverage Status](https://coveralls.io/repos/github/tomaszwpasternak/ng2-iban/badge.svg?branch=master)](https://coveralls.io/github/tomaszwpasternak/ng2-iban?branch=master)
![GitHub package.json version](https://img.shields.io/github/package-json/v/tomaszwpasternak/ng2-iban)
![NPM](https://img.shields.io/npm/l/ng2-iban)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/tomaszwpasternak/ng2-iban)

Angular 2+ module for IBAN (International bank account number) operations

- [Navigation](#navigation)
- [Installation](#installation)
- [Usage](#usage)
- [Pipe](#pipe)
- [Pipe default options](#pipe-default-options)
- [Pipe in components and services](#pipe-in-components-and-services)
- [Service](#service)
- [Validator](#validator)
- [Template driven](#template-driven)
- [Reactive forms](#reactive-forms)
- [Iban operations](#iban-operations)
- [Pipe](#pipe)
- [Pipe default options](#pipe-default-options)
- [Pipe in components and services](#pipe-in-components-and-services)
- [Service](#service)
- [Validator](#validator)
- [Template driven](#template-driven)
- [Reactive forms](#reactive-forms)
- [Bank account operations](#bank-account-operations)
- [Module options](#module-options)
- [bank information file](#bank-information-file)
- [Bank information service](#bank-information-service)
- [Bank information pipe](#bank-information-pipe)
- [License](#license)

## Installation
Expand All @@ -41,19 +47,25 @@ export class YourModule {

## Usage

Module provide:
Ng2IbanModule provide two types of functionality. You can management with iban or provide bank information.

### Iban operations

Iban is international bank account number which contains **locale** symbol, **control sum** or **bank code**.
Locale characters are two first letters from iban. Next two are called as control sum. From 4 character to 8 we named bank code.
For operations on that fields you can use:
* pipe,
* service,
* validator.

### Pipe
#### Pipe

You can use pipe to convert `iban` into `electonic` format:
You can use pipe to convert `iban` into `electronic` format:
``` html
{{ 'SE3550000000054910000003' | ibanConverter }} // SE35 5000 0000 0549 1000 0003
```

#### Pipe default options
##### Pipe default options
``` typescript
{
locale: null,
Expand All @@ -66,13 +78,13 @@ To override options pass it to pipe:
{{ 'SE3550000000054910000003' | ibanConverter:options }} // 35-5000-0000-0549-1000-0003
```

#### Pipe in components and services
##### Pipe in components and services

You can inject pipe to angular 2+ component:
``` typescript

@Component({
selector: 'app-your-component',
selector: 'app-your-component',
templateUrl: './your-component.component.html',
providers: [
Ng2IbanPipe
Expand All @@ -90,14 +102,14 @@ export class YourComponent {

```

### Service
#### Service

Angular 2+ service provide methods that you can do with iban.

``` typescript

@Component({
selector: 'app-your-component',
selector: 'app-your-component',
templateUrl: './your-component.component.html'
})
export class YourComponent {
Expand All @@ -117,7 +129,7 @@ Service API
| `onFormatIban(iban: string, separator: string)` | string | Format iban |


### Validator
#### Validator

At the first you must inject module `FormsModule`
``` typescript
Expand All @@ -133,7 +145,7 @@ export class YourModule { }

```

#### Template driven
##### Template driven

You can use directive for template driven

Expand All @@ -159,7 +171,7 @@ export class Component {
}
```

#### Reactive forms
##### Reactive forms

Reactive forms validation

Expand All @@ -178,6 +190,88 @@ const formGroup = formBuilder.group({
});
```

### Bank account operations

This part of package focus on converting

#### Module options

``` typescript
import { Ng2IbanModule } from 'ng2-iban';

@NgModule({
declarations: [],
imports: [Ng2IbanModule.forRoot({
bankInformationConfig: {
bankInformationPath: 'assets/my-bank-json.json', // Path to bank code list
bankInformationNotFound: 'Your bank code cannot be found' // Message returned when service cant find bank information
}
)
]
})
export class YourModule {
}
```
#### Bank information file
You need to create json file *(assets/ng2-bank-information.json)*. Example:
``` json
[
{
"locale": "SE",
"codes": [
{
"code": "5000",
"information": {
"img": "https://...",
"title": "Your bank",
"description": "Any custom informations",
"customField": "You can add whatever you want"
}
}
]
}
]

```
#### Bank information service
Angular 2+ service for getting bank information.
``` typescript

@Component({
selector: 'app-your-component',
templateUrl: './your-component.component.html'
})
export class YourComponent {
onGetLoadedBankInformationSubscription: Subscription;

constructor(private ng2BankInformationService: Ng2BankInformationService) {
this.onGetLoadedBankInformationSubscription = this.ng2BankInformationService
.onGetLoadedBankInformationSubject.subscribe(() => {
let bankInformation = this.ng2BankInformationService.onGetBankInformation('SE3550000000054910000003');
}
);
}
}
```
#### Bank information pipe
``` html
{{ 'SE3550000000054910000003' | bankInformation }} // return property title from json
```
If you want override options:
``` html
{{ 'SE3550000000054910000003' | bankInformation:{locale: null, property: 'title'}}
```
## License
[The MIT License](https://github.com/tomaszwpasternak/ng2-iban/blob/master/LICENSE)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-iban",
"version": "1.0.0",
"version": "0.2.0",
"scripts": {
"ng": "ng",
"test": "ng test --code-coverage",
Expand Down
2 changes: 1 addition & 1 deletion projects/ng2-iban/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng2-iban",
"version": "0.1.1",
"version": "0.2.0",
"description": "Angular 2+ module for IBAN (International bank account number) operations",
"author": "tomaszwpasternak",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {Ng2BankInformationConfig} from './service/bank-information/ng2-bank-information.config';

export interface Ng2IbanProviderConfigInterface {
bankInformationConfig: Partial<Ng2BankInformationConfig>;
}
42 changes: 42 additions & 0 deletions projects/ng2-iban/src/lib/ng2-iban.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {inject, TestBed} from '@angular/core/testing';
import {Ng2IbanModule} from './ng2-iban.module';
import {Ng2BankInformationService} from './service/bank-information/ng2-bank-information.service';
import {HttpClientModule} from '@angular/common/http';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';

describe('Ng2IbanModule', () => {
let module: Ng2IbanModule;
let bankInformationService: Ng2BankInformationService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
HttpClientTestingModule,
Ng2IbanModule.forRoot(
{
bankInformationConfig: {
bankInformationPath: 'testPath',
bankInformationNotFound: 'testNotFound'
}
}
)
]
});
module = TestBed.get(Ng2IbanModule);

bankInformationService = TestBed.get(Ng2BankInformationService);
});

it('should create an instance', inject([HttpTestingController],
(backend: HttpTestingController) => {
backend.match({
url: 'testPath',
method: 'GET'
})[0].flush([]);

expect(bankInformationService).toBeTruthy();
expect(bankInformationService['config'].bankInformationPath).toEqual('testPath');
expect(bankInformationService['config'].bankInformationNotFound).toEqual('testNotFound');
}));
});
24 changes: 20 additions & 4 deletions projects/ng2-iban/src/lib/ng2-iban.module.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import { NgModule } from '@angular/core';
import {ModuleWithProviders, NgModule} from '@angular/core';
import {Ng2IbanPipe} from './pipe/iban/ng2-iban.pipe';
import {Ng2IbanDirective} from './directive/iban/ng2-iban.directive';
import {Ng2BankInformationConfig} from './service/bank-information/ng2-bank-information.config';
import {Ng2IbanProviderConfigInterface} from './ng2-iban-provider-config.interface';
import {Ng2BankInformationPipe} from './pipe/bank-information/ng2-bank-information.pipe';

@NgModule({
declarations: [
Ng2IbanPipe,
Ng2BankInformationPipe,
Ng2IbanDirective
],
imports: [
],
imports: [],
exports: [
Ng2IbanPipe,
Ng2BankInformationPipe,
Ng2IbanDirective
]
})
export class Ng2IbanModule { }

export class Ng2IbanModule {
static forRoot(ng2IbanProviderConfig?: Partial<Ng2IbanProviderConfigInterface>): ModuleWithProviders {
return {
ngModule: Ng2IbanModule,
providers: [
{
provide: Ng2BankInformationConfig, useValue: ng2IbanProviderConfig.bankInformationConfig
}
]
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Ng2BankInformationOptionInterface {
locale: string;
property: string;
}
Loading

0 comments on commit 29e2e82

Please sign in to comment.