Total Complexity | 3 |
Complexity/F | 1.5 |
Lines of Code | 23 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 0 |
1 | /** |
||
5 | export default class Int extends Number { |
||
6 | /** |
||
7 | * Constructor that receive the value, |
||
8 | * and pass it to the number constructor. |
||
9 | * |
||
10 | * @param {number} value |
||
11 | */ |
||
12 | constructor(value) { |
||
13 | 4 | super(value); |
|
14 | 4 | this.validate(value); |
|
15 | } |
||
16 | |||
17 | /** |
||
18 | * Validate the value, it should throw an error if it isnt a integer. |
||
19 | * |
||
20 | * @param {number} value |
||
21 | */ |
||
22 | validate(value) { |
||
23 | 4 | if (parseInt(value, 10) !== value) { |
|
24 | 1 | throw new Error(`${value} isnt an integer`); |
|
25 | } |
||
26 | } |
||
27 | } |
||
28 |