MCPcopy Index your code
hub / github.com/ether/etherpad / checkValidRev

Function checkValidRev

src/node/utils/checkValidRev.ts:7–28  ·  view source on GitHub ↗
(rev: number|string)

Source from the content-addressed store, hash-verified

5// checks if a rev is a legal number
6// pre-condition is that `rev` is not undefined
7const 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
31const isInt = (value:number) => (parseFloat(String(value)) === parseInt(String(value), 10)) && !isNaN(value);

Callers 4

ExportHelper.tsFile · 0.85
API.tsFile · 0.85
ExportHandler.tsFile · 0.85
handleChangesetRequestFunction · 0.85

Calls 1

isIntFunction · 0.70

Tested by

no test coverage detected