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

Commit 1dae344

Browse files
perf(isin): Use AbstractString
1 parent 0184d8b commit 1dae344

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/rules/isin.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import { AbstractRule } from './abstract-rule';
2-
import { Regex } from './regex';
1+
import { AbstractString } from './abstract-string';
32

4-
export class Isin extends AbstractRule {
3+
export class Isin extends AbstractString {
54

65
/**
7-
* Validate.
6+
* Validate string.
87
*/
9-
public validate(input: any): boolean {
10-
if (!new Regex(/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/).validate(input)) {
8+
protected validateString(input: string): boolean {
9+
if (!/^[A-Z]{2}[0-9A-Z]{9}[0-9]$/.test(input)) {
1110
return false;
1211
}
1312

14-
const inputString: string = String(input);
15-
const checksumStr: string = inputString.replace(/[A-Z]/g, (c: string): string => parseInt(c, 36).toString());
13+
const checksumStr: string = input.replace(/[A-Z]/g, (c: string): string => parseInt(c, 36).toString());
1614

1715
let sum: number = 0;
1816
let digit: string;
@@ -33,7 +31,7 @@ export class Isin extends AbstractRule {
3331
shouldDouble = !shouldDouble;
3432
}
3533

36-
return parseInt(inputString.substr(inputString.length - 1), 10) === (10000 - sum) % 10;
34+
return parseInt(input.substr(input.length - 1), 10) === (10000 - sum) % 10;
3735
}
3836
}
3937

0 commit comments

Comments
 (0)