Skip to content
This repository was archived by the owner on Oct 20, 2021. It is now read-only.

Commit a0102b0

Browse files
fix(calculation): The get Length method is abstract now, if zero is returned it will be not verified
1 parent d17aef1 commit a0102b0

5 files changed

Lines changed: 30 additions & 5 deletions

File tree

src/rules/abstract-calculation.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,17 @@ export abstract class AbstractCalculation extends AbstractRule {
99
const c: string = String(input).replace(/[^\d]/g, '');
1010
const length: number = this.getLength();
1111

12-
if (c.length !== length || RegExp(`${Number(c[0])}{${length}}`).test(c)) {
12+
if (!c || (length > 0 && (c.length !== length || RegExp(`${Number(c[0])}{${length}}`).test(c)))) {
1313
return false;
1414
}
1515

1616
return this.validateCalculation(c);
17-
1817
}
1918

2019
/**
2120
* Get Length.
2221
*/
23-
protected getLength(): number {
24-
return 11;
25-
}
22+
protected abstract getLength(): number;
2623

2724
/**
2825
* Validate Calculation.

src/rules/cnh.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { AbstractCalculation } from './abstract-calculation';
22

33
export class Cnh extends AbstractCalculation {
44

5+
/**
6+
* Get Length.
7+
*/
8+
protected getLength(): number {
9+
return 11;
10+
}
11+
512
/**
613
* Validate Calculation.
714
*/

src/rules/cpf.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { AbstractCalculation } from './abstract-calculation';
22

33
export class Cpf extends AbstractCalculation {
44

5+
/**
6+
* Get Length.
7+
*/
8+
protected getLength(): number {
9+
return 11;
10+
}
11+
512
/**
613
* Validate Calculation.
714
*/

src/rules/pesel.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import { AbstractCalculation } from './abstract-calculation';
33

44
export class Pesel extends AbstractCalculation {
55

6+
/**
7+
* Get Length.
8+
*/
9+
protected getLength(): number {
10+
return 11;
11+
}
12+
613
/**
714
* Validate Calculation.
815
*/

src/rules/pis.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { AbstractCalculation } from './abstract-calculation';
22

33
export class Pis extends AbstractCalculation {
44

5+
/**
6+
* Get Length.
7+
*/
8+
protected getLength(): number {
9+
return 11;
10+
}
11+
512
/**
613
* Validate Calculation.
714
*/

0 commit comments

Comments
 (0)