(rev: number|string)
| 5 | // checks if a rev is a legal number |
| 6 | // pre-condition is that `rev` is not undefined |
| 7 | const checkValidRev = (rev: number|string) => { |
| 8 | if (typeof rev !== 'number') { |
| 9 | rev = parseInt(rev, 10); |
| 10 | } |
| 11 | |
| 12 | // check if rev is a number |
| 13 | if (isNaN(rev)) { |
| 14 | throw new CustomError('rev is not a number', 'apierror'); |
| 15 | } |
| 16 | |
| 17 | // ensure this is not a negative number |
| 18 | if (rev < 0) { |
| 19 | throw new CustomError('rev is not a negative number', 'apierror'); |
| 20 | } |
| 21 | |
| 22 | // ensure this is not a float value |
| 23 | if (!isInt(rev)) { |
| 24 | throw new CustomError('rev is a float value', 'apierror'); |
| 25 | } |
| 26 | |
| 27 | return rev; |
| 28 | }; |
| 29 | |
| 30 | // checks if a number is an int |
| 31 | const isInt = (value:number) => (parseFloat(String(value)) === parseInt(String(value), 10)) && !isNaN(value); |
no test coverage detected